mirror of
https://github.com/nextcloud/server.git
synced 2025-02-24 08:56:48 +00:00
feat(taskprocessing): add appId filter to taskprocessing occ commands
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
This commit is contained in:
parent
af21f7dbd9
commit
df11aa9efc
5 changed files with 40 additions and 7 deletions
core/Command/TaskProcessing
lib
|
@ -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);
|
||||
|
|
|
@ -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)];
|
||||
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue