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

View file

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