From 051a1405e7150dcb5ef9523b42bafb226f5434b6 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 7 Mar 2024 10:27:21 +0100 Subject: [PATCH] Refactor backup execution and cleanup functionality --- app/Livewire/Project/Database/Backup/Execution.php | 8 +++++++- app/Livewire/Project/Database/BackupExecutions.php | 4 ++-- .../livewire/project/database/backup/execution.blade.php | 5 ++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/Livewire/Project/Database/Backup/Execution.php b/app/Livewire/Project/Database/Backup/Execution.php index 07f7db03c..1f790d643 100644 --- a/app/Livewire/Project/Database/Backup/Execution.php +++ b/app/Livewire/Project/Database/Backup/Execution.php @@ -10,7 +10,8 @@ class Execution extends Component public $backup; public $executions; public $s3s; - public function mount() { + public function mount() + { $backup_uuid = request()->route('backup_uuid'); $project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first(); if (!$project) { @@ -34,6 +35,11 @@ class Execution extends Component $this->executions = $executions; $this->s3s = currentTeam()->s3s; } + public function cleanupFailed() + { + $this->backup->executions()->where('status', 'failed')->delete(); + $this->dispatch('refreshBackupExecutions'); + } public function render() { return view('livewire.project.database.backup.execution'); diff --git a/app/Livewire/Project/Database/BackupExecutions.php b/app/Livewire/Project/Database/BackupExecutions.php index c78a8cbee..5484dfdc8 100644 --- a/app/Livewire/Project/Database/BackupExecutions.php +++ b/app/Livewire/Project/Database/BackupExecutions.php @@ -34,7 +34,7 @@ class BackupExecutions extends Component } $execution->delete(); $this->dispatch('success', 'Backup deleted.'); - $this->dispatch('refreshBackupExecutions'); + $this->refreshBackupExecutions(); } public function download($exeuctionId) { @@ -65,6 +65,6 @@ class BackupExecutions extends Component } public function refreshBackupExecutions(): void { - $this->executions = data_get($this->backup, 'executions', []); + $this->executions = $this->backup->executions()->get()->sortByDesc('created_at'); } } diff --git a/resources/views/livewire/project/database/backup/execution.blade.php b/resources/views/livewire/project/database/backup/execution.blade.php index 437186b60..f63ed2be7 100644 --- a/resources/views/livewire/project/database/backup/execution.blade.php +++ b/resources/views/livewire/project/database/backup/execution.blade.php @@ -13,7 +13,10 @@
-

Executions

+
+

Executions

+ Cleanup Failed Backups +