Skip to content

Commit d1a86f8

Browse files
Refactor task processing code
1 parent 40a567c commit d1a86f8

11 files changed

+149
-134
lines changed

composer.lock

Lines changed: 31 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Controllers/Clients/CreateClientController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Psr\Http\Message\ServerRequestInterface;
77
use Reconmap\Controllers\Controller;
88
use Reconmap\Models\AuditActions\AuditActions;
9-
use Reconmap\Models\AuditActions\ClientAuditActions;
109
use Reconmap\Models\Client;
1110
use Reconmap\Repositories\ClientRepository;
1211
use Reconmap\Services\ActivityPublisherService;

src/Controllers/Commands/UploadCommandOutputController.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public function __invoke(ServerRequestInterface $request, array $args): array
2727
{
2828
$params = $request->getParsedBody();
2929
$commandUsageId = (int)$params['commandUsageId'];
30-
$taskId = isset($params['taskId']) ? intval($params['taskId']) : null;
3130

3231
$files = $request->getUploadedFiles();
3332
$resultFile = $files['resultFile'];
@@ -39,16 +38,19 @@ public function __invoke(ServerRequestInterface $request, array $args): array
3938

4039
$attachment = $this->uploadAttachment($resultFile, 'command', $command['id'], $userId);
4140

42-
$result = $this->redisServer->lPush('tasks:queue',
43-
json_encode([
44-
'commandId' => $command['id'],
45-
'taskId' => $taskId,
46-
'userId' => $userId,
47-
'filePath' => $this->attachmentFilePathService->generateFilePath($attachment->file_name)
48-
])
49-
);
50-
if (false === $result) {
51-
$this->logger->error('Item could not be pushed to the queue', ['queue' => 'tasks-results:queue']);
41+
$projectId = isset($params['projectId']) ? intval($params['projectId']) : null;
42+
if ($projectId) {
43+
$result = $this->redisServer->lPush('tasks:queue',
44+
json_encode([
45+
'commandUsageId' => $commandUsageId,
46+
'projectId' => $projectId,
47+
'userId' => $userId,
48+
'filePath' => $this->attachmentFilePathService->generateFilePath($attachment->file_name)
49+
])
50+
);
51+
if (false === $result) {
52+
$this->logger->error('Item could not be pushed to the queue', ['queue' => 'tasks-results:queue']);
53+
}
5254
}
5355

5456
return ['success' => true];

src/Controllers/Documents/UpdateDocumentController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
use Psr\Http\Message\ServerRequestInterface;
66
use Reconmap\Controllers\Controller;
77
use Reconmap\Models\AuditActions\AuditActions;
8-
use Reconmap\Models\AuditActions\DocumentAuditActions;
98
use Reconmap\Repositories\DocumentRepository;
109
use Reconmap\Services\ActivityPublisherService;
1110

1211
class UpdateDocumentController extends Controller
1312
{
1413
public function __construct(
15-
private DocumentRepository $repository,
16-
private ActivityPublisherService $activityPublisherService)
14+
private readonly DocumentRepository $repository,
15+
private readonly ActivityPublisherService $activityPublisherService)
1716
{
1817
}
1918

src/Controllers/Notifications/DeleteNotificationController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
namespace Reconmap\Controllers\Notifications;
44

55
use Reconmap\Controllers\DeleteEntityController;
6-
use Reconmap\Models\AuditActions\NotificationAuditActions;
6+
use Reconmap\Models\AuditActions\AuditActions;
77
use Reconmap\Repositories\NotificationsRepository;
88
use Reconmap\Services\ActivityPublisherService;
99
use Reconmap\Services\Security\AuthorisationService;
1010

1111
class DeleteNotificationController extends DeleteEntityController
1212
{
1313
public function __construct(
14-
private AuthorisationService $authorisationService,
15-
private ActivityPublisherService $activityPublisherService,
16-
private NotificationsRepository $repository,
14+
private readonly AuthorisationService $authorisationService,
15+
private readonly ActivityPublisherService $activityPublisherService,
16+
private readonly NotificationsRepository $repository,
1717
)
1818
{
1919
parent::__construct(
2020
$this->authorisationService,
2121
$this->activityPublisherService,
2222
$this->repository,
2323
'notification',
24-
NotificationAuditActions::DELETED,
24+
AuditActions::DELETED,
2525
'notificationId'
2626
);
2727
}

src/Controllers/Notifications/UpdateNotificationController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Reconmap\Controllers\Notifications;
44

55
use Reconmap\Controllers\UpdateEntityController;
6-
use Reconmap\Models\AuditActions\NotificationAuditActions;
6+
use Reconmap\Models\AuditActions\AuditActions;
77
use Reconmap\Repositories\NotificationsRepository;
88
use Reconmap\Services\ActivityPublisherService;
99
use Reconmap\Services\Security\AuthorisationService;
@@ -12,6 +12,6 @@ class UpdateNotificationController extends UpdateEntityController
1212
{
1313
public function __construct(AuthorisationService $authorisationService, ActivityPublisherService $activityPublisherService, NotificationsRepository $repository)
1414
{
15-
parent::__construct($authorisationService, $activityPublisherService, $repository, 'notification', NotificationAuditActions::UPDATED, 'notificationId');
15+
parent::__construct($authorisationService, $activityPublisherService, $repository, 'notification', AuditActions::UPDATED, 'notificationId');
1616
}
1717
}

src/Controllers/Tasks/CreateTaskController.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,26 @@
22

33
namespace Reconmap\Controllers\Tasks;
44

5+
use Psr\Http\Message\ResponseInterface;
56
use Psr\Http\Message\ServerRequestInterface;
67
use Reconmap\Controllers\Controller;
78
use Reconmap\Models\Task;
89
use Reconmap\Repositories\TaskRepository;
910

1011
class CreateTaskController extends Controller
1112
{
12-
public function __construct(private TaskRepository $repository)
13+
public function __construct(private readonly TaskRepository $repository)
1314
{
1415
}
1516

16-
public function __invoke(ServerRequestInterface $request): array
17+
public function __invoke(ServerRequestInterface $request): ResponseInterface
1718
{
1819
/** @var Task $task */
1920
$task = $this->getJsonBodyDecodedAsClass($request, new Task());
2021
$task->creator_uid = $request->getAttribute('userId');
2122

22-
$this->repository->insert($task);
23+
$taskId = $this->repository->insert($task);
2324

24-
return ['success' => true];
25+
return $this->createStatusCreatedResponse(['taskId' => $taskId]);
2526
}
2627
}

src/Controllers/Vault/UpdateVaultItemController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
use Psr\Http\Message\ServerRequestInterface;
77
use Reconmap\Controllers\Controller;
88
use Reconmap\Models\AuditActions\AuditActions;
9-
use Reconmap\Models\AuditActions\VaultAuditActions;
109
use Reconmap\Repositories\VaultRepository;
1110
use Reconmap\Services\AuditLogService;
1211

1312
class UpdateVaultItemController extends Controller
1413
{
15-
public function __construct(private VaultRepository $repository,
16-
private AuditLogService $auditLogService)
14+
public function __construct(private readonly VaultRepository $repository,
15+
private readonly AuditLogService $auditLogService)
1716
{
1817
}
1918

0 commit comments

Comments
 (0)