Skip to content

Commit 806ba71

Browse files
authored
Merge pull request wavelog#248 from int2001/delete_really
Delete all fragments which belongs to a user upon deleting
2 parents 6236908 + 44477dc commit 806ba71

File tree

6 files changed

+229
-159
lines changed

6 files changed

+229
-159
lines changed

application/controllers/Qsl.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,8 @@ public function upload() {
4242
public function delete() {
4343
$this->load->model('user_model');
4444
if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
45-
4645
$id = $this->input->post('id');
4746
$this->load->model('Qsl_model');
48-
49-
$path = $this->Qsl_model->get_imagePath('p');
50-
$file = $this->Qsl_model->getFilename($id)->row();
51-
$filename = $file->filename;
52-
unlink($path.'/'.$filename);
53-
5447
$this->Qsl_model->deleteQsl($id);
5548
}
5649

@@ -174,4 +167,4 @@ function viewQsl() {
174167
$this->load->view('qslcard/qslcarousel', $data);
175168
}
176169

177-
}
170+
}

application/models/Eqsl_images.php

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@ function get_image($qso_id) {
1515
}
1616
}
1717

18+
function del_image($qso_id, $user_id = null) {
19+
// QSO belongs to station_profile. But since we have folders for Users (and therefore an extra indirect relation) we need to lookup user for station first...
20+
$eqsl_img=$this->db->query('SELECT e.image_file,e.id, qso.station_id, s.user_id FROM `eQSL_images` e INNER JOIN '.$this->config->item('table_name').' qso ON (e.qso_id = qso.COL_PRIMARY_KEY) inner join station_profile s on (s.station_id=qso.station_id) where qso.COL_PRIMARY_KEY=?',$qso_id);
21+
foreach ($eqsl_img->result() as $row) {
22+
if (($user_id ?? '') == '') { // Calling as User? Check if User-id matches User-id from QSO
23+
$user_id = $this->session->userdata('user_id');
24+
if ($row->user_id != $user_id) {
25+
return "No Image"; // Image doesn't belong to user, so return
26+
}
27+
}
28+
$image=$this->get_imagePath('p',$row->user_id).'/'.$row->image_file;
29+
unlink($image);
30+
$this->db->delete('eQSL_images', array('id' => $row->id));
31+
return $image;
32+
}
33+
}
34+
1835
function save_image($qso_id, $image_name) {
1936
$data = array(
2037
'qso_id' => $qso_id,
@@ -36,36 +53,37 @@ function eqsl_qso_list() {
3653
}
3754

3855
// return path of eQsl file : u=url / p=real path
39-
function get_imagePath($pathorurl='u') {
56+
function get_imagePath($pathorurl='u', $user_id = null) {
4057

4158
// test if new folder directory option is enabled
4259
$userdata_dir = $this->config->item('userdata');
43-
60+
4461
if (isset($userdata_dir)) {
4562

4663
$eqsl_dir = "eqsl_card"; // make sure this is the same as in Debug_model.php function migrate_userdata()
4764

48-
$user_id = $this->session->userdata('user_id');
49-
65+
if (($user_id ?? '') == '') {
66+
$user_id = $this->session->userdata('user_id');
67+
}
68+
5069
// check if there is a user_id in the session data and it's not empty
5170
if ($user_id != '') {
52-
53-
// create the folder
54-
if (!file_exists(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_id.'/'.$eqsl_dir)) {
55-
mkdir(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_id.'/'.$eqsl_dir, 0755, true);
56-
}
57-
58-
// and return it
59-
if ($pathorurl=='u') {
60-
return $userdata_dir.'/'.$user_id.'/'.$eqsl_dir;
61-
} else {
62-
return realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_id.'/'.$eqsl_dir;
63-
}
64-
} else {
71+
72+
// create the folder
73+
if (!file_exists(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_id.'/'.$eqsl_dir)) {
74+
mkdir(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_id.'/'.$eqsl_dir, 0755, true);
75+
}
76+
77+
// and return it
78+
if ($pathorurl=='u') {
79+
return $userdata_dir.'/'.$user_id.'/'.$eqsl_dir;
80+
} else {
81+
return realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_id.'/'.$eqsl_dir;
82+
}
83+
} else {
6584
log_message('info', 'Can not get eqsl image path because no user_id in session data');
6685
}
67-
} else {
68-
86+
} else {
6987
// if the config option is not set we just return the old path
7088
return 'images/eqsl_card_images';
7189
}

application/models/Logbook_model.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3045,14 +3045,23 @@ function total_countries_confirmed_lotw() {
30453045
}
30463046

30473047
/* Delete QSO based on the QSO ID */
3048-
function delete($id) {
3049-
if ($this->check_qso_is_accessible($id)) {
3050-
$this->db->where('COL_PRIMARY_KEY', $id);
3051-
$this->db->delete($this->config->item('table_name'));
3052-
} else {
3053-
return;
3054-
}
3055-
}
3048+
function delete($id) {
3049+
if ($this->check_qso_is_accessible($id)) {
3050+
$this->load->model('qsl_model');
3051+
$this->load->model('eqsl_images');
3052+
3053+
$this->qsl_model->del_image_for_qso($id);
3054+
$this->eqsl_images->del_image($id);
3055+
3056+
$this->db->where('COL_PRIMARY_KEY', $id);
3057+
$this->db->delete($this->config->item('table_name'));
3058+
3059+
$this->db->where('qsoid', $id);
3060+
$this->db->delete("oqrs");
3061+
} else {
3062+
return;
3063+
}
3064+
}
30563065

30573066
/* Used to check if the qso is already in the database */
30583067
function import_check($datetime, $callsign, $band, $mode, $station_callsign, $station_id = null) {

0 commit comments

Comments
 (0)