setName("ot:site:gen-config-file") ->setDescription("Update an organization configuration file") ->setHelp("This CLI command creates or updates the organization config file") ->addOption( 'all', null, InputOption::VALUE_NONE, "Update all of the organization websites" ) ->addArgument( 'organization-id', InputArgument::OPTIONAL, "The organization's id in the opentalent DB" ); } /** * -- 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'); 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('ot_websites'); $sites = $queryBuilder ->select('organization_id') ->from('ot_websites') ->where($queryBuilder->expr()->eq('deleted', 0)) ->andWhere($queryBuilder->expr()->gt('organization_id', 0)) ->execute() ->fetchAll(); $io->progressStart(count($sites)); foreach ($sites as $site) { $org_id = $site['organization_id']; try { $siteController->updateConfigFileAction($org_id); } catch (\Throwable $e) { $io->error('Organization Id: ' . $org_id . ' - ' . $e->getMessage()); } $io->progressAdvance(1); } $io->progressFinish(); $io->success(sprintf("The websites config files have all been updated")); } else { $identifier = $siteController->updateConfigFileAction($org_id); $io->success(sprintf("The config file with identifier " . $identifier . " has been updated")); } } }