deferring the sending of notification to kernel.terminate: prepare

This commit is contained in:
2022-04-22 11:34:41 +02:00
parent e246ccbcd9
commit 33f93d484d
6 changed files with 137 additions and 13 deletions

View File

@@ -13,6 +13,7 @@ namespace Chill\PersonBundle\AccompanyingPeriod\Events;
use Chill\MainBundle\Entity\Notification;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Notification\NotificationPersisterInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\Event\LifecycleEventArgs;
@@ -24,7 +25,8 @@ use Symfony\Contracts\Translation\TranslatorInterface;
class UserRefEventSubscriber implements EventSubscriberInterface
{
private EntityManagerInterface $em;
private NotificationPersisterInterface $notificationPersister;
private EngineInterface $engine;
@@ -32,12 +34,12 @@ class UserRefEventSubscriber implements EventSubscriberInterface
private TranslatorInterface $translator;
public function __construct(Security $security, TranslatorInterface $translator, EngineInterface $engine, EntityManagerInterface $em)
public function __construct(Security $security, TranslatorInterface $translator, EngineInterface $engine, NotificationPersisterInterface $notificationPersister)
{
$this->security = $security;
$this->translator = $translator;
$this->engine = $engine;
$this->em = $em;
$this->notificationPersister = $notificationPersister;
}
public static function getSubscribedEvents()
@@ -65,9 +67,6 @@ class UserRefEventSubscriber implements EventSubscriberInterface
) {
$this->generateNotificationToUser($period);
}
// we are just out of a flush operation. Launch a new one
$this->em->flush();
}
private function generateNotificationToUser(AccompanyingPeriod $period)
@@ -89,7 +88,7 @@ class UserRefEventSubscriber implements EventSubscriberInterface
))
->addAddressee($period->getUser());
$this->em->persist($notification);
$this->notificationPersister->persist($notification);
}
private function onPeriodConfirmed(AccompanyingPeriod $period)