allFiles('cms'); } catch (Throwable) { return; } sort($files); foreach ($files as $path) { if (! $this->isImage($path) || WebsiteMediaAlias::query()->where('legacy_path', $path)->exists()) { continue; } $bytes = $public->get($path); if (! is_string($bytes) || $bytes === '') { continue; } $hash = hash('sha256', $bytes); $twin = WebsiteMediaAlias::query()->where('sha256', $hash)->first(); if ($twin instanceof WebsiteMediaAlias) { WebsiteMediaAlias::query()->create(['legacy_path' => $path, 'content_element_id' => $twin->content_element_id, 'sha256' => $hash]); continue; } Storage::disk('cms_incoming')->put($path, $bytes); $element = $intake->acceptImage($path, self::titleFor($path)); WebsiteMediaAlias::query()->create(['legacy_path' => $path, 'content_element_id' => $element->id, 'sha256' => $hash]); } } /** „cms/platzhalter-karte-1-liyjqa.jpg“ → „Platzhalter Karte 1“ (ohne die angehängte Zufallskennung). */ public static function titleFor(string $path): string { $name = pathinfo($path, PATHINFO_FILENAME); $name = preg_replace('/-[a-z0-9]{6}$/', '', $name) ?? $name; $title = trim(str_replace(['-', '_'], ' ', $name)); return $title === '' ? 'Website-Bild' : Str::title($title); } private function isImage(string $path): bool { return str_starts_with($path, 'cms/') && ! str_contains($path, '..') && preg_match('#^cms/[A-Za-z0-9._\-/]+$#', $path) === 1 && in_array(strtolower(pathinfo($path, PATHINFO_EXTENSION)), self::EXTENSIONS, true); } }