summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-07-17 20:33:27 -0400
committerFrederic Guillot <fred@kanboard.net>2016-07-17 20:33:27 -0400
commitd9d37882228771bca0c7f53f5ffcef90ba7ac1c5 (patch)
treef5df4446273878fc0bc9bf6e6db4bef1535b9de3 /app
parentcbe52e57200a66522d88dfc5d5f46de8eb87ffb2 (diff)
Subtasks events refactoring and show delete in activity stream
Diffstat (limited to 'app')
-rw-r--r--app/Core/Base.php1
-rw-r--r--app/EventBuilder/SubtaskEventBuilder.php79
-rw-r--r--app/Job/NotificationJob.php4
-rw-r--r--app/Job/SubtaskEventJob.php48
-rw-r--r--app/Model/NotificationModel.php5
-rw-r--r--app/Model/SubtaskModel.php22
-rw-r--r--app/ServiceProvider/ClassProvider.php6
-rw-r--r--app/ServiceProvider/JobProvider.php52
-rw-r--r--app/ServiceProvider/QueueProvider.php6
-rw-r--r--app/Subscriber/NotificationSubscriber.php1
-rw-r--r--app/Template/event/subtask_delete.php15
-rw-r--r--app/Template/notification/subtask_delete.php11
-rw-r--r--app/common.php1
13 files changed, 222 insertions, 29 deletions
diff --git a/app/Core/Base.php b/app/Core/Base.php
index 09e04456..6650680b 100644
--- a/app/Core/Base.php
+++ b/app/Core/Base.php
@@ -151,6 +151,7 @@ use Pimple\Container;
* @property \Kanboard\Core\Filter\LexerBuilder $taskLexer
* @property \Kanboard\Core\Filter\LexerBuilder $projectActivityLexer
* @property \Kanboard\Job\CommentEventJob $commentEventJob
+ * @property \Kanboard\Job\SubtaskEventJob $subtaskEventJob
* @property \Kanboard\Job\TaskFileEventJob $taskFileEventJob
* @property \Kanboard\Job\ProjectFileEventJob $projectFileEventJob
* @property \Kanboard\Job\NotificationJob $notificationJob
diff --git a/app/EventBuilder/SubtaskEventBuilder.php b/app/EventBuilder/SubtaskEventBuilder.php
new file mode 100644
index 00000000..f0271257
--- /dev/null
+++ b/app/EventBuilder/SubtaskEventBuilder.php
@@ -0,0 +1,79 @@
+<?php
+
+namespace Kanboard\EventBuilder;
+
+use Kanboard\Event\SubtaskEvent;
+use Kanboard\Event\GenericEvent;
+
+/**
+ * Class SubtaskEventBuilder
+ *
+ * @package Kanboard\EventBuilder
+ * @author Frederic Guillot
+ */
+class SubtaskEventBuilder extends BaseEventBuilder
+{
+ /**
+ * SubtaskId
+ *
+ * @access protected
+ * @var int
+ */
+ protected $subtaskId = 0;
+
+ /**
+ * Changed values
+ *
+ * @access protected
+ * @var array
+ */
+ protected $values = array();
+
+ /**
+ * Set SubtaskId
+ *
+ * @param int $subtaskId
+ * @return $this
+ */
+ public function withSubtaskId($subtaskId)
+ {
+ $this->subtaskId = $subtaskId;
+ return $this;
+ }
+
+ /**
+ * Set values
+ *
+ * @param array $values
+ * @return $this
+ */
+ public function withValues(array $values)
+ {
+ $this->values = $values;
+ return $this;
+ }
+
+ /**
+ * Build event data
+ *
+ * @access public
+ * @return GenericEvent|null
+ */
+ public function build()
+ {
+ $eventData = array();
+ $eventData['subtask'] = $this->subtaskModel->getById($this->subtaskId, true);
+
+ if (empty($eventData['subtask'])) {
+ $this->logger->debug(__METHOD__.': Subtask not found');
+ return null;
+ }
+
+ if (! empty($this->values)) {
+ $eventData['changes'] = array_diff_assoc($this->values, $eventData['subtask']);
+ }
+
+ $eventData['task'] = $this->taskFinderModel->getDetails($eventData['subtask']['task_id']);
+ return new SubtaskEvent($eventData);
+ }
+}
diff --git a/app/Job/NotificationJob.php b/app/Job/NotificationJob.php
index ed568e47..5a52eb31 100644
--- a/app/Job/NotificationJob.php
+++ b/app/Job/NotificationJob.php
@@ -66,10 +66,6 @@ class NotificationJob extends BaseJob
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;
default:
$values = $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/Model/NotificationModel.php b/app/Model/NotificationModel.php
index df481fc7..ac8d9bae 100644
--- a/app/Model/NotificationModel.php
+++ b/app/Model/NotificationModel.php
@@ -70,6 +70,8 @@ class NotificationModel extends Base
return e('%s updated a subtask for the task #%d', $event_author, $event_data['task']['id']);
case SubtaskModel::EVENT_CREATE:
return e('%s created a subtask for the task #%d', $event_author, $event_data['task']['id']);
+ case SubtaskModel::EVENT_DELETE:
+ return e('%s removed a subtask for the task #%d', $event_author, $event_data['task']['id']);
case CommentModel::EVENT_UPDATE:
return e('%s updated a comment on the task #%d', $event_author, $event_data['task']['id']);
case CommentModel::EVENT_CREATE:
@@ -110,6 +112,8 @@ class NotificationModel extends Base
return e('New subtask on task #%d', $event_data['subtask']['task_id']);
case SubtaskModel::EVENT_UPDATE:
return e('Subtask updated on task #%d', $event_data['subtask']['task_id']);
+ case SubtaskModel::EVENT_DELETE:
+ return e('Subtask removed on task #%d', $event_data['subtask']['task_id']);
case TaskModel::EVENT_CREATE:
return e('New task #%d: %s', $event_data['task']['id'], $event_data['task']['title']);
case TaskModel::EVENT_UPDATE:
@@ -157,6 +161,7 @@ class NotificationModel extends Base
return $event_data['comment']['task_id'];
case SubtaskModel::EVENT_CREATE:
case SubtaskModel::EVENT_UPDATE:
+ case SubtaskModel::EVENT_DELETE:
return $event_data['subtask']['task_id'];
case TaskModel::EVENT_CREATE:
case TaskModel::EVENT_UPDATE:
diff --git a/app/Model/SubtaskModel.php b/app/Model/SubtaskModel.php
index a97bddbf..6dd1f26a 100644
--- a/app/Model/SubtaskModel.php
+++ b/app/Model/SubtaskModel.php
@@ -66,7 +66,7 @@ class SubtaskModel extends Base
->join(TaskModel::TABLE, 'id', 'task_id')
->findOneColumn(TaskModel::TABLE . '.project_id') ?: 0;
}
-
+
/**
* Get available status
*
@@ -235,10 +235,7 @@ class SubtaskModel extends Base
$subtask_id = $this->db->table(self::TABLE)->persist($values);
if ($subtask_id !== false) {
- $this->container['dispatcher']->dispatch(
- self::EVENT_CREATE,
- new SubtaskEvent(array('id' => $subtask_id) + $values)
- );
+ $this->queueManager->push($this->subtaskEventJob->withParams($subtask_id, self::EVENT_CREATE));
}
return $subtask_id;
@@ -255,13 +252,10 @@ class SubtaskModel extends Base
public function update(array $values, $fire_events = true)
{
$this->prepare($values);
- $subtask = $this->getById($values['id']);
$result = $this->db->table(self::TABLE)->eq('id', $values['id'])->save($values);
if ($result && $fire_events) {
- $event = $subtask;
- $event['changes'] = array_diff_assoc($values, $subtask);
- $this->container['dispatcher']->dispatch(self::EVENT_UPDATE, new SubtaskEvent($event));
+ $this->queueManager->push($this->subtaskEventJob->withParams($values['id'], self::EVENT_UPDATE, $values));
}
return $result;
@@ -377,14 +371,8 @@ class SubtaskModel extends Base
*/
public function remove($subtask_id)
{
- $subtask = $this->getById($subtask_id);
- $result = $this->db->table(self::TABLE)->eq('id', $subtask_id)->remove();
-
- if ($result) {
- $this->container['dispatcher']->dispatch(self::EVENT_DELETE, new SubtaskEvent($subtask));
- }
-
- return $result;
+ $this->subtaskEventJob->execute($subtask_id, self::EVENT_DELETE);
+ return $this->db->table(self::TABLE)->eq('id', $subtask_id)->remove();
}
/**
diff --git a/app/ServiceProvider/ClassProvider.php b/app/ServiceProvider/ClassProvider.php
index 428a8015..e32c0d43 100644
--- a/app/ServiceProvider/ClassProvider.php
+++ b/app/ServiceProvider/ClassProvider.php
@@ -26,12 +26,6 @@ class ClassProvider implements ServiceProviderInterface
'AverageLeadCycleTimeAnalytic',
'AverageTimeSpentColumnAnalytic',
),
- 'Job' => array(
- 'CommentEventJob',
- 'TaskFileEventJob',
- 'ProjectFileEventJob',
- 'NotificationJob',
- ),
'Model' => array(
'ActionModel',
'ActionParameterModel',
diff --git a/app/ServiceProvider/JobProvider.php b/app/ServiceProvider/JobProvider.php
new file mode 100644
index 00000000..bfea6e6e
--- /dev/null
+++ b/app/ServiceProvider/JobProvider.php
@@ -0,0 +1,52 @@
+<?php
+
+namespace Kanboard\ServiceProvider;
+
+use Kanboard\Job\CommentEventJob;
+use Kanboard\Job\NotificationJob;
+use Kanboard\Job\ProjectFileEventJob;
+use Kanboard\Job\SubtaskEventJob;
+use Kanboard\Job\TaskFileEventJob;
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+
+/**
+ * Class JobProvider
+ *
+ * @package Kanboard\ServiceProvider
+ * @author Frederic Guillot
+ */
+class JobProvider implements ServiceProviderInterface
+{
+ /**
+ * Register providers
+ *
+ * @access public
+ * @param \Pimple\Container $container
+ * @return \Pimple\Container
+ */
+ public function register(Container $container)
+ {
+ $container['commentEventJob'] = $container->factory(function ($c) {
+ return new CommentEventJob($c);
+ });
+
+ $container['subtaskEventJob'] = $container->factory(function ($c) {
+ return new SubtaskEventJob($c);
+ });
+
+ $container['taskFileEventJob'] = $container->factory(function ($c) {
+ return new TaskFileEventJob($c);
+ });
+
+ $container['projectFileEventJob'] = $container->factory(function ($c) {
+ return new ProjectFileEventJob($c);
+ });
+
+ $container['notificationJob'] = $container->factory(function ($c) {
+ return new NotificationJob($c);
+ });
+
+ return $container;
+ }
+}
diff --git a/app/ServiceProvider/QueueProvider.php b/app/ServiceProvider/QueueProvider.php
index 946b436a..570f2e77 100644
--- a/app/ServiceProvider/QueueProvider.php
+++ b/app/ServiceProvider/QueueProvider.php
@@ -15,9 +15,11 @@ use Pimple\ServiceProviderInterface;
class QueueProvider implements ServiceProviderInterface
{
/**
- * Registers services on the given container.
+ * Register providers
*
- * @param Container $container
+ * @access public
+ * @param \Pimple\Container $container
+ * @return \Pimple\Container
*/
public function register(Container $container)
{
diff --git a/app/Subscriber/NotificationSubscriber.php b/app/Subscriber/NotificationSubscriber.php
index 47222f73..0b3760c4 100644
--- a/app/Subscriber/NotificationSubscriber.php
+++ b/app/Subscriber/NotificationSubscriber.php
@@ -26,6 +26,7 @@ class NotificationSubscriber extends BaseSubscriber implements EventSubscriberIn
TaskModel::EVENT_ASSIGNEE_CHANGE => 'handleEvent',
SubtaskModel::EVENT_CREATE => 'handleEvent',
SubtaskModel::EVENT_UPDATE => 'handleEvent',
+ SubtaskModel::EVENT_DELETE => 'handleEvent',
CommentModel::EVENT_CREATE => 'handleEvent',
CommentModel::EVENT_UPDATE => 'handleEvent',
CommentModel::EVENT_REMOVE => 'handleEvent',
diff --git a/app/Template/event/subtask_delete.php b/app/Template/event/subtask_delete.php
new file mode 100644
index 00000000..8ac11853
--- /dev/null
+++ b/app/Template/event/subtask_delete.php
@@ -0,0 +1,15 @@
+<p class="activity-title">
+ <?= e('%s removed a subtask for the task %s',
+ $this->text->e($author),
+ $this->url->link(t('#%d', $task['id']), 'TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))
+ ) ?>
+ <span class="activity-date"><?= $this->dt->datetime($date_creation) ?></span>
+</p>
+<div class="activity-description">
+ <p class="activity-task-title"><?= $this->text->e($task['title']) ?></p>
+ <ul>
+ <li>
+ <?= $this->text->e($subtask['title']) ?> (<strong><?= $this->text->e($subtask['status_name']) ?></strong>)
+ </li>
+ </ul>
+</div>
diff --git a/app/Template/notification/subtask_delete.php b/app/Template/notification/subtask_delete.php
new file mode 100644
index 00000000..8c5f262c
--- /dev/null
+++ b/app/Template/notification/subtask_delete.php
@@ -0,0 +1,11 @@
+<h2><?= $this->text->e($task['title']) ?> (#<?= $task['id'] ?>)</h2>
+
+<h3><?= t('Subtask removed') ?></h3>
+
+<ul>
+ <li><?= t('Title:') ?> <?= $this->text->e($subtask['title']) ?></li>
+ <li><?= t('Status:') ?> <?= $this->text->e($subtask['status_name']) ?></li>
+ <li><?= t('Assignee:') ?> <?= $this->text->e($subtask['name'] ?: $subtask['username'] ?: '?') ?></li>
+</ul>
+
+<?= $this->render('notification/footer', array('task' => $task, 'application_url' => $application_url)) ?>
diff --git a/app/common.php b/app/common.php
index 72be3603..15fd7a75 100644
--- a/app/common.php
+++ b/app/common.php
@@ -46,6 +46,7 @@ $container->register(new Kanboard\ServiceProvider\ActionProvider());
$container->register(new Kanboard\ServiceProvider\ExternalLinkProvider());
$container->register(new Kanboard\ServiceProvider\AvatarProvider());
$container->register(new Kanboard\ServiceProvider\FilterProvider());
+$container->register(new Kanboard\ServiceProvider\JobProvider());
$container->register(new Kanboard\ServiceProvider\QueueProvider());
$container->register(new Kanboard\ServiceProvider\ApiProvider());
$container->register(new Kanboard\ServiceProvider\CommandProvider());