From 3429f37a373d32b16ba2f26f13d08ff05620fe81 Mon Sep 17 00:00:00 2001 From: stevan Date: Wed, 13 Aug 2025 16:41:07 +0200 Subject: [PATCH] Fix issue RSS use old theme ids --- app/Console/Commands/api/GermanTraits.php | 31 ++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/api/GermanTraits.php b/app/Console/Commands/api/GermanTraits.php index 47183fd28..696fc5e27 100644 --- a/app/Console/Commands/api/GermanTraits.php +++ b/app/Console/Commands/api/GermanTraits.php @@ -4,6 +4,7 @@ use App\Event; use App\Tag; +use App\Theme; use App\User; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Log; @@ -134,7 +135,10 @@ private function createGermanEvent($city): void $event->audiences()->attach(explode(',', $this->audience)); } if ($this->themes) { - $event->themes()->attach(explode(',', $this->themes)); + $validThemeIds = $this->validateThemes($this->themes); + if (count($validThemeIds) > 0 ) { + $event->themes()->attach($validThemeIds); + } } if ($this->tags) { @@ -151,5 +155,30 @@ private function createGermanEvent($city): void $event->tags()->sync($tagsArray); } } + + protected function validateThemes(string $input): array + { + if (empty($input)) { + return []; + } + + $themeIds = array_unique(array_filter(array_map('trim', explode(',', $input)))); + + // Mapping deleted old id to new id group + $themeIdMapping = [ + 7 => 6, + 10 => 9, + 12 => 1, + 15 => 16, + ]; + + $mappedThemeIds = array_map(function ($id) use ($themeIdMapping) { + return $themeIdMapping[$id] ?? $id; + }, $themeIds); + + $validThemeIds = Theme::whereIn('id', $mappedThemeIds)->pluck('id')->toArray(); + + return $validThemeIds; + } }