From 38b119f0c151c9270016b93c58ae694785f8f81d Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Sun, 5 May 2024 09:33:35 +0200 Subject: [PATCH 1/2] moved functions to the update_model --- application/controllers/Update.php | 359 ++++++------------------- application/libraries/Genfunctions.php | 12 + application/models/Update_model.php | 237 ++++++++++++++++ 3 files changed, 324 insertions(+), 284 deletions(-) create mode 100644 application/models/Update_model.php diff --git a/application/controllers/Update.php b/application/controllers/Update.php index d0c4acece..81421665c 100644 --- a/application/controllers/Update.php +++ b/application/controllers/Update.php @@ -30,27 +30,14 @@ class Update extends CI_Controller { } - /* - * Create a path to a file in the updates folder, respecting the datadir - * configuration option. - */ - private function make_update_path($path) { - $path = "updates/" . $path; - $datadir = $this->config->item('datadir'); - if(!$datadir) { - return $path; - } - return $datadir . "/" . $path; - } - /* * Load the dxcc entities */ public function dxcc_entities() { - // Load Database connectors - // Load the cty file - $xml_data = simplexml_load_file($this->make_update_path("cty.xml")); + // Load the cty file + $this->load->library('Genfunctions'); + $xml_data = simplexml_load_file($this->genfunctions->make_update_path("cty.xml")); //$xml_data->entities->entity->count(); @@ -98,9 +85,10 @@ class Update extends CI_Controller { * Load the dxcc exceptions */ public function dxcc_exceptions() { - // Load Database connectors - // Load the cty file - $xml_data = simplexml_load_file($this->make_update_path("cty.xml")); + + // Load the cty file + $this->load->library('Genfunctions'); + $xml_data = simplexml_load_file($this->genfunctions->make_update_path("cty.xml")); $count = 0; $a_data=[]; @@ -139,9 +127,10 @@ class Update extends CI_Controller { * Load the dxcc prefixes */ public function dxcc_prefixes() { - // Load Database connectors + // Load the cty file - $xml_data = simplexml_load_file($this->make_update_path("cty.xml")); + $this->load->library('Genfunctions'); + $xml_data = simplexml_load_file($this->genfunctions->make_update_path("cty.xml")); $count = 0; $a_data=[]; @@ -180,59 +169,63 @@ class Update extends CI_Controller { // Updates the DXCC & Exceptions from the Club Log Cty.xml file. public function dxcc() { + $this->load->library('Genfunctions'); + // set the last run in cron table for the correct cron id $this->load->model('cron_model'); - $this->cron_model->set_last_run($this->router->class.'_'.$this->router->method); + $this->cron_model->set_last_run($this->router->class.'_'.$this->router->method); - $this->update_status("Downloading file"); + $this->update_status("Downloading file"); - // give it 10 minutes... - set_time_limit(600); + // give it 10 minutes... + set_time_limit(600); - // Load Migration data if any. - $this->load->library('migration'); - $this->fix_migrations(); - $this->migration->latest(); + // Load Migration data if any. + $this->load->library('migration'); + $this->fix_migrations(); + $this->migration->latest(); - // Download latest file. - $url = "https://cdn.clublog.org/cty.php?api=608df94896cb9c5421ae748235492b43815610c9"; + // Download latest file. + $url = "https://cdn.clublog.org/cty.php?api=608df94896cb9c5421ae748235492b43815610c9"; - $gz = gzopen($url, 'r'); - if ($gz === FALSE) { - $this->update_status("FAILED: Could not download from clublog.org"); - log_message('error', 'FAILED: Could not download exceptions from clublog.org'); - return; - } + $gz = gzopen($url, 'r'); + if ($gz === FALSE) { + $this->update_status("FAILED: Could not download from clublog.org"); + log_message('error', 'FAILED: Could not download exceptions from clublog.org'); + return; + } - $data = ""; - while (!gzeof($gz)) { - $data .= gzgetc($gz); - } - gzclose($gz); + $data = ""; + while (!gzeof($gz)) { + $data .= gzgetc($gz); + } + gzclose($gz); - if (file_put_contents($this->make_update_path("cty.xml"), $data) === FALSE) { - $this->update_status("FAILED: Could not write to cty.xml file"); - return; - } + if (file_put_contents($this->genfunctions->make_update_path("cty.xml"), $data) === FALSE) { + $this->update_status("FAILED: Could not write to cty.xml file"); + return; + } - // Clear the tables, ready for new data - $this->db->empty_table("dxcc_entities"); - $this->db->empty_table("dxcc_exceptions"); - $this->db->empty_table("dxcc_prefixes"); - $this->update_status(); + // Clear the tables, ready for new data + $this->db->empty_table("dxcc_entities"); + $this->db->empty_table("dxcc_exceptions"); + $this->db->empty_table("dxcc_prefixes"); + $this->update_status(); - // Parse the three sections of the file and update the tables - $this->db->trans_start(); - $this->dxcc_entities(); - $this->dxcc_exceptions(); - $this->dxcc_prefixes(); - $this->db->trans_complete(); + // Parse the three sections of the file and update the tables + $this->db->trans_start(); + $this->dxcc_entities(); + $this->dxcc_exceptions(); + $this->dxcc_prefixes(); + $this->db->trans_complete(); - $this->update_status("DONE"); + $this->update_status("DONE"); } public function update_status($done=""){ + $this->load->library('Genfunctions'); + if ($done != "Downloading file"){ // Check that everything is done? if ($done == ""){ @@ -246,18 +239,18 @@ class Update extends CI_Controller { $html = $done."....
"; } - file_put_contents($this->make_update_path("status.html"), $html); + file_put_contents($this->genfunctions->make_update_path("status.html"), $html); } private function fix_migrations(){ - $res = $this->db->query("select version from migrations"); + $res = $this->db->query("SELECT version FROM migrations"); if ($res->num_rows() >0){ $row = $res->row(); $version = $row->version; if ($version < 7){ - $this->db->query("update migrations set version=7"); + $this->db->query("UPDATE migrations SET version=7"); } } } @@ -308,37 +301,10 @@ class Update extends CI_Controller { public function update_clublog_scp() { - // set the last run in cron table for the correct cron id - $this->load->model('cron_model'); - $this->cron_model->set_last_run($this->router->class.'_'.$this->router->method); + $this->load->model('Update_model'); + $result = $this->Update_model->clublog_scp(); + echo $result; - $strFile = $this->make_update_path("clublog_scp.txt"); - $url = "https://cdn.clublog.org/clublog.scp.gz"; - set_time_limit(300); - echo "Downloading Club Log SCP file...
"; - $gz = gzopen($url, 'r'); - if ($gz) - { - $data = ""; - while (!gzeof($gz)) { - $data .= gzgetc($gz); - } - gzclose($gz); - if (file_put_contents($strFile, $data) !== FALSE) - { - $nCount = count(file($strFile)); - if ($nCount > 0) - { - echo "DONE: " . number_format($nCount) . " callsigns loaded"; - } else { - echo "FAILED: Empty file"; - } - } else { - echo "FAILED: Could not write to Club Log SCP file"; - } - } else { - echo "FAILED: Could not connect to Club Log"; - } } public function download_lotw_users() { @@ -360,48 +326,10 @@ class Update extends CI_Controller { public function lotw_users() { - // set the last run in cron table for the correct cron id - $this->load->model('cron_model'); - $this->cron_model->set_last_run($this->router->class.'_'.$this->router->method); + $this->load->model('Update_model'); + $result = $this->Update_model->lotw_users(); + echo $result; - $mtime = microtime(); - $mtime = explode(" ",$mtime); - $mtime = $mtime[1] + $mtime[0]; - $starttime = $mtime; - - $file = 'https://lotw.arrl.org/lotw-user-activity.csv'; - - $handle = fopen($file, "r"); - if ($handle === FALSE) { - echo "Something went wrong with fetching the LoTW uses file"; - return; - } - $this->db->empty_table("lotw_users"); - $i = 0; - $data = fgetcsv($handle,1000,","); - do { - if ($data[0]) { - $lotwdata[$i]['callsign'] = $data[0]; - $lotwdata[$i]['lastupload'] = $data[1] . ' ' . $data[2]; - if (($i % 2000) == 0) { - $this->db->insert_batch('lotw_users', $lotwdata); - unset($lotwdata); - // echo 'Record ' . $i . '
'; - } - $i++; - } - } while ($data = fgetcsv($handle,1000,",")); - fclose($handle); - - $this->db->insert_batch('lotw_users', $lotwdata); - - $mtime = microtime(); - $mtime = explode(" ",$mtime); - $mtime = $mtime[1] + $mtime[0]; - $endtime = $mtime; - $totaltime = ($endtime - $starttime); - echo "This page was created in ".$totaltime." seconds
"; - echo "Records inserted: " . $i . "
"; } public function lotw_check() { @@ -422,29 +350,10 @@ class Update extends CI_Controller { */ public function update_dok() { - // set the last run in cron table for the correct cron id - $this->load->model('cron_model'); - $this->cron_model->set_last_run($this->router->class.'_'.$this->router->method); - - $contents = file_get_contents('https://www.df2et.de/cqrlog/dok_and_sdok.txt', true); - - if($contents === FALSE) { - echo "Something went wrong with fetching the DOK file."; - } else { - $file = './assets/json/dok.txt'; - - if (file_put_contents($file, $contents) !== FALSE) { // Save our content to the file. - $nCount = count(file($file)); - if ($nCount > 0) - { - echo "DONE: " . number_format($nCount) . " DOKs and SDOKs saved"; - } else { - echo"FAILED: Empty file"; - } - } else { - echo"FAILED: Could not write to dok.txt file"; - } - } + $this->load->model('Update_model'); + $result = $this->Update_model->dok(); + echo $result; + } /* @@ -452,47 +361,10 @@ class Update extends CI_Controller { */ public function update_sota() { - // set the last run in cron table for the correct cron id - $this->load->model('cron_model'); - $this->cron_model->set_last_run($this->router->class.'_'.$this->router->method); - - $csvfile = 'https://www.sotadata.org.uk/summitslist.csv'; - - $sotafile = './assets/json/sota.txt'; - - $csvhandle = fopen($csvfile,"r"); - if ($csvhandle === FALSE) { - echo "Something went wrong with fetching the SOTA file"; - return; - } - - $data = fgetcsv($csvhandle,1000,","); // Skip line we are not interested in - $data = fgetcsv($csvhandle,1000,","); // Skip line we are not interested in - $data = fgetcsv($csvhandle,1000,","); - $sotafilehandle = fopen($sotafile, 'w'); - - if ($sotafilehandle === FALSE) { - echo"FAILED: Could not write to sota.txt file"; - return; - } - - $nCount = 0; - do { - if ($data[0]) { - fwrite($sotafilehandle, $data[0].PHP_EOL); - $nCount++; - } - } while ($data = fgetcsv($csvhandle,1000,",")); - - fclose($csvhandle); - fclose($sotafilehandle); - - if ($nCount > 0) - { - echo "DONE: " . number_format($nCount) . " SOTA's saved"; - } else { - echo"FAILED: Empty file"; - } + $this->load->model('Update_model'); + $result = $this->Update_model->sota(); + echo $result; + } /* @@ -500,99 +372,18 @@ class Update extends CI_Controller { */ public function update_wwff() { - // set the last run in cron table for the correct cron id - $this->load->model('cron_model'); - $this->cron_model->set_last_run($this->router->class.'_'.$this->router->method); + $this->load->model('Update_model'); + $result = $this->Update_model->wwff(); + echo $result; - $csvfile = 'https://wwff.co/wwff-data/wwff_directory.csv'; - - $wwfffile = './assets/json/wwff.txt'; - - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $csvfile); - curl_setopt($ch, CURLOPT_HEADER, false); - curl_setopt($ch, CURLOPT_USERAGENT, 'Wavelog Updater'); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - $csv = curl_exec($ch); - curl_close($ch); - if ($csv === FALSE) { - echo "Something went wrong with fetching the WWFF file"; - return; - } - - $wwfffilehandle = fopen($wwfffile, 'w'); - if ($wwfffilehandle === FALSE) { - echo"FAILED: Could not write to wwff.txt file"; - return; - } - - $data = str_getcsv($csv,"\n"); - $nCount = 0; - foreach ($data as $idx => $row) { - if ($idx == 0) continue; // Skip line we are not interested in - $row = str_getcsv($row, ','); - if ($row[0]) { - fwrite($wwfffilehandle, $row[0].PHP_EOL); - $nCount++; - } - } - - fclose($wwfffilehandle); - - if ($nCount > 0) - { - echo "DONE: " . number_format($nCount) . " WWFF's saved"; - } else { - echo"FAILED: Empty file"; - } } public function update_pota() { - // set the last run in cron table for the correct cron id - $this->load->model('cron_model'); - $this->cron_model->set_last_run($this->router->class.'_'.$this->router->method); - - $csvfile = 'https://pota.app/all_parks.csv'; - - $potafile = './assets/json/pota.txt'; - - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $csvfile); - curl_setopt($ch, CURLOPT_HEADER, false); - curl_setopt($ch, CURLOPT_USERAGENT, 'Wavelog Updater'); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - $csv = curl_exec($ch); - curl_close($ch); - if ($csv === FALSE) { - echo "Something went wrong with fetching the POTA file"; - return; - } - - $potafilehandle = fopen($potafile, 'w'); - if ($potafilehandle === FALSE) { - echo"FAILED: Could not write to pota.txt file"; - return; - } - $data = str_getcsv($csv,"\n"); - $nCount = 0; - foreach ($data as $idx => $row) { - if ($idx == 0) continue; // Skip line we are not interested in - $row = str_getcsv($row, ','); - if ($row[0]) { - fwrite($potafilehandle, $row[0].PHP_EOL); - $nCount++; - } - } - - fclose($potafilehandle); - - if ($nCount > 0) - { - echo "DONE: " . number_format($nCount) . " POTA's saved"; - } else { - echo"FAILED: Empty file"; - } + $this->load->model('Update_model'); + $result = $this->Update_model->pota(); + echo $result; + } } diff --git a/application/libraries/Genfunctions.php b/application/libraries/Genfunctions.php index 71315b771..ec9fe87c6 100644 --- a/application/libraries/Genfunctions.php +++ b/application/libraries/Genfunctions.php @@ -111,4 +111,16 @@ class Genfunctions } } + function make_update_path($path) { + + $CI = & get_instance(); + + $path = "updates/" . $path; + $datadir = $CI->config->item('datadir'); + if(!$datadir) { + return $path; + } + return $datadir . "/" . $path; + } + } diff --git a/application/models/Update_model.php b/application/models/Update_model.php new file mode 100644 index 000000000..a71836764 --- /dev/null +++ b/application/models/Update_model.php @@ -0,0 +1,237 @@ +load->model('cron_model'); + $this->load->library('Genfunctions'); + + $this->cron_model->set_last_run($this->router->class . '_' . $this->router->method); + + $strFile = $this->genfunctions->make_update_path("clublog_scp.txt"); + + $url = "https://cdn.clublog.org/clublog.scp.gz"; + set_time_limit(300); + + $gz = gzopen($url, 'r'); + if ($gz) { + $data = ""; + while (!gzeof($gz)) { + $data .= gzgetc($gz); + } + gzclose($gz); + if (file_put_contents($strFile, $data) !== FALSE) { + $nCount = count(file($strFile)); + if ($nCount > 0) { + return "DONE: " . number_format($nCount) . " callsigns loaded"; + } else { + return "FAILED: Empty file"; + } + } else { + return "FAILED: Could not write to Club Log SCP file"; + } + } else { + return "FAILED: Could not connect to Club Log"; + } + } + + function dok() { + // set the last run in cron table for the correct cron id + $this->load->model('cron_model'); + $this->cron_model->set_last_run($this->router->class . '_' . $this->router->method); + + $contents = file_get_contents('https://www.df2et.de/cqrlog/dok_and_sdok.txt', true); + + if ($contents === FALSE) { + return "Something went wrong with fetching the DOK file."; + } else { + $file = './assets/json/dok.txt'; + + if (file_put_contents($file, $contents) !== FALSE) { // Save our content to the file. + $nCount = count(file($file)); + if ($nCount > 0) { + return "DONE: " . number_format($nCount) . " DOKs and SDOKs saved"; + } else { + return "FAILED: Empty file"; + } + } else { + return "FAILED: Could not write to dok.txt file"; + } + } + } + + function sota() { + // set the last run in cron table for the correct cron id + $this->load->model('cron_model'); + $this->cron_model->set_last_run($this->router->class . '_' . $this->router->method); + + $csvfile = 'https://www.sotadata.org.uk/summitslist.csv'; + + $sotafile = './assets/json/sota.txt'; + + $csvhandle = fopen($csvfile, "r"); + if ($csvhandle === FALSE) { + return "Something went wrong with fetching the SOTA file"; + } + + $data = fgetcsv($csvhandle, 1000, ","); // Skip line we are not interested in + $data = fgetcsv($csvhandle, 1000, ","); // Skip line we are not interested in + $data = fgetcsv($csvhandle, 1000, ","); + $sotafilehandle = fopen($sotafile, 'w'); + + if ($sotafilehandle === FALSE) { + return "FAILED: Could not write to sota.txt file"; + } + + $nCount = 0; + do { + if ($data[0]) { + fwrite($sotafilehandle, $data[0] . PHP_EOL); + $nCount++; + } + } while ($data = fgetcsv($csvhandle, 1000, ",")); + + fclose($csvhandle); + fclose($sotafilehandle); + + if ($nCount > 0) { + return "DONE: " . number_format($nCount) . " SOTA's saved"; + } else { + return "FAILED: Empty file"; + } + } + + function wwff() { + // set the last run in cron table for the correct cron id + $this->load->model('cron_model'); + $this->cron_model->set_last_run($this->router->class . '_' . $this->router->method); + + $csvfile = 'https://wwff.co/wwff-data/wwff_directory.csv'; + + $wwfffile = './assets/json/wwff.txt'; + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $csvfile); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_USERAGENT, 'Wavelog Updater'); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $csv = curl_exec($ch); + curl_close($ch); + if ($csv === FALSE) { + return "Something went wrong with fetching the WWFF file"; + } + + $wwfffilehandle = fopen($wwfffile, 'w'); + if ($wwfffilehandle === FALSE) { + return "FAILED: Could not write to wwff.txt file"; + } + + $data = str_getcsv($csv, "\n"); + $nCount = 0; + foreach ($data as $idx => $row) { + if ($idx == 0) continue; // Skip line we are not interested in + $row = str_getcsv($row, ','); + if ($row[0]) { + fwrite($wwfffilehandle, $row[0] . PHP_EOL); + $nCount++; + } + } + + fclose($wwfffilehandle); + + if ($nCount > 0) { + return "DONE: " . number_format($nCount) . " WWFF's saved"; + } else { + return "FAILED: Empty file"; + } + } + + function pota() { + // set the last run in cron table for the correct cron id + $this->load->model('cron_model'); + $this->cron_model->set_last_run($this->router->class . '_' . $this->router->method); + + $csvfile = 'https://pota.app/all_parks.csv'; + + $potafile = './assets/json/pota.txt'; + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $csvfile); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_USERAGENT, 'Wavelog Updater'); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $csv = curl_exec($ch); + curl_close($ch); + if ($csv === FALSE) { + return "Something went wrong with fetching the POTA file"; + } + + $potafilehandle = fopen($potafile, 'w'); + if ($potafilehandle === FALSE) { + return "FAILED: Could not write to pota.txt file"; + } + $data = str_getcsv($csv, "\n"); + $nCount = 0; + foreach ($data as $idx => $row) { + if ($idx == 0) continue; // Skip line we are not interested in + $row = str_getcsv($row, ','); + if ($row[0]) { + fwrite($potafilehandle, $row[0] . PHP_EOL); + $nCount++; + } + } + + fclose($potafilehandle); + + if ($nCount > 0) { + return "DONE: " . number_format($nCount) . " POTA's saved"; + } else { + return "FAILED: Empty file"; + } + } + + function lotw_users() { + // set the last run in cron table for the correct cron id + $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; + + $file = 'https://lotw.arrl.org/lotw-user-activity.csv'; + + $handle = fopen($file, "r"); + if ($handle === FALSE) { + return "Something went wrong with fetching the LoTW uses file"; + } + $this->db->empty_table("lotw_users"); + $i = 0; + $data = fgetcsv($handle, 1000, ","); + do { + if ($data[0]) { + $lotwdata[$i]['callsign'] = $data[0]; + $lotwdata[$i]['lastupload'] = $data[1] . ' ' . $data[2]; + if (($i % 2000) == 0) { + $this->db->insert_batch('lotw_users', $lotwdata); + unset($lotwdata); + // echo 'Record ' . $i . '
'; + } + $i++; + } + } while ($data = fgetcsv($handle, 1000, ",")); + fclose($handle); + + $this->db->insert_batch('lotw_users', $lotwdata); + + $mtime = microtime(); + $mtime = explode(" ", $mtime); + $mtime = $mtime[1] + $mtime[0]; + $endtime = $mtime; + $totaltime = ($endtime - $starttime); + return "Records inserted: " . $i . " in " . $totaltime . " seconds
"; + } +} From 33d7e28275cc6da4a2bde11d95dc9463f406b76b Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Sun, 5 May 2024 10:05:48 +0200 Subject: [PATCH 2/2] moved make_update_path to paths library --- application/controllers/Update.php | 20 ++++++++++---------- application/libraries/Genfunctions.php | 12 ------------ application/libraries/Paths.php | 12 ++++++++++++ application/models/Update_model.php | 4 ++-- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/application/controllers/Update.php b/application/controllers/Update.php index 81421665c..b355b0342 100644 --- a/application/controllers/Update.php +++ b/application/controllers/Update.php @@ -36,8 +36,8 @@ class Update extends CI_Controller { public function dxcc_entities() { // Load the cty file - $this->load->library('Genfunctions'); - $xml_data = simplexml_load_file($this->genfunctions->make_update_path("cty.xml")); + $this->load->library('Paths'); + $xml_data = simplexml_load_file($this->paths->make_update_path("cty.xml")); //$xml_data->entities->entity->count(); @@ -87,8 +87,8 @@ class Update extends CI_Controller { public function dxcc_exceptions() { // Load the cty file - $this->load->library('Genfunctions'); - $xml_data = simplexml_load_file($this->genfunctions->make_update_path("cty.xml")); + $this->load->library('Paths'); + $xml_data = simplexml_load_file($this->paths->make_update_path("cty.xml")); $count = 0; $a_data=[]; @@ -129,8 +129,8 @@ class Update extends CI_Controller { public function dxcc_prefixes() { // Load the cty file - $this->load->library('Genfunctions'); - $xml_data = simplexml_load_file($this->genfunctions->make_update_path("cty.xml")); + $this->load->library('Paths'); + $xml_data = simplexml_load_file($this->paths->make_update_path("cty.xml")); $count = 0; $a_data=[]; @@ -169,7 +169,7 @@ class Update extends CI_Controller { // Updates the DXCC & Exceptions from the Club Log Cty.xml file. public function dxcc() { - $this->load->library('Genfunctions'); + $this->load->library('Paths'); // set the last run in cron table for the correct cron id $this->load->model('cron_model'); @@ -201,7 +201,7 @@ class Update extends CI_Controller { } gzclose($gz); - if (file_put_contents($this->genfunctions->make_update_path("cty.xml"), $data) === FALSE) { + if (file_put_contents($this->paths->make_update_path("cty.xml"), $data) === FALSE) { $this->update_status("FAILED: Could not write to cty.xml file"); return; } @@ -224,7 +224,7 @@ class Update extends CI_Controller { public function update_status($done=""){ - $this->load->library('Genfunctions'); + $this->load->library('Paths'); if ($done != "Downloading file"){ // Check that everything is done? @@ -239,7 +239,7 @@ class Update extends CI_Controller { $html = $done."....
"; } - file_put_contents($this->genfunctions->make_update_path("status.html"), $html); + file_put_contents($this->paths->make_update_path("status.html"), $html); } diff --git a/application/libraries/Genfunctions.php b/application/libraries/Genfunctions.php index ec9fe87c6..71315b771 100644 --- a/application/libraries/Genfunctions.php +++ b/application/libraries/Genfunctions.php @@ -111,16 +111,4 @@ class Genfunctions } } - function make_update_path($path) { - - $CI = & get_instance(); - - $path = "updates/" . $path; - $datadir = $CI->config->item('datadir'); - if(!$datadir) { - return $path; - } - return $datadir . "/" . $path; - } - } diff --git a/application/libraries/Paths.php b/application/libraries/Paths.php index 35e69919b..9d4d262aa 100644 --- a/application/libraries/Paths.php +++ b/application/libraries/Paths.php @@ -20,4 +20,16 @@ class Paths $CI->load->model('Qsl_model'); return $CI->Qsl_model->get_imagePath(); } + + function make_update_path($path) { + + $CI = & get_instance(); + + $path = "updates/" . $path; + $datadir = $CI->config->item('datadir'); + if(!$datadir) { + return $path; + } + return $datadir . "/" . $path; + } } diff --git a/application/models/Update_model.php b/application/models/Update_model.php index a71836764..6e54a3a19 100644 --- a/application/models/Update_model.php +++ b/application/models/Update_model.php @@ -6,11 +6,11 @@ class Update_model extends CI_Model { function clublog_scp() { // set the last run in cron table for the correct cron id $this->load->model('cron_model'); - $this->load->library('Genfunctions'); + $this->load->library('Paths'); $this->cron_model->set_last_run($this->router->class . '_' . $this->router->method); - $strFile = $this->genfunctions->make_update_path("clublog_scp.txt"); + $strFile = $this->paths->make_update_path("clublog_scp.txt"); $url = "https://cdn.clublog.org/clublog.scp.gz"; set_time_limit(300);