Saisonfotos am Foto statt am Erscheinungsbild
Ein Foto gehoert zu keinem (ganzjaehrig) oder mehreren Erscheinungsbildern und erscheint nur dort, vor den ganzjaehrigen Fotos. Bausteine waehlen "automatisch" oder eine eigene Auswahl; Titelbereich und Abschluss zeigen das erste passende Foto ihrer Liste. Titelbild und "Bilder je Baustein" des Erscheinungsbilds werden in die Bausteine uebernommen und entfallen dort. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d02f3e05c7
commit
791786ed3e
21 files changed
+449
-235
No files matched your search
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Seasonal photos move from the appearance to the photo: a photo lists the appearances it belongs to
|
||||
* (none = all year). Title photos and "Bilder je Baustein" of an appearance become chosen photos of the
|
||||
* sections, tagged with that appearance (the default appearance's photos stay all-year). Hero and closing
|
||||
* sections now hold a list of photos (photo_ids); the first one fitting the season is shown.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('photos', function (Blueprint $table) {
|
||||
$table->json('appearance_ids')->nullable()->after('category');
|
||||
});
|
||||
|
||||
$pages = DB::table('pages')->get(['id', 'site_id', 'sections'])
|
||||
->map(fn (object $page): object => (object) ['id' => $page->id, 'site_id' => $page->site_id, 'sections' => json_decode((string) $page->sections, true) ?: []]);
|
||||
$tags = [];
|
||||
|
||||
foreach (DB::table('appearances')->get() as $appearance) {
|
||||
$sitePages = $pages->where('site_id', $appearance->site_id);
|
||||
$seasonal = ! $appearance->is_default;
|
||||
|
||||
if ($appearance->hero_photo_id !== null) {
|
||||
if ($seasonal) {
|
||||
$tags[$appearance->hero_photo_id][] = $appearance->id;
|
||||
}
|
||||
foreach ($sitePages as $page) {
|
||||
foreach ($page->sections as $index => $section) {
|
||||
if (($section['type'] ?? null) === 'hero') {
|
||||
$page->sections[$index]['data']['photo_ids'] = $this->prepend([$appearance->hero_photo_id], $section['data']['photo_ids'] ?? []);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (json_decode((string) $appearance->section_photos, true) ?: [] as $sectionId => $slots) {
|
||||
$ids = collect($slots)->except('mode')->flatten()->filter()->map(fn ($id): int => (int) $id)->all();
|
||||
foreach ($seasonal ? $ids : [] as $id) {
|
||||
$tags[$id][] = $appearance->id;
|
||||
}
|
||||
|
||||
foreach ($sitePages as $page) {
|
||||
foreach ($page->sections as $index => $section) {
|
||||
if (($section['data']['id'] ?? null) === $sectionId && in_array($section['type'] ?? null, ['hero', 'cta', 'text_image'], true)) {
|
||||
$page->sections[$index]['data']['photo_ids'] = $this->prepend($ids, $section['data']['photo_ids'] ?? []);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($pages as $page) {
|
||||
foreach ($page->sections as $index => $section) {
|
||||
if (in_array($section['type'] ?? null, ['hero', 'cta'], true) && array_key_exists('photo_id', $section['data'] ?? [])) {
|
||||
$legacy = $section['data']['photo_id'];
|
||||
unset($page->sections[$index]['data']['photo_id']);
|
||||
$page->sections[$index]['data']['photo_ids'] = array_values(array_unique([...($page->sections[$index]['data']['photo_ids'] ?? []), ...array_filter([(int) $legacy])]));
|
||||
}
|
||||
}
|
||||
DB::table('pages')->where('id', $page->id)->update(['sections' => json_encode($page->sections)]);
|
||||
}
|
||||
|
||||
foreach ($tags as $photoId => $appearanceIds) {
|
||||
DB::table('photos')->where('id', $photoId)->update(['appearance_ids' => json_encode(array_values(array_unique($appearanceIds)))]);
|
||||
}
|
||||
|
||||
Schema::table('appearances', function (Blueprint $table) {
|
||||
$table->dropConstrainedForeignId('hero_photo_id');
|
||||
$table->dropColumn('section_photos');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('appearances', function (Blueprint $table) {
|
||||
$table->foreignId('hero_photo_id')->nullable()->constrained('photos')->nullOnDelete();
|
||||
$table->json('section_photos')->nullable()->after('hero_photo_id');
|
||||
});
|
||||
|
||||
Schema::table('photos', function (Blueprint $table) {
|
||||
$table->dropColumn('appearance_ids');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $first
|
||||
* @param list<int|string> $rest
|
||||
* @return list<int>
|
||||
*/
|
||||
private function prepend(array $first, array $rest): array
|
||||
{
|
||||
return array_values(array_unique(array_map('intval', [...$first, ...$rest])));
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user