ResetBeUserPermsCommand.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. }
  46. /**
  47. * -- This method is expected by Typo3, do not rename ou remove --
  48. *
  49. * @param InputInterface $input
  50. * @param OutputInterface $output
  51. * @throws \Exception
  52. */
  53. protected function execute(InputInterface $input, OutputInterface $output)
  54. {
  55. $org_id = $input->getArgument('organization-id');
  56. $all = $input->getOption('all');
  57. if ($all && $org_id) {
  58. throw new \InvalidArgumentException("You can not pass both an organization id and the --all option");
  59. }
  60. if (!$all && !$org_id) {
  61. throw new \InvalidArgumentException("You shall either pass an organization id or use the --all option");
  62. }
  63. $io = new SymfonyStyle($input, $output);
  64. $siteController = GeneralUtility::makeInstance(ObjectManager::class)->get(SiteController::class);
  65. if ($all) {
  66. $siteController->resetAllBeUserPermsAction();
  67. $io->success(sprintf("Be users permissions were reset for every website"));
  68. } else {
  69. $rootUid = $siteController->resetBeUserPermsAction($org_id);
  70. $io->success(sprintf("The website with root uid " . $rootUid . " had its be users permissions reset"));
  71. }
  72. }
  73. }