This commit is contained in:
Jürgen Mummert
2025-12-27 22:41:36 +01:00
parent c645e3caa8
commit e5cce34619
4 changed files with 239 additions and 185 deletions
+30 -38
View File
@@ -20,72 +20,64 @@ class MeilisearchImageHelper
*/
public function resolveImagePath(?string $uuid): ?string
{
error_log('--- MeiliImg START ---');
if (!$uuid) {
error_log('[MeiliImg] UUID leer → return null');
return null;
}
error_log('[MeiliImg] UUID = ' . $uuid);
// Contao-Framework initialisieren (CLI & Frontend)
$this->framework->initialize();
error_log('[MeiliImg] Framework initialized');
/** @var FilesModel|null $file */
$file = FilesModel::findByUuid($uuid);
if (!$file) {
error_log('[MeiliImg] FilesModel::findByUuid() = NULL');
try {
$this->framework->initialize();
} catch (\Throwable $e) {
error_log('[ContaoMeilisearch] ImageHelper: Framework init failed: ' . $e->getMessage());
return null;
}
error_log('[MeiliImg] FilesModel gefunden');
error_log('[MeiliImg] file->path = ' . $file->path);
error_log('[MeiliImg] file->uuid = ' . ($file->uuid ?? '(n/a)'));
/** @var FilesModel|null $file */
try {
$file = FilesModel::findByUuid($uuid);
} catch (\Throwable $e) {
error_log(
'[ContaoMeilisearch] ImageHelper: FilesModel lookup failed (' . $uuid . '): ' . $e->getMessage()
);
return null;
}
if (!$file) {
error_log('[ContaoMeilisearch] ImageHelper: File not found for UUID ' . $uuid);
return null;
}
// ImageSize aus tl_settings
$rawSize = Config::get('meilisearch_imagesize');
$imageSizeId = (int) $rawSize;
error_log('[MeiliImg] meilisearch_imagesize raw = ' . var_export($rawSize, true));
error_log('[MeiliImg] meilisearch_imagesize int = ' . $imageSizeId);
$imageSizeId = (int) Config::get('meilisearch_imagesize');
// Fallback: Originaldatei
if ($imageSizeId <= 0) {
error_log('[MeiliImg] imageSizeId <= 0 → FALLBACK file->path = ' . $file->path);
error_log('--- MeiliImg END ---');
return $file->path;
}
try {
$builder = $this->studio
$figure = $this->studio
->createFigureBuilder()
->from($file->path)
->setSize($imageSizeId);
error_log('[MeiliImg] FigureBuilder erstellt (from=' . $file->path . ', size=' . $imageSizeId . ')');
$figure = $builder->build();
error_log('[MeiliImg] Figure build() OK');
->setSize($imageSizeId)
->build();
$image = $figure->getImage();
if ($image === null) {
error_log('[MeiliImg] figure->getImage() = NULL');
error_log(
'[ContaoMeilisearch] ImageHelper: Image generation failed for ' . $file->path
);
return null;
}
$src = $image->getImageSrc();
error_log('[MeiliImg] image->getImageSrc() = ' . $src);
return $src ?: null;
return $image->getImageSrc() ?: null;
} catch (\Throwable $e) {
error_log('[MeiliImg] EXCEPTION ' . get_class($e) . ': ' . $e->getMessage());
error_log('--- MeiliImg END ---');
error_log(
'[ContaoMeilisearch] ImageHelper: Image processing failed for '
. $file->path . ': ' . $e->getMessage()
);
return null;
}
}