From ae486d651be3a622dd1307bc0c681ecf5a894058 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Mon, 7 Jun 2021 21:53:42 +0200 Subject: [PATCH] folding Persistance\PurgeLimiter into Data\Filesystem --- lib/Data/Filesystem.php | 99 ++++++++++++++++--------- lib/Model.php | 1 + lib/Persistence/AbstractPersistence.php | 22 ++++++ lib/Persistence/PurgeLimiter.php | 14 +--- tst/Persistence/PurgeLimiterTest.php | 4 + 5 files changed, 94 insertions(+), 46 deletions(-) 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()