From 63c7252f82a555bbe69e0256187d539d25377fad Mon Sep 17 00:00:00 2001 From: phl0 Date: Tue, 5 Mar 2024 17:33:51 +0100 Subject: [PATCH 1/3] Use APP field from LoTW to set QSLRDATE --- application/controllers/Lotw.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/controllers/Lotw.php b/application/controllers/Lotw.php index ffdea9090..21651e312 100644 --- a/application/controllers/Lotw.php +++ b/application/controllers/Lotw.php @@ -500,7 +500,7 @@ class Lotw extends CI_Controller { $time_on = date('Y-m-d', strtotime($record['qso_date'])) ." ".date('H:i', strtotime($record['time_on'])); - $qsl_date = date('Y-m-d', strtotime($record['qslrdate'])) ." ".date('H:i', strtotime($record['qslrdate'])); + $qsl_date = date('Y-m-d H:i', strtotime($record['app_lotw_rxqsl'])); if (isset($record['time_off'])) { $time_off = date('Y-m-d', strtotime($record['qso_date'])) ." ".date('H:i', strtotime($record['time_off'])); From 7251892ccf91b241a1e9b04bb96c58b65f4e8423 Mon Sep 17 00:00:00 2001 From: phl0 Date: Tue, 5 Mar 2024 17:34:21 +0100 Subject: [PATCH 2/3] Also update QSOs which have received LoTW cnfm beofre --- application/models/Logbook_model.php | 1 - 1 file changed, 1 deletion(-) diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index f1e13e7e0..3020611d7 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -3144,7 +3144,6 @@ function lotw_update($datetime, $callsign, $band, $qsl_date, $qsl_status, $state $this->db->where('date_format(COL_TIME_ON, \'%Y-%m-%d %H:%i\') = "'.$datetime.'"'); $this->db->where('COL_CALL', $callsign); $this->db->where('COL_BAND', $band); - $this->db->where('ifnull(COL_LOTW_QSL_RCVD,\'\') !=', $qsl_status); // Prevent QSO from beeing updated twice (or more) $this->db->where('COL_STATION_CALLSIGN', $station_callsign); $this->db->update($this->config->item('table_name'), $data); From 296d57ceacf0942b493bd1d756e1ee6206145d5c Mon Sep 17 00:00:00 2001 From: int2001 Date: Tue, 5 Mar 2024 17:14:45 +0000 Subject: [PATCH 3/3] Reduce 4 non-indexed queries to only 1 --- application/controllers/Lotw.php | 3 +- application/models/Logbook_model.php | 143 ++++++++++++++------------- 2 files changed, 75 insertions(+), 71 deletions(-) diff --git a/application/controllers/Lotw.php b/application/controllers/Lotw.php index 21651e312..0f25b67e4 100644 --- a/application/controllers/Lotw.php +++ b/application/controllers/Lotw.php @@ -517,6 +517,7 @@ class Lotw extends CI_Controller { $status = $this->logbook_model->import_check($time_on, $record['call'], $record['band'], $record['mode'], $record['station_callsign']); if($status[0] == "Found") { + $qso_id4lotw=$status[1]; if (isset($record['state'])) { $state = $record['state']; } else { @@ -559,7 +560,7 @@ class Lotw extends CI_Controller { $ituz = ""; } - $lotw_status = $this->logbook_model->lotw_update($time_on, $record['call'], $record['band'], $qsl_date, $record['qsl_rcvd'], $state, $qsl_gridsquare, $qsl_vucc_grids, $iota, $cnty, $cqz, $ituz, $record['station_callsign']); + $lotw_status = $this->logbook_model->lotw_update($time_on, $record['call'], $record['band'], $qsl_date, $record['qsl_rcvd'], $state, $qsl_gridsquare, $qsl_vucc_grids, $iota, $cnty, $cqz, $ituz, $record['station_callsign'],$qso_id4lotw); $table .= ""; $table .= "".$record['station_callsign'].""; diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 3020611d7..80cfb30d6 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -3104,88 +3104,91 @@ function check_if_callsign_worked_in_logbook($callsign, $StationLocationsArray = } -function lotw_update($datetime, $callsign, $band, $qsl_date, $qsl_status, $state, $qsl_gridsquare, $qsl_vucc_grids, $iota, $cnty, $cqz, $ituz, $station_callsign) { + function lotw_update($datetime, $callsign, $band, $qsl_date, $qsl_status, $state, $qsl_gridsquare, $qsl_vucc_grids, $iota, $cnty, $cqz, $ituz, $station_callsign, $qsoid) { - $data = array( - 'COL_LOTW_QSLRDATE' => $qsl_date, - 'COL_LOTW_QSL_RCVD' => $qsl_status, - 'COL_LOTW_QSL_SENT' => 'Y' - ); - if($state != "") { - $data['COL_STATE'] = $state; - } - if($iota != "") { - $data['COL_IOTA'] = $iota; - } + $data = array( + 'COL_LOTW_QSLRDATE' => $qsl_date, + 'COL_LOTW_QSL_RCVD' => $qsl_status, + 'COL_LOTW_QSL_SENT' => 'Y' + ); + if($state != "") { + $data['COL_STATE'] = $state; + } + if($iota != "") { + $data['COL_IOTA'] = $iota; + } - if($cnty != "") { - $data['COL_CNTY'] = $cnty; - } + if($cnty != "") { + $data['COL_CNTY'] = $cnty; + } - if($cqz != "") { - $data['COL_CQZ'] = $cqz; - } + if($cqz != "") { + $data['COL_CQZ'] = $cqz; + } - if($ituz != "") { - $data['COL_ITUZ'] = $ituz; - } + if($ituz != "") { + $data['COL_ITUZ'] = $ituz; + } - // Check if QRZ or ClubLog is already uploaded. If so, set qso to reupload to qrz.com (M) or clublog - $qsql = "select COL_CLUBLOG_QSO_UPLOAD_STATUS as CL_STATE, COL_QRZCOM_QSO_UPLOAD_STATUS as QRZ_STATE from ".$this->config->item('table_name')." where COL_BAND=? and COL_CALL=? and COL_STATION_CALLSIGN=? and date_format(COL_TIME_ON, '%Y-%m-%d %H:%i') = ?"; - $query = $this->db->query($qsql, array($band, $callsign,$station_callsign,$datetime)); - $row = $query->row(); - if (($row->QRZ_STATE ?? '') == 'Y') { - $data['COL_QRZCOM_QSO_UPLOAD_STATUS'] = 'M'; - } - if (($row->CL_STATE ?? '') == 'Y') { - $data['COL_CLUBLOG_QSO_UPLOAD_STATUS'] = 'M'; - } + // Check if QRZ or ClubLog is already uploaded. If so, set qso to reupload to qrz.com (M) or clublog + $qsql = "select COL_CLUBLOG_QSO_UPLOAD_STATUS as CL_STATE, COL_QRZCOM_QSO_UPLOAD_STATUS as QRZ_STATE from ".$this->config->item('table_name')." where COL_BAND=? and COL_CALL=? and COL_STATION_CALLSIGN=? and date_format(COL_TIME_ON, '%Y-%m-%d %H:%i') = ? and COL_PRIMARY_KEY = ?"; + $query = $this->db->query($qsql, array($band, $callsign,$station_callsign,$datetime,$qsoid)); + $row = $query->row(); + if (($row->QRZ_STATE ?? '') == 'Y') { + $data['COL_QRZCOM_QSO_UPLOAD_STATUS'] = 'M'; + } + if (($row->CL_STATE ?? '') == 'Y') { + $data['COL_CLUBLOG_QSO_UPLOAD_STATUS'] = 'M'; + } - $this->db->where('date_format(COL_TIME_ON, \'%Y-%m-%d %H:%i\') = "'.$datetime.'"'); - $this->db->where('COL_CALL', $callsign); - $this->db->where('COL_BAND', $band); - $this->db->where('COL_STATION_CALLSIGN', $station_callsign); + $this->db->where('date_format(COL_TIME_ON, \'%Y-%m-%d %H:%i\') = "'.$datetime.'"'); + $this->db->where('COL_CALL', $callsign); + $this->db->where('COL_BAND', $band); + $this->db->where('COL_STATION_CALLSIGN', $station_callsign); + $this->db->where('COL_PRIMARY_KEY', $qsoid); - $this->db->update($this->config->item('table_name'), $data); - unset($data); + $this->db->update($this->config->item('table_name'), $data); + unset($data); - if($qsl_gridsquare != "" || $qsl_vucc_grids != "") { - $data = array( - 'COL_DISTANCE' => 0 - ); - $this->db->select('station_profile.station_gridsquare as station_gridsquare'); - $this->db->where('date_format(COL_TIME_ON, \'%Y-%m-%d %H:%i\') = "'.$datetime.'"'); - $this->db->where('COL_CALL', $callsign); - $this->db->where('COL_BAND', $band); - $this->db->join('station_profile', $this->config->item('table_name').'.station_id = station_profile.station_id', 'left outer'); - $this->db->limit(1); - $query = $this->db->get($this->config->item('table_name')); - $row = $query->row(); - $station_gridsquare = ''; - if (isset($row)) { - $station_gridsquare = $row->station_gridsquare; - } - if(!$this->load->is_loaded('Qra')) { - $this->load->library('Qra'); - } - if ($qsl_gridsquare != "") { - $data['COL_GRIDSQUARE'] = $qsl_gridsquare; - $data['COL_DISTANCE'] = $this->qra->distance($station_gridsquare, $qsl_gridsquare, 'K'); - } elseif ($qsl_vucc_grids != "") { - $data['COL_VUCC_GRIDS'] = $qsl_vucc_grids; - $data['COL_DISTANCE'] = $this->qra->distance($station_gridsquare, $qsl_vucc_grids, 'K'); - } + if($qsl_gridsquare != "" || $qsl_vucc_grids != "") { + $data = array( + 'COL_DISTANCE' => 0 + ); + $this->db->select('station_profile.station_gridsquare as station_gridsquare'); + $this->db->where('date_format(COL_TIME_ON, \'%Y-%m-%d %H:%i\') = "'.$datetime.'"'); + $this->db->where('COL_CALL', $callsign); + $this->db->where('COL_BAND', $band); + $this->db->where('COL_PRIMARY_KEY', $qsoid); + $this->db->join('station_profile', $this->config->item('table_name').'.station_id = station_profile.station_id', 'left outer'); + $this->db->limit(1); + $query = $this->db->get($this->config->item('table_name')); + $row = $query->row(); + $station_gridsquare = ''; + if (isset($row)) { + $station_gridsquare = $row->station_gridsquare; + } + if(!$this->load->is_loaded('Qra')) { + $this->load->library('Qra'); + } + if ($qsl_gridsquare != "") { + $data['COL_GRIDSQUARE'] = $qsl_gridsquare; + $data['COL_DISTANCE'] = $this->qra->distance($station_gridsquare, $qsl_gridsquare, 'K'); + } elseif ($qsl_vucc_grids != "") { + $data['COL_VUCC_GRIDS'] = $qsl_vucc_grids; + $data['COL_DISTANCE'] = $this->qra->distance($station_gridsquare, $qsl_vucc_grids, 'K'); + } - $this->db->where('date_format(COL_TIME_ON, \'%Y-%m-%d %H:%i\') = "'.$datetime.'"'); - $this->db->where('COL_CALL', $callsign); - $this->db->where('COL_BAND', $band); + $this->db->where('date_format(COL_TIME_ON, \'%Y-%m-%d %H:%i\') = "'.$datetime.'"'); + $this->db->where('COL_CALL', $callsign); + $this->db->where('COL_BAND', $band); + $this->db->where('COL_PRIMARY_KEY', $qsoid); - $this->db->update($this->config->item('table_name'), $data); + $this->db->update($this->config->item('table_name'), $data); + } + + return "Updated"; } - return "Updated"; - } - function qrz_last_qsl_date($user_id) { $sql="SELECT date_format(MAX(COALESCE(COL_QRZCOM_QSO_DOWNLOAD_DATE, str_to_date('1900-01-01','%Y-%m-%d'))),'%Y-%m-%d') MAXDATE FROM ".$this->config->item('table_name')." INNER JOIN station_profile ON (".$this->config->item('table_name').".station_id = station_profile.station_id)