Add error handling for backup location checks and improve backup fetching logic
This commit is contained in:
@@ -31,15 +31,25 @@ class Create extends Component
|
||||
return true;
|
||||
}
|
||||
|
||||
$proxmox = new Proxmox;
|
||||
$currentBackups = $proxmox->request('/nodes/' . $this->server->node->name . '/storage/' . $this->server->node->backup_location . '/content', data: [
|
||||
'content' => 'backup',
|
||||
'vmid' => $this->server->vm_id,
|
||||
])->json()['data'] ?? [];
|
||||
// Check if backup_location is configured
|
||||
if (empty($this->server->node->backup_location)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$currentBackupCount = count($currentBackups);
|
||||
try {
|
||||
$proxmox = new Proxmox;
|
||||
$currentBackups = $proxmox->request('/nodes/' . $this->server->node->name . '/storage/' . $this->server->node->backup_location . '/content', data: [
|
||||
'content' => 'backup',
|
||||
'vmid' => $this->server->vm_id,
|
||||
])->json()['data'] ?? [];
|
||||
|
||||
return $currentBackupCount < $backupLimit;
|
||||
$currentBackupCount = count($currentBackups);
|
||||
|
||||
return $currentBackupCount < $backupLimit;
|
||||
} catch (\Exception $e) {
|
||||
\Illuminate\Support\Facades\Log::error('Failed to check backup limit: ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function backup()
|
||||
@@ -66,17 +76,22 @@ class Create extends Component
|
||||
$backupSettings = $this->server->service->product->settings()->where('key', 'backups')->first();
|
||||
$backupLimit = $backupSettings?->value ?? 0;
|
||||
|
||||
if ($backupLimit > 0) {
|
||||
$proxmox = new Proxmox;
|
||||
$currentBackups = $proxmox->request('/nodes/' . $this->server->node->name . '/storage/' . $this->server->node->backup_location . '/content', data: [
|
||||
'content' => 'backup',
|
||||
'vmid' => $this->server->vm_id,
|
||||
])->json()['data'] ?? [];
|
||||
if ($backupLimit > 0 && !empty($this->server->node->backup_location)) {
|
||||
try {
|
||||
$proxmox = new Proxmox;
|
||||
$currentBackups = $proxmox->request('/nodes/' . $this->server->node->name . '/storage/' . $this->server->node->backup_location . '/content', data: [
|
||||
'content' => 'backup',
|
||||
'vmid' => $this->server->vm_id,
|
||||
])->json()['data'] ?? [];
|
||||
|
||||
$currentBackupCount = count($currentBackups);
|
||||
$currentBackupCount = count($currentBackups);
|
||||
|
||||
if ($currentBackupCount >= $backupLimit) {
|
||||
$this->notify("Backup limit reached. You can only create {$backupLimit} backup(s). Please delete an existing backup before creating a new one.", 'error');
|
||||
if ($currentBackupCount >= $backupLimit) {
|
||||
$this->notify("Backup limit reached. You can only create {$backupLimit} backup(s). Please delete an existing backup before creating a new one.", 'error');
|
||||
return;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->notify('Failed to check backup limit: ' . $e->getMessage(), 'error');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,10 +34,24 @@ class Index extends Component
|
||||
return;
|
||||
}
|
||||
|
||||
$this->backups = $proxmox->request('/nodes/' . $this->server->node->name . '/storage/' . $this->server->node->backup_location . '/content', data: [
|
||||
'content' => 'backup',
|
||||
'vmid' => $this->server->vm_id,
|
||||
])->json()['data'];
|
||||
// Check if backup_location is configured
|
||||
if (empty($this->server->node->backup_location)) {
|
||||
$this->backups = [];
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$response = $proxmox->request('/nodes/' . $this->server->node->name . '/storage/' . $this->server->node->backup_location . '/content', data: [
|
||||
'content' => 'backup',
|
||||
'vmid' => $this->server->vm_id,
|
||||
]);
|
||||
|
||||
$this->backups = $response->json()['data'] ?? [];
|
||||
} catch (\Exception $e) {
|
||||
$this->backups = [];
|
||||
// Log the error for debugging
|
||||
\Illuminate\Support\Facades\Log::error('Failed to fetch backups: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function restoreBackup()
|
||||
|
||||
Reference in New Issue
Block a user