From 32ae2f8f0df7ea9de3510a75a41024357b66b90c Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 13 Dec 2023 10:12:56 +0100 Subject: [PATCH] Add a separate method for onPersist, use same private resetCache method --- .../Notification/Counter/NotificationByUserCounter.php | 6 ++++++ .../ChillMainBundle/config/services/notification.yaml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillMainBundle/Notification/Counter/NotificationByUserCounter.php b/src/Bundle/ChillMainBundle/Notification/Counter/NotificationByUserCounter.php index 15a33d836..e08543e8c 100644 --- a/src/Bundle/ChillMainBundle/Notification/Counter/NotificationByUserCounter.php +++ b/src/Bundle/ChillMainBundle/Notification/Counter/NotificationByUserCounter.php @@ -16,6 +16,7 @@ use Chill\MainBundle\Entity\NotificationComment; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Repository\NotificationRepository; use Chill\MainBundle\Templating\UI\NotificationCounterInterface; +use Doctrine\ORM\Event\PostPersistEventArgs; use Doctrine\ORM\Event\PostUpdateEventArgs; use Doctrine\ORM\Event\PreFlushEventArgs; use Psr\Cache\CacheItemPoolInterface; @@ -62,6 +63,11 @@ final readonly class NotificationByUserCounter implements NotificationCounterInt return 'chill_main_notif_unread_by_'.$user->getId(); } + public function onPersistNotificationComment(NotificationComment $notificationComment, PostPersistEventArgs $eventArgs): void + { + $this->resetCacheForNotification($notificationComment->getNotification()); + } + public function onEditNotificationComment(NotificationComment $notificationComment, PostUpdateEventArgs $eventArgs): void { $this->resetCacheForNotification($notificationComment->getNotification()); diff --git a/src/Bundle/ChillMainBundle/config/services/notification.yaml b/src/Bundle/ChillMainBundle/config/services/notification.yaml index 29cbce946..be3252003 100644 --- a/src/Bundle/ChillMainBundle/config/services/notification.yaml +++ b/src/Bundle/ChillMainBundle/config/services/notification.yaml @@ -41,7 +41,7 @@ services: entity: 'Chill\MainBundle\Entity\NotificationComment' # set the 'lazy' option to TRUE to only instantiate listeners when they are used lazy: true - method: 'onEditNotificationComment' + method: 'onPersistNotificationComment' Chill\MainBundle\Notification\Email\NotificationMailer: autowire: true