1
|
|
|
<?php declare(strict_types=1); defined('BASEPATH') OR exit('No direct script access allowed'); |
2
|
|
|
|
3
|
|
|
class AdminPanel extends Admin_Controller { |
4
|
|
|
public function __construct() { |
5
|
|
|
parent::__construct(); |
6
|
|
|
|
7
|
|
|
$this->load->library('table'); |
8
|
|
|
|
9
|
|
|
$this->load->helper('form'); |
10
|
|
|
$this->load->library('form_validation'); |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
public function index() : void { |
14
|
|
|
$this->header_data['title'] = 'Admin Panel'; |
15
|
|
|
$this->header_data['page'] = 'admin-panel'; |
16
|
|
|
|
17
|
|
|
$this->body_data['complete_list'] = array_merge([['id', 'site_class', 'url']], $this->_list_complete_titles()); |
18
|
|
|
$this->body_data['id_sql'] = 'SELECT * FROM `tracker_titles` WHERE id IN('.implode(',', array_column($this->body_data['complete_list'], 'id')).')'; |
19
|
|
|
|
20
|
|
|
$template = array( |
21
|
|
|
'table_open' => '<table class="table table-striped">' |
22
|
|
|
); |
23
|
|
|
|
24
|
|
|
$this->table->set_template($template); |
25
|
|
|
$this->_render_page('AdminPanel'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function update_normal() { |
29
|
|
|
set_time_limit(0); |
30
|
|
|
|
31
|
|
|
ob_start(); |
32
|
|
|
$this->Tracker->admin->updateLatestChapters(); |
33
|
|
|
ob_end_clean(); |
34
|
|
|
|
35
|
|
|
$this->_redirect('Normal Update complete.'); |
36
|
|
|
} |
37
|
|
|
public function update_custom() { |
38
|
|
|
set_time_limit(0); |
39
|
|
|
ob_start(); |
40
|
|
|
$this->Tracker->admin->updateCustom(); |
41
|
|
|
ob_end_clean(); |
42
|
|
|
|
43
|
|
|
$this->_redirect('Custom Update complete.'); |
44
|
|
|
} |
45
|
|
|
public function update_titles() { |
46
|
|
|
set_time_limit(0); |
47
|
|
|
$this->Tracker->admin->updateTitles(); |
|
|
|
|
48
|
|
|
|
49
|
|
|
$this->_redirect('(Actual) Titles updated.'); |
50
|
|
|
} |
51
|
|
|
public function update_mal_id() { |
52
|
|
|
set_time_limit(0); |
53
|
|
|
$this->_update_mal_backend(); |
54
|
|
|
|
55
|
|
|
$this->_redirect('MAL Backend IDs updated.'); |
56
|
|
|
} |
57
|
|
|
public function populate_db() { |
58
|
|
|
if(ENVIRONMENT === 'development') { |
59
|
|
|
//Populate list |
60
|
|
|
$randomUpdateData = [ |
61
|
|
|
['mangadex.org', '18806:--:English', '12612:--:v1/c1'], |
62
|
|
|
['helveticascans.com', 'mousou-telepathy', 'en/0/1'], |
63
|
|
|
['elpsycongroo.tk', 'otomedanshi', 'en/1/1'] |
64
|
|
|
]; |
65
|
|
|
foreach($randomUpdateData as $updateData) { |
66
|
|
|
$updateData[] = TRUE; //Active marker |
67
|
|
|
$this->Tracker->list->update($this->User->id, ...$updateData); |
|
|
|
|
68
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
//Populate favorites |
72
|
|
|
$randomFavouriteData = [ |
73
|
|
|
['mangadex.org', '18806:--:English', '306123:--:c19', 10], |
74
|
|
|
['helveticascans.com', 'mousou-telepathy', 'en/0/564', NULL], |
75
|
|
|
['elpsycongroo.tk', 'otomedanshi', 'en/2/239', NULL] |
76
|
|
|
]; |
77
|
|
|
foreach($randomFavouriteData as $favouriteData) { |
78
|
|
|
$favouriteData[] = FALSE; |
79
|
|
|
$this->Tracker->favourites->set($this->User->id, ...$favouriteData); |
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$this->_redirect('Populated Dev DB with data.'); |
83
|
|
|
} else { |
84
|
|
|
$this->_redirect('Populate Dev DB failed as ENVIRONMENT is not development.'); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
private function _redirect(string $message) : void { |
89
|
|
|
$this->session->set_flashdata('notices', $message); |
90
|
|
|
redirect(site_url('admin_panel')); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
private function _list_complete_titles() { |
94
|
|
|
$query = $this->db->select('tracker_titles.id, tracker_sites.site_class, tracker_titles.title, tracker_titles.title_url') |
95
|
|
|
->from('tracker_chapters') |
96
|
|
|
->join('tracker_titles', 'tracker_chapters.title_id = tracker_titles.id', 'left') |
97
|
|
|
->join('tracker_sites', 'tracker_sites.id = tracker_titles.site_id', 'left') |
98
|
|
|
->like('tracker_chapters.tags', 'complete') |
99
|
|
|
->where('tracker_titles.status', 0) |
100
|
|
|
->get(); |
101
|
|
|
|
102
|
|
|
$completeList = []; |
103
|
|
|
if($query->num_rows() > 0) { |
104
|
|
|
foreach($query->result() as $row) { |
105
|
|
|
$data = [ |
106
|
|
|
'id' => $row->id, |
107
|
|
|
'site_class' => $row->site_class, |
108
|
|
|
'url' => "<a href='".$this->Tracker->sites->{$row->site_class}->getFullTitleURL($row->title_url)."'>{$row->title}</a>" |
109
|
|
|
]; |
110
|
|
|
$completeList[] = $data; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
return $completeList; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
private function _update_mal_backend() : void { |
118
|
|
|
//Would prefer to use the query generator here, but don't think it's possible with what I'd like to do here. |
119
|
|
|
|
120
|
|
|
//Set backend MAL id if more than one person has it set as the same ID. |
121
|
|
|
//- This should be bumped up as we get more users to avoid abuse. |
122
|
|
|
$this->db->query(' |
123
|
|
|
UPDATE |
124
|
|
|
tracker_titles dest, |
125
|
|
|
( |
126
|
|
|
SELECT tt.id, tc.mal_id |
127
|
|
|
FROM `tracker_chapters` tc |
128
|
|
|
LEFT JOIN `tracker_titles` tt ON tt.`id` = tc.`title_id` |
129
|
|
|
WHERE tt.mal_id IS NULL AND tc.mal_id IS NOT NULL |
130
|
|
|
GROUP BY tt.id, tc.mal_id |
131
|
|
|
HAVING COUNT(tc.mal_id) > 1 |
132
|
|
|
) src |
133
|
|
|
SET dest.mal_id = src.mal_id |
134
|
|
|
WHERE dest.id = src.id |
135
|
|
|
'); |
136
|
|
|
|
137
|
|
|
//Set backend MAL id if an admin has it set. |
138
|
|
|
//TODO: Preferably we'd have a trusted users group, but that is for later down the line... |
139
|
|
|
$this->db->query(' |
140
|
|
|
UPDATE |
141
|
|
|
tracker_titles dest, |
142
|
|
|
( |
143
|
|
|
SELECT tt.id, tc.mal_id |
144
|
|
|
FROM `tracker_chapters` tc |
145
|
|
|
LEFT JOIN `tracker_titles` tt ON tt.`id` = tc.`title_id` |
146
|
|
|
LEFT JOIN `auth_users_groups` aug ON tc.`user_id` = aug.`user_id` |
147
|
|
|
WHERE tc.mal_id IS NOT NULL |
148
|
|
|
AND aug.`group_id` = 1 |
149
|
|
|
) src |
150
|
|
|
SET dest.mal_id = src.mal_id |
151
|
|
|
WHERE dest.id = src.id |
152
|
|
|
'); |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.