Skip to content

Commit

Permalink
feat(taskprocessing): add appId filter to taskprocessing occ commands
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
  • Loading branch information
julien-nc committed Jul 23, 2024
1 parent 0780bd3 commit 0f2da49
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
9 changes: 8 additions & 1 deletion core/Command/TaskProcessing/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ protected function configure() {
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,
Expand Down Expand Up @@ -70,12 +76,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$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);
Expand Down
9 changes: 8 additions & 1 deletion core/Command/TaskProcessing/Statistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ protected function configure() {
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,
Expand Down Expand Up @@ -70,12 +76,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$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)];

Expand Down
18 changes: 17 additions & 1 deletion lib/private/TaskProcessing/Db/TaskMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,20 @@ public function findUserTasksByApp(?string $userId, string $appId, ?string $cust
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);
Expand All @@ -148,6 +161,9 @@ public function findTasks(?string $userId, ?string $taskType = null, ?string $cu
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)));
}
Expand Down
5 changes: 3 additions & 2 deletions lib/private/TaskProcessing/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -851,10 +851,11 @@ public function getUserTasks(?string $userId, ?string $taskTypeId = null, ?strin
}

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 {

Check failure

Code scanning / Psalm

MoreSpecificReturnType Error

The declared return type 'list<OCP\TaskProcessing\Task>' for OC\TaskProcessing\Manager::getTasks is more specific than the inferred return type 'array<array-key, OCP\TaskProcessing\Task>'

Check failure on line 856 in lib/private/TaskProcessing/Manager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

MoreSpecificReturnType

lib/private/TaskProcessing/Manager.php:856:5: MoreSpecificReturnType: The declared return type 'list<OCP\TaskProcessing\Task>' for OC\TaskProcessing\Manager::getTasks is more specific than the inferred return type 'array<array-key, OCP\TaskProcessing\Task>' (see https://psalm.dev/070)
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);

Check failure

Code scanning / Psalm

LessSpecificReturnStatement Error

The type 'array<array-key, OCP\TaskProcessing\Task>' is more general than the declared return type 'list<OCP\TaskProcessing\Task>' for OC\TaskProcessing\Manager::getTasks

Check failure on line 859 in lib/private/TaskProcessing/Manager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

LessSpecificReturnStatement

lib/private/TaskProcessing/Manager.php:859:11: LessSpecificReturnStatement: The type 'array<array-key, OCP\TaskProcessing\Task>' is more general than the declared return type 'list<OCP\TaskProcessing\Task>' for OC\TaskProcessing\Manager::getTasks (see https://psalm.dev/129)
} catch (\OCP\DB\Exception $e) {
throw new \OCP\TaskProcessing\Exception\Exception('There was a problem finding the tasks', 0, $e);
Expand Down
6 changes: 4 additions & 2 deletions lib/public/TaskProcessing/IManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ public function getUserTasks(?string $userId, ?string $taskTypeId = null, ?strin
/**
* @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
Expand All @@ -153,7 +154,8 @@ public function getUserTasks(?string $userId, ?string $taskTypeId = null, ?strin
* @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;

/**
Expand Down

0 comments on commit 0f2da49

Please sign in to comment.