diff --git a/application/config/migration.php b/application/config/migration.php index 7c7fc559..7b38f822 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -21,7 +21,7 @@ $config['migration_enabled'] = TRUE; | be upgraded / downgraded to. | */ -$config['migration_version'] = 117; +$config['migration_version'] = 118; /* |-------------------------------------------------------------------------- diff --git a/application/controllers/Lotw.php b/application/controllers/Lotw.php index e5be23f0..dae87a32 100644 --- a/application/controllers/Lotw.php +++ b/application/controllers/Lotw.php @@ -153,20 +153,20 @@ class Lotw extends CI_Controller { } // Check to see if certificate is already in the system - $new_certificate = $this->LotwCert->find_cert($info['issued_callsign'], $dxcc, $this->session->userdata('user_id')); + $new_certificate = $this->LotwCert->find_cert($info['issued_callsign'], $info['dxcc-id'], $this->session->userdata('user_id')); if($new_certificate == 0) { // New Certificate Store in Database // Store Certificate Data into MySQL - $this->LotwCert->store_certificate($this->session->userdata('user_id'), $info['issued_callsign'], $dxcc, $info['validFrom'], $info['validTo_Date'], $info['qso-first-date'], $info['qso-end-date'], $info['pem_key'], $info['general_cert']); + $this->LotwCert->store_certificate($this->session->userdata('user_id'), $info['issued_callsign'], $info['dxcc-id'], $info['validFrom'], $info['validTo_Date'], $info['qso-first-date'], $info['qso-end-date'], $info['pem_key'], $info['general_cert']); // Cert success flash message $this->session->set_flashdata('Success', $info['issued_callsign'].' Certificate Imported.'); } else { // Certificate is in the system time to update - $this->LotwCert->update_certificate($this->session->userdata('user_id'), $info['issued_callsign'], $dxcc, $info['validFrom'], $info['validTo_Date'], $info['pem_key'], $info['general_cert']); + $this->LotwCert->update_certificate($this->session->userdata('user_id'), $info['issued_callsign'], $info['dxcc-id'], $info['validFrom'], $info['validTo_Date'], $info['pem_key'], $info['general_cert']); // Cert success flash message $this->session->set_flashdata('Success', $info['issued_callsign'].' Certificate Updated.'); @@ -443,6 +443,7 @@ class Lotw extends CI_Controller { // https://oidref.com/1.3.6.1.4.1.12348.1 $data['qso-first-date'] = $certdata['extensions']['1.3.6.1.4.1.12348.1.2']; $data['qso-end-date'] = $certdata['extensions']['1.3.6.1.4.1.12348.1.3']; + $data['dxcc-id'] = $certdata['extensions']['1.3.6.1.4.1.12348.1.4']; return $data; } diff --git a/application/migrations/118_make_lotw_use_dxcc_id.php b/application/migrations/118_make_lotw_use_dxcc_id.php new file mode 100644 index 00000000..69fd7d2c --- /dev/null +++ b/application/migrations/118_make_lotw_use_dxcc_id.php @@ -0,0 +1,37 @@ +db->field_exists('cert_dxcc_id', 'lotw_certs')) { + $this->dbforge->add_column('lotw_certs', $fields); + } + + $sql = 'UPDATE `lotw_certs` JOIN `dxcc_entities` ON `lotw_certs`.`cert_dxcc` = `dxcc_entities`.`name` SET `lotw_certs`.`cert_dxcc_id` = `dxcc_entities`.`adif`;'; + $this->db->query($sql); + + $this->dbforge->drop_column('lotw_certs', 'cert_dxcc'); + } + + public function down() + { + $fields = array( + 'cert_dxcc VARCHAR(255) NOT NULL AFTER `callsign`', + ); + + if (!$this->db->field_exists('cert_dxcc', 'lotw_certs')) { + $this->dbforge->add_column('lotw_certs', $fields); + } + + $sql = 'UPDATE `lotw_certs` JOIN `dxcc_entities` ON `lotw_certs`.`cert_dxcc_id` = `dxcc_entities`.`adif` SET `lotw_certs`.`cert_dxcc` = `dxcc_entities`.`name`;'; + $this->db->query($sql); + + $this->dbforge->drop_column('lotw_certs', 'cert_dxcc_id'); + } +} diff --git a/application/models/LotwCert.php b/application/models/LotwCert.php index 185e3fa2..28862ff0 100644 --- a/application/models/LotwCert.php +++ b/application/models/LotwCert.php @@ -12,7 +12,9 @@ class LotwCert extends CI_Model { */ function lotw_certs($user_id) { + $this->db->select('lotw_certs.lotw_cert_id as lotw_cert_id, lotw_certs.callsign as callsign, dxcc_entities.name as cert_dxcc, lotw_certs.qso_start_date as qso_start_date, lotw_certs.qso_end_date as qso_end_date, lotw_certs.date_created as date_created, lotw_certs.date_expires as date_expires, lotw_certs.last_upload as last_upload'); $this->db->where('user_id', $user_id); + $this->db->join('dxcc_entities','lotw_certs.cert_dxcc_id = dxcc_entities.adif','left'); $this->db->order_by('cert_dxcc', 'ASC'); $query = $this->db->get('lotw_certs'); @@ -29,7 +31,7 @@ class LotwCert extends CI_Model { function find_cert($callsign, $dxcc, $user_id) { $this->db->where('user_id', $user_id); - $this->db->where('cert_dxcc', $dxcc); + $this->db->where('cert_dxcc_id', $dxcc); $this->db->where('callsign', $callsign); $query = $this->db->get('lotw_certs'); @@ -40,7 +42,7 @@ class LotwCert extends CI_Model { $data = array( 'user_id' => $user_id, 'callsign' => $callsign, - 'cert_dxcc' => $dxcc, + 'cert_dxcc_id' => $dxcc, 'date_created' => $date_created, 'date_expires' => $date_expires, 'qso_start_date' => $qso_start_date, @@ -54,7 +56,7 @@ class LotwCert extends CI_Model { function update_certificate($user_id, $callsign, $dxcc, $date_created, $date_expires, $cert_key, $general_cert) { $data = array( - 'cert_dxcc' => $dxcc, + 'cert_dxcc_id' => $dxcc, 'date_created' => $date_created, 'date_expires' => $date_expires, 'cert_key' => $cert_key, @@ -63,7 +65,7 @@ class LotwCert extends CI_Model { $this->db->where('user_id', $user_id); $this->db->where('callsign', $callsign); - $this->db->where('cert_dxcc', $dxcc); + $this->db->where('cert_dxcc_id', $dxcc); $this->db->update('lotw_certs', $data); } diff --git a/application/views/lotw_views/index.php b/application/views/lotw_views/index.php index 24b42e2f..14f8e376 100644 --- a/application/views/lotw_views/index.php +++ b/application/views/lotw_views/index.php @@ -44,7 +44,7 @@ result() as $row) { ?>