You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Index.php 2.2KB

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