From d7d06c2bbc6d76912d38c73afff43c2aefdab40d Mon Sep 17 00:00:00 2001 From: Hugo Silva Date: Fri, 17 Mar 2023 13:11:04 +0000 Subject: [PATCH] Store webadif upload data in separate table --- .../migrations/115_add_webadif_api_export.php | 32 +++++++++++-------- application/models/Logbook_model.php | 8 ++--- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/application/migrations/115_add_webadif_api_export.php b/application/migrations/115_add_webadif_api_export.php index 7997c83b..22e29007 100644 --- a/application/migrations/115_add_webadif_api_export.php +++ b/application/migrations/115_add_webadif_api_export.php @@ -25,18 +25,25 @@ class Migration_add_webadif_api_export extends CI_Migration { $this->dbforge->add_column('station_profile', $fields); } - if (!$this->db->field_exists('webadif_upload_date', $this->config->item('table_name'))) { - $fields = array( - "webadif_upload_date datetime DEFAULT NULL" - ); - $this->dbforge->add_column($this->config->item('table_name'), $fields); - } - if (!$this->db->field_exists('webadif_upload_status', $this->config->item('table_name'))) { - $fields = array( - "webadif_upload_status varchar(1) DEFAULT 'N'" - ); - $this->dbforge->add_column($this->config->item('table_name'), $fields); + if (!$this->db->table_exists('webadif')) { + $this->dbforge->add_field(array( + 'id' => array( + 'type' => 'INT', + 'auto_increment' => TRUE + ), + 'qso_id' => array( + 'type' => 'int', + ), + 'upload_date' => array( + 'type' => 'datetime', + ), + )); + + $this->dbforge->add_key('id', TRUE); + $this->dbforge->add_key(array('qso_id','upload_date'), FALSE); + + $this->dbforge->create_table('webadif'); } } @@ -46,7 +53,6 @@ class Migration_add_webadif_api_export extends CI_Migration { $this->dbforge->drop_column('station_profile', 'webadifapikey'); $this->dbforge->drop_column('station_profile', 'webadifapiurl'); $this->dbforge->drop_column('station_profile', 'webadifrealtime'); - $this->dbforge->drop_column($this->config->item('table_name'), 'webadif_upload_date'); - $this->dbforge->drop_column($this->config->item('table_name'), 'webadif_upload_status'); + $this->dbforge->drop_table('webadif'); } } diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 79b86b35..53299b8a 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -637,13 +637,11 @@ class Logbook_model extends CI_Model { function mark_webadif_qsos_sent($primarykey) { $data = array( - 'webadif_upload_date' => date("Y-m-d H:i:s", strtotime("now")), - 'webadif_upload_status' => 'Y', + 'upload_date' => date("Y-m-d H:i:s", strtotime("now")), + 'qso_id' => $primarykey, ); - $this->db->where('COL_PRIMARY_KEY', $primarykey); - - $this->db->update($this->config->item('table_name'), $data); + $this->db->insert('webadif', $data); return true; }