diff --git a/database/migrations/shop/2026_02_09_070000_fix_logo_url_in_mail_templates.php b/database/migrations/shop/2026_02_09_070000_fix_logo_url_in_mail_templates.php new file mode 100644 index 00000000..3d8d1b03 --- /dev/null +++ b/database/migrations/shop/2026_02_09_070000_fix_logo_url_in_mail_templates.php @@ -0,0 +1,56 @@ +replaceLogoInAllTemplates($this->oldSrc, $this->newSrc); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + $this->replaceLogoInAllTemplates($this->newSrc, $this->oldSrc); + } + + private function replaceLogoInAllTemplates(string $from, string $to): void + { + $templates = DB::table('mail_templates')->get(); + + foreach ($templates as $template) { + $translations = json_decode($template->html_template, true); + + if (! $translations) { + continue; + } + + $changed = false; + + foreach ($translations as $lang => $html) { + $updated = str_replace($from, $to, $html); + if ($updated !== $html) { + $translations[$lang] = $updated; + $changed = true; + } + } + + if ($changed) { + DB::table('mail_templates') + ->where('id', $template->id) + ->update(['html_template' => json_encode($translations, JSON_UNESCAPED_UNICODE)]); + } + } + } +};