From f8226cf892f47a7ed72554a4240a3488c1be523a Mon Sep 17 00:00:00 2001
From: ayntk-ai <122374094+ayntk-ai@users.noreply.github.com>
Date: Sat, 31 Aug 2024 19:31:01 +0200
Subject: [PATCH] confirm backup deletion
---
.../Project/Database/BackupExecutions.php | 43 ++++++++++++++++---
.../database/backup-executions.blade.php | 21 ++++++---
2 files changed, 52 insertions(+), 12 deletions(-)
diff --git a/app/Livewire/Project/Database/BackupExecutions.php b/app/Livewire/Project/Database/BackupExecutions.php
index de1bac36f..b6827895f 100644
--- a/app/Livewire/Project/Database/BackupExecutions.php
+++ b/app/Livewire/Project/Database/BackupExecutions.php
@@ -4,6 +4,9 @@ namespace App\Livewire\Project\Database;
use App\Models\ScheduledDatabaseBackup;
use Livewire\Component;
+use Illuminate\Support\Facades\Hash;
+use Illuminate\Support\Facades\Auth;
+use Livewire\Attributes\On;
class BackupExecutions extends Component
{
@@ -13,9 +16,12 @@ class BackupExecutions extends Component
public $setDeletableBackup;
+ public $delete_backup_s3 = true;
+ public $delete_backup_sftp = true;
+
public function getListeners()
{
- $userId = auth()->user()->id;
+ $userId = Auth::id();
return [
"echo-private:team.{$userId},BackupCreated" => 'refreshBackupExecutions',
@@ -32,19 +38,34 @@ class BackupExecutions extends Component
}
}
- public function deleteBackup($exeuctionId)
+ #[On('deleteBackup')]
+ public function deleteBackup($executionId, $password)
{
- $execution = $this->backup->executions()->where('id', $exeuctionId)->first();
- if (is_null($execution)) {
- $this->dispatch('error', 'Backup execution not found.');
-
+ if (!Hash::check($password, Auth::user()->password)) {
+ $this->addError('password', 'The provided password is incorrect.');
return;
}
+
+ $execution = $this->backup->executions()->where('id', $executionId)->first();
+ if (is_null($execution)) {
+ $this->dispatch('error', 'Backup execution not found.');
+ return;
+ }
+
if ($execution->scheduledDatabaseBackup->database->getMorphClass() === 'App\Models\ServiceDatabase') {
delete_backup_locally($execution->filename, $execution->scheduledDatabaseBackup->database->service->destination->server);
} else {
delete_backup_locally($execution->filename, $execution->scheduledDatabaseBackup->database->destination->server);
}
+
+ if ($this->delete_backup_s3) {
+ // Add logic to delete from S3
+ }
+
+ if ($this->delete_backup_sftp) {
+ // Add logic to delete from SFTP
+ }
+
$execution->delete();
$this->dispatch('success', 'Backup deleted.');
$this->refreshBackupExecutions();
@@ -61,4 +82,14 @@ class BackupExecutions extends Component
$this->executions = $this->backup->executions()->get()->sortBy('created_at');
}
}
+
+ public function render()
+ {
+ return view('livewire.project.database.backup-executions', [
+ 'checkboxes' => [
+ ['id' => 'delete_backup_s3', 'label' => 'Delete the selected backup permanently form S3 Storage'],
+ ['id' => 'delete_backup_sftp', 'label' => 'Delete the selected backup permanently form SFTP Storage'],
+ ]
+ ]);
+ }
}
diff --git a/resources/views/livewire/project/database/backup-executions.blade.php b/resources/views/livewire/project/database/backup-executions.blade.php
index 644ac9fa4..978198b72 100644
--- a/resources/views/livewire/project/database/backup-executions.blade.php
+++ b/resources/views/livewire/project/database/backup-executions.blade.php
@@ -34,12 +34,21 @@
Download
@endif
-
-
- Delete
-
- This will delete this backup. It is not reversible.
Please think again.
-
+