mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-09-02 13:21:02 +00:00
* refactor: stabilize model identities for domain migration * refactor: extract module platform context * refactor: assign models to domain contexts * refactor: extract ai platform context * refactor: extract storage platform context * refactor: extract mail platform context * refactor: extract pdf platform context * refactor: extract operations platform context * refactor: move installation into operations platform * refactor: extract money domain context * refactor: extract taxation domain context * refactor: extract catalog domain context * refactor: extract metadata domain context * refactor: extract reporting domain context * refactor: extract purchases domain context * refactor: extract receivables domain context * refactor: extract accounts domain context * refactor: complete reporting statement boundary * refactor: extract contacts domain context * refactor: extract sales domain context * refactor: remove legacy application layers * fix: migrate legacy bouncer role identities
52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Platform\Storage\Application;
|
|
|
|
use App\Platform\Operations\Models\Setting;
|
|
use App\Platform\Storage\Models\FileDisk;
|
|
use Spatie\Backup\BackupDestination\BackupDestination;
|
|
|
|
class BackupService
|
|
{
|
|
public function __construct(
|
|
private readonly FileDiskService $fileDiskService,
|
|
) {}
|
|
|
|
/**
|
|
* Resolve the backup FileDisk from the given ID, settings, or default.
|
|
*/
|
|
public function resolveBackupDisk(?int $fileDiskId = null): ?FileDisk
|
|
{
|
|
if ($fileDiskId) {
|
|
$disk = FileDisk::find($fileDiskId);
|
|
if ($disk) {
|
|
return $disk;
|
|
}
|
|
}
|
|
|
|
$backupDiskId = Setting::getSetting('backup_disk_id');
|
|
if ($backupDiskId) {
|
|
$disk = FileDisk::find($backupDiskId);
|
|
if ($disk) {
|
|
return $disk;
|
|
}
|
|
}
|
|
|
|
return FileDisk::where('set_as_default', true)->first();
|
|
}
|
|
|
|
/**
|
|
* Create a BackupDestination pointing at the resolved disk.
|
|
*/
|
|
public function getDestination(?int $fileDiskId = null): BackupDestination
|
|
{
|
|
$disk = $this->resolveBackupDisk($fileDiskId);
|
|
|
|
$diskName = $disk
|
|
? $this->fileDiskService->registerDisk($disk)
|
|
: config('filesystems.default');
|
|
|
|
return BackupDestination::create($diskName, config('backup.backup.name'));
|
|
}
|
|
}
|