From 88731929634442fe1fb88fe777694a091e169b22 Mon Sep 17 00:00:00 2001 From: "Joseph.Rawlings" Date: Sun, 1 Feb 2026 13:25:12 -0500 Subject: [PATCH] Add error handling for backup location checks and improve backup fetching logic --- .../Proxmox/Livewire/Backups/Create.php | 47 ++++++++++++------- .../Proxmox/Livewire/Backups/Index.php | 22 +++++++-- 2 files changed, 49 insertions(+), 20 deletions(-) diff --git a/extensions/Servers/Proxmox/Livewire/Backups/Create.php b/extensions/Servers/Proxmox/Livewire/Backups/Create.php index c36e218bb..779d9c0b4 100644 --- a/extensions/Servers/Proxmox/Livewire/Backups/Create.php +++ b/extensions/Servers/Proxmox/Livewire/Backups/Create.php @@ -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; } } diff --git a/extensions/Servers/Proxmox/Livewire/Backups/Index.php b/extensions/Servers/Proxmox/Livewire/Backups/Index.php index 5092a5796..e98c7b852 100644 --- a/extensions/Servers/Proxmox/Livewire/Backups/Index.php +++ b/extensions/Servers/Proxmox/Livewire/Backups/Index.php @@ -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()