mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 22:46:16 +00:00
init
This commit is contained in:
47
app/Jobs/Backup/RestoreDatabase.php
Normal file
47
app/Jobs/Backup/RestoreDatabase.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Backup;
|
||||
|
||||
use App\Events\Broadcast;
|
||||
use App\Jobs\Job;
|
||||
use App\Models\BackupFile;
|
||||
use App\Models\Database;
|
||||
|
||||
class RestoreDatabase extends Job
|
||||
{
|
||||
protected BackupFile $backupFile;
|
||||
|
||||
protected Database $database;
|
||||
|
||||
public function __construct(BackupFile $backupFile, Database $database)
|
||||
{
|
||||
$this->backupFile = $backupFile;
|
||||
$this->database = $database;
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$this->database->server->database()->handler()->restoreBackup($this->backupFile, $this->database->name);
|
||||
|
||||
$this->backupFile->status = 'restored';
|
||||
$this->backupFile->restored_at = now();
|
||||
$this->backupFile->save();
|
||||
|
||||
event(
|
||||
new Broadcast('backup-restore-finished', [
|
||||
'file' => $this->backupFile,
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
public function failed(): void
|
||||
{
|
||||
$this->backupFile->status = 'restore_failed';
|
||||
$this->backupFile->save();
|
||||
event(
|
||||
new Broadcast('backup-restore-failed', [
|
||||
'file' => $this->backupFile,
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
44
app/Jobs/Backup/RunBackup.php
Normal file
44
app/Jobs/Backup/RunBackup.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Backup;
|
||||
|
||||
use App\Events\Broadcast;
|
||||
use App\Jobs\Job;
|
||||
use App\Models\BackupFile;
|
||||
|
||||
class RunBackup extends Job
|
||||
{
|
||||
protected BackupFile $backupFile;
|
||||
|
||||
public function __construct(BackupFile $backupFile)
|
||||
{
|
||||
$this->backupFile = $backupFile;
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
if ($this->backupFile->backup->type === 'database') {
|
||||
$this->backupFile->backup->server->database()->handler()->runBackup($this->backupFile);
|
||||
}
|
||||
|
||||
$this->backupFile->status = 'finished';
|
||||
$this->backupFile->save();
|
||||
|
||||
event(
|
||||
new Broadcast('run-backup-finished', [
|
||||
'file' => $this->backupFile,
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
public function failed(): void
|
||||
{
|
||||
$this->backupFile->status = 'failed';
|
||||
$this->backupFile->save();
|
||||
event(
|
||||
new Broadcast('run-backup-failed', [
|
||||
'file' => $this->backupFile,
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user