From 323c4e2b047dce80885914a6e861f092d68aecf8 Mon Sep 17 00:00:00 2001 From: Lars Vierbergen Date: Sun, 13 May 2018 13:27:18 +0200 Subject: [PATCH] Fix reference to wrong table name in the entity; handle non-existing event more gracefully by logging a critical error --- AuthserverExpireEmailValidationBundle.php | 6 ++++++ Command/ExpireEmailValidationCommand.php | 6 ++++++ Entity/ExpiredUser.php | 2 +- EventListener/CheckExpiryListener.php | 13 +++++++++---- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/AuthserverExpireEmailValidationBundle.php b/AuthserverExpireEmailValidationBundle.php index 0ad4577..74ec43e 100644 --- a/AuthserverExpireEmailValidationBundle.php +++ b/AuthserverExpireEmailValidationBundle.php @@ -1,8 +1,14 @@ addOption('dry-run', null, InputOption::VALUE_NONE, 'Do not actually execute the expiration.'); } + public function isEnabled() + { + return AuthserverExpireEmailValidationBundle::hasUserCheckEvent(); + } + protected function execute(InputInterface $input, OutputInterface $output) { $em = $this->getApplication() diff --git a/Entity/ExpiredUser.php b/Entity/ExpiredUser.php index 37821c3..5dcc14f 100644 --- a/Entity/ExpiredUser.php +++ b/Entity/ExpiredUser.php @@ -10,7 +10,7 @@ use Doctrine\ORM\Mapping\Column; /** * @Entity() - * @Table(name="vierbergenlars_expire_users") + * @Table(name="vierbergenlars_expire_email_validation") */ class ExpiredUser { diff --git a/EventListener/CheckExpiryListener.php b/EventListener/CheckExpiryListener.php index 159012a..13e6e17 100644 --- a/EventListener/CheckExpiryListener.php +++ b/EventListener/CheckExpiryListener.php @@ -16,6 +16,7 @@ use Symfony\Component\VarDumper\VarDumper; use Psr\Log\LoggerInterface; use App\Mail\PrimedTwigMailer; use Symfony\Component\Security\Core\Role\SwitchUserRole; +use vierbergenlars\AuthserverExpireEmailValidationBundle\AuthserverExpireEmailValidationBundle; class CheckExpiryListener implements EventSubscriberInterface { @@ -40,10 +41,7 @@ class CheckExpiryListener implements EventSubscriberInterface public static function getSubscribedEvents() { - return [ - AppEvents::SECURITY_USER_CHECK_POST => [ - 'onUserCheck' - ], + $events = [ AuthenticationEvents::AUTHENTICATION_SUCCESS => [ 'onAuthenticationSuccess' ], @@ -52,6 +50,10 @@ class CheckExpiryListener implements EventSubscriberInterface -10 ] ]; + if (AuthserverExpireEmailValidationBundle::hasUserCheckEvent()) { + $events[AppEvents::SECURITY_USER_CHECK_POST] = 'onUserCheck'; + } + return $events; } public function __construct(EntityManagerInterface $em, PrimedTwigMailer $mailer, LoggerInterface $logger) @@ -59,6 +61,9 @@ class CheckExpiryListener implements EventSubscriberInterface $this->em = $em; $this->mailer = $mailer; $this->logger = $logger; + if (!AuthserverExpireEmailValidationBundle::hasUserCheckEvent()) { + $this->logger->critical('ExpireEmailValidationBundle can not be fully activated because the ' . AppEvents::class . '::SECURITY_USER_CHECK_POST event does not exist'); + } } /**