fix(portal): delete old logo only after the branding update commits

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
feat/portal-design
nexxo 2026-07-25 15:04:27 +02:00
parent f6efa4f200
commit 99081284a4
1 changed files with 9 additions and 6 deletions

View File

@ -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'));
}