From bd1c648e500e7c8ceb5ef362cd32a235d1ce41b8 Mon Sep 17 00:00:00 2001 From: Piotr Szymaszek Date: Mon, 14 Oct 2019 11:45:51 +0200 Subject: [PATCH] Fixed new activation token not being persisted to database --- EventListener/PersistDoctrineUserListener.php | 6 ++++++ .../PersistDoctrineUserListenerSpec.php | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/EventListener/PersistDoctrineUserListener.php b/EventListener/PersistDoctrineUserListener.php index dfd664cd..8f061ead 100644 --- a/EventListener/PersistDoctrineUserListener.php +++ b/EventListener/PersistDoctrineUserListener.php @@ -40,6 +40,7 @@ public static function getSubscribedEvents(): array AdminSecurityEvents::CHANGE_PASSWORD => 'onChangePassword', AdminSecurityEvents::RESET_PASSWORD_REQUEST => 'onResetPasswordRequest', AdminSecurityEvents::ACTIVATION => 'onActivation', + AdminSecurityEvents::RESEND_ACTIVATION_TOKEN => 'onActivationResend', AdminSecurityEvents::DEACTIVATION => 'onDeactivation', AdminSecurityEvents::USER_CREATED => 'onUserCreated', AdminSecurityEvents::PROMOTE_USER => 'onPromoteUser', @@ -53,6 +54,11 @@ public function onActivation(ActivationEvent $event): void $this->flushUserObjectManager($event->getUser()); } + public function onActivationResend(ActivationEvent $event): void + { + $this->flushUserObjectManager($event->getUser()); + } + public function onDeactivation(ActivationEvent $event): void { $this->flushUserObjectManager($event->getUser()); diff --git a/spec/FSi/Bundle/AdminSecurityBundle/EventListener/PersistDoctrineUserListenerSpec.php b/spec/FSi/Bundle/AdminSecurityBundle/EventListener/PersistDoctrineUserListenerSpec.php index 9a1617a0..9792a754 100644 --- a/spec/FSi/Bundle/AdminSecurityBundle/EventListener/PersistDoctrineUserListenerSpec.php +++ b/spec/FSi/Bundle/AdminSecurityBundle/EventListener/PersistDoctrineUserListenerSpec.php @@ -39,6 +39,7 @@ function it_subscribes_all_events() AdminSecurityEvents::CHANGE_PASSWORD => 'onChangePassword', AdminSecurityEvents::RESET_PASSWORD_REQUEST => 'onResetPasswordRequest', AdminSecurityEvents::ACTIVATION => 'onActivation', + AdminSecurityEvents::RESEND_ACTIVATION_TOKEN => 'onActivationResend', AdminSecurityEvents::DEACTIVATION => 'onDeactivation', AdminSecurityEvents::USER_CREATED => 'onUserCreated', AdminSecurityEvents::PROMOTE_USER => 'onPromoteUser', @@ -86,6 +87,19 @@ function it_flushes_om_after_activation( $this->onActivation($event); } + function it_flushes_om_after_resending_activation_token( + ActivationEvent $event, + ObjectManager $objectManager, + User $user + ) { + $event->getUser()->willReturn($user); + + $objectManager->persist($user)->shouldBeCalled(); + $objectManager->flush()->shouldBeCalled(); + + $this->onActivationResend($event); + } + function it_flushes_om_after_deactivation( ActivationEvent $event, ObjectManager $objectManager,