diff --git a/src/EventListener/IndexPageListener.php b/src/EventListener/IndexPageListener.php index ba41bc6..8e1885d 100644 --- a/src/EventListener/IndexPageListener.php +++ b/src/EventListener/IndexPageListener.php @@ -4,55 +4,42 @@ namespace MummertMedia\ContaoMeilisearchBundle\EventListener; use Contao\CoreBundle\ServiceAnnotation\Hook; use MummertMedia\ContaoMeilisearchBundle\Service\SearchDataProvider; +use Psr\Log\LoggerInterface; -/** - * IndexPage Listener for Contao search index - */ class IndexPageListener { public function __construct( - private readonly SearchDataProvider $dataProvider + private readonly SearchDataProvider $dataProvider, + private readonly LoggerInterface $logger ) {} /** - * This hook is executed for every indexed document - * * @Hook("indexPage") */ public function onIndexPage(string $content, array &$data, array &$set): void { - // --------------------------------------------------------------------- - // DEBUG: prove that the hook is executed (CLI + Frontend safe) - // --------------------------------------------------------------------- - error_log('[MEILI] onIndexPage fired'); + // Log into Symfony / Monolog + $this->logger->info('[MEILI] onIndexPage fired', [ + 'type' => $set['type'] ?? null, + 'set' => $set, + ]); - // log basic context - error_log('[MEILI] type=' . ($set['type'] ?? 'NULL')); - error_log('[MEILI] set=' . json_encode($set, JSON_UNESCAPED_SLASHES)); - - // --------------------------------------------------------------------- - // Fetch search data (priority + keywords) - // --------------------------------------------------------------------- $searchData = $this->dataProvider->getSearchData($set); - // log provider result - error_log('[MEILI] provider result=' . json_encode($searchData)); + $this->logger->info('[MEILI] provider result', [ + 'result' => $searchData, + ]); if ($searchData === null) { - error_log('[MEILI] no search data resolved'); return; } - // --------------------------------------------------------------------- - // Write into tl_search (this array IS the DB record) - // --------------------------------------------------------------------- $data['priority'] = (int) $searchData['priority']; $data['keywords'] = (string) $searchData['keywords']; - // final confirmation - error_log('[MEILI] tl_search updated: priority=' - . $data['priority'] - . ' keywords="' . $data['keywords'] . '"' - ); + $this->logger->info('[MEILI] tl_search updated', [ + 'priority' => $data['priority'], + 'keywords' => $data['keywords'], + ]); } } \ No newline at end of file