From 6a7b8ec60f265413ca88878dba6180456257d370 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 16 Jan 2016 21:06:36 -0500 Subject: Make sure that some event subscribers are not executed multiple times --- app/Subscriber/NotificationSubscriber.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'app/Subscriber/NotificationSubscriber.php') diff --git a/app/Subscriber/NotificationSubscriber.php b/app/Subscriber/NotificationSubscriber.php index 1bde24dd..6c24b08c 100644 --- a/app/Subscriber/NotificationSubscriber.php +++ b/app/Subscriber/NotificationSubscriber.php @@ -2,7 +2,6 @@ namespace Kanboard\Subscriber; -use Kanboard\Core\Base; use Kanboard\Event\GenericEvent; use Kanboard\Model\Task; use Kanboard\Model\Comment; @@ -10,7 +9,7 @@ use Kanboard\Model\Subtask; use Kanboard\Model\File; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -class NotificationSubscriber extends Base implements EventSubscriberInterface +class NotificationSubscriber extends BaseSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents() { @@ -35,14 +34,17 @@ class NotificationSubscriber extends Base implements EventSubscriberInterface public function handleEvent(GenericEvent $event, $event_name) { - $event_data = $this->getEventData($event); + if (! $this->isExecuted()) { + $this->logger->debug('Subscriber executed: '.__CLASS__.'::'.__METHOD__); + $event_data = $this->getEventData($event); - if (! empty($event_data)) { - if (! empty($event['mention'])) { - $this->userNotification->sendUserNotification($event['mention'], $event_name, $event_data); - } else { - $this->userNotification->sendNotifications($event_name, $event_data); - $this->projectNotification->sendNotifications($event_data['task']['project_id'], $event_name, $event_data); + if (! empty($event_data)) { + if (! empty($event['mention'])) { + $this->userNotification->sendUserNotification($event['mention'], $event_name, $event_data); + } else { + $this->userNotification->sendNotifications($event_name, $event_data); + $this->projectNotification->sendNotifications($event_data['task']['project_id'], $event_name, $event_data); + } } } } -- cgit v1.2.3