diff --git a/src/Command/MeilisearchFilesCleanupCommand.php b/src/Command/MeilisearchFilesCleanupCommand.php
index 26e0490..2b88cd0 100644
--- a/src/Command/MeilisearchFilesCleanupCommand.php
+++ b/src/Command/MeilisearchFilesCleanupCommand.php
@@ -39,39 +39,68 @@ 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;
+ $this->log('Cleaner gestartet');
- if ($dryRun) {
- $count = Database::getInstance()
- ->prepare('SELECT COUNT(*) AS cnt FROM tl_search_pdf WHERE last_seen < ?')
+ try {
+ $grace = max(0, (int) $input->getOption('grace'));
+ $dryRun = (bool) $input->getOption('dry-run');
+ $cutoff = time() - $grace;
+
+ if ($dryRun) {
+ $count = Database::getInstance()
+ ->prepare('SELECT COUNT(*) AS cnt FROM tl_search_pdf WHERE last_seen < ?')
+ ->execute($cutoff)
+ ->cnt;
+
+ $message = sprintf(
+ '[DRY-RUN] %d stale file(s) would be removed (last_seen < %s)',
+ $count,
+ date('Y-m-d H:i:s', $cutoff)
+ );
+
+ $output->writeln('' . $message . '');
+ $this->log($message);
+
+ $this->log('Cleaner successfully stopped');
+ return Command::SUCCESS;
+ }
+
+ $affected = Database::getInstance()
+ ->prepare('DELETE FROM tl_search_pdf WHERE last_seen < ?')
->execute($cutoff)
- ->cnt;
+ ->affectedRows;
- $output->writeln(sprintf(
- '[DRY-RUN] %d stale file(s) would be removed (last_seen < %s)',
- $count,
+ $message = sprintf(
+ 'Removed %d stale file(s) (last_seen < %s)',
+ $affected,
date('Y-m-d H:i:s', $cutoff)
- ));
+ );
+ $output->writeln('' . $message . '');
+ $this->log($message);
+
+ $this->log('Cleaner successfully stopped');
return Command::SUCCESS;
+
+ } catch (\Throwable $e) {
+ $this->log('Cleaner ERROR: ' . $e->getMessage());
+ $output->writeln('' . $e->getMessage() . '');
+
+ return Command::FAILURE;
}
+ }
- $affected = Database::getInstance()
- ->prepare('DELETE FROM tl_search_pdf WHERE last_seen < ?')
- ->execute($cutoff)
- ->affectedRows;
-
- $output->writeln(sprintf(
- 'Removed %d stale file(s) (last_seen < %s)',
- $affected,
- date('Y-m-d H:i:s', $cutoff)
+ /**
+ * Einheitliches Logging mit Zeitstempel
+ */
+ private function log(string $message): void
+ {
+ error_log(sprintf(
+ '[%s] %s',
+ date('Y-m-d H:i:s'),
+ $message
));
-
- return Command::SUCCESS;
}
}
\ No newline at end of file
diff --git a/src/Command/MeilisearchIndexCommand.php b/src/Command/MeilisearchIndexCommand.php
index 4753633..19261a7 100644
--- a/src/Command/MeilisearchIndexCommand.php
+++ b/src/Command/MeilisearchIndexCommand.php
@@ -24,12 +24,34 @@ class MeilisearchIndexCommand extends Command
protected function execute(InputInterface $input, OutputInterface $output): int
{
+ $this->log('Meilisearch index gestartet');
$output->writeln('Meilisearch index started');
- $this->indexService->run();
+ try {
+ $this->indexService->run();
- $output->writeln('Meilisearch index finished');
+ $this->log('Meilisearch index successfully stopped');
+ $output->writeln('Meilisearch index finished');
- return Command::SUCCESS;
+ return Command::SUCCESS;
+
+ } catch (\Throwable $e) {
+ $this->log('Meilisearch index ERROR: ' . $e->getMessage());
+ $output->writeln('' . $e->getMessage() . '');
+
+ return Command::FAILURE;
+ }
+ }
+
+ /**
+ * Einheitliches Logging mit Zeitstempel
+ */
+ private function log(string $message): void
+ {
+ error_log(sprintf(
+ '[%s] %s',
+ date('Y-m-d H:i:s'),
+ $message
+ ));
}
}
\ No newline at end of file