Index.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\WorkflowEngine\Command;
  8. use OCA\WorkflowEngine\Helper\ScopeContext;
  9. use OCA\WorkflowEngine\Manager;
  10. use OCP\WorkflowEngine\IManager;
  11. use Symfony\Component\Console\Command\Command;
  12. use Symfony\Component\Console\Input\InputArgument;
  13. use Symfony\Component\Console\Input\InputInterface;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. class Index extends Command {
  16. /** @var Manager */
  17. private $manager;
  18. public function __construct(Manager $manager) {
  19. $this->manager = $manager;
  20. parent::__construct();
  21. }
  22. protected function configure() {
  23. $this
  24. ->setName('workflows:list')
  25. ->setDescription('Lists configured workflows')
  26. ->addArgument(
  27. 'scope',
  28. InputArgument::OPTIONAL,
  29. 'Lists workflows for "admin", "user"',
  30. 'admin'
  31. )
  32. ->addArgument(
  33. 'scopeId',
  34. InputArgument::OPTIONAL,
  35. 'User IDs when the scope is "user"',
  36. null
  37. );
  38. }
  39. protected function mappedScope(string $scope): int {
  40. static $scopes = [
  41. 'admin' => IManager::SCOPE_ADMIN,
  42. 'user' => IManager::SCOPE_USER,
  43. ];
  44. return $scopes[$scope] ?? -1;
  45. }
  46. protected function execute(InputInterface $input, OutputInterface $output): int {
  47. $ops = $this->manager->getAllOperations(
  48. new ScopeContext(
  49. $this->mappedScope($input->getArgument('scope')),
  50. $input->getArgument('scopeId')
  51. )
  52. );
  53. $output->writeln(\json_encode($ops));
  54. return 0;
  55. }
  56. }