diff --git a/lib/Data/Filesystem.php b/lib/Data/Filesystem.php index 76c2600..f24691b 100644 --- a/lib/Data/Filesystem.php +++ b/lib/Data/Filesystem.php @@ -253,7 +253,10 @@ class Filesystem extends AbstractData { switch ($namespace) { case 'purge_limiter': - ; + return self::_storeString( + self::$_path . DIRECTORY_SEPARATOR . 'purge_limiter.php', + '_conf); + PurgeLimiter::setStore($this->_getStore()); if (PurgeLimiter::canPurge()) { $this->_getStore()->purge($this->_conf->getKey('batchsize', 'purge')); } diff --git a/lib/Persistence/AbstractPersistence.php b/lib/Persistence/AbstractPersistence.php index 489836d..73f0ab2 100644 --- a/lib/Persistence/AbstractPersistence.php +++ b/lib/Persistence/AbstractPersistence.php @@ -13,6 +13,7 @@ namespace PrivateBin\Persistence; use Exception; +use PrivateBin\Data\AbstractData; /** * AbstractPersistence @@ -30,6 +31,15 @@ abstract class AbstractPersistence */ private static $_path = 'data'; + /** + * data storage to use to persist something + * + * @access private + * @static + * @var AbstractData + */ + protected static $_store; + /** * set the path * @@ -42,6 +52,18 @@ abstract class AbstractPersistence self::$_path = $path; } + /** + * set the path + * + * @access public + * @static + * @param AbstractData $store + */ + public static function setStore(AbstractData $store) + { + self::$_store = $store; + } + /** * get the path * diff --git a/lib/Persistence/PurgeLimiter.php b/lib/Persistence/PurgeLimiter.php index ea07e32..19b83e2 100644 --- a/lib/Persistence/PurgeLimiter.php +++ b/lib/Persistence/PurgeLimiter.php @@ -71,17 +71,11 @@ class PurgeLimiter extends AbstractPersistence } $now = time(); - $file = 'purge_limiter.php'; - if (self::_exists($file)) { - require self::getPath($file); - $pl = $GLOBALS['purge_limiter']; - if ($pl + self::$_limit >= $now) { - return false; - } + $pl = (int) self::$_store->getValue('purge_limiter'); + if ($pl + self::$_limit >= $now) { + return false; } - - $content = 'setValue((string) $now, 'purge_limiter'); return true; } } diff --git a/tst/Persistence/PurgeLimiterTest.php b/tst/Persistence/PurgeLimiterTest.php index 391a840..e8cedc0 100644 --- a/tst/Persistence/PurgeLimiterTest.php +++ b/tst/Persistence/PurgeLimiterTest.php @@ -1,5 +1,6 @@ _path); } PurgeLimiter::setPath($this->_path); + PurgeLimiter::setStore( + Filesystem::getInstance(array('dir' => $this->_path)) + ); } public function tearDown()