Remove unneeded migration and refactor SQL

This commit is contained in:
phl0
2026-01-20 13:50:22 +01:00
parent 90695f19a8
commit 0762f81e94
5 changed files with 29 additions and 52 deletions

View File

@@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE;
|
*/
$config['migration_version'] = 270;
$config['migration_version'] = 269;
/*
|--------------------------------------------------------------------------

View File

@@ -18,7 +18,7 @@ class Logbook extends CI_Controller {
$this->load->library('pagination');
$config['base_url'] = base_url().'index.php/logbook/index/';
$config['total_rows'] = $this->logbook_model->total_qsos();
$config['per_page'] = '25';
$config['per_page'] = 25;
$config['num_links'] = 6;
$config['full_tag_open'] = '';
$config['full_tag_close'] = '';

View File

@@ -1,22 +0,0 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Migration_sat_name_null extends CI_Migration {
public function up() {
$this->dbtry("UPDATE ".$this->config->item('table_name')." SET COL_SAT_NAME = null WHERE COL_SAT_NAME = '';");
}
public function down(){
$this->dbtry("UPDATE ".$this->config->item('table_name')." SET COL_SAT_NAME = '' WHERE COL_SAT_NAME IS null;");
}
function dbtry($what) {
try {
$this->db->query($what);
} catch (Exception $e) {
log_message("error", "Something gone wrong while altering the QSO table: ".$e." // Executing: ".$this->db->last_query());
}
}
}

View File

@@ -364,7 +364,7 @@ class Logbook_model extends CI_Model {
'COL_RST_SENT' => $this->input->post('rst_sent'),
'COL_NAME' => $qso_name,
'COL_COMMENT' => $this->input->post('comment'),
'COL_SAT_NAME' => $this->input->post('sat_name') == null ? null : strtoupper($this->input->post('sat_name')),
'COL_SAT_NAME' => $this->input->post('sat_name') == null ? '' : strtoupper($this->input->post('sat_name')),
'COL_SAT_MODE' => $this->input->post('sat_mode') == null ? '' : strtoupper($this->input->post('sat_mode')),
'COL_COUNTRY' => $country,
'COL_CONT' => $continent,
@@ -2284,39 +2284,38 @@ class Logbook_model extends CI_Model {
return array();
}
$this->db->select($this->config->item('table_name') . '.*, station_profile.*, dxcc_entities.*, lotw_users.callsign, lotw_users.lastupload, satellite.displayname AS sat_displayname');
$this->db->from($this->config->item('table_name'));
$this->db->join('station_profile', 'station_profile.station_id = ' . $this->config->item('table_name') . '.station_id');
$this->db->join('dxcc_entities', $this->config->item('table_name') . '.col_dxcc = dxcc_entities.adif', 'left');
$this->db->join('lotw_users', 'lotw_users.callsign = ' . $this->config->item('table_name') . '.col_call', 'left outer');
$this->db->join('satellite', 'satellite.name = ' . $this->config->item('table_name') . '.COL_SAT_NAME', 'left outer');
$binding = array();
$sql = "SELECT qsos.*, station_profile.*, dxcc_entities.*, lotw_users.callsign, lotw_users.lastupload, satellite.displayname AS sat_displayname
FROM ".$this->config->item('table_name')." qsos
JOIN `station_profile` ON `station_profile`.`station_id` = qsos.`station_id`
LEFT JOIN `dxcc_entities` ON qsos.`col_dxcc` = `dxcc_entities`.`adif`
LEFT OUTER JOIN `lotw_users` ON `lotw_users`.`callsign` = qsos.`col_call`
LEFT OUTER JOIN satellite ON qsos.col_prop_mode='SAT' and qsos.COL_SAT_NAME = COALESCE(NULLIF(satellite.name, ''), NULLIF(satellite.displayname, ''))
WHERE 1=1";
if ($band != '') {
if ($band == 'SAT') {
$this->db->where($this->config->item('table_name') . '.col_prop_mode', 'SAT');
$sql .= " AND qsos.`col_prop_mode` = 'SAT'";
} else {
$this->db->where($this->config->item('table_name') . '.col_prop_mode !="SAT"');
$this->db->where($this->config->item('table_name') . '.col_band', $band);
$sql .= " AND qsos.`col_prop_mode` != 'SAT' AND qsos.`col_band` = ?";
$bindings[] = $band;
}
}
if ($map == true) {
$this->db->group_start();
$this->db->where($this->config->item('table_name') . '.col_gridsquare !=', '');
$this->db->or_where($this->config->item('table_name') . '.col_vucc_grids !=', '');
$this->db->group_end();
$sql .= " AND ( qsos.`col_gridsquare` != '' OR qsos.`col_vucc_grids` != '')";
}
$this->db->where_in($this->config->item('table_name') . '.station_id', $logbooks_locations_array);
$this->db->order_by('' . $this->config->item('table_name') . '.COL_TIME_ON', "desc");
$this->db->order_by('' . $this->config->item('table_name') . '.COL_PRIMARY_KEY', "desc");
$this->db->limit($num);
$this->db->offset($offset);
return $this->db->get();
$sql .= " AND qsos.`station_id` IN ?
ORDER BY qsos.`COL_TIME_ON` DESC, qsos.`COL_PRIMARY_KEY` DESC";
$binding[] = $logbooks_locations_array;
if ($num) {
$sql .= " LIMIT ?";
$binding[] = (int) $num;
}
if ($offset) {
$sql .= " OFFSET ?";
$binding[] = (int) $offset;
}
$sql .= ";";
return $this->db->query($sql, $binding);
}
function get_qso($id, $trusted = false) {

View File

@@ -1170,7 +1170,7 @@ class Logbookadvanced_model extends CI_Model {
$bandtx = $value3 == '' ? '' : $value3;
$bandrx = $value4 == '' ? '' : $value4;
$bindings[] = $value == '' ? null : $value;
$bindings[] = $value;
$bindings[] = $propmode;
$sql = "UPDATE ".$this->config->item('table_name')." JOIN station_profile ON ". $this->config->item('table_name').".station_id = station_profile.station_id" .