ResetBeUserPermsCommand.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace Opentalent\OtAdmin\Command;
  3. use Opentalent\OtAdmin\Controller\SiteController;
  4. use Symfony\Component\Console\Command\Command;
  5. use Symfony\Component\Console\Input\InputArgument;
  6. use Symfony\Component\Console\Input\InputInterface;
  7. use Symfony\Component\Console\Input\InputOption;
  8. use Symfony\Component\Console\Output\OutputInterface;
  9. use Symfony\Component\Console\Style\SymfonyStyle;
  10. use TYPO3\CMS\Core\Utility\GeneralUtility;
  11. use TYPO3\CMS\Extbase\Object\ObjectManager;
  12. /**
  13. * This CLI command resets the permissions granted to
  14. * this website be users
  15. *
  16. * @package Opentalent\OtAdmin\Command
  17. */
  18. class ResetBeUserPermsCommand extends Command
  19. {
  20. /**
  21. * -- This method is expected by Typo3, do not rename ou remove --
  22. *
  23. * Allows to configure the command.
  24. * Allows to add a description, a help text, and / or define arguments.
  25. *
  26. */
  27. protected function configure()
  28. {
  29. $this
  30. ->setName("ot:site:reset-perms")
  31. ->setDescription("Reset the permissions granted to the be users")
  32. ->setHelp("This CLI command resets the permissions granted to
  33. either one website be users, or every websites be users")
  34. ->addArgument(
  35. 'organization-id',
  36. InputArgument::OPTIONAL,
  37. "The organization's id in the opentalent DB"
  38. )
  39. ->addOption(
  40. "all",
  41. null,
  42. InputOption::VALUE_NONE,
  43. "Reset all of the websites be_users permissions."
  44. )
  45. ->addOption(
  46. "create",
  47. 'c',
  48. InputOption::VALUE_NONE,
  49. "Create the be_user and/or be_group when they are missing"
  50. );
  51. }
  52. /**
  53. * -- This method is expected by Typo3, do not rename ou remove --
  54. *
  55. * @param InputInterface $input
  56. * @param OutputInterface $output
  57. * @throws \Exception
  58. */
  59. protected function execute(InputInterface $input, OutputInterface $output)
  60. {
  61. $org_id = $input->getArgument('organization-id');
  62. $all = $input->getOption('all');
  63. $create = $input->getOption('create');
  64. if ($all && $org_id) {
  65. throw new \InvalidArgumentException("You can not pass both an organization id and the --all option");
  66. }
  67. if (!$all && !$org_id) {
  68. throw new \InvalidArgumentException("You shall either pass an organization id or use the --all option");
  69. }
  70. $io = new SymfonyStyle($input, $output);
  71. $siteController = GeneralUtility::makeInstance(ObjectManager::class)->get(SiteController::class);
  72. if ($all) {
  73. $siteController->resetAllBeUserPermsAction($create);
  74. $io->success(sprintf("Be users permissions were reset for every website"));
  75. } else {
  76. $rootUid = $siteController->resetBeUserPermsAction($org_id, $create);
  77. $io->success(sprintf("The website with root uid " . $rootUid . " had its be users permissions reset"));
  78. }
  79. }
  80. }