mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
Fix #1457 : EntityManager:clear should not be called in a controller
This commit is contained in:
@@ -113,18 +113,9 @@ class FailureManager
|
|||||||
->findOldFailures('-2 months');
|
->findOldFailures('-2 months');
|
||||||
|
|
||||||
if (0 < count($failures)) {
|
if (0 < count($failures)) {
|
||||||
$n = 0;
|
|
||||||
foreach ($failures as $failure) {
|
foreach ($failures as $failure) {
|
||||||
$this->em->remove($failure);
|
$this->em->remove($failure);
|
||||||
|
|
||||||
if (0 === $n++ % 1000) {
|
|
||||||
$this->em->flush();
|
|
||||||
$this->em->clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->em->flush();
|
|
||||||
$this->em->clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -56,7 +56,7 @@ class patch_3805 implements patchInterface
|
|||||||
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
|
|
||||||
$n = 0;
|
$n = 1;
|
||||||
|
|
||||||
foreach ($rs as $row) {
|
foreach ($rs as $row) {
|
||||||
$date = Datetime::createFromFormat('Y-m-d h:i:s', $row['date']);
|
$date = Datetime::createFromFormat('Y-m-d h:i:s', $row['date']);
|
||||||
|
@@ -3,9 +3,11 @@
|
|||||||
namespace Alchemy\Tests\Phrasea\Authentication\Phrasea;
|
namespace Alchemy\Tests\Phrasea\Authentication\Phrasea;
|
||||||
|
|
||||||
use Alchemy\Phrasea\Authentication\Phrasea\FailureManager;
|
use Alchemy\Phrasea\Authentication\Phrasea\FailureManager;
|
||||||
|
use Entities\AuthFailure;
|
||||||
|
use Gedmo\Timestampable\TimestampableListener;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
class FailureManagerTest extends \PHPUnit_Framework_TestCase
|
class FailureManagerTest extends \PhraseanetPHPUnitAbstract
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @covers Alchemy\Phrasea\Authentication\Phrasea\FailureManager::saveFailure
|
* @covers Alchemy\Phrasea\Authentication\Phrasea\FailureManager::saveFailure
|
||||||
@@ -241,6 +243,54 @@ class FailureManagerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$manager->checkFailures($username, $request);
|
$manager->checkFailures($username, $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFailureOlderThan2MonthsAreRemovedOnFailure()
|
||||||
|
{
|
||||||
|
self::$DI['app']['EM']->getEventManager()->removeEventSubscriber(new TimestampableListener());
|
||||||
|
$recaptcha = $this->getReCaptchaMock(null);
|
||||||
|
|
||||||
|
$ip = '192.168.16.178';
|
||||||
|
$username = 'romainneutron';
|
||||||
|
|
||||||
|
$request = $this->getRequestMock();
|
||||||
|
$request->expects($this->any())
|
||||||
|
->method('getClientIp')
|
||||||
|
->will($this->returnValue($ip));
|
||||||
|
|
||||||
|
for ($i = 0; $i < 10; $i++) {
|
||||||
|
$failure = new AuthFailure();
|
||||||
|
$failure->setIp($ip);
|
||||||
|
$failure->setUsername($username);
|
||||||
|
$failure->setLocked(false);
|
||||||
|
$failure->setCreated(new \DateTime('-3 months'));
|
||||||
|
self::$DI['app']['EM']->persist($failure);
|
||||||
|
}
|
||||||
|
for ($i = 0; $i < 2; $i++) {
|
||||||
|
$failure = new AuthFailure();
|
||||||
|
$failure->setIp($ip);
|
||||||
|
$failure->setUsername($username);
|
||||||
|
$failure->setLocked(false);
|
||||||
|
$failure->setCreated(new \DateTime('-1 months'));
|
||||||
|
self::$DI['app']['EM']->persist($failure);
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$DI['app']['EM']->flush();
|
||||||
|
|
||||||
|
$this->assertCount(10, self::$DI['app']['EM']->getRepository('Entities\AuthFailure')
|
||||||
|
->findOldFailures());
|
||||||
|
$this->assertCount(12, self::$DI['app']['EM']->getRepository('Entities\AuthFailure')
|
||||||
|
->findAll());
|
||||||
|
|
||||||
|
$manager = new FailureManager(self::$DI['app']['EM'], $recaptcha, 9);
|
||||||
|
$manager->saveFailure($username, $request);
|
||||||
|
|
||||||
|
$this->assertCount(0, self::$DI['app']['EM']->getRepository('Entities\AuthFailure')
|
||||||
|
->findOldFailures());
|
||||||
|
$this->assertCount(3, self::$DI['app']['EM']->getRepository('Entities\AuthFailure')
|
||||||
|
->findAll());
|
||||||
|
|
||||||
|
self::$DI['app']['EM']->getEventManager()->addEventSubscriber(new TimestampableListener());
|
||||||
|
}
|
||||||
|
|
||||||
private function ArrayIze($failure, $n)
|
private function ArrayIze($failure, $n)
|
||||||
{
|
{
|
||||||
$failures = array();
|
$failures = array();
|
||||||
|
Reference in New Issue
Block a user