1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* |
6
|
|
|
* @package phpBB Gallery |
7
|
|
|
* @copyright (c) 2014 nickvergessen |
8
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
9
|
|
|
* |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace phpbbgallery\core; |
13
|
|
|
|
14
|
|
|
class cache |
15
|
|
|
{ |
16
|
|
|
private $phpbb_cache; |
17
|
|
|
private $phpbb_db; |
18
|
|
|
protected $table_albums; |
19
|
|
|
protected $table_images; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* cache constructor. |
23
|
|
|
* @param \phpbb\cache\service $cache |
24
|
|
|
* @param \phpbb\db\driver\driver_interface $db |
25
|
|
|
* @param $albums_table |
26
|
|
|
* @param $images_table |
27
|
|
|
*/ |
28
|
141 |
|
public function __construct(\phpbb\cache\service $cache, \phpbb\db\driver\driver_interface $db, |
|
|
|
|
29
|
|
|
$albums_table, $images_table) |
30
|
|
|
{ |
31
|
141 |
|
$this->phpbb_cache = $cache; |
32
|
141 |
|
$this->phpbb_db = $db; |
33
|
141 |
|
$this->table_albums = $albums_table; |
34
|
141 |
|
$this->table_images = $images_table; |
35
|
141 |
|
} |
36
|
|
|
|
37
|
109 |
|
public function get($data = 'albums') |
38
|
|
|
{ |
39
|
109 |
|
switch ($data) |
40
|
|
|
{ |
41
|
109 |
|
case 'albums': |
42
|
109 |
|
return $this->get_albums(); |
43
|
|
|
default: |
44
|
|
|
return false; |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
109 |
|
public function get_albums() |
49
|
|
|
{ |
50
|
109 |
|
static $albums; |
51
|
|
|
|
52
|
109 |
|
if (isset($albums)) |
53
|
|
|
{ |
54
|
109 |
|
return $albums; |
55
|
|
|
} |
56
|
|
|
|
57
|
1 |
|
if (($albums = $this->phpbb_cache->get('_albums')) === false) |
58
|
|
|
{ |
59
|
|
|
$sql = 'SELECT a.album_id, a.parent_id, a.album_name, a.album_type, a.left_id, a.right_id, a.album_user_id, a.display_in_rrc, a.album_auth_access |
60
|
1 |
|
FROM ' . $this->table_albums. ' a |
61
|
1 |
|
LEFT JOIN ' . USERS_TABLE . ' u |
|
|
|
|
62
|
|
|
ON (u.user_id = a.album_user_id) |
63
|
|
|
ORDER BY u.username_clean, a.album_user_id, a.left_id ASC'; |
64
|
1 |
|
$result = $this->phpbb_db->sql_query($sql); |
65
|
|
|
|
66
|
1 |
|
$albums = array(); |
67
|
1 |
|
while ($row = $this->phpbb_db->sql_fetchrow($result)) |
68
|
|
|
{ |
69
|
1 |
|
$albums[(int) $row['album_id']] = array( |
70
|
1 |
|
'album_id' => (int) $row['album_id'], |
71
|
1 |
|
'parent_id' => (int) $row['parent_id'], |
72
|
1 |
|
'album_name' => $row['album_name'], |
73
|
1 |
|
'album_type' => (int) $row['album_type'], |
74
|
1 |
|
'left_id' => (int) $row['left_id'], |
75
|
1 |
|
'right_id' => (int) $row['right_id'], |
76
|
1 |
|
'album_user_id' => (int) $row['album_user_id'], |
77
|
1 |
|
'display_in_rrc' => (bool) $row['display_in_rrc'], |
78
|
1 |
|
'album_auth_access' => (int) $row['album_auth_access'], |
79
|
|
|
); |
80
|
|
|
} |
81
|
1 |
|
$this->phpbb_db->sql_freeresult($result); |
82
|
1 |
|
$this->phpbb_cache->put('_albums', $albums); |
83
|
|
|
} |
84
|
|
|
|
85
|
1 |
|
return $albums; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Get images cache - get some images and put them in cache |
90
|
|
|
* @param (array) $image_ids_array Array of images to be put in cache |
91
|
|
|
* return (array) $images Array of the information we have for that images |
92
|
|
|
* @return array |
93
|
|
|
*/ |
94
|
1 |
|
public function get_images($image_ids_array) |
95
|
|
|
{ |
96
|
1 |
|
static $images; |
97
|
|
|
|
98
|
1 |
|
if (isset($images)) |
99
|
|
|
{ |
100
|
|
|
return $images; |
101
|
|
|
} |
102
|
|
|
|
103
|
1 |
|
if (($albums = $this->phpbb_cache->get('_images')) === false) |
|
|
|
|
104
|
|
|
{ |
105
|
|
|
$sql_array = array( |
106
|
1 |
|
'SELECT' => 'i.*, a.album_name', |
107
|
|
|
'FROM' => array( |
108
|
1 |
|
$this->table_images => 'i', |
109
|
1 |
|
$this->table_albums => 'a' |
110
|
|
|
), |
111
|
1 |
|
'WHERE' => $this->phpbb_db->sql_in_set('image_id', $image_ids_array) . ' AND i.image_album_id = a.album_id' |
112
|
|
|
); |
113
|
1 |
|
$sql = $this->phpbb_db->sql_build_query('SELECT', $sql_array); |
114
|
1 |
|
$result = $this->phpbb_db->sql_query($sql); |
115
|
|
|
|
116
|
1 |
|
$images = array(); |
117
|
1 |
|
while ($row = $this->phpbb_db->sql_fetchrow($result)) |
118
|
|
|
{ |
119
|
1 |
|
$images[(int) $row['image_id']] = array( |
120
|
1 |
|
'image_id' => $row['image_id'], |
121
|
1 |
|
'image_filename' => $row['image_filename'], |
122
|
1 |
|
'image_name' => $row['image_name'], |
123
|
1 |
|
'image_name_clean' => $row['image_name_clean'], |
124
|
1 |
|
'image_desc' => $row['image_desc'], |
125
|
1 |
|
'image_desc_uid' => $row['image_desc_uid'], |
126
|
1 |
|
'image_desc_bitfield' => $row['image_desc_bitfield'], |
127
|
1 |
|
'image_user_id' => $row['image_user_id'], |
128
|
1 |
|
'image_username' => $row['image_username'], |
129
|
1 |
|
'image_username_clean' => $row['image_username_clean'], |
130
|
1 |
|
'image_user_colour' => $row['image_user_colour'], |
131
|
1 |
|
'image_user_ip' => $row['image_user_ip'], |
132
|
1 |
|
'image_time' => $row['image_time'], |
133
|
1 |
|
'image_album_id' => $row['image_album_id'], |
134
|
1 |
|
'image_view_count' => $row['image_view_count'], |
135
|
1 |
|
'image_status' => $row['image_status'], |
136
|
1 |
|
'image_filemissing' => $row['image_filemissing'], |
137
|
1 |
|
'image_rates' => $row['image_rates'], |
138
|
1 |
|
'image_rate_points' => $row['image_rate_points'], |
139
|
1 |
|
'image_rate_avg' => $row['image_rate_avg'], |
140
|
1 |
|
'image_comments' => $row['image_comments'], |
141
|
1 |
|
'image_last_comment' => $row['image_last_comment'], |
142
|
1 |
|
'image_allow_comments' => $row['image_allow_comments'], |
143
|
1 |
|
'image_favorited' => $row['image_favorited'], |
144
|
1 |
|
'image_reported' => $row['image_reported'], |
145
|
1 |
|
'filesize_upload' => $row['filesize_upload'], |
146
|
1 |
|
'filesize_medium' => $row['filesize_medium'], |
147
|
1 |
|
'filesize_cache' => $row['filesize_cache'], |
148
|
1 |
|
'album_name' => $row['album_name'], |
149
|
|
|
); |
150
|
|
|
} |
151
|
1 |
|
$this->phpbb_db->sql_freeresult($result); |
152
|
1 |
|
$this->phpbb_cache->put('_images', $images); |
153
|
|
|
} |
154
|
1 |
|
return $images; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Destroy images cache - if we had updated image information or we want other set - we will have to destroy cache |
159
|
|
|
*/ |
160
|
|
|
public function destroy_images() |
161
|
|
|
{ |
162
|
|
|
$this->phpbb_cache->destroy('_images'); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Destroy album cache |
167
|
|
|
* Basicly some tests fail due album cache not destroyed ... |
168
|
|
|
* So lets try it now? |
169
|
|
|
*/ |
170
|
|
|
public function destroy_albums() |
171
|
|
|
{ |
172
|
|
|
$this->phpbb_cache->destroy('_albums'); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Destroy interface for phpbb_cache destroy |
177
|
|
|
* @param $target |
178
|
|
|
* @param bool $subtarget |
179
|
|
|
*/ |
180
|
|
|
public function destroy($target, $subtarget = false) |
181
|
|
|
{ |
182
|
|
|
if ($subtarget) |
183
|
|
|
{ |
184
|
|
|
$this->phpbb_cache->destroy($target, $subtarget); |
185
|
|
|
} |
186
|
|
|
else |
187
|
|
|
{ |
188
|
|
|
$this->phpbb_cache->destroy($target); |
189
|
|
|
} |
190
|
|
|
} |
191
|
|
|
} |
192
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths