setName("ot:site:reset-perms") ->setDescription("Reset the permissions granted to the be users") ->setHelp("This CLI command resets the permissions granted to either one website be users, or every websites be users") ->addArgument( 'organization-id', InputArgument::OPTIONAL, "The organization's id in the opentalent DB" ) ->addOption( "all", null, InputOption::VALUE_NONE, "Reset all of the websites be_users permissions." ) ->addOption( "create", 'c', InputOption::VALUE_NONE, "Create the be_user and/or be_group when they are missing" ); } /** * -- This method is expected by Typo3, do not rename ou remove -- * * @param InputInterface $input * @param OutputInterface $output * @throws \Exception */ protected function execute(InputInterface $input, OutputInterface $output) { $org_id = $input->getArgument('organization-id'); $all = $input->getOption('all'); $create = $input->getOption('create'); if ($all && $org_id) { throw new \InvalidArgumentException("You can not pass both an organization id and the --all option"); } if (!$all && !$org_id) { throw new \InvalidArgumentException("You shall either pass an organization id or use the --all option"); } $io = new SymfonyStyle($input, $output); $siteController = GeneralUtility::makeInstance(ObjectManager::class)->get(SiteController::class); if ($all) { $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); $queryBuilder = $connectionPool->getQueryBuilderForTable('pages'); $sites = $queryBuilder ->select('tx_opentalent_structure_id') ->from('pages') ->where('is_siteroot=1') ->andWhere($queryBuilder->expr()->gt('tx_opentalent_structure_id', 0)) ->execute() ->fetchAll(); $io->progressStart(count($sites)); foreach ($sites as $site) { $org_id = $site['tx_opentalent_structure_id']; try { $siteController->resetBeUserPermsAction($org_id, $create); } catch (\Throwable $e) { $io->error('Organization Id: ' . $org_id . ' - ' . sprintf($e)); } $io->progressAdvance(1); } $io->progressFinish(); $io->success(sprintf("Be users permissions were reset for every website")); } else { $rootUid = $siteController->resetBeUserPermsAction($org_id, $create); $io->success(sprintf("The website with root uid " . $rootUid . " had its be users permissions reset")); } } }