Bugfix
This commit is contained in:
@@ -13,17 +13,37 @@ class IndexPageListener
|
|||||||
private readonly OfficeIndexService $officeIndexService,
|
private readonly OfficeIndexService $officeIndexService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
private function debug(string $message, array $context = []): void
|
||||||
|
{
|
||||||
|
// Debug bewusst immer aktiv (bis du es wieder entfernst)
|
||||||
|
// Kontext kurz halten, damit Logs nicht explodieren
|
||||||
|
$ctx = $context ? ' | ' . json_encode($context, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) : '';
|
||||||
|
error_log('[ContaoMeilisearch][IndexPageListener] ' . $message . $ctx);
|
||||||
|
}
|
||||||
|
|
||||||
public function onIndexPage(string $content, array &$data, array &$set): void
|
public function onIndexPage(string $content, array &$data, array &$set): void
|
||||||
{
|
{
|
||||||
|
$this->debug('Hook start', [
|
||||||
|
'url' => $data['url'] ?? null,
|
||||||
|
'protected' => $data['protected'] ?? null,
|
||||||
|
'checksum' => $data['checksum'] ?? null,
|
||||||
|
'set_keys' => array_keys($set),
|
||||||
|
]);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* =====================
|
* =====================
|
||||||
* PDF: Reset genau 1× pro Crawl
|
* PDF: Reset genau 1× pro Crawl
|
||||||
* =====================
|
* =====================
|
||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
|
$this->debug('PDF resetTableOnce(): call');
|
||||||
$this->pdfIndexService->resetTableOnce();
|
$this->pdfIndexService->resetTableOnce();
|
||||||
|
$this->debug('PDF resetTableOnce(): ok');
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
error_log('[ContaoMeilisearch] PDF reset failed: ' . $e->getMessage());
|
$this->debug('PDF resetTableOnce(): failed', [
|
||||||
|
'error' => $e->getMessage(),
|
||||||
|
'class' => $e::class,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -31,11 +51,24 @@ class IndexPageListener
|
|||||||
* SEITEN-METADATEN
|
* SEITEN-METADATEN
|
||||||
* =====================
|
* =====================
|
||||||
*/
|
*/
|
||||||
if (str_contains($content, 'MEILISEARCH_JSON')) {
|
$hasMeta = str_contains($content, 'MEILISEARCH_JSON');
|
||||||
|
$this->debug('Meta marker scan', [
|
||||||
|
'contains_MEILISEARCH_JSON' => $hasMeta,
|
||||||
|
'content_length' => strlen($content),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($hasMeta) {
|
||||||
try {
|
try {
|
||||||
$parsed = $this->extractMeilisearchJson($content);
|
$parsed = $this->extractMeilisearchJson($content);
|
||||||
|
$this->debug('extractMeilisearchJson(): done', [
|
||||||
|
'parsed_is_array' => is_array($parsed),
|
||||||
|
'parsed_keys' => is_array($parsed) ? array_keys($parsed) : null,
|
||||||
|
]);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
error_log('[ContaoMeilisearch] Failed to extract MEILISEARCH_JSON: ' . $e->getMessage());
|
$this->debug('Failed to extract MEILISEARCH_JSON', [
|
||||||
|
'error' => $e->getMessage(),
|
||||||
|
'class' => $e::class,
|
||||||
|
]);
|
||||||
$parsed = null;
|
$parsed = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,6 +81,8 @@ class IndexPageListener
|
|||||||
?? $parsed['page']['priority']
|
?? $parsed['page']['priority']
|
||||||
?? null;
|
?? null;
|
||||||
|
|
||||||
|
$this->debug('Meta: priority candidate', ['priority' => $priority]);
|
||||||
|
|
||||||
if ($priority !== null && $priority !== '') {
|
if ($priority !== null && $priority !== '') {
|
||||||
$set['priority'] = (int) $priority;
|
$set['priority'] = (int) $priority;
|
||||||
}
|
}
|
||||||
@@ -59,6 +94,8 @@ class IndexPageListener
|
|||||||
$parsed['page']['keywords'] ?? null,
|
$parsed['page']['keywords'] ?? null,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$this->debug('Meta: keyword sources', ['sources' => $keywordSources]);
|
||||||
|
|
||||||
$keywords = [];
|
$keywords = [];
|
||||||
foreach ($keywordSources as $src) {
|
foreach ($keywordSources as $src) {
|
||||||
if (!is_string($src) || trim($src) === '') {
|
if (!is_string($src) || trim($src) === '') {
|
||||||
@@ -73,9 +110,17 @@ class IndexPageListener
|
|||||||
$set['keywords'] = implode(' ', array_unique($keywords));
|
$set['keywords'] = implode(' ', array_unique($keywords));
|
||||||
}
|
}
|
||||||
|
|
||||||
// IMAGEPATH
|
$this->debug('Meta: keywords result', [
|
||||||
if (!empty($parsed['page']['searchimage'])) {
|
'keywords' => $set['keywords'] ?? null,
|
||||||
$set['imagepath'] = trim((string) $parsed['page']['searchimage']);
|
]);
|
||||||
|
|
||||||
|
// IMAGEPATH (UUID)
|
||||||
|
$searchImage = $parsed['page']['searchimage'] ?? null;
|
||||||
|
$this->debug('Meta: searchimage candidate', ['searchimage' => $searchImage]);
|
||||||
|
|
||||||
|
if (!empty($searchImage)) {
|
||||||
|
// >>> HINWEIS: falls dein tl_search-Feld "image" heißt, hier auf $set['image'] ändern!
|
||||||
|
$set['imagepath'] = trim((string) $searchImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
// STARTDATE
|
// STARTDATE
|
||||||
@@ -84,6 +129,8 @@ class IndexPageListener
|
|||||||
?? $parsed['news']['startDate']
|
?? $parsed['news']['startDate']
|
||||||
?? null;
|
?? null;
|
||||||
|
|
||||||
|
$this->debug('Meta: startDate candidate', ['startDate' => $startDate]);
|
||||||
|
|
||||||
if (is_numeric($startDate) && (int) $startDate > 0) {
|
if (is_numeric($startDate) && (int) $startDate > 0) {
|
||||||
$set['startDate'] = (int) $startDate;
|
$set['startDate'] = (int) $startDate;
|
||||||
}
|
}
|
||||||
@@ -97,9 +144,25 @@ class IndexPageListener
|
|||||||
$checksumSeed .= '|' . ($set['startDate'] ?? '');
|
$checksumSeed .= '|' . ($set['startDate'] ?? '');
|
||||||
|
|
||||||
$set['checksum'] = md5($checksumSeed);
|
$set['checksum'] = md5($checksumSeed);
|
||||||
|
|
||||||
|
$this->debug('Checksum generated', [
|
||||||
|
'seed_preview' => substr($checksumSeed, 0, 120) . (strlen($checksumSeed) > 120 ? '…' : ''),
|
||||||
|
'checksum' => $set['checksum'],
|
||||||
|
]);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
error_log('[ContaoMeilisearch] Failed to generate checksum: ' . $e->getMessage());
|
$this->debug('Failed to generate checksum', [
|
||||||
|
'error' => $e->getMessage(),
|
||||||
|
'class' => $e::class,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->debug('Meta: final set snapshot', [
|
||||||
|
'priority' => $set['priority'] ?? null,
|
||||||
|
'keywords' => $set['keywords'] ?? null,
|
||||||
|
'imagepath' => $set['imagepath'] ?? null,
|
||||||
|
'startDate' => $set['startDate'] ?? null,
|
||||||
|
'checksum' => $set['checksum'] ?? null,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,17 +172,25 @@ class IndexPageListener
|
|||||||
* =====================
|
* =====================
|
||||||
*/
|
*/
|
||||||
if ((int) ($data['protected'] ?? 0) !== 0) {
|
if ((int) ($data['protected'] ?? 0) !== 0) {
|
||||||
|
$this->debug('Abort: protected page', ['protected' => $data['protected'] ?? null]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$indexPdfs = (bool) Config::get('meilisearch_index_pdfs');
|
$indexPdfs = (bool) Config::get('meilisearch_index_pdfs');
|
||||||
$indexOffice = (bool) Config::get('meilisearch_index_office');
|
$indexOffice = (bool) Config::get('meilisearch_index_office');
|
||||||
|
|
||||||
|
$this->debug('File indexing settings', [
|
||||||
|
'meilisearch_index_pdfs' => $indexPdfs,
|
||||||
|
'meilisearch_index_office' => $indexOffice,
|
||||||
|
]);
|
||||||
|
|
||||||
if (!$indexPdfs && !$indexOffice) {
|
if (!$indexPdfs && !$indexOffice) {
|
||||||
|
$this->debug('Abort: file indexing disabled');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$links = $this->findAllLinks($content);
|
$links = $this->findAllLinks($content);
|
||||||
|
$this->debug('Links found', ['count' => count($links)]);
|
||||||
|
|
||||||
$pdfLinks = [];
|
$pdfLinks = [];
|
||||||
$officeLinks = [];
|
$officeLinks = [];
|
||||||
@@ -132,25 +203,45 @@ class IndexPageListener
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (in_array($type, ['docx', 'xlsx', 'pptx'], true) && $indexOffice) {
|
||||||
in_array($type, ['docx', 'xlsx', 'pptx'], true)
|
|
||||||
&& $indexOffice
|
|
||||||
) {
|
|
||||||
$officeLinks[] = $link;
|
$officeLinks[] = $link;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->debug('Indexable file links', [
|
||||||
|
'pdf' => count($pdfLinks),
|
||||||
|
'office' => count($officeLinks),
|
||||||
|
]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($pdfLinks !== []) {
|
if ($pdfLinks !== []) {
|
||||||
|
$this->debug('PDF handlePdfLinks(): call', ['count' => count($pdfLinks)]);
|
||||||
$this->pdfIndexService->handlePdfLinks($pdfLinks);
|
$this->pdfIndexService->handlePdfLinks($pdfLinks);
|
||||||
|
$this->debug('PDF handlePdfLinks(): ok');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($officeLinks !== []) {
|
if ($officeLinks !== []) {
|
||||||
|
$this->debug('Office handleOfficeLinks(): call', ['count' => count($officeLinks)]);
|
||||||
$this->officeIndexService->handleOfficeLinks($officeLinks);
|
$this->officeIndexService->handleOfficeLinks($officeLinks);
|
||||||
|
$this->debug('Office handleOfficeLinks(): ok');
|
||||||
}
|
}
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
error_log('[ContaoMeilisearch] File indexing failed: ' . $e->getMessage());
|
$this->debug('File indexing failed', [
|
||||||
|
'error' => $e->getMessage(),
|
||||||
|
'class' => $e::class,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->debug('Hook end', [
|
||||||
|
'final_set_keys' => array_keys($set),
|
||||||
|
'final_set' => [
|
||||||
|
'priority' => $set['priority'] ?? null,
|
||||||
|
'keywords' => $set['keywords'] ?? null,
|
||||||
|
'imagepath' => $set['imagepath'] ?? null,
|
||||||
|
'startDate' => $set['startDate'] ?? null,
|
||||||
|
'checksum' => $set['checksum'] ?? null,
|
||||||
|
],
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user