1
0

Index.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. public function __construct(
  17. private Manager $manager,
  18. ) {
  19. parent::__construct();
  20. }
  21. protected function configure() {
  22. $this
  23. ->setName('workflows:list')
  24. ->setDescription('Lists configured workflows')
  25. ->addArgument(
  26. 'scope',
  27. InputArgument::OPTIONAL,
  28. 'Lists workflows for "admin", "user"',
  29. 'admin'
  30. )
  31. ->addArgument(
  32. 'scopeId',
  33. InputArgument::OPTIONAL,
  34. 'User IDs when the scope is "user"',
  35. null
  36. );
  37. }
  38. protected function mappedScope(string $scope): int {
  39. static $scopes = [
  40. 'admin' => IManager::SCOPE_ADMIN,
  41. 'user' => IManager::SCOPE_USER,
  42. ];
  43. return $scopes[$scope] ?? -1;
  44. }
  45. protected function execute(InputInterface $input, OutputInterface $output): int {
  46. $ops = $this->manager->getAllOperations(
  47. new ScopeContext(
  48. $this->mappedScope($input->getArgument('scope')),
  49. $input->getArgument('scopeId')
  50. )
  51. );
  52. $output->writeln(\json_encode($ops));
  53. return 0;
  54. }
  55. }