2023-08-10 13:52:54 +00:00
|
|
|
<?php
|
|
|
|
|
2023-12-07 18:06:32 +00:00
|
|
|
namespace App\Livewire\Project\Database;
|
2023-08-10 13:52:54 +00:00
|
|
|
|
2023-10-25 07:28:26 +00:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
2023-08-10 13:52:54 +00:00
|
|
|
use Livewire\Component;
|
2024-04-10 13:00:46 +00:00
|
|
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
2023-08-10 13:52:54 +00:00
|
|
|
|
|
|
|
class BackupExecutions extends Component
|
|
|
|
{
|
|
|
|
public $backup;
|
2023-12-14 14:01:19 +00:00
|
|
|
public $executions = [];
|
2023-10-24 12:31:28 +00:00
|
|
|
public $setDeletableBackup;
|
2023-12-11 09:23:10 +00:00
|
|
|
public function getListeners()
|
|
|
|
{
|
|
|
|
$userId = auth()->user()->id;
|
|
|
|
return [
|
|
|
|
"echo-private:team.{$userId},BackupCreated" => 'refreshBackupExecutions',
|
|
|
|
"refreshBackupExecutions",
|
|
|
|
"deleteBackup"
|
|
|
|
];
|
|
|
|
}
|
2023-08-10 13:52:54 +00:00
|
|
|
|
2023-10-24 12:31:28 +00:00
|
|
|
public function deleteBackup($exeuctionId)
|
|
|
|
{
|
|
|
|
$execution = $this->backup->executions()->where('id', $exeuctionId)->first();
|
|
|
|
if (is_null($execution)) {
|
2023-12-07 18:06:32 +00:00
|
|
|
$this->dispatch('error', 'Backup execution not found.');
|
2023-10-24 12:31:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-11-07 11:11:47 +00:00
|
|
|
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);
|
|
|
|
}
|
2023-10-24 12:31:28 +00:00
|
|
|
$execution->delete();
|
2024-02-22 13:53:42 +00:00
|
|
|
$this->dispatch('success', 'Backup deleted.');
|
2024-03-07 09:27:21 +00:00
|
|
|
$this->refreshBackupExecutions();
|
2023-10-24 12:31:28 +00:00
|
|
|
}
|
2024-04-10 13:00:46 +00:00
|
|
|
public function download_file($exeuctionId)
|
2023-10-25 07:28:26 +00:00
|
|
|
{
|
2024-04-10 13:00:46 +00:00
|
|
|
return redirect()->route('download.backup', $exeuctionId);
|
2023-10-25 07:28:26 +00:00
|
|
|
}
|
2023-08-10 13:52:54 +00:00
|
|
|
public function refreshBackupExecutions(): void
|
|
|
|
{
|
2024-03-07 09:27:21 +00:00
|
|
|
$this->executions = $this->backup->executions()->get()->sortByDesc('created_at');
|
2023-08-10 13:52:54 +00:00
|
|
|
}
|
|
|
|
}
|