ListCommand.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OC\Core\Command\TaskProcessing;
  7. use OC\Core\Command\Base;
  8. use OCP\TaskProcessing\IManager;
  9. use OCP\TaskProcessing\Task;
  10. use Symfony\Component\Console\Input\InputInterface;
  11. use Symfony\Component\Console\Input\InputOption;
  12. use Symfony\Component\Console\Output\OutputInterface;
  13. class ListCommand extends Base {
  14. public function __construct(
  15. protected IManager $taskProcessingManager,
  16. ) {
  17. parent::__construct();
  18. }
  19. protected function configure() {
  20. $this
  21. ->setName('taskprocessing:task:list')
  22. ->setDescription('list tasks')
  23. ->addOption(
  24. 'userIdFilter',
  25. 'u',
  26. InputOption::VALUE_OPTIONAL,
  27. 'only get the tasks for one user ID'
  28. )
  29. ->addOption(
  30. 'type',
  31. 't',
  32. InputOption::VALUE_OPTIONAL,
  33. 'only get the tasks for one task type'
  34. )
  35. ->addOption(
  36. 'appId',
  37. null,
  38. InputOption::VALUE_OPTIONAL,
  39. 'only get the tasks for one app ID'
  40. )
  41. ->addOption(
  42. 'customId',
  43. null,
  44. InputOption::VALUE_OPTIONAL,
  45. 'only get the tasks for one custom ID'
  46. )
  47. ->addOption(
  48. 'status',
  49. 's',
  50. InputOption::VALUE_OPTIONAL,
  51. 'only get the tasks that have a specific status (STATUS_UNKNOWN=0, STATUS_SCHEDULED=1, STATUS_RUNNING=2, STATUS_SUCCESSFUL=3, STATUS_FAILED=4, STATUS_CANCELLED=5)'
  52. )
  53. ->addOption(
  54. 'scheduledAfter',
  55. null,
  56. InputOption::VALUE_OPTIONAL,
  57. 'only get the tasks that were scheduled after a specific date (Unix timestamp)'
  58. )
  59. ->addOption(
  60. 'endedBefore',
  61. null,
  62. InputOption::VALUE_OPTIONAL,
  63. 'only get the tasks that ended before a specific date (Unix timestamp)'
  64. );
  65. parent::configure();
  66. }
  67. protected function execute(InputInterface $input, OutputInterface $output): int {
  68. $userIdFilter = $input->getOption('userIdFilter');
  69. if ($userIdFilter === null) {
  70. $userIdFilter = '';
  71. } elseif ($userIdFilter === '') {
  72. $userIdFilter = null;
  73. }
  74. $type = $input->getOption('type');
  75. $appId = $input->getOption('appId');
  76. $customId = $input->getOption('customId');
  77. $status = $input->getOption('status');
  78. $scheduledAfter = $input->getOption('scheduledAfter');
  79. $endedBefore = $input->getOption('endedBefore');
  80. $tasks = $this->taskProcessingManager->getTasks($userIdFilter, $type, $appId, $customId, $status, $scheduledAfter, $endedBefore);
  81. $arrayTasks = array_map(static function (Task $task) {
  82. $jsonTask = $task->jsonSerialize();
  83. $jsonTask['error_message'] = $task->getErrorMessage();
  84. return $jsonTask;
  85. }, $tasks);
  86. $this->writeArrayInOutputFormat($input, $output, $arrayTasks);
  87. return 0;
  88. }
  89. }