From af053cabc11e001029282b70ffb4ccf005ed753c Mon Sep 17 00:00:00 2001 From: int2001 Date: Tue, 2 Apr 2024 16:53:28 +0000 Subject: [PATCH] Move deletion of QSOs / Stationprofiles to station_model --- application/models/Stations.php | 31 +++++++++++++++++++++---------- application/models/User_model.php | 15 +++------------ 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/application/models/Stations.php b/application/models/Stations.php index 66165d953..4f7bfce53 100644 --- a/application/models/Stations.php +++ b/application/models/Stations.php @@ -202,29 +202,40 @@ class Stations extends CI_Model { $this->user_options_model->set_option('eqsl_default_qslmsg', 'key_station_id', array(xss_clean($this->input->post('station_id', true)) => $eqsl_default_qslmsg)); } - function delete($id) { + function delete($id,$force = false) { // Clean ID $clean_id = $this->security->xss_clean($id); // do not delete active station - if ($clean_id === $this->find_active()) { + if ((!($force)) && ($clean_id === $this->find_active())) { return; } + + # Del options for that station_id $this->user_options_model->del_option('eqsl_default_qslmsg', 'key_station_id', array('option_key' => $id)); - // Delete QSOs - $this->db->where('station_id', $id); - $this->db->delete($this->config->item('table_name')); + // Delete Contents of log for that station_id + $this->deletelog($clean_id); - // Delete Station Profile + // Delete Station Profile, links, contests and oqrs-requests + $this->db->query("DELETE c FROM contest_session c WHERE c.station_id =?",$clean_id); + $this->db->query("DELETE FROM oqrs WHERE station_id = ?",$clean_id); + $this->db->query("DELETE FROM station_logbooks_relationship WHERE station_location_id = ?",$clean_id); $this->db->delete('station_profile', array('station_id' => $clean_id)); } function deletelog($id) { - // Delete QSOs - $this->db->where('station_id', $id); - $this->db->delete($this->config->item('table_name')); - } + // Clean ID + $clean_id = $this->security->xss_clean($id); + + // Todo: Fetch EACH COL_PRIMARY_KEY (via inner join) from Log-table and delete also eQSL-file within filesystem (Function missing here) depending on path-configuration + $this->db->query("DELETE e FROM `eQSL_images` e inner join ".$this->config->item('table_name')." qsos where e.qso_id=qsos.COL_PRIMARY_KEY and qsos.station_id=?",$clean_id); + // Todo: Fetch EACH COL_PRIMARY_KEY (via inner join) from Log-table and delete also QSL-file within filesystem (Function missing here) depending on path-configuration + $this->db->query("DELETE q FROM qsl_images q inner join ".$this->config->item('table_name')." qsos WHERE q.qsoid=qsos.COL_PRIMARY_KEY and qsos.station_id = ?",$clean_id); + + // Delete QSOs + $this->db->query("DELETE FROM ".$this->config->item('table_name')." WHERE station_id = ?",$clean_id); + } function set_active($current, $new) { // Clean inputs diff --git a/application/models/User_model.php b/application/models/User_model.php index 05bd503b8..2027c6896 100644 --- a/application/models/User_model.php +++ b/application/models/User_model.php @@ -330,21 +330,12 @@ class User_Model extends CI_Model { // FUNCTION: bool delete() // Deletes a user function delete($user_id) { - if($this->exists_by_id($user_id)) { $this->load->model('Stations'); $stations = $this->Stations->all_of_user($user_id); - foreach ($stations->result() as $row) { - // Todo: Fetch EACH COL_PRIMARY_KEY (via inner join) from Log-table and delete also eQSL-file within filesystem (Function missing here) depending on path-configuration - $this->db->query("DELETE e FROM `eQSL_images` e inner join ".$this->config->item('table_name')." qsos where e.qso_id=qsos.COL_PRIMARY_KEY and qsos.station_id=?",$row->station_id); - // Todo: Fetch EACH COL_PRIMARY_KEY (via inner join) from Log-table and delete also QSL-file within filesystem (Function missing here) depending on path-configuration - $this->db->query("DELETE q FROM qsl_images q inner join ".$this->config->item('table_name')." qsos WHERE q.qsoid=qsos.COL_PRIMARY_KEY and qsos.station_id = ?",$row->station_id); - - $this->db->query("DELETE c FROM contest_session c WHERE c.station_id =?",$row->station_id); - $this->db->query("DELETE FROM oqrs WHERE station_id = ?",$row->station_id); - $this->db->query("DELETE FROM ".$this->config->item('table_name')." WHERE station_id = ?",$row->station_id); - $this->db->query("DELETE FROM station_logbooks_relationship WHERE station_location_id = ?",$row->station_id); - } + foreach ($stations->result() as $row) { + $this->Stations->delete($row->station_id,true); + } // Delete QSOs from $this->config->item('table_name') $this->db->query("DELETE FROM bandxuser WHERE userid = ?",$user_id); $this->db->query("DELETE FROM api WHERE user_id = ?",$user_id);