summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--app/Subscriber/AuthSubscriber.php7
-rw-r--r--app/Subscriber/BaseSubscriber.php40
-rw-r--r--app/Subscriber/BootstrapSubscriber.php4
-rw-r--r--app/Subscriber/NotificationSubscriber.php20
-rw-r--r--app/Subscriber/ProjectDailySummarySubscriber.php15
-rw-r--r--app/Subscriber/ProjectModificationDateSubscriber.php21
-rw-r--r--app/Subscriber/RecurringTaskSubscriber.php10
-rw-r--r--app/Subscriber/SubtaskTimeTrackingSubscriber.php8
-rw-r--r--app/Subscriber/TransitionSubscriber.php6
10 files changed, 95 insertions, 39 deletions
diff --git a/ChangeLog b/ChangeLog
index 46669325..99688c66 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -14,7 +14,8 @@ Improvements:
* Move validators to a separate namespace
* Improve and write unit tests for reports
* Reduce the number of SQL queries for project daily column stats
-* Remove subscriber to update date_moved field
+* Remove event subscriber to update date_moved field
+* Make sure that some event subscribers are not executed multiple times
Bug fixes:
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)) {