diff --git a/src/Command/MeilisearchFilesCleanupCommand.php b/src/Command/MeilisearchFilesCleanupCommand.php index 6a0d53e..11c2202 100644 --- a/src/Command/MeilisearchFilesCleanupCommand.php +++ b/src/Command/MeilisearchFilesCleanupCommand.php @@ -11,8 +11,6 @@ use Symfony\Component\Console\Output\OutputInterface; class MeilisearchFilesCleanupCommand extends Command { - protected static $defaultName = 'meilisearch:files:cleanup'; - public function __construct( private readonly ContaoFramework $framework, ) { @@ -22,13 +20,14 @@ class MeilisearchFilesCleanupCommand extends Command protected function configure(): void { $this - ->setDescription('Removes stale indexed files (PDF, DOCX, XLSX, PPTX) from tl_search_pdf') + ->setName('meilisearch:files:cleanup') + ->setDescription('Remove stale indexed files (PDF, DOCX, XLSX, PPTX) from tl_search_pdf') ->addOption( 'grace', null, InputOption::VALUE_OPTIONAL, 'Grace period in seconds (files newer than now-grace are kept)', - 3600 // 1 Stunde Default + 3600 ) ->addOption( 'dry-run', @@ -40,11 +39,12 @@ class MeilisearchFilesCleanupCommand extends Command protected function execute(InputInterface $input, OutputInterface $output): int { + // wichtig für Contao 4.13 & 5.x $this->framework->initialize(); - $grace = max(0, (int) $input->getOption('grace')); - $dryRun = (bool) $input->getOption('dry-run'); - $cutoff = time() - $grace; + $grace = max(0, (int) $input->getOption('grace')); + $dryRun = (bool) $input->getOption('dry-run'); + $cutoff = time() - $grace; if ($dryRun) { $count = Database::getInstance() @@ -53,7 +53,7 @@ class MeilisearchFilesCleanupCommand extends Command ->cnt; $output->writeln(sprintf( - '[DRY-RUN] %d stale file(s) would be removed (last_seen < %s)', + '[DRY-RUN] %d stale file(s) would be removed (last_seen < %s)', $count, date('Y-m-d H:i:s', $cutoff) )); @@ -67,7 +67,7 @@ class MeilisearchFilesCleanupCommand extends Command ->affectedRows; $output->writeln(sprintf( - 'Removed %d stale file(s) from tl_search_pdf (last_seen < %s)', + 'Removed %d stale file(s) (last_seen < %s)', $affected, date('Y-m-d H:i:s', $cutoff) ));