Add a separate method for onPersist, use same private resetCache method

This commit is contained in:
Julie Lenaerts 2023-12-13 10:12:56 +01:00 committed by Julien Fastré
parent d58c0a867d
commit 32ae2f8f0d
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
2 changed files with 7 additions and 1 deletions

View File

@ -16,6 +16,7 @@ use Chill\MainBundle\Entity\NotificationComment;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Repository\NotificationRepository; use Chill\MainBundle\Repository\NotificationRepository;
use Chill\MainBundle\Templating\UI\NotificationCounterInterface; use Chill\MainBundle\Templating\UI\NotificationCounterInterface;
use Doctrine\ORM\Event\PostPersistEventArgs;
use Doctrine\ORM\Event\PostUpdateEventArgs; use Doctrine\ORM\Event\PostUpdateEventArgs;
use Doctrine\ORM\Event\PreFlushEventArgs; use Doctrine\ORM\Event\PreFlushEventArgs;
use Psr\Cache\CacheItemPoolInterface; use Psr\Cache\CacheItemPoolInterface;
@ -62,6 +63,11 @@ final readonly class NotificationByUserCounter implements NotificationCounterInt
return 'chill_main_notif_unread_by_'.$user->getId(); 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 public function onEditNotificationComment(NotificationComment $notificationComment, PostUpdateEventArgs $eventArgs): void
{ {
$this->resetCacheForNotification($notificationComment->getNotification()); $this->resetCacheForNotification($notificationComment->getNotification());

View File

@ -41,7 +41,7 @@ services:
entity: 'Chill\MainBundle\Entity\NotificationComment' entity: 'Chill\MainBundle\Entity\NotificationComment'
# set the 'lazy' option to TRUE to only instantiate listeners when they are used # set the 'lazy' option to TRUE to only instantiate listeners when they are used
lazy: true lazy: true
method: 'onEditNotificationComment' method: 'onPersistNotificationComment'
Chill\MainBundle\Notification\Email\NotificationMailer: Chill\MainBundle\Notification\Email\NotificationMailer:
autowire: true autowire: true