diff --git a/application/config/migration.php b/application/config/migration.php index 698d351c6..f46573a92 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE; | */ -$config['migration_version'] = 237; +$config['migration_version'] = 238; /* |-------------------------------------------------------------------------- diff --git a/application/models/Update_model.php b/application/models/Update_model.php index 40239a6de..29fa27b5b 100644 --- a/application/models/Update_model.php +++ b/application/models/Update_model.php @@ -316,10 +316,11 @@ class Update_model extends CI_Model { $this->load->model('cron_model'); $this->cron_model->set_last_run($this->router->class . '_' . $this->router->method); $mtime = microtime(); - $mtime = explode(" ",$mtime); - $mtime = $mtime[1] + $mtime[0]; - $starttime = $mtime; + $mtime = explode(" ",$mtime); + $mtime = $mtime[1] + $mtime[0]; + $starttime = $mtime; + $this->update_norad_ids(); $url = 'https://www.amsat.org/tle/dailytle.txt'; $curl = curl_init($url); @@ -345,18 +346,18 @@ class Update_model extends CI_Model { // Check if there are at least three lines remaining if (isset($lines[$i], $lines[$i + 1], $lines[$i + 2])) { // Get the three lines - $satname = $lines[$i]; + $satname = substr($lines[$i+1], 2, 5); $tleline1 = $lines[$i + 1]; $tleline2 = $lines[$i + 2]; $sql = " INSERT INTO tle (satelliteid, tle) SELECT id, ? FROM satellite - WHERE name = ? OR displayname = ? + WHERE norad_id = ? ON DUPLICATE KEY UPDATE tle = VALUES(tle), updated = now() "; - $this->db->query($sql, array($tleline1 . "\n" . $tleline2, $satname, $satname)); + $this->db->query($sql, array($tleline1 . "\n" . $tleline2, $satname)); } } } @@ -472,4 +473,15 @@ class Update_model extends CI_Model { } } + function update_norad_ids() { + $csvfile = 'https://www.df2et.de/cqrlog/lotw_norad.csv'; + $csvhandle = fopen($csvfile, "r"); + while (false !== ($data = fgetcsv($csvhandle, 1000, ","))) { + $this->db->set('norad_id', $data[1]); + $this->db->where('name', $data[0]); + $this->db->update('satellite'); + } + return; + } + }