confirm backup deletion
This commit is contained in:
@@ -4,6 +4,9 @@ namespace App\Livewire\Project\Database;
|
|||||||
|
|
||||||
use App\Models\ScheduledDatabaseBackup;
|
use App\Models\ScheduledDatabaseBackup;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Livewire\Attributes\On;
|
||||||
|
|
||||||
class BackupExecutions extends Component
|
class BackupExecutions extends Component
|
||||||
{
|
{
|
||||||
@@ -13,9 +16,12 @@ class BackupExecutions extends Component
|
|||||||
|
|
||||||
public $setDeletableBackup;
|
public $setDeletableBackup;
|
||||||
|
|
||||||
|
public $delete_backup_s3 = true;
|
||||||
|
public $delete_backup_sftp = true;
|
||||||
|
|
||||||
public function getListeners()
|
public function getListeners()
|
||||||
{
|
{
|
||||||
$userId = auth()->user()->id;
|
$userId = Auth::id();
|
||||||
|
|
||||||
return [
|
return [
|
||||||
"echo-private:team.{$userId},BackupCreated" => 'refreshBackupExecutions',
|
"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 (!Hash::check($password, Auth::user()->password)) {
|
||||||
if (is_null($execution)) {
|
$this->addError('password', 'The provided password is incorrect.');
|
||||||
$this->dispatch('error', 'Backup execution not found.');
|
|
||||||
|
|
||||||
return;
|
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') {
|
if ($execution->scheduledDatabaseBackup->database->getMorphClass() === 'App\Models\ServiceDatabase') {
|
||||||
delete_backup_locally($execution->filename, $execution->scheduledDatabaseBackup->database->service->destination->server);
|
delete_backup_locally($execution->filename, $execution->scheduledDatabaseBackup->database->service->destination->server);
|
||||||
} else {
|
} else {
|
||||||
delete_backup_locally($execution->filename, $execution->scheduledDatabaseBackup->database->destination->server);
|
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();
|
$execution->delete();
|
||||||
$this->dispatch('success', 'Backup deleted.');
|
$this->dispatch('success', 'Backup deleted.');
|
||||||
$this->refreshBackupExecutions();
|
$this->refreshBackupExecutions();
|
||||||
@@ -61,4 +82,14 @@ class BackupExecutions extends Component
|
|||||||
$this->executions = $this->backup->executions()->get()->sortBy('created_at');
|
$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'],
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,12 +34,21 @@
|
|||||||
<x-forms.button class=" dark:hover:bg-coolgray-400"
|
<x-forms.button class=" dark:hover:bg-coolgray-400"
|
||||||
x-on:click="download_file('{{ data_get($execution, 'id') }}')">Download</x-forms.button>
|
x-on:click="download_file('{{ data_get($execution, 'id') }}')">Download</x-forms.button>
|
||||||
@endif
|
@endif
|
||||||
<x-modal-confirmation isErrorButton action="deleteBackup({{ data_get($execution, 'id') }})">
|
<x-modal-confirmation
|
||||||
<x-slot:button-title>
|
title="Confirm Backup Deletion?"
|
||||||
Delete
|
buttonTitle="Delete"
|
||||||
</x-slot:button-title>
|
isErrorButton
|
||||||
This will delete this backup. It is not reversible.<br>Please think again.
|
type="button"
|
||||||
</x-modal-confirmation>
|
submitAction="deleteBackup({{ data_get($execution, 'id') }})"
|
||||||
|
{{-- :checkboxes="$checkboxes" --}}
|
||||||
|
:actions="[
|
||||||
|
'This backup will be permanently deleted from local storage.'
|
||||||
|
]"
|
||||||
|
confirmationText="{{ data_get($execution, 'filename') }}"
|
||||||
|
confirmationLabel="Please confirm the execution of the actions by entering the Backup Filename below"
|
||||||
|
shortConfirmationLabel="Backup Filename"
|
||||||
|
step3ButtonText="Permanently Delete Backup"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user