| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace Opentalent\OtAdmin\Command;
- use Opentalent\OtAdmin\Controller\ScanController;
- use Opentalent\OtAdmin\Controller\SiteController;
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Input\InputOption;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\Console\Style\SymfonyStyle;
- use Twig\Environment;
- use Twig\Loader\FilesystemLoader;
- use TYPO3\CMS\Core\Utility\GeneralUtility;
- use TYPO3\CMS\Extbase\Object\ObjectManager;
- /**
- * This CLI command performs a full scan on the Typo3 db
- *
- * @package Opentalent\OtAdmin\Command
- */
- class ScanCommand extends Command
- {
- public function __construct(
- private readonly ScanController $scanController
- ) {
- parent::__construct();
- }
- /**
- * -- This method is expected by Typo3, do not rename ou remove --
- *
- * Allows to configure the command.
- * Allows to add a description, a help text, and / or define arguments.
- *
- */
- protected function configure(): void
- {
- $this
- ->setName("ot:site:scan")
- ->setDescription("Scan the typo3 DB")
- ->setHelp("This CLI command performs a full scan on the Typo3 db.")
- ->addOption(
- 'deep',
- 'd',
- InputOption::VALUE_NONE,
- 'Performs a deeper scan, with more control operations'
- )->addOption(
- 'report',
- 'r',
- InputOption::VALUE_OPTIONAL,
- 'Build an html report file with the given name.'
- );
- }
- /**
- * -- This method is expected by Typo3, do not rename ou remove --
- *
- * @param InputInterface $input
- * @param OutputInterface $output
- * @return int
- * @throws \Exception
- */
- protected function execute(InputInterface $input, OutputInterface $output): int
- {
- $deep = $input->getOption('deep');
- $io = new SymfonyStyle($input, $output);
- // instanciate twig loader
- $loader = new FilesystemLoader(__DIR__ . '/../../templates');
- $twig = new Environment($loader);
- // evaluate the report path
- $report_path = $input->getOption('report');
- if ($report_path == null) {
- $report_path = getcwd() . '/scan_report.html';
- } else {
- $info = pathinfo($report_path);
- if ($info['extension'] !== 'html') {
- $report_path .= '.html';
- }
- }
- // perform the scan
- $progressBar = $io->createProgressBar();
- $progressBar->display();
- $scan = $this->scanController->scanAllAction(
- $deep,
- function ($i, $total) use ($progressBar) {
- $progressBar->setProgress($i);
- if ($total !== $progressBar->getMaxSteps()) {
- $progressBar->setMaxSteps($total);
- }
- }
- );
- // render the twig template
- $template = $twig->load('scan_report.twig');
- $html_report = $template->render(['scan' => $scan]);
- $f = fopen($report_path, 'wb+');
- try {
- fwrite($f, $html_report);
- $io->success(sprintf("Report file was created at: " . $report_path));
- } finally {
- fclose($f);
- }
- return 0;
- }
- }
|