From 7b8f767db4ba30b30c736cc86848e4f9014aa6be Mon Sep 17 00:00:00 2001 From: phl0 Date: Sun, 1 Dec 2024 23:49:51 +0100 Subject: [PATCH] Exchange column names for display and lotw name --- application/controllers/Satellite.php | 2 +- application/controllers/Update.php | 2 +- .../migrations/228_rename_satellites.php | 50 +++++++++++++++---- application/models/Satellite_model.php | 6 +-- application/views/satellite/create.php | 14 +++--- application/views/satellite/edit.php | 14 +++--- application/views/satellite/index.php | 6 +-- assets/js/sections/satellite.js | 4 +- 8 files changed, 65 insertions(+), 33 deletions(-) diff --git a/application/controllers/Satellite.php b/application/controllers/Satellite.php index d7f18cc83..32d0979db 100644 --- a/application/controllers/Satellite.php +++ b/application/controllers/Satellite.php @@ -75,7 +75,7 @@ class Satellite extends CI_Controller { $id = $this->security->xss_clean($this->input->post('id', true)); $satellite['name'] = $this->security->xss_clean($this->input->post('name')); - $satellite['exportname'] = $this->security->xss_clean($this->input->post('exportname')); + $satellite['displayname'] = $this->security->xss_clean($this->input->post('displayname')); $satellite['orbit'] = $this->security->xss_clean($this->input->post('orbit')); if ($this->security->xss_clean($this->input->post('lotw')) == 'Y') { $satellite['lotw'] = 'Y'; diff --git a/application/controllers/Update.php b/application/controllers/Update.php index f8fca53cd..5c6937735 100644 --- a/application/controllers/Update.php +++ b/application/controllers/Update.php @@ -423,7 +423,7 @@ class Update extends CI_Controller { $satname = $lines[$i]; $tleline1 = $lines[$i + 1]; $tleline2 = $lines[$i + 2]; - $sql = "INSERT INTO tle (satelliteid, tle) select id, ? from satellite where name = ? or exportname = ?"; + $sql = "INSERT INTO tle (satelliteid, tle) select id, ? from satellite where name = ? or displayname = ?"; $this->db->query($sql,array($tleline1."\n".$tleline2,$satname,$satname)); } } diff --git a/application/migrations/228_rename_satellites.php b/application/migrations/228_rename_satellites.php index 94f05dbb1..edd287562 100644 --- a/application/migrations/228_rename_satellites.php +++ b/application/migrations/228_rename_satellites.php @@ -126,23 +126,53 @@ class Migration_rename_satellites extends CI_Migration { $this->update_sat_table($exportname, $name); $this->update_log_table($exportname, $name); } - } - if (!$this->db->field_exists('lotw', 'satellite')) { + if (!$this->db->field_exists('lotw', 'satellite')) { + $fields = array( + 'lotw VARCHAR(1) NOT NULL DEFAULT "N" AFTER `orbit`', + ); + $this->dbforge->add_column('satellite', $fields); + } + + $this->set_lotw($this->lotw_sats); + + $query = $this->db->get_where('satellite', array('name' => 'SONATE')); + if ($query->num_rows() > 0) { + $this->set_lotw(array("SONATE")); + } else { + $this->insert_sat("SONATE", "SONATE-2", "LEO", "V/V", "PKT", "145825000", "PKT", "145825000", "Y"); + } + $query = $this->db->get_where('satellite', array('name' => 'MO-122')); + if ($query->num_rows() > 0) { + $this->set_lotw(array("MO-122")); + } else { + $this->insert_sat("MO-122", "MESAT1", "LEO", "V/U", "LSB", "145925000", "USB", "435825000", "Y"); + } + $fields = array( - 'lotw VARCHAR(1) NOT NULL DEFAULT "N" AFTER `orbit`', + 'exportname' => array( + 'name' => 'displayname', + 'type' => 'VARCHAR', + 'constraint' => 255, + ), ); - $this->dbforge->add_column('satellite', $fields); + $this->dbforge->modify_column('satellite', $fields); } - - $this->set_lotw($this->lotw_sats); - $this->insert_sat("SONATE", "SONATE-2", "LEO", "V/V", "PKT", "145825000", "PKT", "145825000"); - $this->insert_sat("MO-122", "MESAT1", "LEO", "V/U", "LSB", "145925000", "USB", "435825000"); } public function down() { if ($this->db->table_exists('satellite')) { + $fields = array( + 'displayname' => array( + 'name' => 'exportname', + 'type' => 'VARCHAR', + 'constraint' => 255, + ), + ); + + $this->dbforge->modify_column('satellite', $fields); + foreach ($this->satellites as $exportname => $name) { $this->update_sat_table($name, $exportname); $this->update_log_table($name, $exportname); @@ -171,10 +201,11 @@ class Migration_rename_satellites extends CI_Migration { $this->db->query($sql); } - function insert_sat($name, $exportname, $orbit, $modename, $uplink_mode, $uplink_freq, $downlink_mode, $downlink_freq) { + function insert_sat($name, $exportname, $orbit, $modename, $uplink_mode, $uplink_freq, $downlink_mode, $downlink_freq, $lotw) { $data = array( 'name' => $name, 'exportname' => $exportname, + 'lotw' => $lotw, 'orbit' => $orbit, ); $this->db->where('name', $name); @@ -182,6 +213,7 @@ class Migration_rename_satellites extends CI_Migration { if ($result->num_rows() == 0) { $this->db->insert('satellite', $data); + log_message('debug', 'SQL: '.$this->db->last_query()); $insert_id = $this->db->insert_id(); $modedata = array( diff --git a/application/models/Satellite_model.php b/application/models/Satellite_model.php index 07fd82409..503391419 100644 --- a/application/models/Satellite_model.php +++ b/application/models/Satellite_model.php @@ -3,10 +3,10 @@ class Satellite_model extends CI_Model { function get_all_satellites() { - $sql = "select satellite.id, satellite.name as satname, group_concat(distinct satellitemode.name separator ', ') as modename, satellite.exportname, satellite.orbit, satellite.lotw as lotw + $sql = "select satellite.id, satellite.name as satname, group_concat(distinct satellitemode.name separator ', ') as modename, satellite.displayname, satellite.orbit, satellite.lotw as lotw from satellite left outer join satellitemode on satellite.id = satellitemode.satelliteid - group by satellite.name, satellite.exportname, satellite.orbit, satellite.id"; + group by satellite.name, satellite.displayname, satellite.orbit, satellite.id"; return $this->db->query($sql)->result(); } @@ -52,7 +52,7 @@ class Satellite_model extends CI_Model { function add() { $data = array( 'name' => xss_clean($this->input->post('name', true)), - 'exportname' => xss_clean($this->input->post('exportname', true)), + 'displayname' => xss_clean($this->input->post('displayname', true)), 'orbit' => xss_clean($this->input->post('orbit', true)), ); if (xss_clean($this->input->post('lotw', true)) == 'Y') { diff --git a/application/views/satellite/create.php b/application/views/satellite/create.php index 115d9f5d3..50b980f94 100644 --- a/application/views/satellite/create.php +++ b/application/views/satellite/create.php @@ -20,14 +20,14 @@
- - - + + +
- - - + + +
@@ -71,7 +71,7 @@ - +
diff --git a/application/views/satellite/edit.php b/application/views/satellite/edit.php index 763bd6509..08d6c1062 100644 --- a/application/views/satellite/edit.php +++ b/application/views/satellite/edit.php @@ -4,14 +4,14 @@
- - name; } ?>" required> - + + displayname; } ?>" required> +
- - exportname; } ?>" required> - + + name; } ?>" required> +
@@ -31,7 +31,7 @@ - +
diff --git a/application/views/satellite/index.php b/application/views/satellite/index.php index fc48a06f3..2e88f4965 100644 --- a/application/views/satellite/index.php +++ b/application/views/satellite/index.php @@ -18,8 +18,8 @@ - - + + @@ -31,7 +31,7 @@ - +
satname) ?>exportname ? htmlentities($sat->exportname) : '' ?>displayname ? htmlentities($sat->displayname) : '' ?>