From 99081284a47b7b79df99d75578741334fb737a9d Mon Sep 17 00:00:00 2001 From: nexxo Date: Sat, 25 Jul 2026 15:04:27 +0200 Subject: [PATCH] fix(portal): delete old logo only after the branding update commits Co-Authored-By: Claude Opus 4.8 --- app/Livewire/Settings.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/Livewire/Settings.php b/app/Livewire/Settings.php index d594526..7de9a26 100644 --- a/app/Livewire/Settings.php +++ b/app/Livewire/Settings.php @@ -102,14 +102,13 @@ class Settings extends Component 'logo' => 'nullable|image|mimes:png,webp|max:2048', ]); + // Store the new upload, but keep the old file until the DB row that + // references it is updated — delete the old one only after that commits, + // so a failed update never orphans a file or dangles a reference. + $oldToDelete = null; if ($this->logo !== null) { - // Store the new file FIRST; only drop the old one once the write - // succeeded, so a failed upload never leaves a dangling reference. - $old = $this->brandLogoPath; + $oldToDelete = $this->brandLogoPath; $this->brandLogoPath = $this->logo->store('branding', 'public'); - if ($old !== null && $old !== $this->brandLogoPath) { - Storage::disk('public')->delete($old); - } $this->logo = null; } @@ -120,6 +119,10 @@ class Settings extends Component 'brand_logo_path' => $this->brandLogoPath, ]); + if ($oldToDelete !== null && $oldToDelete !== $this->brandLogoPath) { + Storage::disk('public')->delete($oldToDelete); + } + $this->dispatch('notify', message: __('settings.branding_saved')); }