1
0

Index.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de>
  5. *
  6. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCA\WorkflowEngine\Command;
  26. use OCA\WorkflowEngine\Helper\ScopeContext;
  27. use OCA\WorkflowEngine\Manager;
  28. use OCP\WorkflowEngine\IManager;
  29. use Symfony\Component\Console\Command\Command;
  30. use Symfony\Component\Console\Input\InputArgument;
  31. use Symfony\Component\Console\Input\InputInterface;
  32. use Symfony\Component\Console\Output\OutputInterface;
  33. class Index extends Command {
  34. /** @var Manager */
  35. private $manager;
  36. public function __construct(Manager $manager) {
  37. $this->manager = $manager;
  38. parent::__construct();
  39. }
  40. protected function configure() {
  41. $this
  42. ->setName('workflows:list')
  43. ->setDescription('Lists configured workflows')
  44. ->addArgument(
  45. 'scope',
  46. InputArgument::OPTIONAL,
  47. 'Lists workflows for "admin", "user"',
  48. 'admin'
  49. )
  50. ->addArgument(
  51. 'scopeId',
  52. InputArgument::OPTIONAL,
  53. 'User IDs when the scope is "user"',
  54. null
  55. );
  56. }
  57. protected function mappedScope(string $scope): int {
  58. static $scopes = [
  59. 'admin' => IManager::SCOPE_ADMIN,
  60. 'user' => IManager::SCOPE_USER,
  61. ];
  62. return $scopes[$scope] ?? -1;
  63. }
  64. protected function execute(InputInterface $input, OutputInterface $output): int {
  65. $ops = $this->manager->getAllOperations(
  66. new ScopeContext(
  67. $this->mappedScope($input->getArgument('scope')),
  68. $input->getArgument('scopeId')
  69. )
  70. );
  71. $output->writeln(\json_encode($ops));
  72. return 0;
  73. }
  74. }