From 4013406982cc695b825b2230df6b5e3fe8ef3a95 Mon Sep 17 00:00:00 2001 From: Ludmil Simeonov Date: Mon, 6 Aug 2018 12:54:02 +0300 Subject: [PATCH] Keep cache of passwords changed during request so we won't trigger twice --- src/EventListener/PasswordEntityListener.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/EventListener/PasswordEntityListener.php b/src/EventListener/PasswordEntityListener.php index fd984eb..df461e3 100644 --- a/src/EventListener/PasswordEntityListener.php +++ b/src/EventListener/PasswordEntityListener.php @@ -39,6 +39,11 @@ class PasswordEntityListener */ private $processedNewEntities = []; + /** + * @var array + */ + private $processedPasswords =[]; + /** * PasswordEntityListener constructor. * @param \Despark\PasswordPolicyBundle\Service\PasswordHistoryServiceInterface $passwordHistoryService @@ -118,6 +123,10 @@ public function createPasswordHistory( return null; } + if(array_key_exists($oldPassword, $this->processedPasswords)){ + return null; + } + $uow = $em->getUnitOfWork(); $entityMeta = $em->getClassMetadata(get_class($entity)); @@ -145,6 +154,7 @@ public function createPasswordHistory( $entity->addPasswordHistory($history); + $this->processedPasswords[$oldPassword] = $history; $stalePasswords = $this->passwordHistoryService->getHistoryItemsForCleanup($entity, $this->historyLimit);