From e4741bb9110688bcc19c3add514d0e536b094d39 Mon Sep 17 00:00:00 2001 From: Lloric Mayuga Garcia Date: Mon, 30 Oct 2023 23:50:41 +0800 Subject: [PATCH] Fix undefind SIGINT by using artican to call spatie backup. (#55) --- src/Enums/Option.php | 10 +++++++++ src/Jobs/CreateBackupJob.php | 39 ++++++++++++++---------------------- src/Pages/Backups.php | 3 ++- 3 files changed, 27 insertions(+), 25 deletions(-) create mode 100644 src/Enums/Option.php diff --git a/src/Enums/Option.php b/src/Enums/Option.php new file mode 100644 index 0000000..a1c031a --- /dev/null +++ b/src/Enums/Option.php @@ -0,0 +1,10 @@ +option = $option; - } + public function __construct( + protected readonly Option $option = Option::ALL + ){} public function handle(): void { - $backupJob = BackupJobFactory::createFromArray(config('backup')); - - if ($this->option === 'only-db') { - $backupJob->dontBackupFilesystem(); - } - - if ($this->option === 'only-files') { - $backupJob->dontBackupDatabases(); - } - - if (! empty($this->option)) { - $prefix = str_replace('_', '-', $this->option) . '-'; - - $backupJob->setFilename($prefix . date('Y-m-d-H-i-s') . '.zip'); - } - - $backupJob->run(); + Artisan::call(BackupCommand::class, [ + '--only-db' => $this->option === Option::ONLY_DB, + '--only-files' => $this->option === Option::ONLY_FILES, + '--filename' => match ($this->option) { + Option::ALL => null, + default => str_replace('_', '-', $this->option->value). + '-'.date('Y-m-d-H-i-s').'.zip' + }, + ]); } } diff --git a/src/Pages/Backups.php b/src/Pages/Backups.php index 1e248ed..e728d63 100644 --- a/src/Pages/Backups.php +++ b/src/Pages/Backups.php @@ -6,6 +6,7 @@ use Filament\Notifications\Notification; use Filament\Pages\Page; use Illuminate\Contracts\Support\Htmlable; +use ShuvroRoy\FilamentSpatieLaravelBackup\Enums\Option; use ShuvroRoy\FilamentSpatieLaravelBackup\FilamentSpatieLaravelBackupPlugin; use ShuvroRoy\FilamentSpatieLaravelBackup\Jobs\CreateBackupJob; @@ -50,7 +51,7 @@ public function create(string $option = ''): void /** @var FilamentSpatieLaravelBackupPlugin $plugin */ $plugin = filament()->getPlugin('filament-spatie-backup'); - dispatch(new CreateBackupJob($option)) + CreateBackupJob::dispatch(Option::from($option)) ->onQueue($plugin->getQueue()) ->afterResponse();