From e5dab05b0280315e8c44d4d7209d7dca82f2653e Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Sun, 19 Oct 2025 08:00:31 +0200 Subject: [PATCH] Added cron job and debug button --- application/controllers/Debug.php | 1 + application/controllers/Update.php | 4 +++ .../migrations/261_add_grid_country.php | 26 +++++++++++++++++++ application/views/debug/index.php | 5 ++++ 4 files changed, 36 insertions(+) diff --git a/application/controllers/Debug.php b/application/controllers/Debug.php index 2668fc4ae..4c3a63ab0 100644 --- a/application/controllers/Debug.php +++ b/application/controllers/Debug.php @@ -113,6 +113,7 @@ class Debug extends CI_Controller $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['vucc_grids_update'] = $this->cron_model->cron('update_update_vucc_grids')->row(); $data['page_title'] = __("Debug"); diff --git a/application/controllers/Update.php b/application/controllers/Update.php index ac54c9cef..95c16b2c3 100644 --- a/application/controllers/Update.php +++ b/application/controllers/Update.php @@ -706,6 +706,10 @@ class Update extends CI_Controller { } public function update_vucc_grids() { + // set the last run in cron table for the correct cron id + $this->load->model('cron_model'); + $this->cron_model->set_last_run($this->router->class . '_' . $this->router->method); + $this->load->model('Update_model'); $this->Update_model->update_vucc_grids(); } diff --git a/application/migrations/261_add_grid_country.php b/application/migrations/261_add_grid_country.php index 7e1dd60e4..f5737709e 100644 --- a/application/migrations/261_add_grid_country.php +++ b/application/migrations/261_add_grid_country.php @@ -18,12 +18,31 @@ class Migration_add_grid_country extends CI_Migration { );"; $this->dbtry($sql); + + if ($this->chk4cron('vucc_grid_file') == 0) { + $data = array( + array( + 'id' => 'vucc_grid_file', + 'enabled' => '0', + 'status' => 'disabled', + 'description' => 'Update TQSL VUCC Grids file', + 'function' => 'index.php/update/update_vucc_grids', + 'expression' => '45 4 * * *', + 'last_run' => null, + 'next_run' => null + )); + $this->db->insert_batch('cron', $data); + } } public function down() { $sql = "DROP TABLE IF EXISTS vuccgrids;"; $this->dbtry($sql); + + if ($this->chk4cron('vucc_grid_file') > 0) { + $this->db->query("delete from cron where id='vucc_grid_file'"); + } } function dbtry($what) { @@ -33,4 +52,11 @@ class Migration_add_grid_country extends CI_Migration { log_message("error", "Something gone wrong while altering a table: ".$e." // Executing: ".$this->db->last_query()); } } + + function chk4cron($cronkey) { + $query = $this->db->query("select count(id) as cid from cron where id=?",$cronkey); + $row = $query->row(); + return $row->cid ?? 0; + } + } diff --git a/application/views/debug/index.php b/application/views/debug/index.php index a477ff5bc..cdf7e505e 100644 --- a/application/views/debug/index.php +++ b/application/views/debug/index.php @@ -568,6 +568,11 @@ last_run ?? __("never"); ?> + + + + last_run ?? __("never"); ?> +