From 19561c63cbff8a5e507a2b031abcb3da6d738ec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 22 Apr 2022 12:31:23 +0200 Subject: [PATCH] do not persist if no notification is scheduled --- .../PersistNotificationOnTerminateEventSubscriber.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Notification/EventListener/PersistNotificationOnTerminateEventSubscriber.php b/src/Bundle/ChillMainBundle/Notification/EventListener/PersistNotificationOnTerminateEventSubscriber.php index 1f19def23..9a61043ff 100644 --- a/src/Bundle/ChillMainBundle/Notification/EventListener/PersistNotificationOnTerminateEventSubscriber.php +++ b/src/Bundle/ChillMainBundle/Notification/EventListener/PersistNotificationOnTerminateEventSubscriber.php @@ -46,10 +46,12 @@ class PersistNotificationOnTerminateEventSubscriber implements EventSubscriberIn private function persistNotifications(): void { - foreach ($this->persister->getWaitingNotifications() as $notification) { - $this->em->persist($notification); - } + if (0 < count($this->persister->getWaitingNotifications())) { + foreach ($this->persister->getWaitingNotifications() as $notification) { + $this->em->persist($notification); + } - $this->em->flush(); + $this->em->flush(); + } } }