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