Changeset 59141 for trunk/src/wp-includes/SimplePie/src/Cache/MySQL.php
- Timestamp:
- 09/30/2024 10:48:16 PM (6 weeks ago)
- Location:
- trunk/src/wp-includes/SimplePie/src
- Files:
-
- 1 added
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/SimplePie/src/Cache/MySQL.php
r47733 r59141 1 1 <?php 2 2 3 /** 3 4 * SimplePie … … 6 7 * Takes the hard work out of managing a complete RSS/Atom solution. 7 8 * 8 * Copyright (c) 2004-20 16, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors9 * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors 9 10 * All rights reserved. 10 11 * … … 42 43 */ 43 44 45 namespace SimplePie\Cache; 46 44 47 /** 45 48 * Caches data to a MySQL database … … 53 56 * @package SimplePie 54 57 * @subpackage Caching 58 * @deprecated since SimplePie 1.8.0, use implementation of "Psr\SimpleCache\CacheInterface" instead 55 59 */ 56 class SimplePie_Cache_MySQL extends SimplePie_Cache_DB60 class MySQL extends DB 57 61 { 58 /** 59 * PDO instance 60 * 61 * @var PDO 62 */ 63 protected $mysql; 64 65 /** 66 * Options 67 * 68 * @var array 69 */ 70 protected $options; 71 72 /** 73 * Cache ID 74 * 75 * @var string 76 */ 77 protected $id; 78 79 /** 80 * Create a new cache object 81 * 82 * @param string $location Location string (from SimplePie::$cache_location) 83 * @param string $name Unique ID for the cache 84 * @param string $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data 85 */ 86 public function __construct($location, $name, $type) 87 { 88 $this->options = array( 89 'user' => null, 90 'pass' => null, 91 'host' => '127.0.0.1', 92 'port' => '3306', 93 'path' => '', 94 'extras' => array( 95 'prefix' => '', 96 'cache_purge_time' => 2592000 97 ), 98 ); 99 100 $this->options = SimplePie_Misc::array_merge_recursive($this->options, SimplePie_Cache::parse_URL($location)); 101 102 // Path is prefixed with a "/" 103 $this->options['dbname'] = substr($this->options['path'], 1); 104 105 try 106 { 107 $this->mysql = new PDO("mysql:dbname={$this->options['dbname']};host={$this->options['host']};port={$this->options['port']}", $this->options['user'], $this->options['pass'], array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); 108 } 109 catch (PDOException $e) 110 { 111 $this->mysql = null; 112 return; 113 } 114 115 $this->id = $name . $type; 116 117 if (!$query = $this->mysql->query('SHOW TABLES')) 118 { 119 $this->mysql = null; 120 return; 121 } 122 123 $db = array(); 124 while ($row = $query->fetchColumn()) 125 { 126 $db[] = $row; 127 } 128 129 if (!in_array($this->options['extras']['prefix'] . 'cache_data', $db)) 130 { 131 $query = $this->mysql->exec('CREATE TABLE `' . $this->options['extras']['prefix'] . 'cache_data` (`id` TEXT CHARACTER SET utf8 NOT NULL, `items` SMALLINT NOT NULL DEFAULT 0, `data` BLOB NOT NULL, `mtime` INT UNSIGNED NOT NULL, UNIQUE (`id`(125)))'); 132 if ($query === false) 133 { 134 trigger_error("Can't create " . $this->options['extras']['prefix'] . "cache_data table, check permissions", E_USER_WARNING); 135 $this->mysql = null; 136 return; 137 } 138 } 139 140 if (!in_array($this->options['extras']['prefix'] . 'items', $db)) 141 { 142 $query = $this->mysql->exec('CREATE TABLE `' . $this->options['extras']['prefix'] . 'items` (`feed_id` TEXT CHARACTER SET utf8 NOT NULL, `id` TEXT CHARACTER SET utf8 NOT NULL, `data` MEDIUMBLOB NOT NULL, `posted` INT UNSIGNED NOT NULL, INDEX `feed_id` (`feed_id`(125)))'); 143 if ($query === false) 144 { 145 trigger_error("Can't create " . $this->options['extras']['prefix'] . "items table, check permissions", E_USER_WARNING); 146 $this->mysql = null; 147 return; 148 } 149 } 150 } 151 152 /** 153 * Save data to the cache 154 * 155 * @param array|SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property 156 * @return bool Successfulness 157 */ 158 public function save($data) 159 { 160 if ($this->mysql === null) 161 { 162 return false; 163 } 164 165 $query = $this->mysql->prepare('DELETE i, cd FROM `' . $this->options['extras']['prefix'] . 'cache_data` cd, ' . 166 '`' . $this->options['extras']['prefix'] . 'items` i ' . 167 'WHERE cd.id = i.feed_id ' . 168 'AND cd.mtime < (unix_timestamp() - :purge_time)'); 169 $query->bindValue(':purge_time', $this->options['extras']['cache_purge_time']); 170 171 if (!$query->execute()) 172 { 173 return false; 174 } 175 176 if ($data instanceof SimplePie) 177 { 178 $data = clone $data; 179 180 $prepared = self::prepare_simplepie_object_for_cache($data); 181 182 $query = $this->mysql->prepare('SELECT COUNT(*) FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed'); 183 $query->bindValue(':feed', $this->id); 184 if ($query->execute()) 185 { 186 if ($query->fetchColumn() > 0) 187 { 188 $items = count($prepared[1]); 189 if ($items) 190 { 191 $sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = :items, `data` = :data, `mtime` = :time WHERE `id` = :feed'; 192 $query = $this->mysql->prepare($sql); 193 $query->bindValue(':items', $items); 194 } 195 else 196 { 197 $sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `data` = :data, `mtime` = :time WHERE `id` = :feed'; 198 $query = $this->mysql->prepare($sql); 199 } 200 201 $query->bindValue(':data', $prepared[0]); 202 $query->bindValue(':time', time()); 203 $query->bindValue(':feed', $this->id); 204 if (!$query->execute()) 205 { 206 return false; 207 } 208 } 209 else 210 { 211 $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:feed, :count, :data, :time)'); 212 $query->bindValue(':feed', $this->id); 213 $query->bindValue(':count', count($prepared[1])); 214 $query->bindValue(':data', $prepared[0]); 215 $query->bindValue(':time', time()); 216 if (!$query->execute()) 217 { 218 return false; 219 } 220 } 221 222 $ids = array_keys($prepared[1]); 223 if (!empty($ids)) 224 { 225 foreach ($ids as $id) 226 { 227 $database_ids[] = $this->mysql->quote($id); 228 } 229 230 $query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `id` = ' . implode(' OR `id` = ', $database_ids) . ' AND `feed_id` = :feed'); 231 $query->bindValue(':feed', $this->id); 232 233 if ($query->execute()) 234 { 235 $existing_ids = array(); 236 while ($row = $query->fetchColumn()) 237 { 238 $existing_ids[] = $row; 239 } 240 241 $new_ids = array_diff($ids, $existing_ids); 242 243 foreach ($new_ids as $new_id) 244 { 245 if (!($date = $prepared[1][$new_id]->get_date('U'))) 246 { 247 $date = time(); 248 } 249 250 $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'items` (`feed_id`, `id`, `data`, `posted`) VALUES(:feed, :id, :data, :date)'); 251 $query->bindValue(':feed', $this->id); 252 $query->bindValue(':id', $new_id); 253 $query->bindValue(':data', serialize($prepared[1][$new_id]->data)); 254 $query->bindValue(':date', $date); 255 if (!$query->execute()) 256 { 257 return false; 258 } 259 } 260 return true; 261 } 262 } 263 else 264 { 265 return true; 266 } 267 } 268 } 269 else 270 { 271 $query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed'); 272 $query->bindValue(':feed', $this->id); 273 if ($query->execute()) 274 { 275 if ($query->rowCount() > 0) 276 { 277 $query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = 0, `data` = :data, `mtime` = :time WHERE `id` = :feed'); 278 $query->bindValue(':data', serialize($data)); 279 $query->bindValue(':time', time()); 280 $query->bindValue(':feed', $this->id); 281 if ($this->execute()) 282 { 283 return true; 284 } 285 } 286 else 287 { 288 $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:id, 0, :data, :time)'); 289 $query->bindValue(':id', $this->id); 290 $query->bindValue(':data', serialize($data)); 291 $query->bindValue(':time', time()); 292 if ($query->execute()) 293 { 294 return true; 295 } 296 } 297 } 298 } 299 return false; 300 } 301 302 /** 303 * Retrieve the data saved to the cache 304 * 305 * @return array Data for SimplePie::$data 306 */ 307 public function load() 308 { 309 if ($this->mysql === null) 310 { 311 return false; 312 } 313 314 $query = $this->mysql->prepare('SELECT `items`, `data` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id'); 315 $query->bindValue(':id', $this->id); 316 if ($query->execute() && ($row = $query->fetch())) 317 { 318 $data = unserialize($row[1]); 319 320 if (isset($this->options['items'][0])) 321 { 322 $items = (int) $this->options['items'][0]; 323 } 324 else 325 { 326 $items = (int) $row[0]; 327 } 328 329 if ($items !== 0) 330 { 331 if (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0])) 332 { 333 $feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]; 334 } 335 elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0])) 336 { 337 $feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]; 338 } 339 elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0])) 340 { 341 $feed =& $data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]; 342 } 343 elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0])) 344 { 345 $feed =& $data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]; 346 } 347 else 348 { 349 $feed = null; 350 } 351 352 if ($feed !== null) 353 { 354 $sql = 'SELECT `data` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :feed ORDER BY `posted` DESC'; 355 if ($items > 0) 356 { 357 $sql .= ' LIMIT ' . $items; 358 } 359 360 $query = $this->mysql->prepare($sql); 361 $query->bindValue(':feed', $this->id); 362 if ($query->execute()) 363 { 364 while ($row = $query->fetchColumn()) 365 { 366 $feed['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry'][] = unserialize($row); 367 } 368 } 369 else 370 { 371 return false; 372 } 373 } 374 } 375 return $data; 376 } 377 return false; 378 } 379 380 /** 381 * Retrieve the last modified time for the cache 382 * 383 * @return int Timestamp 384 */ 385 public function mtime() 386 { 387 if ($this->mysql === null) 388 { 389 return false; 390 } 391 392 $query = $this->mysql->prepare('SELECT `mtime` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id'); 393 $query->bindValue(':id', $this->id); 394 if ($query->execute() && ($time = $query->fetchColumn())) 395 { 396 return $time; 397 } 398 399 return false; 400 } 401 402 /** 403 * Set the last modified time to the current time 404 * 405 * @return bool Success status 406 */ 407 public function touch() 408 { 409 if ($this->mysql === null) 410 { 411 return false; 412 } 413 414 $query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `mtime` = :time WHERE `id` = :id'); 415 $query->bindValue(':time', time()); 416 $query->bindValue(':id', $this->id); 417 418 return $query->execute() && $query->rowCount() > 0; 419 } 420 421 /** 422 * Remove the cache 423 * 424 * @return bool Success status 425 */ 426 public function unlink() 427 { 428 if ($this->mysql === null) 429 { 430 return false; 431 } 432 433 $query = $this->mysql->prepare('DELETE FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id'); 434 $query->bindValue(':id', $this->id); 435 $query2 = $this->mysql->prepare('DELETE FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :id'); 436 $query2->bindValue(':id', $this->id); 437 438 return $query->execute() && $query2->execute(); 439 } 62 /** 63 * PDO instance 64 * 65 * @var \PDO 66 */ 67 protected $mysql; 68 69 /** 70 * Options 71 * 72 * @var array 73 */ 74 protected $options; 75 76 /** 77 * Cache ID 78 * 79 * @var string 80 */ 81 protected $id; 82 83 /** 84 * Create a new cache object 85 * 86 * @param string $location Location string (from SimplePie::$cache_location) 87 * @param string $name Unique ID for the cache 88 * @param Base::TYPE_FEED|Base::TYPE_IMAGE $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data 89 */ 90 public function __construct($location, $name, $type) 91 { 92 $this->options = [ 93 'user' => null, 94 'pass' => null, 95 'host' => '127.0.0.1', 96 'port' => '3306', 97 'path' => '', 98 'extras' => [ 99 'prefix' => '', 100 'cache_purge_time' => 2592000 101 ], 102 ]; 103 104 $this->options = array_replace_recursive($this->options, \SimplePie\Cache::parse_URL($location)); 105 106 // Path is prefixed with a "/" 107 $this->options['dbname'] = substr($this->options['path'], 1); 108 109 try { 110 $this->mysql = new \PDO("mysql:dbname={$this->options['dbname']};host={$this->options['host']};port={$this->options['port']}", $this->options['user'], $this->options['pass'], [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']); 111 } catch (\PDOException $e) { 112 $this->mysql = null; 113 return; 114 } 115 116 $this->id = $name . $type; 117 118 if (!$query = $this->mysql->query('SHOW TABLES')) { 119 $this->mysql = null; 120 return; 121 } 122 123 $db = []; 124 while ($row = $query->fetchColumn()) { 125 $db[] = $row; 126 } 127 128 if (!in_array($this->options['extras']['prefix'] . 'cache_data', $db)) { 129 $query = $this->mysql->exec('CREATE TABLE `' . $this->options['extras']['prefix'] . 'cache_data` (`id` TEXT CHARACTER SET utf8 NOT NULL, `items` SMALLINT NOT NULL DEFAULT 0, `data` BLOB NOT NULL, `mtime` INT UNSIGNED NOT NULL, UNIQUE (`id`(125)))'); 130 if ($query === false) { 131 trigger_error("Can't create " . $this->options['extras']['prefix'] . "cache_data table, check permissions", \E_USER_WARNING); 132 $this->mysql = null; 133 return; 134 } 135 } 136 137 if (!in_array($this->options['extras']['prefix'] . 'items', $db)) { 138 $query = $this->mysql->exec('CREATE TABLE `' . $this->options['extras']['prefix'] . 'items` (`feed_id` TEXT CHARACTER SET utf8 NOT NULL, `id` TEXT CHARACTER SET utf8 NOT NULL, `data` MEDIUMBLOB NOT NULL, `posted` INT UNSIGNED NOT NULL, INDEX `feed_id` (`feed_id`(125)))'); 139 if ($query === false) { 140 trigger_error("Can't create " . $this->options['extras']['prefix'] . "items table, check permissions", \E_USER_WARNING); 141 $this->mysql = null; 142 return; 143 } 144 } 145 } 146 147 /** 148 * Save data to the cache 149 * 150 * @param array|\SimplePie\SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property 151 * @return bool Successfulness 152 */ 153 public function save($data) 154 { 155 if ($this->mysql === null) { 156 return false; 157 } 158 159 $query = $this->mysql->prepare('DELETE i, cd FROM `' . $this->options['extras']['prefix'] . 'cache_data` cd, ' . 160 '`' . $this->options['extras']['prefix'] . 'items` i ' . 161 'WHERE cd.id = i.feed_id ' . 162 'AND cd.mtime < (unix_timestamp() - :purge_time)'); 163 $query->bindValue(':purge_time', $this->options['extras']['cache_purge_time']); 164 165 if (!$query->execute()) { 166 return false; 167 } 168 169 if ($data instanceof \SimplePie\SimplePie) { 170 $data = clone $data; 171 172 $prepared = self::prepare_simplepie_object_for_cache($data); 173 174 $query = $this->mysql->prepare('SELECT COUNT(*) FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed'); 175 $query->bindValue(':feed', $this->id); 176 if ($query->execute()) { 177 if ($query->fetchColumn() > 0) { 178 $items = count($prepared[1]); 179 if ($items) { 180 $sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = :items, `data` = :data, `mtime` = :time WHERE `id` = :feed'; 181 $query = $this->mysql->prepare($sql); 182 $query->bindValue(':items', $items); 183 } else { 184 $sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `data` = :data, `mtime` = :time WHERE `id` = :feed'; 185 $query = $this->mysql->prepare($sql); 186 } 187 188 $query->bindValue(':data', $prepared[0]); 189 $query->bindValue(':time', time()); 190 $query->bindValue(':feed', $this->id); 191 if (!$query->execute()) { 192 return false; 193 } 194 } else { 195 $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:feed, :count, :data, :time)'); 196 $query->bindValue(':feed', $this->id); 197 $query->bindValue(':count', count($prepared[1])); 198 $query->bindValue(':data', $prepared[0]); 199 $query->bindValue(':time', time()); 200 if (!$query->execute()) { 201 return false; 202 } 203 } 204 205 $ids = array_keys($prepared[1]); 206 if (!empty($ids)) { 207 foreach ($ids as $id) { 208 $database_ids[] = $this->mysql->quote($id); 209 } 210 211 $query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `id` = ' . implode(' OR `id` = ', $database_ids) . ' AND `feed_id` = :feed'); 212 $query->bindValue(':feed', $this->id); 213 214 if ($query->execute()) { 215 $existing_ids = []; 216 while ($row = $query->fetchColumn()) { 217 $existing_ids[] = $row; 218 } 219 220 $new_ids = array_diff($ids, $existing_ids); 221 222 foreach ($new_ids as $new_id) { 223 if (!($date = $prepared[1][$new_id]->get_date('U'))) { 224 $date = time(); 225 } 226 227 $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'items` (`feed_id`, `id`, `data`, `posted`) VALUES(:feed, :id, :data, :date)'); 228 $query->bindValue(':feed', $this->id); 229 $query->bindValue(':id', $new_id); 230 $query->bindValue(':data', serialize($prepared[1][$new_id]->data)); 231 $query->bindValue(':date', $date); 232 if (!$query->execute()) { 233 return false; 234 } 235 } 236 return true; 237 } 238 } else { 239 return true; 240 } 241 } 242 } else { 243 $query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed'); 244 $query->bindValue(':feed', $this->id); 245 if ($query->execute()) { 246 if ($query->rowCount() > 0) { 247 $query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = 0, `data` = :data, `mtime` = :time WHERE `id` = :feed'); 248 $query->bindValue(':data', serialize($data)); 249 $query->bindValue(':time', time()); 250 $query->bindValue(':feed', $this->id); 251 if ($query->execute()) { 252 return true; 253 } 254 } else { 255 $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:id, 0, :data, :time)'); 256 $query->bindValue(':id', $this->id); 257 $query->bindValue(':data', serialize($data)); 258 $query->bindValue(':time', time()); 259 if ($query->execute()) { 260 return true; 261 } 262 } 263 } 264 } 265 return false; 266 } 267 268 /** 269 * Retrieve the data saved to the cache 270 * 271 * @return array Data for SimplePie::$data 272 */ 273 public function load() 274 { 275 if ($this->mysql === null) { 276 return false; 277 } 278 279 $query = $this->mysql->prepare('SELECT `items`, `data` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id'); 280 $query->bindValue(':id', $this->id); 281 if ($query->execute() && ($row = $query->fetch())) { 282 $data = unserialize($row[1]); 283 284 if (isset($this->options['items'][0])) { 285 $items = (int) $this->options['items'][0]; 286 } else { 287 $items = (int) $row[0]; 288 } 289 290 if ($items !== 0) { 291 if (isset($data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['feed'][0])) { 292 $feed = &$data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['feed'][0]; 293 } elseif (isset($data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['feed'][0])) { 294 $feed = &$data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['feed'][0]; 295 } elseif (isset($data['child'][\SimplePie\SimplePie::NAMESPACE_RDF]['RDF'][0])) { 296 $feed = &$data['child'][\SimplePie\SimplePie::NAMESPACE_RDF]['RDF'][0]; 297 } elseif (isset($data['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['rss'][0])) { 298 $feed = &$data['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['rss'][0]; 299 } else { 300 $feed = null; 301 } 302 303 if ($feed !== null) { 304 $sql = 'SELECT `data` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :feed ORDER BY `posted` DESC'; 305 if ($items > 0) { 306 $sql .= ' LIMIT ' . $items; 307 } 308 309 $query = $this->mysql->prepare($sql); 310 $query->bindValue(':feed', $this->id); 311 if ($query->execute()) { 312 while ($row = $query->fetchColumn()) { 313 $feed['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['entry'][] = unserialize($row); 314 } 315 } else { 316 return false; 317 } 318 } 319 } 320 return $data; 321 } 322 return false; 323 } 324 325 /** 326 * Retrieve the last modified time for the cache 327 * 328 * @return int Timestamp 329 */ 330 public function mtime() 331 { 332 if ($this->mysql === null) { 333 return false; 334 } 335 336 $query = $this->mysql->prepare('SELECT `mtime` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id'); 337 $query->bindValue(':id', $this->id); 338 if ($query->execute() && ($time = $query->fetchColumn())) { 339 return $time; 340 } 341 342 return false; 343 } 344 345 /** 346 * Set the last modified time to the current time 347 * 348 * @return bool Success status 349 */ 350 public function touch() 351 { 352 if ($this->mysql === null) { 353 return false; 354 } 355 356 $query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `mtime` = :time WHERE `id` = :id'); 357 $query->bindValue(':time', time()); 358 $query->bindValue(':id', $this->id); 359 360 return $query->execute() && $query->rowCount() > 0; 361 } 362 363 /** 364 * Remove the cache 365 * 366 * @return bool Success status 367 */ 368 public function unlink() 369 { 370 if ($this->mysql === null) { 371 return false; 372 } 373 374 $query = $this->mysql->prepare('DELETE FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id'); 375 $query->bindValue(':id', $this->id); 376 $query2 = $this->mysql->prepare('DELETE FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :id'); 377 $query2->bindValue(':id', $this->id); 378 379 return $query->execute() && $query2->execute(); 380 } 440 381 } 382 383 class_alias('SimplePie\Cache\MySQL', 'SimplePie_Cache_MySQL');
Note: See TracChangeset
for help on using the changeset viewer.