From 66d6fc91a8ff36e6e6ced6479b551b137220053a Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Sat, 9 Aug 2025 21:35:47 +0100 Subject: [PATCH] Improve update status handling and error reporting Added get_status endpoint to Update controller for serving update status. Enhanced update_status to handle directory creation and log errors. Updated footer view to use new endpoint, improved error handling and retry logic for status updates. --- application/controllers/Update.php | 21 ++++++++++++++++++- application/views/interface_assets/footer.php | 10 ++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/application/controllers/Update.php b/application/controllers/Update.php index deb74779..bd8ba7cc 100644 --- a/application/controllers/Update.php +++ b/application/controllers/Update.php @@ -219,6 +219,16 @@ class Update extends CI_Controller { $this->update_status("DONE"); } + public function get_status() { + $status_file = $this->make_update_path("status.html"); + if (file_exists($status_file)) { + $content = file_get_contents($status_file); + echo $content; + } else { + echo "No status available"; + } + } + public function update_status($done=""){ if ($done != "Downloading file"){ @@ -234,7 +244,16 @@ class Update extends CI_Controller { $html = $done."....
"; } - file_put_contents($this->make_update_path("status.html"), $html); + $status_file = $this->make_update_path("status.html"); + if (file_put_contents($status_file, $html) === FALSE) { + log_message('error', 'Failed to write status file: ' . $status_file); + // Try to create the directory if it doesn't exist + $dir = dirname($status_file); + if (!is_dir($dir)) { + mkdir($dir, 0755, true); + file_put_contents($status_file, $html); + } + } } diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 17d81303..f21b1d66 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -1935,12 +1935,16 @@ if ($this->session->userdata('user_id') != null) { }); function update_stats() { - $('#dxcc_update_status').load('updates/status.html', function(val) { - $('#dxcc_update_staus').html(val); + $('#dxcc_update_status').load('index.php/update/get_status', function(val) { + $('#dxcc_update_status').html(val); - if ((val === null) || (val.substring(0, 4) != "DONE")) { + if ((val === null) || (val === undefined) || (typeof val !== 'string') || (val.substring(0, 4) !== "DONE")) { setTimeout(update_stats, 5000); } + }).fail(function(xhr, status, error) { + console.log('Error loading status: ' + status + ' - ' + error); + $('#dxcc_update_status').html('Error loading status...'); + setTimeout(update_stats, 10000); // Retry in 10 seconds on error }); }