Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

confirm backup and delete all backups of the job

ayntk-ai38845d7eb004
diff --git a/app/Livewire/Project/Database/BackupEdit.php b/app/Livewire/Project/Database/BackupEdit.php
index 59f2f9a399..35ca2c7ecd 100644
--- a/app/Livewire/Project/Database/BackupEdit.php
+++ b/app/Livewire/Project/Database/BackupEdit.php
@@ -5,6 +5,8 @@ namespace App\Livewire\Project\Database;
use App\Models\ScheduledDatabaseBackup;
use Livewire\Component;
use Spatie\Url\Url;
+use Illuminate\Support\Facades\Hash;
+use Illuminate\Support\Facades\Auth;
class BackupEdit extends Component
{
@@ -12,6 +14,8 @@ class BackupEdit extends Component
public $s3s;
+ public bool $delete_associated_backups = false;
+
public ?string $status = null;
public array $parameters;
@@ -46,16 +50,26 @@ class BackupEdit extends Component
}
}
- public function delete()
+ public function delete($password)
{
+ if (!Hash::check($password, Auth::user()->password)) {
+ $this->addError('password', 'The provided password is incorrect.');
+ return;
+ }
+
try {
+ if ($this->delete_associated_backups) {
+ $this->deleteAllBackups();
+ }
+
$this->backup->delete();
+
if ($this->backup->database->getMorphClass() === 'App\Models\ServiceDatabase') {
$previousUrl = url()->previous();
$url = Url::fromString($previousUrl);
$url = $url->withoutQueryParameter('selectedBackupId');
$url = $url->withFragment('backups');
- $url = $url->getPath()."#{$url->getFragment()}";
+ $url = $url->getPath() . "#{$url->getFragment()}";
return redirect($url);
} else {
@@ -104,4 +118,28 @@ class BackupEdit extends Component
$this->dispatch('error', $e->getMessage());
}
}
+
+ public function deleteAllBackups()
+ {
+ $executions = $this->backup->executions;
+
+ foreach ($executions as $execution) {
+ if ($this->backup->database->getMorphClass() === 'App\Models\ServiceDatabase') {
+ delete_backup_locally($execution->filename, $this->backup->database->service->destination->server);
+ } else {
+ delete_backup_locally($execution->filename, $this->backup->database->destination->server);
+ }
+ $execution->delete();
+ }
+ }
+
+ public function render()
+ {
+ //Add delete backup form S3 storage and delete backup for SFTP... when it is implemented
+ return view('livewire.project.database.backup-edit', [
+ 'checkboxes' => [
+ ['id' => 'delete_associated_backups', 'label' => 'All backups associated with this backup job from this database will be permanently deleted from local storage.']
+ ]
+ ]);
+ }
}
diff --git a/resources/views/livewire/project/database/backup-edit.blade.php b/resources/views/livewire/project/database/backup-edit.blade.php
index 462d696fa0..a737ec091e 100644
--- a/resources/views/livewire/project/database/backup-edit.blade.php
+++ b/resources/views/livewire/project/database/backup-edit.blade.php
@@ -8,12 +8,17 @@
<livewire:project.database.backup-now :backup="$backup" />
@endif
@if ($backup->database_id !== 0)
- <x-modal-confirmation isErrorButton>
- <x-slot:button-title>
- Delete
- </x-slot:button-title>
- This will stop the scheduled backup for this database.<br>Please think again.
- </x-modal-confirmation>
+ <x-modal-confirmation
+ title="Confirm Backup Schedule Deletion?"
+ buttonTitle="Delete"
+ isErrorButton
+ :checkboxes="$checkboxes"
+ :actions="['The selected backup schedule will be deleted.', 'Scheduled backups for this database will be stopped (if this is the only backup schedule for this database).']"
+ confirmationText="{{ $backup->database->name }}"
+ confirmationLabel="Please confirm the execution of the actions by entering the Database Name of the scheduled backups below"
+ shortConfirmationLabel="Database Name"
+ submitAction="delete"
+ />
@endif
</div>
<div class="w-48 pb-2">