fix(portal): delete old logo only after the branding update commits
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>feat/portal-design
parent
f6efa4f200
commit
99081284a4
|
|
@ -102,14 +102,13 @@ class Settings extends Component
|
||||||
'logo' => 'nullable|image|mimes:png,webp|max:2048',
|
'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) {
|
if ($this->logo !== null) {
|
||||||
// Store the new file FIRST; only drop the old one once the write
|
$oldToDelete = $this->brandLogoPath;
|
||||||
// succeeded, so a failed upload never leaves a dangling reference.
|
|
||||||
$old = $this->brandLogoPath;
|
|
||||||
$this->brandLogoPath = $this->logo->store('branding', 'public');
|
$this->brandLogoPath = $this->logo->store('branding', 'public');
|
||||||
if ($old !== null && $old !== $this->brandLogoPath) {
|
|
||||||
Storage::disk('public')->delete($old);
|
|
||||||
}
|
|
||||||
$this->logo = null;
|
$this->logo = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,6 +119,10 @@ class Settings extends Component
|
||||||
'brand_logo_path' => $this->brandLogoPath,
|
'brand_logo_path' => $this->brandLogoPath,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($oldToDelete !== null && $oldToDelete !== $this->brandLogoPath) {
|
||||||
|
Storage::disk('public')->delete($oldToDelete);
|
||||||
|
}
|
||||||
|
|
||||||
$this->dispatch('notify', message: __('settings.branding_saved'));
|
$this->dispatch('notify', message: __('settings.branding_saved'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue