GetCommand.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 Symfony\Component\Console\Input\InputArgument;
  10. use Symfony\Component\Console\Input\InputInterface;
  11. use Symfony\Component\Console\Output\OutputInterface;
  12. class GetCommand extends Base {
  13. public function __construct(
  14. protected IManager $taskProcessingManager,
  15. ) {
  16. parent::__construct();
  17. }
  18. protected function configure() {
  19. $this
  20. ->setName('taskprocessing:task:get')
  21. ->setDescription('Display all information for a specific task')
  22. ->addArgument(
  23. 'task-id',
  24. InputArgument::REQUIRED,
  25. 'ID of the task to display'
  26. );
  27. parent::configure();
  28. }
  29. protected function execute(InputInterface $input, OutputInterface $output): int {
  30. $taskId = (int)$input->getArgument('task-id');
  31. $task = $this->taskProcessingManager->getTask($taskId);
  32. $jsonTask = $task->jsonSerialize();
  33. $jsonTask['error_message'] = $task->getErrorMessage();
  34. $this->writeArrayInOutputFormat($input, $output, $jsonTask);
  35. return 0;
  36. }
  37. }