From 798aaadb7e1658b286b5ae30d30ce88a634ccfd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Mummert?= Date: Thu, 25 Dec 2025 15:19:44 +0100 Subject: [PATCH] Bugfix --- src/EventListener/IndexPageListener.php | 26 ++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/EventListener/IndexPageListener.php b/src/EventListener/IndexPageListener.php index 828b1d1..a4bab13 100644 --- a/src/EventListener/IndexPageListener.php +++ b/src/EventListener/IndexPageListener.php @@ -7,12 +7,10 @@ use MummertMedia\ContaoMeilisearchBundle\Service\PdfIndexService; class IndexPageListener { - public function __construct( - private PdfIndexService $pdfIndexService - ) {} + private ?PdfIndexService $pdfIndexService = null; + public function onIndexPage(string $content, array &$data, array &$set): void { - $this->pdfIndexService->startCrawl(); // Marker vorhanden? if (!str_contains($content, 'MEILISEARCH_JSON')) { return; @@ -98,18 +96,27 @@ class IndexPageListener /* * ===================== - * PDF-ERKENNUNG (DEBUG) + * PDF-ERKENNUNG * ===================== */ $pdfLinks = $this->findPdfLinks($content); if ($pdfLinks !== []) { - $this->pdfIndexService->startCrawl(); error_log('PDF gefunden'); + + // PdfIndexService lazy aus dem Container holen + if ($this->pdfIndexService === null) { + $this->pdfIndexService = System::getContainer()->get(PdfIndexService::class); + } + + $this->pdfIndexService->startCrawl(); $this->pdfIndexService->handlePdfLinks($pdfLinks); } } + /* ===================================================== + * JSON aus Marker extrahieren + * ===================================================== */ private function extractMeilisearchJson(string $content): ?array { if (!preg_match('//s', $content, $m)) { @@ -122,6 +129,9 @@ class IndexPageListener return is_array($data) ? $data : null; } + /* ===================================================== + * PDF-Links im Markup finden + * ===================================================== */ private function findPdfLinks(string $content): array { if (!preg_match_all( @@ -132,6 +142,8 @@ class IndexPageListener return []; } - return array_unique(array_map('html_entity_decode', $matches[1])); + return array_unique( + array_map('html_entity_decode', $matches[1]) + ); } } \ No newline at end of file