aboutsummaryrefslogtreecommitdiff
path: root/lib/SimplePie/SimplePie/Cache/MySQL.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/SimplePie/SimplePie/Cache/MySQL.php')
-rw-r--r--lib/SimplePie/SimplePie/Cache/MySQL.php23
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/SimplePie/SimplePie/Cache/MySQL.php b/lib/SimplePie/SimplePie/Cache/MySQL.php
index 511ef6d3a..8686b6c67 100644
--- a/lib/SimplePie/SimplePie/Cache/MySQL.php
+++ b/lib/SimplePie/SimplePie/Cache/MySQL.php
@@ -5,7 +5,7 @@
* A PHP-Based RSS and Atom Feed Framework.
* Takes the hard work out of managing a complete RSS/Atom solution.
*
- * Copyright (c) 2004-2012, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
+ * Copyright (c) 2004-2016, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
@@ -33,8 +33,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* @package SimplePie
- * @version 1.4-dev
- * @copyright 2004-2012 Ryan Parman, Geoffrey Sneddon, Ryan McCue
+ * @copyright 2004-2016 Ryan Parman, Geoffrey Sneddon, Ryan McCue
* @author Ryan Parman
* @author Geoffrey Sneddon
* @author Ryan McCue
@@ -94,6 +93,7 @@ class SimplePie_Cache_MySQL extends SimplePie_Cache_DB
'path' => '',
'extras' => array(
'prefix' => '',
+ 'cache_purge_time' => 2592000
),
);
@@ -131,16 +131,20 @@ class SimplePie_Cache_MySQL extends SimplePie_Cache_DB
$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)))');
if ($query === false)
{
+ trigger_error("Can't create " . $this->options['extras']['prefix'] . "cache_data table, check permissions", E_USER_WARNING);
$this->mysql = null;
+ return;
}
}
if (!in_array($this->options['extras']['prefix'] . 'items', $db))
{
- $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 CHARACTER SET utf8 NOT NULL, `posted` INT UNSIGNED NOT NULL, INDEX `feed_id` (`feed_id`(125)))');
+ $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)))');
if ($query === false)
{
+ trigger_error("Can't create " . $this->options['extras']['prefix'] . "items table, check permissions", E_USER_WARNING);
$this->mysql = null;
+ return;
}
}
}
@@ -158,6 +162,17 @@ class SimplePie_Cache_MySQL extends SimplePie_Cache_DB
return false;
}
+ $query = $this->mysql->prepare('DELETE i, cd FROM `' . $this->options['extras']['prefix'] . 'cache_data` cd, ' .
+ '`' . $this->options['extras']['prefix'] . 'items` i ' .
+ 'WHERE cd.id = i.feed_id ' .
+ 'AND cd.mtime < (unix_timestamp() - :purge_time)');
+ $query->bindValue(':purge_time', $this->options['extras']['cache_purge_time']);
+
+ if (!$query->execute())
+ {
+ return false;
+ }
+
if ($data instanceof SimplePie)
{
$data = clone $data;