diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-01-16 21:06:36 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-01-16 21:06:36 -0500 |
commit | 6a7b8ec60f265413ca88878dba6180456257d370 (patch) | |
tree | 5b36bf3122d6884cb09b66e623e28768e92ed9ba /app/Subscriber | |
parent | 6a0895ef765ea7b83df02bb9789fda7415dee9a5 (diff) |
Make sure that some event subscribers are not executed multiple times
Diffstat (limited to 'app/Subscriber')
-rw-r--r-- | app/Subscriber/AuthSubscriber.php | 7 | ||||
-rw-r--r-- | app/Subscriber/BaseSubscriber.php | 40 | ||||
-rw-r--r-- | app/Subscriber/BootstrapSubscriber.php | 4 | ||||
-rw-r--r-- | app/Subscriber/NotificationSubscriber.php | 20 | ||||
-rw-r--r-- | app/Subscriber/ProjectDailySummarySubscriber.php | 15 | ||||
-rw-r--r-- | app/Subscriber/ProjectModificationDateSubscriber.php | 21 | ||||
-rw-r--r-- | app/Subscriber/RecurringTaskSubscriber.php | 10 | ||||
-rw-r--r-- | app/Subscriber/SubtaskTimeTrackingSubscriber.php | 8 | ||||
-rw-r--r-- | app/Subscriber/TransitionSubscriber.php | 6 |
9 files changed, 93 insertions, 38 deletions
diff --git a/app/Subscriber/AuthSubscriber.php b/app/Subscriber/AuthSubscriber.php index f834afec..250c1fd3 100644 --- a/app/Subscriber/AuthSubscriber.php +++ b/app/Subscriber/AuthSubscriber.php @@ -3,7 +3,6 @@ namespace Kanboard\Subscriber; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Kanboard\Core\Base; use Kanboard\Core\Security\AuthenticationManager; use Kanboard\Core\Session\SessionManager; use Kanboard\Event\AuthSuccessEvent; @@ -15,7 +14,7 @@ use Kanboard\Event\AuthFailureEvent; * @package subscriber * @author Frederic Guillot */ -class AuthSubscriber extends Base implements EventSubscriberInterface +class AuthSubscriber extends BaseSubscriber implements EventSubscriberInterface { /** * Get event listeners @@ -41,6 +40,8 @@ class AuthSubscriber extends Base implements EventSubscriberInterface */ public function afterLogin(AuthSuccessEvent $event) { + $this->logger->debug('Subscriber executed: '.__CLASS__.'::'.__METHOD__); + $userAgent = $this->request->getUserAgent(); $ipAddress = $this->request->getIpAddress(); @@ -70,6 +71,7 @@ class AuthSubscriber extends Base implements EventSubscriberInterface */ public function afterLogout() { + $this->logger->debug('Subscriber executed: '.__CLASS__.'::'.__METHOD__); $credentials = $this->rememberMeCookie->read(); if ($credentials !== false) { @@ -90,6 +92,7 @@ class AuthSubscriber extends Base implements EventSubscriberInterface */ public function onLoginFailure(AuthFailureEvent $event) { + $this->logger->debug('Subscriber executed: '.__CLASS__.'::'.__METHOD__); $username = $event->getUsername(); if (! empty($username)) { diff --git a/app/Subscriber/BaseSubscriber.php b/app/Subscriber/BaseSubscriber.php new file mode 100644 index 00000000..875c5e26 --- /dev/null +++ b/app/Subscriber/BaseSubscriber.php @@ -0,0 +1,40 @@ +<?php + +namespace Kanboard\Subscriber; + +use Kanboard\Core\Base; + +/** + * Base class for subscribers + * + * @package subscriber + * @author Frederic Guillot + */ +class BaseSubscriber extends Base +{ + /** + * Method called + * + * @access private + * @var array + */ + private $called = array(); + + /** + * Check if a method has been executed + * + * @access public + * @param string $method + * @return boolean + */ + public function isExecuted($method = '') + { + if (isset($this->called[$method])) { + return true; + } + + $this->called[$method] = true; + + return false; + } +} diff --git a/app/Subscriber/BootstrapSubscriber.php b/app/Subscriber/BootstrapSubscriber.php index d114bf86..a65cf651 100644 --- a/app/Subscriber/BootstrapSubscriber.php +++ b/app/Subscriber/BootstrapSubscriber.php @@ -3,9 +3,8 @@ namespace Kanboard\Subscriber; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Kanboard\Core\Base; -class BootstrapSubscriber extends Base implements EventSubscriberInterface +class BootstrapSubscriber extends BaseSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents() { @@ -16,6 +15,7 @@ class BootstrapSubscriber extends Base implements EventSubscriberInterface public function execute() { + $this->logger->debug('Subscriber executed: '.__CLASS__.'::'.__METHOD__); $this->config->setupTranslations(); $this->config->setupTimezone(); $this->actionManager->attachEvents(); 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); + } } } } diff --git a/app/Subscriber/ProjectDailySummarySubscriber.php b/app/Subscriber/ProjectDailySummarySubscriber.php index d9239264..b70eaf71 100644 --- a/app/Subscriber/ProjectDailySummarySubscriber.php +++ b/app/Subscriber/ProjectDailySummarySubscriber.php @@ -6,22 +6,23 @@ use Kanboard\Event\TaskEvent; use Kanboard\Model\Task; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -class ProjectDailySummarySubscriber extends \Kanboard\Core\Base implements EventSubscriberInterface +class ProjectDailySummarySubscriber extends BaseSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents() { return array( - Task::EVENT_CREATE_UPDATE => array('execute', 0), - Task::EVENT_CLOSE => array('execute', 0), - Task::EVENT_OPEN => array('execute', 0), - Task::EVENT_MOVE_COLUMN => array('execute', 0), - Task::EVENT_MOVE_SWIMLANE => array('execute', 0), + Task::EVENT_CREATE_UPDATE => 'execute', + Task::EVENT_CLOSE => 'execute', + Task::EVENT_OPEN => 'execute', + Task::EVENT_MOVE_COLUMN => 'execute', + Task::EVENT_MOVE_SWIMLANE => 'execute', ); } public function execute(TaskEvent $event) { - if (isset($event['project_id'])) { + if (isset($event['project_id']) && !$this->isExecuted()) { + $this->logger->debug('Subscriber executed: '.__CLASS__.'::'.__METHOD__); $this->projectDailyColumnStats->updateTotals($event['project_id'], date('Y-m-d')); $this->projectDailyStats->updateTotals($event['project_id'], date('Y-m-d')); } diff --git a/app/Subscriber/ProjectModificationDateSubscriber.php b/app/Subscriber/ProjectModificationDateSubscriber.php index 1f99840d..ea102910 100644 --- a/app/Subscriber/ProjectModificationDateSubscriber.php +++ b/app/Subscriber/ProjectModificationDateSubscriber.php @@ -6,25 +6,26 @@ use Kanboard\Event\GenericEvent; use Kanboard\Model\Task; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -class ProjectModificationDateSubscriber extends \Kanboard\Core\Base implements EventSubscriberInterface +class ProjectModificationDateSubscriber extends BaseSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents() { return array( - Task::EVENT_CREATE_UPDATE => array('execute', 0), - Task::EVENT_CLOSE => array('execute', 0), - Task::EVENT_OPEN => array('execute', 0), - Task::EVENT_MOVE_SWIMLANE => array('execute', 0), - Task::EVENT_MOVE_COLUMN => array('execute', 0), - Task::EVENT_MOVE_POSITION => array('execute', 0), - Task::EVENT_MOVE_PROJECT => array('execute', 0), - Task::EVENT_ASSIGNEE_CHANGE => array('execute', 0), + Task::EVENT_CREATE_UPDATE => 'execute', + Task::EVENT_CLOSE => 'execute', + Task::EVENT_OPEN => 'execute', + Task::EVENT_MOVE_SWIMLANE => 'execute', + Task::EVENT_MOVE_COLUMN => 'execute', + Task::EVENT_MOVE_POSITION => 'execute', + Task::EVENT_MOVE_PROJECT => 'execute', + Task::EVENT_ASSIGNEE_CHANGE => 'execute', ); } public function execute(GenericEvent $event) { - if (isset($event['project_id'])) { + if (isset($event['project_id']) && !$this->isExecuted()) { + $this->logger->debug('Subscriber executed: '.__CLASS__.'::'.__METHOD__); $this->project->updateModificationDate($event['project_id']); } } diff --git a/app/Subscriber/RecurringTaskSubscriber.php b/app/Subscriber/RecurringTaskSubscriber.php index b03ffcf8..a300483d 100644 --- a/app/Subscriber/RecurringTaskSubscriber.php +++ b/app/Subscriber/RecurringTaskSubscriber.php @@ -6,18 +6,20 @@ use Kanboard\Event\TaskEvent; use Kanboard\Model\Task; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -class RecurringTaskSubscriber extends \Kanboard\Core\Base implements EventSubscriberInterface +class RecurringTaskSubscriber extends BaseSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents() { return array( - Task::EVENT_MOVE_COLUMN => array('onMove', 0), - Task::EVENT_CLOSE => array('onClose', 0), + Task::EVENT_MOVE_COLUMN => 'onMove', + Task::EVENT_CLOSE => 'onClose', ); } public function onMove(TaskEvent $event) { + $this->logger->debug('Subscriber executed: '.__CLASS__.'::'.__METHOD__); + if ($event['recurrence_status'] == Task::RECURRING_STATUS_PENDING) { if ($event['recurrence_trigger'] == Task::RECURRING_TRIGGER_FIRST_COLUMN && $this->board->getFirstColumn($event['project_id']) == $event['src_column_id']) { $this->taskDuplication->duplicateRecurringTask($event['task_id']); @@ -29,6 +31,8 @@ class RecurringTaskSubscriber extends \Kanboard\Core\Base implements EventSubscr public function onClose(TaskEvent $event) { + $this->logger->debug('Subscriber executed: '.__CLASS__.'::'.__METHOD__); + if ($event['recurrence_status'] == Task::RECURRING_STATUS_PENDING && $event['recurrence_trigger'] == Task::RECURRING_TRIGGER_CLOSE) { $this->taskDuplication->duplicateRecurringTask($event['task_id']); } diff --git a/app/Subscriber/SubtaskTimeTrackingSubscriber.php b/app/Subscriber/SubtaskTimeTrackingSubscriber.php index b5e0354d..5e4b2225 100644 --- a/app/Subscriber/SubtaskTimeTrackingSubscriber.php +++ b/app/Subscriber/SubtaskTimeTrackingSubscriber.php @@ -6,13 +6,13 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Kanboard\Model\Subtask; use Kanboard\Event\SubtaskEvent; -class SubtaskTimeTrackingSubscriber extends \Kanboard\Core\Base implements EventSubscriberInterface +class SubtaskTimeTrackingSubscriber extends BaseSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents() { return array( - Subtask::EVENT_CREATE => array('updateTaskTime', 0), - Subtask::EVENT_DELETE => array('updateTaskTime', 0), + Subtask::EVENT_CREATE => 'updateTaskTime', + Subtask::EVENT_DELETE => 'updateTaskTime', Subtask::EVENT_UPDATE => array( array('logStartEnd', 10), array('updateTaskTime', 0), @@ -23,6 +23,7 @@ class SubtaskTimeTrackingSubscriber extends \Kanboard\Core\Base implements Event public function updateTaskTime(SubtaskEvent $event) { if (isset($event['task_id'])) { + $this->logger->debug('Subscriber executed: '.__CLASS__.'::'.__METHOD__); $this->subtaskTimeTracking->updateTaskTimeTracking($event['task_id']); } } @@ -30,6 +31,7 @@ class SubtaskTimeTrackingSubscriber extends \Kanboard\Core\Base implements Event public function logStartEnd(SubtaskEvent $event) { if (isset($event['status']) && $this->config->get('subtask_time_tracking') == 1) { + $this->logger->debug('Subscriber executed: '.__CLASS__.'::'.__METHOD__); $subtask = $this->subtask->getById($event['id']); if (empty($subtask['user_id'])) { diff --git a/app/Subscriber/TransitionSubscriber.php b/app/Subscriber/TransitionSubscriber.php index 35352dc7..df59aa72 100644 --- a/app/Subscriber/TransitionSubscriber.php +++ b/app/Subscriber/TransitionSubscriber.php @@ -6,17 +6,19 @@ use Kanboard\Event\TaskEvent; use Kanboard\Model\Task; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -class TransitionSubscriber extends \Kanboard\Core\Base implements EventSubscriberInterface +class TransitionSubscriber extends BaseSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents() { return array( - Task::EVENT_MOVE_COLUMN => array('execute', 0), + Task::EVENT_MOVE_COLUMN => 'execute', ); } public function execute(TaskEvent $event) { + $this->logger->debug('Subscriber executed: '.__CLASS__.'::'.__METHOD__); + $user_id = $this->userSession->getId(); if (! empty($user_id)) { |