coolify/app/Livewire/Project/Database/BackupNow.php

34 lines
906 B
PHP
Raw Normal View History

2023-08-11 18:48:52 +00:00
<?php
2023-12-07 18:06:32 +00:00
namespace App\Livewire\Project\Database;
2023-08-11 18:48:52 +00:00
use App\Jobs\DatabaseBackupJob;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
2023-08-11 18:48:52 +00:00
use Livewire\Component;
class BackupNow extends Component
{
use AuthorizesRequests;
2023-08-11 18:48:52 +00:00
public $backup;
2024-06-10 20:43:34 +00:00
2024-12-16 09:38:18 +00:00
public function backupNow()
2023-08-11 18:48:52 +00:00
{
try {
$this->authorize('manageBackups', $this->backup->database);
$database = $this->backup->database->refresh();
if ($database->id !== 0 && ! str($database->status)->startsWith('running')) {
$this->dispatch('error', 'The database must be running to start a backup.');
return;
}
DatabaseBackupJob::dispatch($this->backup);
$this->dispatch('success', 'Backup queued. It will be available in a few minutes.');
} catch (\Throwable $e) {
return handleError($e, $this);
}
2023-08-11 18:48:52 +00:00
}
}