mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-15 09:14:08 +00:00
Refactor FileDisk system with per-disk unique names and disk assignments UI
Major changes to the file disk subsystem:
- Each FileDisk now gets a unique Laravel disk name (disk_{id}) instead
of temp_{driver}, fixing the bug where multiple local disks with
different roots overwrote each other's config.
- Move disk registration logic from FileDisk model to FileDiskService
(registerDisk, getDiskName). Model keeps only getDecodedCredentials
and a deprecated setConfig() wrapper.
- Add Disk Assignments admin UI (File Disk tab) with three purpose
dropdowns: Media Storage, PDF Storage, Backup Storage. Stored as
settings (media_disk_id, pdf_disk_id, backup_disk_id).
- Backup tab now uses the assigned backup disk instead of a per-backup
dropdown. BackupsController refactored to use BackupService which
centralizes disk resolution. Removed stale 4-second cache.
- Add local_public disk to config/filesystems.php so system disks
are properly defined.
- Local disk roots stored relative to storage/app/ with hint text
in the admin modal explaining the convention.
- Fix BaseModal watchEffect -> watch to prevent infinite request
loops on the File Disk page.
- Fix string/number comparison for disk purpose IDs from settings.
- Add safeguards: prevent deleting disks with files, warn on
purpose change, prevent deleting system disks.
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Providers;
|
||||
|
||||
use App\Models\FileDisk;
|
||||
use App\Models\Setting;
|
||||
use App\Services\FileDiskService;
|
||||
use App\Services\Setup\InstallUtils;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
@@ -163,28 +164,16 @@ class AppConfigProvider extends ServiceProvider
|
||||
protected function configureFileSystemFromDatabase(): void
|
||||
{
|
||||
try {
|
||||
// Register the default file disk config without changing filesystems.default.
|
||||
// Calling setConfig() mutates the global default which causes side effects
|
||||
// on pages that make multiple API requests (e.g., File Disk admin page).
|
||||
$fileDisk = FileDisk::whereSetAsDefault(true)->first();
|
||||
|
||||
if ($fileDisk) {
|
||||
$prefix = env('DYNAMIC_DISK_PREFIX', 'temp_');
|
||||
$diskName = $prefix.$fileDisk->driver;
|
||||
$credentials = collect(json_decode($fileDisk->credentials));
|
||||
$baseConfig = config('filesystems.disks.'.$fileDisk->driver, []);
|
||||
|
||||
foreach ($baseConfig as $key => $value) {
|
||||
if ($credentials->has($key)) {
|
||||
$baseConfig[$key] = $credentials[$key];
|
||||
}
|
||||
}
|
||||
|
||||
config(['filesystems.disks.'.$diskName => $baseConfig]);
|
||||
|
||||
// Point Spatie Media Library at the same disk
|
||||
config(['media-library.disk_name' => $diskName]);
|
||||
if (! $fileDisk) {
|
||||
return;
|
||||
}
|
||||
|
||||
$diskName = app(FileDiskService::class)->registerDisk($fileDisk);
|
||||
|
||||
// Point Spatie Media Library at the resolved disk
|
||||
config(['media-library.disk_name' => $diskName]);
|
||||
} catch (\Exception $e) {
|
||||
// Silently fail if database is not available (during installation, migrations, etc.)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user