From 06d72c5867af10cb1c5e4730cb1466e55f9c3476 Mon Sep 17 00:00:00 2001 From: Szymon Porwolik Date: Mon, 22 Sep 2025 20:17:17 +0200 Subject: [PATCH] Adds download of HF Propagation and Solar Data from HamQSL --- application/config/migration.php | 2 +- application/controllers/Debug.php | 1 + application/controllers/Update.php | 19 ++++++++++++ .../migrations/257_add_cron_hamqsl.php | 31 +++++++++++++++++++ application/models/Update_model.php | 24 ++++++++++++++ application/views/debug/index.php | 9 ++++-- 6 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 application/migrations/257_add_cron_hamqsl.php diff --git a/application/config/migration.php b/application/config/migration.php index 91f88513b..5acd6dbd9 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE; | */ -$config['migration_version'] = 256; +$config['migration_version'] = 257; /* |-------------------------------------------------------------------------- diff --git a/application/controllers/Debug.php b/application/controllers/Debug.php index dc652037b..2668fc4ae 100644 --- a/application/controllers/Debug.php +++ b/application/controllers/Debug.php @@ -112,6 +112,7 @@ class Debug extends CI_Controller $data['wwff_update'] = $this->cron_model->cron('update_update_wwff')->row(); $data['tle_update'] = $this->cron_model->cron('update_update_tle')->row(); $data['hon_update'] = $this->cron_model->cron('update_update_hamsofnote')->row(); + $data['hamqsl_update'] = $this->cron_model->cron('update_update_hamqsl')->row(); $data['page_title'] = __("Debug"); diff --git a/application/controllers/Update.php b/application/controllers/Update.php index 7679c0ea1..e73488aff 100644 --- a/application/controllers/Update.php +++ b/application/controllers/Update.php @@ -438,6 +438,25 @@ class Update extends CI_Controller { } } + /* + * Pulls the solarxml.php data from hamqsl + */ + public function update_hamqsl() { + + $this->load->model('Update_model'); + $result = $this->Update_model->hamqsl(); + if($this->session->userdata('user_type') == '99') { + if (substr($result, 0, 4) == 'DONE') { + $this->session->set_flashdata('success', __("HAMqsl Update complete. Result: ") . "'" . $result . "'"); + } else { + $this->session->set_flashdata('error', __("HAMqsl Update failed. Result: ") . "'" . $result . "'"); + } + redirect('debug'); + } else { + echo $result; + } + } + public function update_pota() { $this->load->model('Update_model'); diff --git a/application/migrations/257_add_cron_hamqsl.php b/application/migrations/257_add_cron_hamqsl.php new file mode 100644 index 000000000..d81612878 --- /dev/null +++ b/application/migrations/257_add_cron_hamqsl.php @@ -0,0 +1,31 @@ +db->table_exists('cron')) { + + // add cron job for HAMqsl update + $data = array( + array( + 'id' => 'update_update_hamqsl', + 'enabled' => '1', + 'status' => 'pending', + 'description' => 'Download HamQSL HF Propagation Tools and Solar Data', + 'function' => 'index.php/update/update_hamqsl', + 'expression' => '0 */1 * * *', + 'last_run' => null, + 'next_run' => null + ) + ); + $this->db->insert_batch('cron', $data); + } + } + + public function down() { + + $this->dbtry("delete from cron where id = 'update_update_hamqsl';"); + + } +} diff --git a/application/models/Update_model.php b/application/models/Update_model.php index 80cb7f70c..d0569df01 100644 --- a/application/models/Update_model.php +++ b/application/models/Update_model.php @@ -177,6 +177,29 @@ class Update_model extends CI_Model { } } + function hamqsl(){ + // This downloads and store hamqsl propagation data XML file + + $contents = file_get_contents('https://www.hamqsl.com/solarxml.php', true); + + if ($contents === FALSE) { + return "Something went wrong with fetching the solarxml.xml file from HAMqsl website."; + } else { + $file = './updates/solarxml.xml'; + + if (file_put_contents($file, $contents) !== FALSE) { // Save our content to the file. + $nCount = count(file($file)); + if ($nCount > 0) { + return "DONE: solarxml.xml downloaded from HAMqsl website."; + } else { + return "FAILED: Empty file received from HAMqsl website."; + } + } else { + return "FAILED: Could not write solarxml.xml file from HAMqsl website."; + } + } + } + function pota() { // set the last run in cron table for the correct cron id $this->load->model('cron_model'); @@ -499,6 +522,7 @@ class Update_model extends CI_Model { return; } + function update_hams_of_note() { if (($this->optionslib->get_option('hon_url') ?? '') == '') { $file = 'https://api.ham2k.net/data/ham2k/hams-of-note.txt'; diff --git a/application/views/debug/index.php b/application/views/debug/index.php index a2b3ba36b..d71c45bfc 100644 --- a/application/views/debug/index.php +++ b/application/views/debug/index.php @@ -554,15 +554,20 @@ last_run ?? __("never"); ?> - + last_run ?? __("never"); ?> - + last_run ?? __("never"); ?> + + + + last_run ?? __("never"); ?> +