cleanup of PurgeLimiter #342

This commit is contained in:
El RIDO 2018-07-29 16:05:57 +02:00
parent 3470dcd9a8
commit 4a35428499
No known key found for this signature in database
GPG Key ID: 0F5C940A6BD81F92
2 changed files with 12 additions and 17 deletions

View File

@ -70,23 +70,18 @@ class PurgeLimiter extends AbstractPersistence
return true; return true;
} }
$file = 'purge_limiter.php';
$now = time(); $now = time();
$content = '<?php' . PHP_EOL . '$GLOBALS[\'purge_limiter\'] = ' . $now . ';' . PHP_EOL; $file = 'purge_limiter.php';
if (!self::_exists($file)) { if (self::_exists($file)) {
self::_store($file, $content); require self::getPath($file);
}
$path = self::getPath($file);
require $path;
$pl = $GLOBALS['purge_limiter']; $pl = $GLOBALS['purge_limiter'];
if ($pl + self::$_limit >= $now) { if ($pl + self::$_limit >= $now) {
$result = false; return false;
} else { }
$result = true; }
$content = '<?php' . PHP_EOL . '$GLOBALS[\'purge_limiter\'] = ' . $now . ';';
self::_store($file, $content); self::_store($file, $content);
} return true;
return $result;
} }
} }

View File

@ -25,10 +25,10 @@ class PurgeLimiterTest extends PHPUnit_Framework_TestCase
public function testLimit() public function testLimit()
{ {
// initialize it // initialize it
PurgeLimiter::setLimit(1);
PurgeLimiter::canPurge(); PurgeLimiter::canPurge();
// try setting it // try setting it
PurgeLimiter::setLimit(1);
$this->assertEquals(false, PurgeLimiter::canPurge()); $this->assertEquals(false, PurgeLimiter::canPurge());
sleep(2); sleep(2);
$this->assertEquals(true, PurgeLimiter::canPurge()); $this->assertEquals(true, PurgeLimiter::canPurge());