mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-01 14:06:15 +00:00
database backups
This commit is contained in:
67
app/Http/Livewire/Databases/DatabaseBackupFiles.php
Normal file
67
app/Http/Livewire/Databases/DatabaseBackupFiles.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Databases;
|
||||
|
||||
use App\Models\Backup;
|
||||
use App\Models\BackupFile;
|
||||
use App\Models\Database;
|
||||
use App\Models\Server;
|
||||
use App\Traits\HasCustomPaginationView;
|
||||
use App\Traits\RefreshComponentOnBroadcast;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Livewire\Component;
|
||||
|
||||
class DatabaseBackupFiles extends Component
|
||||
{
|
||||
use HasCustomPaginationView;
|
||||
use RefreshComponentOnBroadcast;
|
||||
|
||||
public Server $server;
|
||||
|
||||
public Backup $backup;
|
||||
|
||||
public string $restoreId = "";
|
||||
|
||||
public string $restoreDatabaseId = "";
|
||||
|
||||
public int $deleteId;
|
||||
|
||||
public function backup(): void
|
||||
{
|
||||
$this->backup->run();
|
||||
|
||||
$this->refreshComponent([]);
|
||||
}
|
||||
|
||||
public function restore(): void
|
||||
{
|
||||
/** @var BackupFile $file */
|
||||
$file = BackupFile::query()->findOrFail($this->restoreId);
|
||||
|
||||
/** @var Database $database */
|
||||
$database = Database::query()->findOrFail($this->restoreDatabaseId);
|
||||
|
||||
$file->restore($database);
|
||||
|
||||
$this->refreshComponent([]);
|
||||
|
||||
$this->dispatchBrowserEvent('restored', true);
|
||||
}
|
||||
|
||||
public function delete(): void
|
||||
{
|
||||
/** @var BackupFile $file */
|
||||
$file = BackupFile::query()->findOrFail($this->deleteId);
|
||||
|
||||
$file->delete();
|
||||
|
||||
$this->dispatchBrowserEvent('confirmed', true);
|
||||
}
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
return view('livewire.databases.database-backup-files', [
|
||||
'files' => $this->backup->files()->orderByDesc('id')->simplePaginate(10)
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user