confirm backup and delete all backups of the job

This commit is contained in:
ayntk-ai
2024-08-31 18:29:19 +02:00
parent 3b3bc6c33b
commit 38845d7eb0
2 changed files with 51 additions and 8 deletions

View File

@@ -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.']
]
]);
}
}

View File

@@ -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">