Make sure that some event subscribers are not executed multiple times

This commit is contained in:
Frederic Guillot
2016-01-16 21:06:36 -05:00
parent 6a0895ef76
commit 6a7b8ec60f
10 changed files with 95 additions and 39 deletions

View File

@@ -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);
}
}
}
}