summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-10-17 12:53:11 -0400
committerFrederic Guillot <fred@kanboard.net>2015-10-17 12:53:11 -0400
commit9153c6ff0ddb3170928d33599d9178e67ca466b6 (patch)
tree450891d77f14baf1df068d23609ff326345ef41f /app
parent472f94efee77d8f47ece4ead7d36ee02e5df3e56 (diff)
Move ProjectActivitySubscriber to a new notification type
Diffstat (limited to 'app')
-rw-r--r--app/Model/ProjectActivity.php2
-rw-r--r--app/Notification/ActivityStream.php58
-rw-r--r--app/Notification/Webhook.php2
-rw-r--r--app/ServiceProvider/ClassProvider.php3
-rw-r--r--app/ServiceProvider/EventDispatcherProvider.php2
-rw-r--r--app/Subscriber/ProjectActivitySubscriber.php74
6 files changed, 63 insertions, 78 deletions
diff --git a/app/Model/ProjectActivity.php b/app/Model/ProjectActivity.php
index 2cc1c975..032c1fa6 100644
--- a/app/Model/ProjectActivity.php
+++ b/app/Model/ProjectActivity.php
@@ -238,6 +238,8 @@ class ProjectActivity extends Base
return t('%s updated a comment on the task #%d', $event['author'], $event['task']['id']);
case Comment::EVENT_CREATE:
return t('%s commented on the task #%d', $event['author'], $event['task']['id']);
+ case File::EVENT_CREATE:
+ return t('%s attached a file to the task #%d', $event['author'], $event['task']['id']);
default:
return '';
}
diff --git a/app/Notification/ActivityStream.php b/app/Notification/ActivityStream.php
new file mode 100644
index 00000000..65ae64b1
--- /dev/null
+++ b/app/Notification/ActivityStream.php
@@ -0,0 +1,58 @@
+<?php
+
+namespace Kanboard\Notification;
+
+use Kanboard\Core\Base;
+
+/**
+ * Activity Stream Notification
+ *
+ * @package notification
+ * @author Frederic Guillot
+ */
+class ActivityStream extends Base implements NotificationInterface
+{
+ /**
+ * Send notification to a user
+ *
+ * @access public
+ * @param array $user
+ * @param string $event_name
+ * @param array $event_data
+ */
+ public function notifyUser(array $user, $event_name, array $event_data)
+ {
+ }
+
+ /**
+ * Send notification to a project
+ *
+ * @access public
+ * @param array $project
+ * @param string $event_name
+ * @param array $event_data
+ */
+ public function notifyProject(array $project, $event_name, array $event_data)
+ {
+ if ($this->userSession->isLogged()) {
+
+ $this->projectActivity->createEvent(
+ $project['id'],
+ $event_data['task']['id'],
+ $this->userSession->getId(),
+ $event_name,
+ $event_data
+ );
+
+ // TODO: need to be moved to external plugins
+ foreach (array('slackWebhook', 'hipchatWebhook', 'jabber') as $model) {
+ $this->$model->notify(
+ $project['id'],
+ $event_data['task']['id'],
+ $event_name,
+ $event_data
+ );
+ }
+ }
+ }
+}
diff --git a/app/Notification/Webhook.php b/app/Notification/Webhook.php
index feeee5d6..e187909f 100644
--- a/app/Notification/Webhook.php
+++ b/app/Notification/Webhook.php
@@ -49,7 +49,7 @@ class Webhook extends Base implements NotificationInterface
'event_data' => $event_data,
);
- return $this->httpClient->postJson($url, $payload);
+ $this->httpClient->postJson($url, $payload);
}
}
}
diff --git a/app/ServiceProvider/ClassProvider.php b/app/ServiceProvider/ClassProvider.php
index 182ecf26..b969c289 100644
--- a/app/ServiceProvider/ClassProvider.php
+++ b/app/ServiceProvider/ClassProvider.php
@@ -138,7 +138,8 @@ class ClassProvider implements ServiceProviderInterface
$container['projectNotificationType'] = function ($container) {
$type = new ProjectNotificationType($container);
- $type->setType('webhook', t('Webhook'), '\Kanboard\Notification\Webhook', true);
+ $type->setType('webhook', 'Webhook', '\Kanboard\Notification\Webhook', true);
+ $type->setType('activity_stream', 'ActivityStream', '\Kanboard\Notification\ActivityStream', true);
return $type;
};
diff --git a/app/ServiceProvider/EventDispatcherProvider.php b/app/ServiceProvider/EventDispatcherProvider.php
index 3c9404d0..1711919e 100644
--- a/app/ServiceProvider/EventDispatcherProvider.php
+++ b/app/ServiceProvider/EventDispatcherProvider.php
@@ -8,7 +8,6 @@ use Symfony\Component\EventDispatcher\EventDispatcher;
use Kanboard\Subscriber\AuthSubscriber;
use Kanboard\Subscriber\BootstrapSubscriber;
use Kanboard\Subscriber\NotificationSubscriber;
-use Kanboard\Subscriber\ProjectActivitySubscriber;
use Kanboard\Subscriber\ProjectDailySummarySubscriber;
use Kanboard\Subscriber\ProjectModificationDateSubscriber;
use Kanboard\Subscriber\SubtaskTimeTrackingSubscriber;
@@ -23,7 +22,6 @@ class EventDispatcherProvider implements ServiceProviderInterface
$container['dispatcher'] = new EventDispatcher;
$container['dispatcher']->addSubscriber(new BootstrapSubscriber($container));
$container['dispatcher']->addSubscriber(new AuthSubscriber($container));
- $container['dispatcher']->addSubscriber(new ProjectActivitySubscriber($container));
$container['dispatcher']->addSubscriber(new ProjectDailySummarySubscriber($container));
$container['dispatcher']->addSubscriber(new ProjectModificationDateSubscriber($container));
$container['dispatcher']->addSubscriber(new NotificationSubscriber($container));
diff --git a/app/Subscriber/ProjectActivitySubscriber.php b/app/Subscriber/ProjectActivitySubscriber.php
deleted file mode 100644
index a49a00ed..00000000
--- a/app/Subscriber/ProjectActivitySubscriber.php
+++ /dev/null
@@ -1,74 +0,0 @@
-<?php
-
-namespace Kanboard\Subscriber;
-
-use Kanboard\Event\GenericEvent;
-use Kanboard\Model\Task;
-use Kanboard\Model\Comment;
-use Kanboard\Model\Subtask;
-use Symfony\Component\EventDispatcher\EventSubscriberInterface;
-
-class ProjectActivitySubscriber extends \Kanboard\Core\Base implements EventSubscriberInterface
-{
- public static function getSubscribedEvents()
- {
- return array(
- Task::EVENT_ASSIGNEE_CHANGE => array('execute', 0),
- Task::EVENT_UPDATE => array('execute', 0),
- Task::EVENT_CREATE => 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_POSITION => array('execute', 0),
- Task::EVENT_MOVE_SWIMLANE => array('execute', 0),
- Comment::EVENT_UPDATE => array('execute', 0),
- Comment::EVENT_CREATE => array('execute', 0),
- Subtask::EVENT_UPDATE => array('execute', 0),
- Subtask::EVENT_CREATE => array('execute', 0),
- );
- }
-
- public function execute(GenericEvent $event, $event_name)
- {
- // Executed only when someone is logged
- if ($this->userSession->isLogged() && isset($event['task_id'])) {
- $values = $this->getValues($event);
-
- $this->projectActivity->createEvent(
- $values['task']['project_id'],
- $values['task']['id'],
- $this->userSession->getId(),
- $event_name,
- $values
- );
-
- // Send notifications to third-party services
- foreach (array('slackWebhook', 'hipchatWebhook', 'jabber') as $model) {
- $this->$model->notify(
- $values['task']['project_id'],
- $values['task']['id'],
- $event_name,
- $values
- );
- }
- }
- }
-
- private function getValues(GenericEvent $event)
- {
- $values = array();
- $values['task'] = $this->taskFinder->getDetails($event['task_id']);
- $values['changes'] = isset($event['changes']) ? $event['changes'] : array();
-
- switch (get_class($event)) {
- case 'Kanboard\Event\SubtaskEvent':
- $values['subtask'] = $this->subtask->getById($event['id'], true);
- break;
- case 'Kanboard\Event\CommentEvent':
- $values['comment'] = $this->comment->getById($event['id']);
- break;
- }
-
- return $values;
- }
-}