add logging
This commit is contained in:
@@ -39,39 +39,68 @@ class MeilisearchFilesCleanupCommand extends Command
|
|||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
{
|
{
|
||||||
// wichtig für Contao 4.13 & 5.x
|
|
||||||
$this->framework->initialize();
|
$this->framework->initialize();
|
||||||
|
|
||||||
$grace = max(0, (int) $input->getOption('grace'));
|
$this->log('Cleaner gestartet');
|
||||||
$dryRun = (bool) $input->getOption('dry-run');
|
|
||||||
$cutoff = time() - $grace;
|
|
||||||
|
|
||||||
if ($dryRun) {
|
try {
|
||||||
$count = Database::getInstance()
|
$grace = max(0, (int) $input->getOption('grace'));
|
||||||
->prepare('SELECT COUNT(*) AS cnt FROM tl_search_pdf WHERE last_seen < ?')
|
$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('<comment>' . $message . '</comment>');
|
||||||
|
$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)
|
->execute($cutoff)
|
||||||
->cnt;
|
->affectedRows;
|
||||||
|
|
||||||
$output->writeln(sprintf(
|
$message = sprintf(
|
||||||
'<comment>[DRY-RUN]</comment> %d stale file(s) would be removed (last_seen < %s)',
|
'Removed %d stale file(s) (last_seen < %s)',
|
||||||
$count,
|
$affected,
|
||||||
date('Y-m-d H:i:s', $cutoff)
|
date('Y-m-d H:i:s', $cutoff)
|
||||||
));
|
);
|
||||||
|
|
||||||
|
$output->writeln('<info>' . $message . '</info>');
|
||||||
|
$this->log($message);
|
||||||
|
|
||||||
|
$this->log('Cleaner successfully stopped');
|
||||||
return Command::SUCCESS;
|
return Command::SUCCESS;
|
||||||
|
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
$this->log('Cleaner ERROR: ' . $e->getMessage());
|
||||||
|
$output->writeln('<error>' . $e->getMessage() . '</error>');
|
||||||
|
|
||||||
|
return Command::FAILURE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$affected = Database::getInstance()
|
/**
|
||||||
->prepare('DELETE FROM tl_search_pdf WHERE last_seen < ?')
|
* Einheitliches Logging mit Zeitstempel
|
||||||
->execute($cutoff)
|
*/
|
||||||
->affectedRows;
|
private function log(string $message): void
|
||||||
|
{
|
||||||
$output->writeln(sprintf(
|
error_log(sprintf(
|
||||||
'<info>Removed %d stale file(s)</info> (last_seen < %s)',
|
'[%s] %s',
|
||||||
$affected,
|
date('Y-m-d H:i:s'),
|
||||||
date('Y-m-d H:i:s', $cutoff)
|
$message
|
||||||
));
|
));
|
||||||
|
|
||||||
return Command::SUCCESS;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,12 +24,34 @@ class MeilisearchIndexCommand extends Command
|
|||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
{
|
{
|
||||||
|
$this->log('Meilisearch index gestartet');
|
||||||
$output->writeln('<info>Meilisearch index started</info>');
|
$output->writeln('<info>Meilisearch index started</info>');
|
||||||
|
|
||||||
$this->indexService->run();
|
try {
|
||||||
|
$this->indexService->run();
|
||||||
|
|
||||||
$output->writeln('<info>Meilisearch index finished</info>');
|
$this->log('Meilisearch index successfully stopped');
|
||||||
|
$output->writeln('<info>Meilisearch index finished</info>');
|
||||||
|
|
||||||
return Command::SUCCESS;
|
return Command::SUCCESS;
|
||||||
|
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
$this->log('Meilisearch index ERROR: ' . $e->getMessage());
|
||||||
|
$output->writeln('<error>' . $e->getMessage() . '</error>');
|
||||||
|
|
||||||
|
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
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user