diff --git a/src/EventListener/IndexPageListener.php b/src/EventListener/IndexPageListener.php index a6c1d40..86bc39a 100644 --- a/src/EventListener/IndexPageListener.php +++ b/src/EventListener/IndexPageListener.php @@ -12,21 +12,46 @@ class IndexPageListener public function onIndexPage(string $content, array &$data, array &$set): void { + $debug = (PHP_SAPI === 'cli'); + + if ($debug) { + echo "\n=============================\n"; + echo "INDEXPAGE LISTENER\n"; + echo "URL: " . ($set['url'] ?? $data['url'] ?? '[unknown]') . "\n"; + } + // Marker vorhanden? if (!str_contains($content, 'MEILISEARCH_JSON')) { + if ($debug) { + echo "❌ MEILISEARCH_JSON not found\n"; + echo "=============================\n"; + } return; } + if ($debug) { + echo "✔ MEILISEARCH_JSON marker found\n"; + } + // JSON aus Kommentar extrahieren + parsen $parsed = $this->extractMeilisearchJson($content); if ($parsed === null) { + if ($debug) { + echo "❌ JSON could not be parsed\n"; + echo "=============================\n"; + } return; } + if ($debug) { + echo "✔ JSON parsed successfully:\n"; + print_r($parsed); + } + /* * ===================== - * PRIORITY (event > news > page) + * PRIORITY * ===================== */ $priority = @@ -36,11 +61,15 @@ class IndexPageListener if ($priority !== null && $priority !== '') { $set['priority'] = (int) $priority; + + if ($debug) { + echo "✔ priority set to: {$set['priority']}\n"; + } } /* * ===================== - * KEYWORDS (merge) + * KEYWORDS * ===================== */ $keywordSources = [ @@ -64,11 +93,15 @@ class IndexPageListener if ($kw) { $set['keywords'] = implode(' ', array_unique($kw)); + + if ($debug) { + echo "✔ keywords set to: {$set['keywords']}\n"; + } } /* * ===================== - * IMAGEPATH (event > news > page > custom) + * IMAGEPATH * ===================== */ $image = @@ -77,29 +110,72 @@ class IndexPageListener $parsed['page']['searchimage'] ?? null ?? $parsed['custom']['searchimage'] ?? null; + if ($debug) { + echo "Resolved image UUID: "; + var_dump($image); + } + if (is_string($image) && $image !== '') { + if ($debug) { + echo "→ Calling MeilisearchImageHelper\n"; + } + $path = $this->imageHelper->getImagePathFromUuid($image); + if ($debug) { + echo "← Image helper returned: "; + var_dump($path); + } + if ($path !== null) { $set['imagepath'] = $path; + + if ($debug) { + echo "✔ imagepath set to: {$set['imagepath']}\n"; + } + } elseif ($debug) { + echo "❌ image helper returned NULL\n"; } } /* * ===================== - * STARTDATE (event.date/news.date => timestamp) + * STARTDATE * ===================== */ $date = $parsed['event']['date'] ?? null ?? $parsed['news']['date'] ?? null; + if ($debug) { + echo "Resolved date: "; + var_dump($date); + } + if (is_string($date) && $date !== '') { $ts = strtotime($date); + if ($ts !== false) { $set['startDate'] = $ts; + + if ($debug) { + echo "✔ startDate set to timestamp: {$set['startDate']}\n"; + } + } elseif ($debug) { + echo "❌ strtotime failed\n"; } } + + if ($debug) { + echo "---- FINAL \$set ----\n"; + print_r([ + 'priority' => $set['priority'] ?? null, + 'keywords' => $set['keywords'] ?? null, + 'imagepath' => $set['imagepath'] ?? null, + 'startDate' => $set['startDate'] ?? null, + ]); + echo "=============================\n"; + } } private function extractMeilisearchJson(string $content): ?array diff --git a/src/Service/MeilisearchImageHelper.php b/src/Service/MeilisearchImageHelper.php index 077875a..f1e1845 100644 --- a/src/Service/MeilisearchImageHelper.php +++ b/src/Service/MeilisearchImageHelper.php @@ -16,21 +16,51 @@ class MeilisearchImageHelper public function getImagePathFromUuid(string $uuid): ?string { + if (PHP_SAPI === 'cli') { + echo "\n[MeilisearchImageHelper]\n"; + echo "UUID received: $uuid\n"; + } + $file = FilesModel::findByUuid($uuid); if ($file === null) { + if (PHP_SAPI === 'cli') { + echo "❌ FilesModel::findByUuid() returned NULL\n"; + } return null; } + if (PHP_SAPI === 'cli') { + echo "✔ File found: {$file->path}\n"; + } + // SVG niemals skalieren if (str_ends_with(strtolower($file->path), '.svg')) { - return '/' . ltrim($file->path, '/'); + $path = '/' . ltrim($file->path, '/'); + + if (PHP_SAPI === 'cli') { + echo "✔ SVG detected, returning original path:\n"; + echo "→ $path\n"; + } + + return $path; } $sizeId = (int) Config::get('meilisearch_imagesize'); + if (PHP_SAPI === 'cli') { + echo "Image size ID from tl_settings: $sizeId\n"; + } + if ($sizeId <= 0) { - return '/' . ltrim($file->path, '/'); + $path = '/' . ltrim($file->path, '/'); + + if (PHP_SAPI === 'cli') { + echo "⚠ No image size set, returning original path:\n"; + echo "→ $path\n"; + } + + return $path; } $figure = $this->imageStudio @@ -39,8 +69,29 @@ class MeilisearchImageHelper ->setSize($sizeId) ->build(); + if (!$figure) { + if (PHP_SAPI === 'cli') { + echo "❌ Figure build returned NULL\n"; + } + return null; + } + $image = $figure->getImage(); - return $image ? $image->getImageSrc() : null; + if ($image === null) { + if (PHP_SAPI === 'cli') { + echo "❌ Figure->getImage() returned NULL\n"; + } + return null; + } + + $src = $image->getImageSrc(); + + if (PHP_SAPI === 'cli') { + echo "✔ Processed image path:\n"; + echo "→ $src\n"; + } + + return $src ?: null; } } \ No newline at end of file