diff --git a/MEMORY.md b/MEMORY.md index c9340030..5bfb521f 100644 --- a/MEMORY.md +++ b/MEMORY.md @@ -148,5 +148,15 @@ php artisan config:clear - Richiama `window.calendar.refetchEvents()` per aggiornare la vista FullCalendar - Esposto `window.calendar` globalmente per accesso dall'handler sync +## 2026-06-08 — Fix logo non visibile su installazione remota + +**Problema**: Il logo uploadato non veniva visualizzato su installazioni remote, pur salvandosi correttamente su disco. + +**Root cause**: `getLogoPath()` e `getLogoSmallPath()` in `AppSetting.php` usavano `file_exists(public_path('storage/' . $path))` per verificare l'esistenza del file prima di restituire l'URL. Questo controllo dipendeva dal symlink `public/storage → storage/app/public`. Su installazioni remote dove il symlink era assente o mal configurato, `file_exists` restituiva `false` → metodo restituiva `null` → logo non mostrato. + +**Fix**: +1. **`app/Models/AppSetting.php`**: Sostituito `file_exists(public_path('storage/' . $path))` con `Storage::disk('public')->exists($path)` e `asset('storage/' . $path)` con `Storage::disk('public')->url($path)`. Il controllo ora avviene direttamente su `storage/app/public/` (disk root), bypassando il symlink. +2. **`app/Http/Controllers/ImpostazioniController.php`**: In `uploadLogo()`, aggiunta creazione automatica del symlink `public/storage → storage/app/public` se mancante, per garantire che il browser possa servire l'immagine. + ## Prossimi Passi - *(nessuno — in attesa di nuove richieste)* diff --git a/app/Http/Controllers/ImpostazioniController.php b/app/Http/Controllers/ImpostazioniController.php index cb685ff0..02f6f01c 100644 --- a/app/Http/Controllers/ImpostazioniController.php +++ b/app/Http/Controllers/ImpostazioniController.php @@ -398,6 +398,15 @@ class ImpostazioniController extends Controller $settings->save(); } + $linkPath = public_path('storage'); + if (!file_exists($linkPath) && !is_link($linkPath)) { + try { + symlink(storage_path('app/public'), $linkPath); + } catch (\Throwable $e) { + Log::warning('Impossibile creare symlink storage: ' . $e->getMessage()); + } + } + return redirect('/impostazioni#logo')->with('success', 'Logo caricato con successo.'); } diff --git a/app/Models/AppSetting.php b/app/Models/AppSetting.php index cc007014..4c39d9c2 100644 --- a/app/Models/AppSetting.php +++ b/app/Models/AppSetting.php @@ -5,7 +5,9 @@ declare(strict_types=1); namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Schema; +use Illuminate\Support\Facades\Storage; class AppSetting extends Model { @@ -107,38 +109,38 @@ class AppSetting extends Model public function getLogoUrlInstance(): ?string { - if ($this->logo && file_exists(public_path('storage/' . $this->logo))) { - return asset('storage/' . $this->logo); + if ($this->logo && Storage::disk('public')->exists($this->logo)) { + return Storage::disk('public')->url($this->logo); } return null; } public function getLogoSmallUrlInstance(): ?string { - if ($this->logo_small && file_exists(public_path('storage/' . $this->logo_small))) { - return asset('storage/' . $this->logo_small); + if ($this->logo_small && Storage::disk('public')->exists($this->logo_small)) { + return Storage::disk('public')->url($this->logo_small); } return null; } public function getLogoPath(): ?string { - if ($this->logo_path && file_exists(public_path('storage/' . $this->logo_path))) { - return asset('storage/' . $this->logo_path); + if ($this->logo_path && Storage::disk('public')->exists($this->logo_path)) { + return Storage::disk('public')->url($this->logo_path); } - if ($this->logo && file_exists(public_path('storage/' . $this->logo))) { - return asset('storage/' . $this->logo); + if ($this->logo && Storage::disk('public')->exists($this->logo)) { + return Storage::disk('public')->url($this->logo); } return null; } public function getLogoSmallPath(): ?string { - if ($this->logo_small_path && file_exists(public_path('storage/' . $this->logo_small_path))) { - return asset('storage/' . $this->logo_small_path); + if ($this->logo_small_path && Storage::disk('public')->exists($this->logo_small_path)) { + return Storage::disk('public')->url($this->logo_small_path); } - if ($this->logo_small && file_exists(public_path('storage/' . $this->logo_small))) { - return asset('storage/' . $this->logo_small); + if ($this->logo_small && Storage::disk('public')->exists($this->logo_small)) { + return Storage::disk('public')->url($this->logo_small); } return null; }