add files uuid
This commit is contained in:
@@ -53,7 +53,7 @@ class MeilisearchFileHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------
|
// -------------------------------------------------
|
||||||
// 3. Normalisierten lokalen Pfad ermitteln
|
// 3. Normalisierten lokalen Pfad ermitteln (UUID-first)
|
||||||
// -------------------------------------------------
|
// -------------------------------------------------
|
||||||
$query = [];
|
$query = [];
|
||||||
if (!empty($parts['query'])) {
|
if (!empty($parts['query'])) {
|
||||||
@@ -74,27 +74,66 @@ class MeilisearchFileHelper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$normalizedPath = null;
|
$pathCandidates = array_values(array_unique(array_filter(array_map(
|
||||||
|
static function ($c) {
|
||||||
|
$c = rawurldecode(html_entity_decode((string) $c, ENT_QUOTES));
|
||||||
|
$c = ltrim($c, '/');
|
||||||
|
return $c !== '' ? $c : null;
|
||||||
|
},
|
||||||
|
$pathCandidates
|
||||||
|
))));
|
||||||
|
|
||||||
|
$this->log('Path candidates (normalized)', ['candidates' => $pathCandidates]);
|
||||||
|
|
||||||
|
$resolvedModel = null;
|
||||||
|
|
||||||
|
// Wir testen Kandidaten in dieser Reihenfolge:
|
||||||
|
// - kandidat selbst
|
||||||
|
// - falls nicht mit "files/" beginnt: zusätzlich "files/".$kandidat
|
||||||
foreach ($pathCandidates as $candidate) {
|
foreach ($pathCandidates as $candidate) {
|
||||||
$candidate = rawurldecode(html_entity_decode((string) $candidate, ENT_QUOTES));
|
|
||||||
$candidate = ltrim($candidate, '/');
|
|
||||||
|
|
||||||
if (!str_starts_with($candidate, 'files/')) {
|
// 1) direkt versuchen
|
||||||
continue;
|
$model = FilesModel::findByPath($candidate);
|
||||||
|
if ($model && $model->uuid) {
|
||||||
|
$resolvedModel = $model;
|
||||||
|
$this->log('Resolved via FilesModel (direct)', ['candidate' => $candidate, 'path' => $model->path]);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$abs = System::getContainer()->getParameter('kernel.project_dir') . '/public/' . $candidate;
|
// 2) fallback: "files/" davor (ohne Annahme über Ordnerstruktur)
|
||||||
|
if (!str_starts_with($candidate, 'files/')) {
|
||||||
if (is_file($abs)) {
|
$model = FilesModel::findByPath('files/' . $candidate);
|
||||||
$normalizedPath = $candidate;
|
if ($model && $model->uuid) {
|
||||||
|
$resolvedModel = $model;
|
||||||
|
$this->log('Resolved via FilesModel (files/ prefix)', [
|
||||||
|
'candidate' => $candidate,
|
||||||
|
'path' => $model->path,
|
||||||
|
]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!$normalizedPath) {
|
if (!$resolvedModel) {
|
||||||
$this->log('No valid local file path found, skip', [
|
$this->log('No Contao file model found for candidates, skip', ['candidates' => $pathCandidates]);
|
||||||
'candidates' => $pathCandidates,
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$normalizedPath = (string) $resolvedModel->path;
|
||||||
|
$uuidBin = $resolvedModel->uuid;
|
||||||
|
|
||||||
|
$this->log('UUID resolved', [
|
||||||
|
'path' => $normalizedPath,
|
||||||
|
'uuid' => StringUtil::binToUuid($uuidBin),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$projectDir = System::getContainer()->getParameter('kernel.project_dir');
|
||||||
|
$abs = $projectDir . '/public/' . $normalizedPath;
|
||||||
|
|
||||||
|
if (!is_file($abs)) {
|
||||||
|
$this->log('Resolved model but file missing on FS, skip', [
|
||||||
|
'path' => $normalizedPath,
|
||||||
|
'abs' => $abs,
|
||||||
]);
|
]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user