diff --git a/core/Command/TaskProcessing/ListCommand.php b/core/Command/TaskProcessing/ListCommand.php index 92897c8b9ea..46f32e0bc53 100644 --- a/core/Command/TaskProcessing/ListCommand.php +++ b/core/Command/TaskProcessing/ListCommand.php @@ -35,6 +35,12 @@ class ListCommand extends Base { InputOption::VALUE_OPTIONAL, 'only get the tasks for one task type' ) + ->addOption( + 'appId', + null, + InputOption::VALUE_OPTIONAL, + 'only get the tasks for one app ID' + ) ->addOption( 'customId', null, @@ -70,12 +76,13 @@ class ListCommand extends Base { $userIdFilter = null; } $type = $input->getOption('type'); + $appId = $input->getOption('appId'); $customId = $input->getOption('customId'); $status = $input->getOption('status'); $scheduledAfter = $input->getOption('scheduledAfter'); $endedBefore = $input->getOption('endedBefore'); - $tasks = $this->taskProcessingManager->getTasks($userIdFilter, $type, $customId, $status, $scheduledAfter, $endedBefore); + $tasks = $this->taskProcessingManager->getTasks($userIdFilter, $type, $appId, $customId, $status, $scheduledAfter, $endedBefore); $arrayTasks = array_map(fn (Task $task): array => $task->jsonSerialize(), $tasks); $this->writeArrayInOutputFormat($input, $output, $arrayTasks); diff --git a/core/Command/TaskProcessing/Statistics.php b/core/Command/TaskProcessing/Statistics.php index 13a4c93d036..a3dc9ee0254 100644 --- a/core/Command/TaskProcessing/Statistics.php +++ b/core/Command/TaskProcessing/Statistics.php @@ -35,6 +35,12 @@ class Statistics extends Base { InputOption::VALUE_OPTIONAL, 'only get the tasks for one task type' ) + ->addOption( + 'appId', + null, + InputOption::VALUE_OPTIONAL, + 'only get the tasks for one app ID' + ) ->addOption( 'customId', null, @@ -70,12 +76,13 @@ class Statistics extends Base { $userIdFilter = null; } $type = $input->getOption('type'); + $appId = $input->getOption('appId'); $customId = $input->getOption('customId'); $status = $input->getOption('status'); $scheduledAfter = $input->getOption('scheduledAfter'); $endedBefore = $input->getOption('endedBefore'); - $tasks = $this->taskProcessingManager->getTasks($userIdFilter, $type, $customId, $status, $scheduledAfter, $endedBefore); + $tasks = $this->taskProcessingManager->getTasks($userIdFilter, $type, $appId, $customId, $status, $scheduledAfter, $endedBefore); $stats = ['Number of tasks' => count($tasks)]; diff --git a/lib/private/TaskProcessing/Db/TaskMapper.php b/lib/private/TaskProcessing/Db/TaskMapper.php index 93c4f1b94cf..fda8b0ffcde 100644 --- a/lib/private/TaskProcessing/Db/TaskMapper.php +++ b/lib/private/TaskProcessing/Db/TaskMapper.php @@ -136,7 +136,20 @@ class TaskMapper extends QBMapper { return array_values($this->findEntities($qb)); } - public function findTasks(?string $userId, ?string $taskType = null, ?string $customId = null, ?int $status = null, ?int $scheduleAfter = null, ?int $endedBefore = null): array { + /** + * @param string|null $userId + * @param string|null $taskType + * @param string|null $appId + * @param string|null $customId + * @param int|null $status + * @param int|null $scheduleAfter + * @param int|null $endedBefore + * @return array + * @throws Exception + */ + public function findTasks( + ?string $userId, ?string $taskType = null, ?string $appId = null, ?string $customId = null, + ?int $status = null, ?int $scheduleAfter = null, ?int $endedBefore = null): array { $qb = $this->db->getQueryBuilder(); $qb->select(Task::$columns) ->from($this->tableName); @@ -148,6 +161,9 @@ class TaskMapper extends QBMapper { if ($taskType !== null) { $qb->andWhere($qb->expr()->eq('type', $qb->createPositionalParameter($taskType))); } + if ($appId !== null) { + $qb->andWhere($qb->expr()->eq('app_id', $qb->createPositionalParameter($appId))); + } if ($customId !== null) { $qb->andWhere($qb->expr()->eq('custom_id', $qb->createPositionalParameter($customId))); } diff --git a/lib/private/TaskProcessing/Manager.php b/lib/private/TaskProcessing/Manager.php index 1b2c924ef19..ad690acefd7 100644 --- a/lib/private/TaskProcessing/Manager.php +++ b/lib/private/TaskProcessing/Manager.php @@ -851,10 +851,11 @@ class Manager implements IManager { } public function getTasks( - ?string $userId, ?string $taskTypeId = null, ?string $customId = null, ?int $status = null, ?int $scheduleAfter = null, ?int $endedBefore = null + ?string $userId, ?string $taskTypeId = null, ?string $appId = null, ?string $customId = null, + ?int $status = null, ?int $scheduleAfter = null, ?int $endedBefore = null ): array { try { - $taskEntities = $this->taskMapper->findTasks($userId, $taskTypeId, $customId, $status, $scheduleAfter, $endedBefore); + $taskEntities = $this->taskMapper->findTasks($userId, $taskTypeId, $appId, $customId, $status, $scheduleAfter, $endedBefore); return array_map(fn ($taskEntity): Task => $taskEntity->toPublicTask(), $taskEntities); } catch (\OCP\DB\Exception $e) { throw new \OCP\TaskProcessing\Exception\Exception('There was a problem finding the tasks', 0, $e); diff --git a/lib/public/TaskProcessing/IManager.php b/lib/public/TaskProcessing/IManager.php index 33dfcdeb7c7..d7cd96edc45 100644 --- a/lib/public/TaskProcessing/IManager.php +++ b/lib/public/TaskProcessing/IManager.php @@ -143,7 +143,8 @@ interface IManager { /** * @param string|null $userId The user id that scheduled the task * @param string|null $taskTypeId The task type id to filter by - * @param string|null $customId + * @param string|null $appId The app ID of the app that submitted the task + * @param string|null $customId The custom task ID * @param int|null $status The task status * @param int|null $scheduleAfter Minimum schedule time filter * @param int|null $endedBefore Maximum ending time filter @@ -153,7 +154,8 @@ interface IManager { * @since 30.0.0 */ public function getTasks( - ?string $userId, ?string $taskTypeId = null, ?string $customId = null, ?int $status = null, ?int $scheduleAfter = null, ?int $endedBefore = null + ?string $userId, ?string $taskTypeId = null, ?string $appId = null, ?string $customId = null, + ?int $status = null, ?int $scheduleAfter = null, ?int $endedBefore = null ): array; /**