Debug File Indexing
This commit is contained in:
@@ -181,55 +181,63 @@ class IndexPageListener
|
|||||||
$db = System::getContainer()->get('database_connection');
|
$db = System::getContainer()->get('database_connection');
|
||||||
$time = time();
|
$time = time();
|
||||||
|
|
||||||
|
// ✅ Contao 5.x robust: Projektverzeichnis statt TL_ROOT
|
||||||
|
$projectDir = System::getContainer()->getParameter('kernel.project_dir');
|
||||||
|
|
||||||
foreach ($fileLinks as $file) {
|
foreach ($fileLinks as $file) {
|
||||||
$url = strtok($file['url'], '#');
|
try {
|
||||||
|
$url = strtok($file['url'], '#');
|
||||||
|
|
||||||
$path = parse_url($url, PHP_URL_PATH);
|
$path = parse_url($url, PHP_URL_PATH);
|
||||||
$abs = $path ? TL_ROOT . '/' . ltrim($path, '/') : null;
|
$abs = $path ? $projectDir . '/public/' . ltrim($path, '/') : null;
|
||||||
|
|
||||||
$mtime = ($abs && is_file($abs)) ? filemtime($abs) : 0;
|
$mtime = ($abs && is_file($abs)) ? filemtime($abs) : 0;
|
||||||
$checksum = md5($url . '|' . $mtime);
|
$checksum = md5($url . '|' . $mtime);
|
||||||
|
|
||||||
$existing = $db->fetchAssociative(
|
$existing = $db->fetchAssociative(
|
||||||
'SELECT id, checksum FROM tl_search_files WHERE url = ?',
|
'SELECT id, checksum FROM tl_search_files WHERE url = ?',
|
||||||
[$url]
|
[$url]
|
||||||
);
|
|
||||||
|
|
||||||
if ($existing) {
|
|
||||||
$db->update(
|
|
||||||
'tl_search_files',
|
|
||||||
[
|
|
||||||
'tstamp' => $time,
|
|
||||||
'last_seen' => $time,
|
|
||||||
'page_id' => (int) ($data['pid'] ?? 0),
|
|
||||||
'file_mtime' => $mtime,
|
|
||||||
'checksum' => $checksum,
|
|
||||||
],
|
|
||||||
['id' => $existing['id']]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->debug('File updated', [
|
if ($existing) {
|
||||||
'url' => $url,
|
$db->update(
|
||||||
'checksum' => $checksum,
|
'tl_search_files',
|
||||||
]);
|
[
|
||||||
} else {
|
'tstamp' => $time,
|
||||||
$db->insert(
|
'last_seen' => $time,
|
||||||
'tl_search_files',
|
'page_id' => (int) ($data['pid'] ?? 0),
|
||||||
[
|
'file_mtime' => $mtime,
|
||||||
'tstamp' => $time,
|
'checksum' => $checksum,
|
||||||
'last_seen' => $time,
|
],
|
||||||
'type' => $file['type'],
|
['id' => $existing['id']]
|
||||||
'url' => $url,
|
);
|
||||||
'title' => $file['linkText'] ?? basename($url),
|
|
||||||
'page_id' => (int) ($data['pid'] ?? 0),
|
|
||||||
'file_mtime' => $mtime,
|
|
||||||
'checksum' => $checksum,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->debug('File inserted', [
|
$this->debug('File updated', ['url' => $url, 'checksum' => $checksum]);
|
||||||
'url' => $url,
|
} else {
|
||||||
'checksum' => $checksum,
|
$db->insert(
|
||||||
|
'tl_search_files',
|
||||||
|
[
|
||||||
|
'tstamp' => $time,
|
||||||
|
'last_seen' => $time,
|
||||||
|
'type' => $file['type'],
|
||||||
|
'url' => $url,
|
||||||
|
'title' => $file['linkText'] ?? basename($url),
|
||||||
|
'page_id' => (int) ($data['pid'] ?? 0),
|
||||||
|
'file_mtime' => $mtime,
|
||||||
|
'checksum' => $checksum,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->debug('File inserted', ['url' => $url, 'checksum' => $checksum]);
|
||||||
|
}
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
$this->debug('File upsert FAILED', [
|
||||||
|
'url' => $file['url'] ?? null,
|
||||||
|
'type' => $file['type'] ?? null,
|
||||||
|
'error' => $e->getMessage(),
|
||||||
|
'class' => $e::class,
|
||||||
|
// falls DBAL-Exception: SQLSTATE/Code helfen brutal beim Finden
|
||||||
|
'code' => $e->getCode(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user