From 17dc5bdc9ede52ad618bbf326e67e3b6988170f7 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sat, 27 Dec 2014 19:10:38 -0500 Subject: Move events handling to Symfony\EventDispatcher --- app/Event/Base.php | 79 ------------------------- app/Event/CommentEvent.php | 7 +++ app/Event/FileEvent.php | 7 +++ app/Event/GenericEvent.php | 45 +++++++++++++++ app/Event/NotificationListener.php | 83 --------------------------- app/Event/ProjectActivityListener.php | 61 -------------------- app/Event/ProjectDailySummaryListener.php | 28 --------- app/Event/ProjectModificationDateListener.php | 30 ---------- app/Event/SubtaskEvent.php | 7 +++ app/Event/TaskEvent.php | 7 +++ app/Event/WebhookListener.php | 44 -------------- 11 files changed, 73 insertions(+), 325 deletions(-) delete mode 100644 app/Event/Base.php create mode 100644 app/Event/CommentEvent.php create mode 100644 app/Event/FileEvent.php create mode 100644 app/Event/GenericEvent.php delete mode 100644 app/Event/NotificationListener.php delete mode 100644 app/Event/ProjectActivityListener.php delete mode 100644 app/Event/ProjectDailySummaryListener.php delete mode 100644 app/Event/ProjectModificationDateListener.php create mode 100644 app/Event/SubtaskEvent.php create mode 100644 app/Event/TaskEvent.php delete mode 100644 app/Event/WebhookListener.php (limited to 'app/Event') diff --git a/app/Event/Base.php b/app/Event/Base.php deleted file mode 100644 index 0217fa08..00000000 --- a/app/Event/Base.php +++ /dev/null @@ -1,79 +0,0 @@ -container = $container; - } - - /** - * Return class information - * - * @access public - * @return string - */ - public function __toString() - { - return get_called_class(); - } - - /** - * Load automatically models - * - * @access public - * @param string $name Model name - * @return mixed - */ - public function __get($name) - { - return Tool::loadModel($this->container, $name); - } - - /** - * Get event namespace - * - * Event = task.close | Namespace = task - * - * @access public - * @return string - */ - public function getEventNamespace() - { - $event_name = $this->container['event']->getLastTriggeredEvent(); - return substr($event_name, 0, strpos($event_name, '.')); - } -} diff --git a/app/Event/CommentEvent.php b/app/Event/CommentEvent.php new file mode 100644 index 00000000..75a132d7 --- /dev/null +++ b/app/Event/CommentEvent.php @@ -0,0 +1,7 @@ +container = $values; + } + + public function getAll() + { + return $this->container; + } + + public function offsetSet($offset, $value) + { + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } + } + + public function offsetExists($offset) + { + return isset($this->container[$offset]); + } + + public function offsetUnset($offset) + { + unset($this->container[$offset]); + } + + public function offsetGet($offset) + { + return isset($this->container[$offset]) ? $this->container[$offset] : null; + } +} diff --git a/app/Event/NotificationListener.php b/app/Event/NotificationListener.php deleted file mode 100644 index 3c049327..00000000 --- a/app/Event/NotificationListener.php +++ /dev/null @@ -1,83 +0,0 @@ -template = $template; - } - - /** - * Execute the action - * - * @access public - * @param array $data Event data dictionary - * @return bool True if the action was executed or false when not executed - */ - public function execute(array $data) - { - $values = $this->getTemplateData($data); - $users = $this->notification->getUsersList($values['task']['project_id']); - - if ($users) { - $this->notification->sendEmails($this->template, $users, $values); - return true; - } - - return false; - } - - /** - * Fetch data for the mail template - * - * @access public - * @param array $data Event data - * @return array - */ - public function getTemplateData(array $data) - { - $values = array(); - - switch ($this->getEventNamespace()) { - case 'task': - $values['task'] = $this->taskFinder->getDetails($data['task_id']); - break; - case 'subtask': - $values['subtask'] = $this->subtask->getById($data['id'], true); - $values['task'] = $this->taskFinder->getDetails($data['task_id']); - break; - case 'file': - $values['file'] = $data; - $values['task'] = $this->taskFinder->getDetails($data['task_id']); - break; - case 'comment': - $values['comment'] = $this->comment->getById($data['id']); - $values['task'] = $this->taskFinder->getDetails($values['comment']['task_id']); - break; - } - - return $values; - } -} diff --git a/app/Event/ProjectActivityListener.php b/app/Event/ProjectActivityListener.php deleted file mode 100644 index 75efe65d..00000000 --- a/app/Event/ProjectActivityListener.php +++ /dev/null @@ -1,61 +0,0 @@ -getValues($data); - - return $this->projectActivity->createEvent( - $values['task']['project_id'], - $values['task']['id'], - $this->acl->getUserId(), - $this->container['event']->getLastTriggeredEvent(), - $values - ); - } - - return false; - } - - /** - * Get event activity data - * - * @access private - * @param array $data Event data dictionary - * @return array - */ - private function getValues(array $data) - { - $values = array(); - $values['task'] = $this->taskFinder->getDetails($data['task_id']); - - switch ($this->getEventNamespace()) { - case 'subtask': - $values['subtask'] = $this->subTask->getById($data['id'], true); - break; - case 'comment': - $values['comment'] = $this->comment->getById($data['id']); - break; - } - - return $values; - } -} diff --git a/app/Event/ProjectDailySummaryListener.php b/app/Event/ProjectDailySummaryListener.php deleted file mode 100644 index cd593abc..00000000 --- a/app/Event/ProjectDailySummaryListener.php +++ /dev/null @@ -1,28 +0,0 @@ -projectDailySummary->updateTotals($data['project_id'], date('Y-m-d')); - } - - return false; - } -} diff --git a/app/Event/ProjectModificationDateListener.php b/app/Event/ProjectModificationDateListener.php deleted file mode 100644 index abc176b0..00000000 --- a/app/Event/ProjectModificationDateListener.php +++ /dev/null @@ -1,30 +0,0 @@ -project->updateModificationDate($data['project_id']); - } - - return false; - } -} diff --git a/app/Event/SubtaskEvent.php b/app/Event/SubtaskEvent.php new file mode 100644 index 00000000..229db860 --- /dev/null +++ b/app/Event/SubtaskEvent.php @@ -0,0 +1,7 @@ +url = $url; - } - - /** - * Execute the action - * - * @access public - * @param array $data Event data dictionary - * @return bool True if the action was executed or false when not executed - */ - public function execute(array $data) - { - $this->webhook->notify($this->url, $data); - return true; - } -} -- cgit v1.2.3