kopia lustrzana https://github.com/magicbug/Cloudlog
DXCC match on date as well as callsign. Table schema updates
rodzic
f7fad2457e
commit
3459a81098
|
@ -21,7 +21,7 @@ $config['migration_enabled'] = TRUE;
|
||||||
| be upgraded / downgraded to.
|
| be upgraded / downgraded to.
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
$config['migration_version'] = 10;
|
$config['migration_version'] = 12;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -30,8 +30,10 @@ class Update extends CI_Controller {
|
||||||
|
|
||||||
$count = 0;
|
$count = 0;
|
||||||
foreach ($xml_data->entities->entity as $entity) {
|
foreach ($xml_data->entities->entity as $entity) {
|
||||||
$endinfo = strtotime($entity->end);
|
$startinfo = strtotime($record->start);
|
||||||
|
$endinfo = strtotime($record->end);
|
||||||
|
|
||||||
|
$start_date = ($startinfo) ? date('Y-m-d H:i:s',$startinfo) : "";
|
||||||
$end_date = ($endinfo) ? date('Y-m-d H:i:s',$endinfo) : "";
|
$end_date = ($endinfo) ? date('Y-m-d H:i:s',$endinfo) : "";
|
||||||
|
|
||||||
if(!$entity->cqz) {
|
if(!$entity->cqz) {
|
||||||
|
@ -48,6 +50,7 @@ class Update extends CI_Controller {
|
||||||
'cont' => (string) $entity->cont,
|
'cont' => (string) $entity->cont,
|
||||||
'long' => (float) $entity->long,
|
'long' => (float) $entity->long,
|
||||||
'lat' => (float) $entity->lat,
|
'lat' => (float) $entity->lat,
|
||||||
|
'start' => $start_date,
|
||||||
'end' => $end_date,
|
'end' => $end_date,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -113,6 +116,12 @@ class Update extends CI_Controller {
|
||||||
|
|
||||||
$count = 0;
|
$count = 0;
|
||||||
foreach ($xml_data->prefixes->prefix as $record) {
|
foreach ($xml_data->prefixes->prefix as $record) {
|
||||||
|
$startinfo = strtotime($record->start);
|
||||||
|
$endinfo = strtotime($record->end);
|
||||||
|
|
||||||
|
$start_date = ($startinfo) ? date('Y-m-d H:i:s',$startinfo) : "";
|
||||||
|
$end_date = ($endinfo) ? date('Y-m-d H:i:s',$endinfo) : "";
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'record' => (int) $record->attributes()->record,
|
'record' => (int) $record->attributes()->record,
|
||||||
'call' => (string) $record->call,
|
'call' => (string) $record->call,
|
||||||
|
@ -122,6 +131,8 @@ class Update extends CI_Controller {
|
||||||
'cont' => (string) $record->cont,
|
'cont' => (string) $record->cont,
|
||||||
'long' => (float) $record->long,
|
'long' => (float) $record->long,
|
||||||
'lat' => (float) $record->lat,
|
'lat' => (float) $record->lat,
|
||||||
|
'start' => $start_date,
|
||||||
|
'end' => $end_date,
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->db->insert('dxcc_prefixes', $data);
|
$this->db->insert('dxcc_prefixes', $data);
|
||||||
|
@ -206,9 +217,9 @@ class Update extends CI_Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function check_missing_dxcc(){
|
public function check_missing_dxcc($all = false){
|
||||||
$this->load->model('logbook_model');
|
$this->load->model('logbook_model');
|
||||||
$this->logbook_model->check_missing_dxcc_id();
|
$this->logbook_model->check_missing_dxcc_id($all);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||||
|
|
||||||
|
class Migration_add_dxcc_prefixes_start_end extends CI_Migration {
|
||||||
|
|
||||||
|
public function up(){
|
||||||
|
$fields = (array(
|
||||||
|
'start' => array(
|
||||||
|
'type' => 'date',
|
||||||
|
'Null' => TRUE
|
||||||
|
),
|
||||||
|
'end' => array(
|
||||||
|
'type' => 'date',
|
||||||
|
'Null' => TRUE
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->dbforge->add_column('dxcc_prefixes', $fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(){
|
||||||
|
$this->dbforge->drop_table('dxcc_prefixes');
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||||
|
|
||||||
|
class Migration_add_dxcc_entities_start extends CI_Migration {
|
||||||
|
|
||||||
|
public function up(){
|
||||||
|
$fields = (array(
|
||||||
|
'start' => array(
|
||||||
|
'type' => 'date',
|
||||||
|
'Null' => TRUE
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->dbforge->add_column('dxcc_entities', $fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(){
|
||||||
|
$this->dbforge->drop_table('dxcc_entities');
|
||||||
|
}
|
||||||
|
}
|
|
@ -941,15 +941,22 @@ class Logbook_model extends CI_Model {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function check_dxcc_table($call){
|
private function check_dxcc_table($call, $date){
|
||||||
global $con;
|
|
||||||
$len = strlen($call);
|
$len = strlen($call);
|
||||||
|
|
||||||
// query the table, removing a character from the right until a match
|
// query the table, removing a character from the right until a match
|
||||||
for ($i = $len; $i > 0; $i--){
|
for ($i = $len; $i > 0; $i--){
|
||||||
//printf("searching for %s\n", substr($call, 0, $i));
|
//printf("searching for %s\n", substr($call, 0, $i));
|
||||||
$dxcc_result = $this->db->query("select `call`, `entity`, `adif` from dxcc_prefixes where `call` = '".substr($call, 0, $i) ."'");
|
$dxcc_result = $this->db->select('`call`, `entity`, `adif`')
|
||||||
|
->where('call', substr($call, 0, $i))
|
||||||
|
->where('(start <= ', $date)
|
||||||
|
->or_where("start = '0000-00-00')", NULL, false)
|
||||||
|
->where('(end >= ', $date)
|
||||||
|
->or_where("end = '0000-00-00')", NULL, false)
|
||||||
|
->get('dxcc_prefixes');
|
||||||
|
|
||||||
|
//$dxcc_result = $this->db->query("select `call`, `entity`, `adif` from dxcc_prefixes where `call` = '".substr($call, 0, $i) ."'");
|
||||||
|
//print $this->db->last_query();
|
||||||
|
|
||||||
if ($dxcc_result->num_rows() > 0){
|
if ($dxcc_result->num_rows() > 0){
|
||||||
$row = $dxcc_result->row_array();
|
$row = $dxcc_result->row_array();
|
||||||
|
@ -960,10 +967,15 @@ class Logbook_model extends CI_Model {
|
||||||
return array("Not Found", "Not Found");
|
return array("Not Found", "Not Found");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function check_missing_dxcc_id(){
|
public function check_missing_dxcc_id($all){
|
||||||
// get all records with no COL_DXCC
|
// get all records with no COL_DXCC
|
||||||
$this->db->select("COL_PRIMARY_KEY, COL_CALL");
|
$this->db->select("COL_PRIMARY_KEY, COL_CALL, COL_TIME_ON, COL_TIME_OFF");
|
||||||
|
|
||||||
|
// check which to update - records with no dxcc or all records
|
||||||
|
if (! isset($all)){
|
||||||
$this->db->where("COL_DXCC is NULL");
|
$this->db->where("COL_DXCC is NULL");
|
||||||
|
}
|
||||||
|
|
||||||
$r = $this->db->get($this->config->item('table_name'));
|
$r = $this->db->get($this->config->item('table_name'));
|
||||||
|
|
||||||
$count = 0;
|
$count = 0;
|
||||||
|
@ -971,13 +983,17 @@ class Logbook_model extends CI_Model {
|
||||||
//query dxcc_prefixes
|
//query dxcc_prefixes
|
||||||
if ($r->num_rows() > 0){
|
if ($r->num_rows() > 0){
|
||||||
foreach($r->result_array() as $row){
|
foreach($r->result_array() as $row){
|
||||||
$d = $this->check_dxcc_table($row['COL_CALL']);
|
$qso_date = $row['COL_TIME_OFF']=='' ? $row['COL_TIME_ON'] : $row['COL_TIME_ON'];
|
||||||
|
$qso_date = strftime("%Y-%m-%d", strtotime($qso_date));
|
||||||
|
|
||||||
|
$d = $this->check_dxcc_table($row['COL_CALL'], $qso_date);
|
||||||
|
|
||||||
if ($d[0] != 'Not Found'){
|
if ($d[0] != 'Not Found'){
|
||||||
$sql = sprintf("update %s set COL_COUNTRY = '%s', COL_DXCC='%s' where COL_PRIMARY_KEY=%d",
|
$sql = sprintf("update %s set COL_COUNTRY = '%s', COL_DXCC='%s' where COL_PRIMARY_KEY=%d",
|
||||||
$this->config->item('table_name'), addslashes($d[1]), $d[0], $row['COL_PRIMARY_KEY']);
|
$this->config->item('table_name'), addslashes(ucwords(strtolower($d[1]))), $d[0], $row['COL_PRIMARY_KEY']);
|
||||||
$this->db->query($sql);
|
$this->db->query($sql);
|
||||||
//print($sql."\n");
|
//print($sql."\n");
|
||||||
printf("Updating %s to %s and %s\n<br/>", $row['COL_PRIMARY_KEY'], $d[1], $d[0]);
|
printf("Updating %s to %s and %s\n<br/>", $row['COL_PRIMARY_KEY'], ucwords(strtolower($d[1])), $d[0]);
|
||||||
$count++;
|
$count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
</div>
|
</div>
|
||||||
<br/>
|
<br/>
|
||||||
<a href="update/check_missing_dxcc">Check missing DXCC/Countries values</a>
|
<a href="update/check_missing_dxcc">Check missing DXCC/Countries values</a>
|
||||||
|
<a href="update/check_missing_dxcc/all">[Re-Check ALL]</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
Ładowanie…
Reference in New Issue