confirm backup and delete all backups of the job
This commit is contained in:
@@ -5,6 +5,8 @@ namespace App\Livewire\Project\Database;
|
|||||||
use App\Models\ScheduledDatabaseBackup;
|
use App\Models\ScheduledDatabaseBackup;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
use Spatie\Url\Url;
|
use Spatie\Url\Url;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
class BackupEdit extends Component
|
class BackupEdit extends Component
|
||||||
{
|
{
|
||||||
@@ -12,6 +14,8 @@ class BackupEdit extends Component
|
|||||||
|
|
||||||
public $s3s;
|
public $s3s;
|
||||||
|
|
||||||
|
public bool $delete_associated_backups = false;
|
||||||
|
|
||||||
public ?string $status = null;
|
public ?string $status = null;
|
||||||
|
|
||||||
public array $parameters;
|
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 {
|
try {
|
||||||
|
if ($this->delete_associated_backups) {
|
||||||
|
$this->deleteAllBackups();
|
||||||
|
}
|
||||||
|
|
||||||
$this->backup->delete();
|
$this->backup->delete();
|
||||||
|
|
||||||
if ($this->backup->database->getMorphClass() === 'App\Models\ServiceDatabase') {
|
if ($this->backup->database->getMorphClass() === 'App\Models\ServiceDatabase') {
|
||||||
$previousUrl = url()->previous();
|
$previousUrl = url()->previous();
|
||||||
$url = Url::fromString($previousUrl);
|
$url = Url::fromString($previousUrl);
|
||||||
$url = $url->withoutQueryParameter('selectedBackupId');
|
$url = $url->withoutQueryParameter('selectedBackupId');
|
||||||
$url = $url->withFragment('backups');
|
$url = $url->withFragment('backups');
|
||||||
$url = $url->getPath()."#{$url->getFragment()}";
|
$url = $url->getPath() . "#{$url->getFragment()}";
|
||||||
|
|
||||||
return redirect($url);
|
return redirect($url);
|
||||||
} else {
|
} else {
|
||||||
@@ -104,4 +118,28 @@ class BackupEdit extends Component
|
|||||||
$this->dispatch('error', $e->getMessage());
|
$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.']
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,12 +8,17 @@
|
|||||||
<livewire:project.database.backup-now :backup="$backup" />
|
<livewire:project.database.backup-now :backup="$backup" />
|
||||||
@endif
|
@endif
|
||||||
@if ($backup->database_id !== 0)
|
@if ($backup->database_id !== 0)
|
||||||
<x-modal-confirmation isErrorButton>
|
<x-modal-confirmation
|
||||||
<x-slot:button-title>
|
title="Confirm Backup Schedule Deletion?"
|
||||||
Delete
|
buttonTitle="Delete"
|
||||||
</x-slot:button-title>
|
isErrorButton
|
||||||
This will stop the scheduled backup for this database.<br>Please think again.
|
:checkboxes="$checkboxes"
|
||||||
</x-modal-confirmation>
|
: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
|
@endif
|
||||||
</div>
|
</div>
|
||||||
<div class="w-48 pb-2">
|
<div class="w-48 pb-2">
|
||||||
|
|||||||
Reference in New Issue
Block a user