diff --git a/app/Livewire/Project/Database/BackupEdit.php b/app/Livewire/Project/Database/BackupEdit.php index a387b6f88..1c1bea2f6 100644 --- a/app/Livewire/Project/Database/BackupEdit.php +++ b/app/Livewire/Project/Database/BackupEdit.php @@ -131,7 +131,7 @@ public function syncData(bool $toModel = false) $this->databaseBackupRetentionMaxStorageS3 = $this->backup->database_backup_retention_max_storage_s3; $this->saveS3 = $this->backup->save_s3; $this->disableLocalBackup = $this->backup->disable_local_backup ?? false; - $this->s3StorageId = $this->backup->s3_storage_id; + $this->s3StorageId = $this->backup->s3_storage_id ?? $this->availableS3StorageIds()->first(); $this->databasesToBackup = $this->backup->databases_to_backup; $this->dumpAll = $this->backup->dump_all; $this->timeout = $this->backup->timeout; @@ -217,6 +217,11 @@ public function instantSave() } } + public function updatedS3StorageId(): void + { + $this->instantSave(); + } + private function customValidate() { if (! is_numeric($this->backup->s3_storage_id)) { @@ -225,17 +230,13 @@ private function customValidate() // S3 backup cannot be enabled without a valid S3 storage owned by the team $availableS3Ids = $this->availableS3StorageIds(); - if ($this->backup->save_s3 && ! $availableS3Ids->contains($this->backup->s3_storage_id)) { - if ($availableS3Ids->isEmpty()) { - $this->backup->s3_storage_id = $this->s3StorageId = null; + if ($availableS3Ids->isEmpty()) { + $this->backup->s3_storage_id = $this->s3StorageId = null; + if ($this->backup->save_s3) { $this->backup->save_s3 = $this->saveS3 = false; - } elseif ($this->backup->s3_storage_id === null && $availableS3Ids->count() === 1) { - $this->backup->s3_storage_id = $this->s3StorageId = $availableS3Ids->first(); - } else { - $this->backup->s3_storage_id = $this->s3StorageId = null; - - throw new Exception('Please select a valid S3 storage to enable S3 backups.'); } + } elseif (! $availableS3Ids->contains($this->backup->s3_storage_id)) { + $this->backup->s3_storage_id = $this->s3StorageId = $availableS3Ids->first(); } // Validate that disable_local_backup can only be true when S3 backup is enabled @@ -254,9 +255,14 @@ private function availableS3StorageIds(): Collection { $storages = collect($this->availableS3Storages); $storageIds = $storages->pluck('id')->filter()->all(); + + if (empty($storageIds)) { + return collect(); + } + $teamIds = $storages->pluck('team_id')->reject(fn ($teamId) => $teamId === null)->unique()->values()->all(); - if (empty($storageIds) || empty($teamIds)) { + if (empty($teamIds)) { return collect(); } diff --git a/resources/views/components/modal-confirmation.blade.php b/resources/views/components/modal-confirmation.blade.php index a25e0141f..5efc9102b 100644 --- a/resources/views/components/modal-confirmation.blade.php +++ b/resources/views/components/modal-confirmation.blade.php @@ -132,10 +132,10 @@ @class([ 'relative h-auto', 'w-full' => $buttonFullWidth, - 'w-auto' => ! $buttonFullWidth, + 'w-full sm:w-auto' => ! $buttonFullWidth, ])> @if (isset($trigger)) -