Fix reference to wrong table name in the entity; handle non-existing event more gracefully by logging a critical error

master v0.1.1
Lars Vierbergen 7 years ago
parent a27885d160
commit 323c4e2b04
  1. 6
      AuthserverExpireEmailValidationBundle.php
  2. 6
      Command/ExpireEmailValidationCommand.php
  3. 2
      Entity/ExpiredUser.php
  4. 13
      EventListener/CheckExpiryListener.php

@ -1,8 +1,14 @@
<?php <?php
namespace vierbergenlars\AuthserverExpireEmailValidationBundle; namespace vierbergenlars\AuthserverExpireEmailValidationBundle;
use App\AppEvents;
use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\HttpKernel\Bundle\Bundle;
class AuthserverExpireEmailValidationBundle extends Bundle class AuthserverExpireEmailValidationBundle extends Bundle
{ {
public static function hasUserCheckEvent()
{
return defined(AppEvents::class . '::SECURITY_USER_CHECK_POST');
}
} }

@ -14,6 +14,7 @@ use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Console\Style\SymfonyStyle;
use App\AppBundle; use App\AppBundle;
use vierbergenlars\AuthserverExpireEmailValidationBundle\AuthserverExpireEmailValidationBundle;
class ExpireEmailValidationCommand extends Command class ExpireEmailValidationCommand extends Command
{ {
@ -28,6 +29,11 @@ class ExpireEmailValidationCommand extends Command
->addOption('dry-run', null, InputOption::VALUE_NONE, 'Do not actually execute the expiration.'); ->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) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$em = $this->getApplication() $em = $this->getApplication()

@ -10,7 +10,7 @@ use Doctrine\ORM\Mapping\Column;
/** /**
* @Entity() * @Entity()
* @Table(name="vierbergenlars_expire_users") * @Table(name="vierbergenlars_expire_email_validation")
*/ */
class ExpiredUser class ExpiredUser
{ {

@ -16,6 +16,7 @@ use Symfony\Component\VarDumper\VarDumper;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use App\Mail\PrimedTwigMailer; use App\Mail\PrimedTwigMailer;
use Symfony\Component\Security\Core\Role\SwitchUserRole; use Symfony\Component\Security\Core\Role\SwitchUserRole;
use vierbergenlars\AuthserverExpireEmailValidationBundle\AuthserverExpireEmailValidationBundle;
class CheckExpiryListener implements EventSubscriberInterface class CheckExpiryListener implements EventSubscriberInterface
{ {
@ -40,10 +41,7 @@ class CheckExpiryListener implements EventSubscriberInterface
public static function getSubscribedEvents() public static function getSubscribedEvents()
{ {
return [ $events = [
AppEvents::SECURITY_USER_CHECK_POST => [
'onUserCheck'
],
AuthenticationEvents::AUTHENTICATION_SUCCESS => [ AuthenticationEvents::AUTHENTICATION_SUCCESS => [
'onAuthenticationSuccess' 'onAuthenticationSuccess'
], ],
@ -52,6 +50,10 @@ class CheckExpiryListener implements EventSubscriberInterface
-10 -10
] ]
]; ];
if (AuthserverExpireEmailValidationBundle::hasUserCheckEvent()) {
$events[AppEvents::SECURITY_USER_CHECK_POST] = 'onUserCheck';
}
return $events;
} }
public function __construct(EntityManagerInterface $em, PrimedTwigMailer $mailer, LoggerInterface $logger) public function __construct(EntityManagerInterface $em, PrimedTwigMailer $mailer, LoggerInterface $logger)
@ -59,6 +61,9 @@ class CheckExpiryListener implements EventSubscriberInterface
$this->em = $em; $this->em = $em;
$this->mailer = $mailer; $this->mailer = $mailer;
$this->logger = $logger; $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');
}
} }
/** /**