From f0651498313fd1ce589e636ec3652ee01a470d8b Mon Sep 17 00:00:00 2001 From: michele Date: Tue, 14 Apr 2026 22:03:02 +0000 Subject: [PATCH] Align supplier archive paths with local disk root --- .../Commands/ProvisionFornitoriArchives.php | 8 ++--- .../Pages/Fornitore/ImpostazioniArchivio.php | 36 +++++++++++-------- app/Services/TenantArchivePathService.php | 9 ++--- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/app/Console/Commands/ProvisionFornitoriArchives.php b/app/Console/Commands/ProvisionFornitoriArchives.php index fc3ae61..036bc4a 100644 --- a/app/Console/Commands/ProvisionFornitoriArchives.php +++ b/app/Console/Commands/ProvisionFornitoriArchives.php @@ -53,9 +53,9 @@ public function handle(): int continue; } - $before = Storage::disk('local')->exists($canonicalBase); + $before = Storage::disk('local')->directoryExists($canonicalBase); $fornitore->ensureArchiveStructure(); - $after = Storage::disk('local')->exists($canonicalBase); + $after = Storage::disk('local')->directoryExists($canonicalBase); if (! $before && $after) { $created++; @@ -63,13 +63,13 @@ public function handle(): int $message = '#'. (int) $fornitore->id . ' ' . trim((string) ($fornitore->ragione_sociale ?: ('Fornitore ' . $fornitore->id))) - . ' -> ' . storage_path('app/' . $canonicalBase) + . ' -> ' . Storage::disk('local')->path($canonicalBase) . ' [' . ($after ? ($before ? 'gia_esistente' : 'creata') : 'non_creata') . ']'; $this->line($message); if ($this->option('legacy-too') && is_string($legacyBase) && $legacyBase !== '') { - $this->line(' legacy: ' . storage_path('app/' . $legacyBase) . ' [' . (Storage::disk('local')->exists($legacyBase) ? 'presente' : 'assente') . ']'); + $this->line(' legacy: ' . Storage::disk('local')->path($legacyBase) . ' [' . (Storage::disk('local')->directoryExists($legacyBase) ? 'presente' : 'assente') . ']'); } } }); diff --git a/app/Filament/Pages/Fornitore/ImpostazioniArchivio.php b/app/Filament/Pages/Fornitore/ImpostazioniArchivio.php index 2b274d1..2fedd0f 100644 --- a/app/Filament/Pages/Fornitore/ImpostazioniArchivio.php +++ b/app/Filament/Pages/Fornitore/ImpostazioniArchivio.php @@ -119,7 +119,7 @@ public function saveUploadedTecnoRepairMdb(): void $filename = 'TecnoRepairDB-' . now()->format('Ymd-His') . '.mdb'; $stored = $upload->storeAs($relativeBase . '/tecnorepair/imports', $filename, 'local'); - $this->tecnorepairMdbPath = storage_path('app/' . $stored); + $this->tecnorepairMdbPath = Storage::disk('local')->path($stored); $this->tecnorepairMdbUpload = null; $this->refreshArchiveSummary(); @@ -353,9 +353,9 @@ public function saveOperationalWorkflow(): void private function refreshArchiveSummary(): void { $relativeBase = $this->getArchiveRelativeBase(); - $absoluteBase = $relativeBase ? storage_path('app/' . $relativeBase) : null; + $absoluteBase = $relativeBase ? Storage::disk('local')->path($relativeBase) : null; $legacyRelativeBase = $this->getLegacyArchiveRelativeBase(); - $legacyAbsoluteBase = $legacyRelativeBase ? storage_path('app/' . $legacyRelativeBase) : null; + $legacyAbsoluteBase = $legacyRelativeBase ? Storage::disk('local')->path($legacyRelativeBase) : null; $this->operationalConfigAvailable = Schema::hasColumn('fornitori', 'operational_config'); if ($this->fornitore instanceof Fornitore) { @@ -364,17 +364,17 @@ private function refreshArchiveSummary(): void $this->archiveFolders = $relativeBase === null ? [] : [ ['label' => 'Base archivio', 'path' => (string) $absoluteBase], - ['label' => 'Rubrica fornitore', 'path' => storage_path('app/' . $relativeBase . '/rubrica')], - ['label' => 'FE fornitore', 'path' => storage_path('app/' . $relativeBase . '/fe')], - ['label' => 'Prodotti e catalogo', 'path' => storage_path('app/' . $relativeBase . '/prodotti')], - ['label' => 'Comunicazioni / Post-it', 'path' => storage_path('app/' . $relativeBase . '/comunicazioni')], - ['label' => 'TecnoRepair import', 'path' => storage_path('app/' . $relativeBase . '/tecnorepair/imports')], - ['label' => 'Archivio per anno', 'path' => storage_path('app/' . $relativeBase . '/documenti/archivio_per_anno')], + ['label' => 'Rubrica fornitore', 'path' => Storage::disk('local')->path($relativeBase . '/rubrica')], + ['label' => 'FE fornitore', 'path' => Storage::disk('local')->path($relativeBase . '/fe')], + ['label' => 'Prodotti e catalogo', 'path' => Storage::disk('local')->path($relativeBase . '/prodotti')], + ['label' => 'Comunicazioni / Post-it', 'path' => Storage::disk('local')->path($relativeBase . '/comunicazioni')], + ['label' => 'TecnoRepair import', 'path' => Storage::disk('local')->path($relativeBase . '/tecnorepair/imports')], + ['label' => 'Archivio per anno', 'path' => Storage::disk('local')->path($relativeBase . '/documenti/archivio_per_anno')], ]; if (is_string($legacyAbsoluteBase) && $legacyAbsoluteBase !== '' && $legacyAbsoluteBase !== $absoluteBase && is_dir($legacyAbsoluteBase)) { $this->archiveFolders[] = ['label' => 'Base archivio legacy', 'path' => $legacyAbsoluteBase]; - $this->archiveFolders[] = ['label' => 'TecnoRepair import legacy', 'path' => storage_path('app/' . $legacyRelativeBase . '/tecnorepair/imports')]; + $this->archiveFolders[] = ['label' => 'TecnoRepair import legacy', 'path' => Storage::disk('local')->path($legacyRelativeBase . '/tecnorepair/imports')]; } $currentMdbPath = $this->resolveTecnoRepairMdbPath($this->tecnorepairMdbPath); @@ -575,6 +575,7 @@ private function resolveTecnoRepairMdbPath(?string $rawPath): ?string return null; } + $diskRoot = str_replace('\\', '/', Storage::disk('local')->path('')); $storageBase = str_replace('\\', '/', storage_path('app')); $normalizedInput = str_replace('\\', '/', $path); $candidatePaths = []; @@ -583,23 +584,30 @@ private function resolveTecnoRepairMdbPath(?string $rawPath): ?string $candidatePaths[] = $path; } + if (str_starts_with($normalizedInput, rtrim($diskRoot, '/') . '/')) { + $relative = ltrim(substr($normalizedInput, strlen(rtrim($diskRoot, '/'))), '/'); + if ($relative !== '' && Storage::disk('local')->exists($relative)) { + $candidatePaths[] = Storage::disk('local')->path($relative); + } + } + if (str_starts_with($normalizedInput, $storageBase . '/')) { $relative = ltrim(substr($normalizedInput, strlen($storageBase)), '/'); if ($relative !== '' && Storage::disk('local')->exists($relative)) { - $candidatePaths[] = storage_path('app/' . $relative); + $candidatePaths[] = Storage::disk('local')->path($relative); } } if (! str_starts_with($normalizedInput, '/')) { $relative = ltrim($normalizedInput, '/'); if (Storage::disk('local')->exists($relative)) { - $candidatePaths[] = storage_path('app/' . $relative); + $candidatePaths[] = Storage::disk('local')->path($relative); } foreach ($this->getTecnoRepairImportBases() as $importBase) { $joined = trim($importBase . '/' . $relative, '/'); if (Storage::disk('local')->exists($joined)) { - $candidatePaths[] = storage_path('app/' . $joined); + $candidatePaths[] = Storage::disk('local')->path($joined); } } } @@ -627,7 +635,7 @@ private function discoverLatestTecnoRepairMdbPath(): ?string ->first(); if (is_string($latest) && $latest !== '') { - return storage_path('app/' . $latest); + return Storage::disk('local')->path($latest); } } diff --git a/app/Services/TenantArchivePathService.php b/app/Services/TenantArchivePathService.php index 4cee8cc..0ffc4ad 100644 --- a/app/Services/TenantArchivePathService.php +++ b/app/Services/TenantArchivePathService.php @@ -5,6 +5,7 @@ use App\Models\Fornitore; use App\Models\Stabile; use InvalidArgumentException; +use Illuminate\Support\Facades\Storage; class TenantArchivePathService { @@ -59,7 +60,7 @@ public function amministratoreRelativePath(Amministratore | string $amministrato public function amministratoreAbsolutePath(Amministratore | string $amministratore, ?string $suffix = null): string { - return storage_path('app/' . $this->amministratoreRelativePath($amministratore, $suffix)); + return Storage::disk('local')->path($this->amministratoreRelativePath($amministratore, $suffix)); } public function stabileRelativePath(Stabile $stabile, ?string $suffix = null): string @@ -71,7 +72,7 @@ public function stabileRelativePath(Stabile $stabile, ?string $suffix = null): s public function stabileAbsolutePath(Stabile $stabile, ?string $suffix = null): string { - return storage_path('app/' . $this->stabileRelativePath($stabile, $suffix)); + return Storage::disk('local')->path($this->stabileRelativePath($stabile, $suffix)); } public function fornitoreCode(Fornitore | string $fornitore): string @@ -104,7 +105,7 @@ public function fornitoreRelativePath(Fornitore | string $fornitore, ?string $su public function fornitoreAbsolutePath(Fornitore | string $fornitore, ?string $suffix = null): string { - return storage_path('app/' . $this->fornitoreRelativePath($fornitore, $suffix)); + return Storage::disk('local')->path($this->fornitoreRelativePath($fornitore, $suffix)); } public function fornitoreLegacyRelativePath(Fornitore $fornitore, ?string $suffix = null): string @@ -116,7 +117,7 @@ public function fornitoreLegacyRelativePath(Fornitore $fornitore, ?string $suffi public function fornitoreLegacyAbsolutePath(Fornitore $fornitore, ?string $suffix = null): string { - return storage_path('app/' . $this->fornitoreLegacyRelativePath($fornitore, $suffix)); + return Storage::disk('local')->path($this->fornitoreLegacyRelativePath($fornitore, $suffix)); } private function appendSuffix(string $basePath, ?string $suffix): string