69 lines
1.9 KiB
PHP
69 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Ui\System\Modal;
|
|
|
|
use App\Models\BackupJob;
|
|
use LivewireUI\Modal\ModalComponent;
|
|
|
|
class BackupProgressModal extends ModalComponent
|
|
{
|
|
public int $jobId;
|
|
public string $restoreToken = '';
|
|
public bool $notifiedDone = false;
|
|
|
|
public static function modalMaxWidth(): string { return 'md'; }
|
|
|
|
public function mount(int $jobId, string $restoreToken = ''): void
|
|
{
|
|
$this->jobId = $jobId;
|
|
$this->restoreToken = $restoreToken;
|
|
}
|
|
|
|
public function getJobProperty(): ?BackupJob
|
|
{
|
|
return BackupJob::find($this->jobId);
|
|
}
|
|
|
|
public function getRestoreStatusProperty(): array
|
|
{
|
|
if (empty($this->restoreToken)) {
|
|
return ['status' => 'unknown', 'log' => ''];
|
|
}
|
|
|
|
$file = sys_get_temp_dir() . '/' . $this->restoreToken . '.json';
|
|
|
|
if (!file_exists($file)) {
|
|
return ['status' => 'queued', 'log' => 'Wartend auf Start…'];
|
|
}
|
|
|
|
$data = json_decode(file_get_contents($file), true);
|
|
return $data ?: ['status' => 'unknown', 'log' => ''];
|
|
}
|
|
|
|
public function close(): void
|
|
{
|
|
// Clean up status file for restore jobs
|
|
if ($this->restoreToken) {
|
|
$file = sys_get_temp_dir() . '/' . $this->restoreToken . '.json';
|
|
@unlink($file);
|
|
}
|
|
$this->closeModal();
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
if (!$this->notifiedDone) {
|
|
$status = empty($this->restoreToken)
|
|
? ($this->job?->status ?? 'queued')
|
|
: ($this->restoreStatus['status'] ?? 'queued');
|
|
|
|
if (in_array($status, ['ok', 'failed', 'canceled'])) {
|
|
$this->notifiedDone = true;
|
|
$this->dispatch('backup-list-refresh');
|
|
}
|
|
}
|
|
|
|
return view('livewire.ui.system.modal.backup-progress-modal');
|
|
}
|
|
}
|