ListCommand.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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(fn (Task $task): array => $task->jsonSerialize(), $tasks);
  82. $this->writeArrayInOutputFormat($input, $output, $arrayTasks);
  83. return 0;
  84. }
  85. }