summaryrefslogtreecommitdiff
path: root/app/Job
diff options
context:
space:
mode:
Diffstat (limited to 'app/Job')
-rw-r--r--app/Job/CommentEventJob.php50
-rw-r--r--app/Job/NotificationJob.php60
-rw-r--r--app/Job/ProjectFileEventJob.php45
-rw-r--r--app/Job/SubtaskEventJob.php48
-rw-r--r--app/Job/TaskEventJob.php75
-rw-r--r--app/Job/TaskFileEventJob.php45
6 files changed, 272 insertions, 51 deletions
diff --git a/app/Job/CommentEventJob.php b/app/Job/CommentEventJob.php
new file mode 100644
index 00000000..c89350ed
--- /dev/null
+++ b/app/Job/CommentEventJob.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace Kanboard\Job;
+
+use Kanboard\EventBuilder\CommentEventBuilder;
+use Kanboard\Model\CommentModel;
+
+/**
+ * Class CommentEventJob
+ *
+ * @package Kanboard\Job
+ * @author Frederic Guillot
+ */
+class CommentEventJob extends BaseJob
+{
+ /**
+ * Set job params
+ *
+ * @param int $commentId
+ * @param string $eventName
+ * @return $this
+ */
+ public function withParams($commentId, $eventName)
+ {
+ $this->jobParams = array($commentId, $eventName);
+ return $this;
+ }
+
+ /**
+ * Execute job
+ *
+ * @param int $commentId
+ * @param string $eventName
+ * @return $this
+ */
+ public function execute($commentId, $eventName)
+ {
+ $event = CommentEventBuilder::getInstance($this->container)
+ ->withCommentId($commentId)
+ ->build();
+
+ if ($event !== null) {
+ $this->dispatcher->dispatch($eventName, $event);
+
+ if ($eventName === CommentModel::EVENT_CREATE) {
+ $this->userMentionModel->fireEvents($event['comment']['comment'], CommentModel::EVENT_USER_MENTION, $event);
+ }
+ }
+ }
+}
diff --git a/app/Job/NotificationJob.php b/app/Job/NotificationJob.php
index 904a9273..8fb260e8 100644
--- a/app/Job/NotificationJob.php
+++ b/app/Job/NotificationJob.php
@@ -17,69 +17,27 @@ class NotificationJob extends BaseJob
*
* @param GenericEvent $event
* @param string $eventName
- * @param string $eventObjectName
* @return $this
*/
- public function withParams(GenericEvent $event, $eventName, $eventObjectName)
+ public function withParams(GenericEvent $event, $eventName)
{
- $this->jobParams = array($event->getAll(), $eventName, $eventObjectName);
+ $this->jobParams = array($event->getAll(), $eventName);
return $this;
}
/**
* Execute job
*
- * @param array $event
+ * @param array $eventData
* @param string $eventName
- * @param string $eventObjectName
*/
- public function execute(array $event, $eventName, $eventObjectName)
+ public function execute(array $eventData, $eventName)
{
- $eventData = $this->getEventData($event, $eventObjectName);
-
- if (! empty($eventData)) {
- if (! empty($event['mention'])) {
- $this->userNotificationModel->sendUserNotification($event['mention'], $eventName, $eventData);
- } else {
- $this->userNotificationModel->sendNotifications($eventName, $eventData);
- $this->projectNotificationModel->sendNotifications($eventData['task']['project_id'], $eventName, $eventData);
- }
- }
- }
-
- /**
- * Get event data
- *
- * @param array $event
- * @param string $eventObjectName
- * @return array
- */
- public function getEventData(array $event, $eventObjectName)
- {
- $values = array();
-
- if (! empty($event['changes'])) {
- $values['changes'] = $event['changes'];
+ if (! empty($eventData['mention'])) {
+ $this->userNotificationModel->sendUserNotification($eventData['mention'], $eventName, $eventData);
+ } else {
+ $this->userNotificationModel->sendNotifications($eventName, $eventData);
+ $this->projectNotificationModel->sendNotifications($eventData['task']['project_id'], $eventName, $eventData);
}
-
- switch ($eventObjectName) {
- case 'Kanboard\Event\TaskEvent':
- $values['task'] = $this->taskFinderModel->getDetails($event['task_id']);
- break;
- case 'Kanboard\Event\SubtaskEvent':
- $values['subtask'] = $this->subtaskModel->getById($event['id'], true);
- $values['task'] = $this->taskFinderModel->getDetails($values['subtask']['task_id']);
- break;
- case 'Kanboard\Event\FileEvent':
- $values['file'] = $event;
- $values['task'] = $this->taskFinderModel->getDetails($values['file']['task_id']);
- break;
- case 'Kanboard\Event\CommentEvent':
- $values['comment'] = $this->commentModel->getById($event['id']);
- $values['task'] = $this->taskFinderModel->getDetails($values['comment']['task_id']);
- break;
- }
-
- return $values;
}
}
diff --git a/app/Job/ProjectFileEventJob.php b/app/Job/ProjectFileEventJob.php
new file mode 100644
index 00000000..d68949c5
--- /dev/null
+++ b/app/Job/ProjectFileEventJob.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace Kanboard\Job;
+
+use Kanboard\EventBuilder\ProjectFileEventBuilder;
+
+/**
+ * Class ProjectFileEventJob
+ *
+ * @package Kanboard\Job
+ * @author Frederic Guillot
+ */
+class ProjectFileEventJob extends BaseJob
+{
+ /**
+ * Set job params
+ *
+ * @param int $fileId
+ * @param string $eventName
+ * @return $this
+ */
+ public function withParams($fileId, $eventName)
+ {
+ $this->jobParams = array($fileId, $eventName);
+ return $this;
+ }
+
+ /**
+ * Execute job
+ *
+ * @param int $fileId
+ * @param string $eventName
+ * @return $this
+ */
+ public function execute($fileId, $eventName)
+ {
+ $event = ProjectFileEventBuilder::getInstance($this->container)
+ ->withFileId($fileId)
+ ->build();
+
+ if ($event !== null) {
+ $this->dispatcher->dispatch($eventName, $event);
+ }
+ }
+}
diff --git a/app/Job/SubtaskEventJob.php b/app/Job/SubtaskEventJob.php
new file mode 100644
index 00000000..1dc243ef
--- /dev/null
+++ b/app/Job/SubtaskEventJob.php
@@ -0,0 +1,48 @@
+<?php
+
+namespace Kanboard\Job;
+
+use Kanboard\EventBuilder\SubtaskEventBuilder;
+
+/**
+ * Class SubtaskEventJob
+ *
+ * @package Kanboard\Job
+ * @author Frederic Guillot
+ */
+class SubtaskEventJob extends BaseJob
+{
+ /**
+ * Set job params
+ *
+ * @param int $subtaskId
+ * @param string $eventName
+ * @param array $values
+ * @return $this
+ */
+ public function withParams($subtaskId, $eventName, array $values = array())
+ {
+ $this->jobParams = array($subtaskId, $eventName, $values);
+ return $this;
+ }
+
+ /**
+ * Execute job
+ *
+ * @param int $subtaskId
+ * @param string $eventName
+ * @param array $values
+ * @return $this
+ */
+ public function execute($subtaskId, $eventName, array $values = array())
+ {
+ $event = SubtaskEventBuilder::getInstance($this->container)
+ ->withSubtaskId($subtaskId)
+ ->withValues($values)
+ ->build();
+
+ if ($event !== null) {
+ $this->dispatcher->dispatch($eventName, $event);
+ }
+ }
+}
diff --git a/app/Job/TaskEventJob.php b/app/Job/TaskEventJob.php
new file mode 100644
index 00000000..46f7a16c
--- /dev/null
+++ b/app/Job/TaskEventJob.php
@@ -0,0 +1,75 @@
+<?php
+
+namespace Kanboard\Job;
+
+use Kanboard\Event\TaskEvent;
+use Kanboard\EventBuilder\TaskEventBuilder;
+use Kanboard\Model\TaskModel;
+
+/**
+ * Class TaskEventJob
+ *
+ * @package Kanboard\Job
+ * @author Frederic Guillot
+ */
+class TaskEventJob extends BaseJob
+{
+ /**
+ * Set job params
+ *
+ * @param int $taskId
+ * @param array $eventNames
+ * @param array $changes
+ * @param array $values
+ * @param array $task
+ * @return $this
+ */
+ public function withParams($taskId, array $eventNames, array $changes = array(), array $values = array(), array $task = array())
+ {
+ $this->jobParams = array($taskId, $eventNames, $changes, $values, $task);
+ return $this;
+ }
+
+ /**
+ * Execute job
+ *
+ * @param int $taskId
+ * @param array $eventNames
+ * @param array $changes
+ * @param array $values
+ * @param array $task
+ * @return $this
+ */
+ public function execute($taskId, array $eventNames, array $changes = array(), array $values = array(), array $task = array())
+ {
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId($taskId)
+ ->withChanges($changes)
+ ->withValues($values)
+ ->withTask($task)
+ ->build();
+
+ if ($event !== null) {
+ foreach ($eventNames as $eventName) {
+ $this->fireEvent($eventName, $event);
+ }
+ }
+ }
+
+ /**
+ * Trigger event
+ *
+ * @access protected
+ * @param string $eventName
+ * @param TaskEvent $event
+ */
+ protected function fireEvent($eventName, TaskEvent $event)
+ {
+ $this->logger->debug(__METHOD__.' Event fired: '.$eventName);
+ $this->dispatcher->dispatch($eventName, $event);
+
+ if ($eventName === TaskModel::EVENT_CREATE) {
+ $this->userMentionModel->fireEvents($event['task']['description'], TaskModel::EVENT_USER_MENTION, $event);
+ }
+ }
+}
diff --git a/app/Job/TaskFileEventJob.php b/app/Job/TaskFileEventJob.php
new file mode 100644
index 00000000..de2c40db
--- /dev/null
+++ b/app/Job/TaskFileEventJob.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace Kanboard\Job;
+
+use Kanboard\EventBuilder\TaskFileEventBuilder;
+
+/**
+ * Class TaskFileEventJob
+ *
+ * @package Kanboard\Job
+ * @author Frederic Guillot
+ */
+class TaskFileEventJob extends BaseJob
+{
+ /**
+ * Set job params
+ *
+ * @param int $fileId
+ * @param string $eventName
+ * @return $this
+ */
+ public function withParams($fileId, $eventName)
+ {
+ $this->jobParams = array($fileId, $eventName);
+ return $this;
+ }
+
+ /**
+ * Execute job
+ *
+ * @param int $fileId
+ * @param string $eventName
+ * @return $this
+ */
+ public function execute($fileId, $eventName)
+ {
+ $event = TaskFileEventBuilder::getInstance($this->container)
+ ->withFileId($fileId)
+ ->build();
+
+ if ($event !== null) {
+ $this->dispatcher->dispatch($eventName, $event);
+ }
+ }
+}