Skip to content

Commit 027ac44

Browse files
authored
Merge pull request wavelog#208 from HB9HIL/unique
eQSL bug fix
2 parents 4655087 + 6bd793e commit 027ac44

File tree

4 files changed

+118
-4
lines changed

4 files changed

+118
-4
lines changed

application/config/migration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
|
2323
*/
2424

25-
$config['migration_version'] = 185;
25+
$config['migration_version'] = 186;
2626

2727
/*
2828
|--------------------------------------------------------------------------

application/controllers/Eqsl.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,10 @@ function bulk_download_image($id) {
616616
return $error;
617617
}
618618
$filename = uniqid().'.jpg';
619-
if (file_put_contents($this->Eqsl_images->get_imagePath('p') .'/'. $filename, $content) !== false) {
620-
$this->Eqsl_images->save_image($id, $filename);
619+
if($this->Eqsl_images->get_image($id) == "No Image") {
620+
if (file_put_contents($this->Eqsl_images->get_imagePath('p') .'/'. $filename, $content) !== false) {
621+
$this->Eqsl_images->save_image($id, $filename);
622+
}
621623
}
622624
}
623625
return $error;
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
3+
defined('BASEPATH') or exit('No direct script access allowed');
4+
5+
// Remove Dupes from eQSL-Table and add a unique idx
6+
7+
class Migration_rm_eqsl_dbl extends CI_Migration
8+
{
9+
10+
public function up()
11+
{
12+
$dbltrbl = 1;
13+
while ($dbltrbl>0) {
14+
$sql = 'SELECT MIN(id) as id,qso_id FROM eQSL_images GROUP BY qso_id HAVING count(1)>1;';
15+
$query = $this->db->query($sql);
16+
$dbltrbl = $query->num_rows();
17+
18+
if ($dbltrbl > 0) {
19+
$eqsl2del = [];
20+
21+
foreach ($query->result() as $row)
22+
$eqsl2del[] = $row->id;
23+
24+
foreach ($eqsl2del as $oneeqsl) {
25+
$res = $this->db->query("SELECT image_file FROM eQSL_images WHERE id=?", $oneeqsl)->result()[0]->image_file;
26+
27+
if ($this->config->item('userdata')) {
28+
29+
$userdata_dir = $this->config->item('userdata');
30+
$qso_id = $this->get_qsoid_from_eqsl_filename($res) ?? '';
31+
32+
// we need to get the user ID which corresponds to that particular qso
33+
if (!empty($qso_id)) {
34+
$get_user_id = $this->get_user_id_from_qso($qso_id);
35+
36+
// can be an deleted qso
37+
if (!empty($get_user_id)) {
38+
$user_id = $get_user_id;
39+
} else {
40+
$user_id = 'not_assigned';
41+
}
42+
} else {
43+
$user_id = 'not_assigned';
44+
}
45+
46+
// target path with userdata dir
47+
$target_path = $userdata_dir . '/' . $user_id . '/eqsl_card';
48+
49+
// then remove the file
50+
if (!unlink($target_path . '/' . $res)) {
51+
log_message('error', "Mig 186: File: '" . $target_path . "/" . $res . "' could not be deleted. There is no file with this filename. This shouldn't be a problem.");
52+
} else {
53+
log_message('debug', "Mig 186: File: '" . $target_path . "/" . $res . "' was deleted because it was a dupe.");
54+
}
55+
} else {
56+
// if 'userdata' is disabled we can use the old paths
57+
if (!unlink('images/eqsl_card_images/' . $res)) {
58+
log_message('error', "Mig 186: File: 'images/eqsl_card_images/" . $res . "' could not be deleted. There is no file with this filename. This shouldn't be a problem.");
59+
} else {
60+
log_message('debug', "Mig 186: File: 'images/eqsl_card_images/" . $res . "' was deleted because it was a dupe.");
61+
}
62+
}
63+
}
64+
foreach ($eqsl2del as $oneeqsl) {
65+
$this->db->query('delete from eQSL_images where id=?',$oneeqsl);
66+
}
67+
}
68+
}
69+
70+
$index = $this->db->query("SHOW INDEX FROM eQSL_images WHERE Key_name = 'qso_id_UNIQUE'")->num_rows();
71+
if ($index == 0) {
72+
$this->db->query("ALTER TABLE `eQSL_images` ADD UNIQUE INDEX `qso_id_UNIQUE` (`qso_id` ASC);");
73+
}
74+
75+
}
76+
77+
public function down()
78+
{
79+
$index = $this->db->query("SHOW INDEX FROM eQSL_images WHERE Key_name = 'qso_id_UNIQUE'")->num_rows();
80+
if ($index > 0) {
81+
$this->db->query("ALTER TABLE `eQSL_images` DROP INDEX `qso_id_UNIQUE`;");
82+
}
83+
}
84+
85+
function get_qsoid_from_eqsl_filename($filename)
86+
{
87+
88+
$sql = "SELECT qso_id FROM eQSL_images WHERE image_file = ?";
89+
90+
$result = $this->db->query($sql, $filename);
91+
92+
$row = $result->row();
93+
return $row->qso_id;
94+
}
95+
96+
function get_user_id_from_qso($qso_id)
97+
{
98+
99+
$clean_qsoid = $this->security->xss_clean($qso_id);
100+
101+
$sql = 'SELECT station_profile.user_id
102+
FROM ' . $this->config->item('table_name') . '
103+
INNER JOIN station_profile ON (' . $this->config->item('table_name') . '.station_id = station_profile.station_id)
104+
WHERE ' . $this->config->item('table_name') . '.COL_PRIMARY_KEY = ?';
105+
106+
$result = $this->db->query($sql, $clean_qsoid);
107+
$row = $result->row();
108+
109+
return $row->user_id;
110+
}
111+
}

application/models/Logbook_model.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1678,7 +1678,8 @@ function get_qso($id, $trusted = false) {
16781678
$this->db->join('lotw_users', $this->config->item('table_name').'.COL_CALL = lotw_users.callsign', 'left outer');
16791679
$this->db->join('primary_subdivisions', $this->config->item('table_name').'.COL_DXCC = primary_subdivisions.adif AND '.$this->config->item('table_name').'.COL_STATE = primary_subdivisions.state', 'left outer');
16801680
$this->db->where('COL_PRIMARY_KEY', $id);
1681-
1681+
$this->db->limit(1);
1682+
16821683
return $this->db->get();
16831684
} else {
16841685
return;

0 commit comments

Comments
 (0)