From 6d5ffaa848dcbc09538f79cb0cdea08f5306f4a4 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Mon, 18 May 2015 21:04:06 -0400 Subject: Send all Kanboard events to the webhook (breaking change) --- app/Subscriber/WebhookSubscriber.php | 47 +++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 22 deletions(-) (limited to 'app/Subscriber') diff --git a/app/Subscriber/WebhookSubscriber.php b/app/Subscriber/WebhookSubscriber.php index 6b5abf1b..e28675bd 100644 --- a/app/Subscriber/WebhookSubscriber.php +++ b/app/Subscriber/WebhookSubscriber.php @@ -2,8 +2,13 @@ namespace Subscriber; +use Event\CommentEvent; +use Event\GenericEvent; use Event\TaskEvent; +use Model\Comment; use Model\Task; +use Model\File; +use Model\Subtask; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class WebhookSubscriber extends Base implements EventSubscriberInterface @@ -11,32 +16,30 @@ class WebhookSubscriber extends Base implements EventSubscriberInterface public static function getSubscribedEvents() { return array( - Task::EVENT_CREATE => array('onTaskCreation', 0), - Task::EVENT_UPDATE => array('onTaskModification', 0), - Task::EVENT_CLOSE => array('onTaskModification', 0), - Task::EVENT_OPEN => array('onTaskModification', 0), - Task::EVENT_MOVE_COLUMN => array('onTaskModification', 0), - Task::EVENT_MOVE_POSITION => array('onTaskModification', 0), - Task::EVENT_ASSIGNEE_CHANGE => array('onTaskModification', 0), + Task::EVENT_CREATE => array('execute', 0), + Task::EVENT_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_POSITION => array('execute', 0), + Task::EVENT_ASSIGNEE_CHANGE => array('execute', 0), + Task::EVENT_MOVE_PROJECT => array('execute', 0), + Task::EVENT_MOVE_SWIMLANE => array('execute', 0), + Comment::EVENT_CREATE => array('execute', 0), + Comment::EVENT_UPDATE => array('execute', 0), + File::EVENT_CREATE => array('execute', 0), + Subtask::EVENT_CREATE => array('execute', 0), + Subtask::EVENT_UPDATE => array('execute', 0), ); } - public function onTaskCreation(TaskEvent $event) + public function execute(GenericEvent $event, $event_name) { - $this->executeRequest('webhook_url_task_creation', $event); - } - - public function onTaskModification(TaskEvent $event) - { - $this->executeRequest('webhook_url_task_modification', $event); - } - - public function executeRequest($parameter, TaskEvent $event) - { - $url = $this->config->get($parameter); + $payload = array( + 'event_name' => $event_name, + 'event_data' => $event->getAll(), + ); - if (! empty($url)) { - $this->webhook->notify($url, $event->getAll()); - } + $this->webhook->notify($payload); } } -- cgit v1.2.3