|
|
@@ -8,6 +8,8 @@ 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;
|
|
|
|
|
|
@@ -28,10 +30,15 @@ class ScanCommand extends Command
|
|
|
protected function configure()
|
|
|
{
|
|
|
$this
|
|
|
- ->setName("ot:scan")
|
|
|
+ ->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,
|
|
|
@@ -49,11 +56,13 @@ class ScanCommand extends Command
|
|
|
*/
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
{
|
|
|
+ $deep = $input->getOption('deep');
|
|
|
+
|
|
|
$io = new SymfonyStyle($input, $output);
|
|
|
|
|
|
// instanciate twig loader
|
|
|
- $loader = new \Twig\Loader\FilesystemLoader(dirname(__FILE__) . '/../../templates');
|
|
|
- $twig = new \Twig\Environment($loader);
|
|
|
+ $loader = new FilesystemLoader(__DIR__ . '/../../templates');
|
|
|
+ $twig = new Environment($loader);
|
|
|
|
|
|
// evaluate the report path
|
|
|
$report_path = $input->getOption('report');
|
|
|
@@ -61,21 +70,33 @@ class ScanCommand extends Command
|
|
|
$report_path = getcwd() . '/scan_report.html';
|
|
|
} else {
|
|
|
$info = pathinfo($report_path);
|
|
|
- if ($info['extension'] != 'html') {
|
|
|
+ if ($info['extension'] !== 'html') {
|
|
|
$report_path .= '.html';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// perform the scan
|
|
|
$scanController = GeneralUtility::makeInstance(ObjectManager::class)->get(ScanController::class);
|
|
|
- $scan = $scanController->scanAllAction(true);
|
|
|
+
|
|
|
+ $progressBar = $io->createProgressBar();
|
|
|
+ $progressBar->display();
|
|
|
+
|
|
|
+ $scan = $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, 'w+');
|
|
|
+ $f = fopen($report_path, 'wb+');
|
|
|
try {
|
|
|
fwrite($f, $html_report);
|
|
|
$io->success(sprintf("Report file was created at: " . $report_path));
|