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(); $file = 'purge_limiter.php';
$content = '<?php' . PHP_EOL . '$GLOBALS[\'purge_limiter\'] = ' . $now . ';' . PHP_EOL; if (self::_exists($file)) {
if (!self::_exists($file)) { require self::getPath($file);
self::_store($file, $content); $pl = $GLOBALS['purge_limiter'];
if ($pl + self::$_limit >= $now) {
return false;
}
} }
$path = self::getPath($file); $content = '<?php' . PHP_EOL . '$GLOBALS[\'purge_limiter\'] = ' . $now . ';';
require $path; self::_store($file, $content);
$pl = $GLOBALS['purge_limiter']; return true;
if ($pl + self::$_limit >= $now) {
$result = false;
} else {
$result = true;
self::_store($file, $content);
}
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());