summaryrefslogtreecommitdiff
path: root/app/Model
diff options
context:
space:
mode:
Diffstat (limited to 'app/Model')
-rw-r--r--app/Model/Action.php2
-rw-r--r--app/Model/Base.php14
-rw-r--r--app/Model/Comment.php5
-rw-r--r--app/Model/File.php7
-rw-r--r--app/Model/GithubWebhook.php55
-rw-r--r--app/Model/Notification.php31
-rw-r--r--app/Model/Project.php31
-rw-r--r--app/Model/ProjectActivity.php29
-rw-r--r--app/Model/ProjectDailySummary.php22
-rw-r--r--app/Model/SubTask.php11
-rw-r--r--app/Model/Task.php1
-rw-r--r--app/Model/TaskCreation.php6
-rw-r--r--app/Model/TaskDuplication.php11
-rw-r--r--app/Model/TaskModification.php9
-rw-r--r--app/Model/TaskPosition.php8
-rw-r--r--app/Model/TaskStatus.php6
-rw-r--r--app/Model/Webhook.php89
17 files changed, 99 insertions, 238 deletions
diff --git a/app/Model/Action.php b/app/Model/Action.php
index f8dbd88e..3ed3dc26 100644
--- a/app/Model/Action.php
+++ b/app/Model/Action.php
@@ -248,7 +248,7 @@ class Action extends Base
$listener->setParam($param['name'], $param['value']);
}
- $this->event->attach($action['event_name'], $listener);
+ $this->container['dispatcher']->addListener($action['event_name'], array($listener, 'execute'));
}
}
diff --git a/app/Model/Base.php b/app/Model/Base.php
index 56a4d8e8..a08bd87c 100644
--- a/app/Model/Base.php
+++ b/app/Model/Base.php
@@ -2,10 +2,7 @@
namespace Model;
-use Core\Event;
-use Core\Tool;
use Pimple\Container;
-use PicoDb\Database;
/**
* Base model class
@@ -52,14 +49,6 @@ abstract class Base
protected $db;
/**
- * Event dispatcher instance
- *
- * @access public
- * @var \Core\Event
- */
- public $event;
-
- /**
* Container instance
*
* @access protected
@@ -77,7 +66,6 @@ abstract class Base
{
$this->container = $container;
$this->db = $this->container['db'];
- $this->event = $this->container['event'];
}
/**
@@ -89,7 +77,7 @@ abstract class Base
*/
public function __get($name)
{
- return Tool::loadModel($this->container, $name);
+ return $this->container[$name];
}
/**
diff --git a/app/Model/Comment.php b/app/Model/Comment.php
index 3b7dfbc1..a36f2b45 100644
--- a/app/Model/Comment.php
+++ b/app/Model/Comment.php
@@ -2,6 +2,7 @@
namespace Model;
+use Event\CommentEvent;
use SimpleValidator\Validator;
use SimpleValidator\Validators;
@@ -107,7 +108,7 @@ class Comment extends Base
$comment_id = $this->persist(self::TABLE, $values);
if ($comment_id) {
- $this->event->trigger(self::EVENT_CREATE, array('id' => $comment_id) + $values);
+ $this->container['dispatcher']->dispatch(self::EVENT_CREATE, new CommentEvent(array('id' => $comment_id) + $values));
}
return $comment_id;
@@ -127,7 +128,7 @@ class Comment extends Base
->eq('id', $values['id'])
->update(array('comment' => $values['comment']));
- $this->event->trigger(self::EVENT_UPDATE, $values);
+ $this->container['dispatcher']->dispatch(self::EVENT_UPDATE, new CommentEvent($values));
return $result;
}
diff --git a/app/Model/File.php b/app/Model/File.php
index d5a0c7cd..20fba9bf 100644
--- a/app/Model/File.php
+++ b/app/Model/File.php
@@ -2,6 +2,8 @@
namespace Model;
+use Event\FileEvent;
+
/**
* File model
*
@@ -89,7 +91,10 @@ class File extends Base
*/
public function create($task_id, $name, $path, $is_image)
{
- $this->event->trigger(self::EVENT_CREATE, array('task_id' => $task_id, 'name' => $name));
+ $this->container['dispatcher']->dispatch(
+ self::EVENT_CREATE,
+ new FileEvent(array('task_id' => $task_id, 'name' => $name))
+ );
return $this->db->table(self::TABLE)->save(array(
'task_id' => $task_id,
diff --git a/app/Model/GithubWebhook.php b/app/Model/GithubWebhook.php
index 9c8bd366..f66358eb 100644
--- a/app/Model/GithubWebhook.php
+++ b/app/Model/GithubWebhook.php
@@ -2,6 +2,8 @@
namespace Model;
+use Event\GenericEvent;
+
/**
* Github Webhook model
*
@@ -88,7 +90,10 @@ class GithubWebhook extends Base
}
if ($task['is_active'] == Task::STATUS_OPEN) {
- $this->event->trigger(self::EVENT_COMMIT, array('task_id' => $task_id) + $task);
+ $this->container['dispatcher']->dispatch(
+ self::EVENT_COMMIT,
+ new GenericEvent(array('task_id' => $task_id) + $task)
+ );
}
}
@@ -146,7 +151,11 @@ class GithubWebhook extends Base
'task_id' => $task['id'],
);
- $this->event->trigger(self::EVENT_ISSUE_COMMENT, $event);
+ $this->container['dispatcher']->dispatch(
+ self::EVENT_ISSUE_COMMENT,
+ new GenericEvent($event)
+ );
+
return true;
}
@@ -169,7 +178,11 @@ class GithubWebhook extends Base
'description' => $issue['body']."\n\n[".t('Github Issue').']('.$issue['html_url'].')',
);
- $this->event->trigger(self::EVENT_ISSUE_OPENED, $event);
+ $this->container['dispatcher']->dispatch(
+ self::EVENT_ISSUE_OPENED,
+ new GenericEvent($event)
+ );
+
return true;
}
@@ -191,7 +204,11 @@ class GithubWebhook extends Base
'reference' => $issue['number'],
);
- $this->event->trigger(self::EVENT_ISSUE_CLOSED, $event);
+ $this->container['dispatcher']->dispatch(
+ self::EVENT_ISSUE_CLOSED,
+ new GenericEvent($event)
+ );
+
return true;
}
@@ -216,7 +233,11 @@ class GithubWebhook extends Base
'reference' => $issue['number'],
);
- $this->event->trigger(self::EVENT_ISSUE_REOPENED, $event);
+ $this->container['dispatcher']->dispatch(
+ self::EVENT_ISSUE_REOPENED,
+ new GenericEvent($event)
+ );
+
return true;
}
@@ -244,7 +265,11 @@ class GithubWebhook extends Base
'reference' => $issue['number'],
);
- $this->event->trigger(self::EVENT_ISSUE_ASSIGNEE_CHANGE, $event);
+ $this->container['dispatcher']->dispatch(
+ self::EVENT_ISSUE_ASSIGNEE_CHANGE,
+ new GenericEvent($event)
+ );
+
return true;
}
@@ -271,7 +296,11 @@ class GithubWebhook extends Base
'reference' => $issue['number'],
);
- $this->event->trigger(self::EVENT_ISSUE_ASSIGNEE_CHANGE, $event);
+ $this->container['dispatcher']->dispatch(
+ self::EVENT_ISSUE_ASSIGNEE_CHANGE,
+ new GenericEvent($event)
+ );
+
return true;
}
@@ -299,7 +328,11 @@ class GithubWebhook extends Base
'label' => $label['name'],
);
- $this->event->trigger(self::EVENT_ISSUE_LABEL_CHANGE, $event);
+ $this->container['dispatcher']->dispatch(
+ self::EVENT_ISSUE_LABEL_CHANGE,
+ new GenericEvent($event)
+ );
+
return true;
}
@@ -328,7 +361,11 @@ class GithubWebhook extends Base
'category_id' => 0,
);
- $this->event->trigger(self::EVENT_ISSUE_LABEL_CHANGE, $event);
+ $this->container['dispatcher']->dispatch(
+ self::EVENT_ISSUE_LABEL_CHANGE,
+ new GenericEvent($event)
+ );
+
return true;
}
diff --git a/app/Model/Notification.php b/app/Model/Notification.php
index 8d1fca09..ccda1488 100644
--- a/app/Model/Notification.php
+++ b/app/Model/Notification.php
@@ -94,37 +94,6 @@ class Notification extends Base
}
/**
- * Attach events
- *
- * @access public
- */
- public function attachEvents()
- {
- $events = array(
- Task::EVENT_CREATE => 'task_creation',
- Task::EVENT_UPDATE => 'task_update',
- Task::EVENT_CLOSE => 'task_close',
- Task::EVENT_OPEN => 'task_open',
- Task::EVENT_MOVE_COLUMN => 'task_move_column',
- Task::EVENT_MOVE_POSITION => 'task_move_position',
- Task::EVENT_ASSIGNEE_CHANGE => 'task_assignee_change',
- SubTask::EVENT_CREATE => 'subtask_creation',
- SubTask::EVENT_UPDATE => 'subtask_update',
- Comment::EVENT_CREATE => 'comment_creation',
- Comment::EVENT_UPDATE => 'comment_update',
- File::EVENT_CREATE => 'file_creation',
- );
-
- foreach ($events as $event_name => $template_name) {
-
- $listener = new NotificationListener($this->container);
- $listener->setTemplate($template_name);
-
- $this->event->attach($event_name, $listener);
- }
- }
-
- /**
* Send the email notifications
*
* @access public
diff --git a/app/Model/Project.php b/app/Model/Project.php
index c4ec232a..9c0adee9 100644
--- a/app/Model/Project.php
+++ b/app/Model/Project.php
@@ -4,7 +4,6 @@ namespace Model;
use SimpleValidator\Validator;
use SimpleValidator\Validators;
-use Event\ProjectModificationDateListener;
use Core\Security;
/**
@@ -489,34 +488,4 @@ class Project extends Base
$v->getErrors()
);
}
-
- /**
- * Attach events
- *
- * @access public
- */
- public function attachEvents()
- {
- $events = array(
- Task::EVENT_CREATE_UPDATE,
- Task::EVENT_CLOSE,
- Task::EVENT_OPEN,
- Task::EVENT_MOVE_COLUMN,
- Task::EVENT_MOVE_POSITION,
- Task::EVENT_ASSIGNEE_CHANGE,
- GithubWebhook::EVENT_ISSUE_OPENED,
- GithubWebhook::EVENT_ISSUE_CLOSED,
- GithubWebhook::EVENT_ISSUE_REOPENED,
- GithubWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE,
- GithubWebhook::EVENT_ISSUE_LABEL_CHANGE,
- GithubWebhook::EVENT_ISSUE_COMMENT,
- GithubWebhook::EVENT_COMMIT,
- );
-
- $listener = new ProjectModificationDateListener($this->container);
-
- foreach ($events as $event_name) {
- $this->event->attach($event_name, $listener);
- }
- }
}
diff --git a/app/Model/ProjectActivity.php b/app/Model/ProjectActivity.php
index 000dfa09..b0a079dc 100644
--- a/app/Model/ProjectActivity.php
+++ b/app/Model/ProjectActivity.php
@@ -3,7 +3,6 @@
namespace Model;
use Core\Template;
-use Event\ProjectActivityListener;
/**
* Project activity model
@@ -127,34 +126,6 @@ class ProjectActivity extends Base
}
/**
- * Attach events to be able to record the history
- *
- * @access public
- */
- public function attachEvents()
- {
- $events = array(
- Task::EVENT_ASSIGNEE_CHANGE,
- Task::EVENT_UPDATE,
- Task::EVENT_CREATE,
- Task::EVENT_CLOSE,
- Task::EVENT_OPEN,
- Task::EVENT_MOVE_COLUMN,
- Task::EVENT_MOVE_POSITION,
- Comment::EVENT_UPDATE,
- Comment::EVENT_CREATE,
- SubTask::EVENT_UPDATE,
- SubTask::EVENT_CREATE,
- );
-
- $listener = new ProjectActivityListener($this->container);
-
- foreach ($events as $event_name) {
- $this->event->attach($event_name, $listener);
- }
- }
-
- /**
* Get the event html content
*
* @access public
diff --git a/app/Model/ProjectDailySummary.php b/app/Model/ProjectDailySummary.php
index 0ed3c02b..6c29758a 100644
--- a/app/Model/ProjectDailySummary.php
+++ b/app/Model/ProjectDailySummary.php
@@ -3,7 +3,6 @@
namespace Model;
use Core\Template;
-use Event\ProjectDailySummaryListener;
/**
* Project daily summary
@@ -157,25 +156,4 @@ class ProjectDailySummary extends Base
return $metrics;
}
-
- /**
- * Attach events to be able to record the metrics
- *
- * @access public
- */
- public function attachEvents()
- {
- $events = array(
- Task::EVENT_CREATE,
- Task::EVENT_CLOSE,
- Task::EVENT_OPEN,
- Task::EVENT_MOVE_COLUMN,
- );
-
- $listener = new ProjectDailySummaryListener($this->container);
-
- foreach ($events as $event_name) {
- $this->event->attach($event_name, $listener);
- }
- }
}
diff --git a/app/Model/SubTask.php b/app/Model/SubTask.php
index f301ad62..12558429 100644
--- a/app/Model/SubTask.php
+++ b/app/Model/SubTask.php
@@ -2,6 +2,7 @@
namespace Model;
+use Event\SubtaskEvent;
use SimpleValidator\Validator;
use SimpleValidator\Validators;
@@ -146,7 +147,10 @@ class SubTask extends Base
$subtask_id = $this->persist(self::TABLE, $values);
if ($subtask_id) {
- $this->event->trigger(self::EVENT_CREATE, array('id' => $subtask_id) + $values);
+ $this->container['dispatcher']->dispatch(
+ self::EVENT_CREATE,
+ new SubtaskEvent(array('id' => $subtask_id) + $values)
+ );
}
return $subtask_id;
@@ -165,7 +169,10 @@ class SubTask extends Base
$result = $this->db->table(self::TABLE)->eq('id', $values['id'])->save($values);
if ($result) {
- $this->event->trigger(self::EVENT_UPDATE, $values);
+ $this->container['dispatcher']->dispatch(
+ self::EVENT_UPDATE,
+ new SubtaskEvent($values)
+ );
}
return $result;
diff --git a/app/Model/Task.php b/app/Model/Task.php
index 3cd03741..bc2913ec 100644
--- a/app/Model/Task.php
+++ b/app/Model/Task.php
@@ -30,6 +30,7 @@ class Task extends Base
*
* @var string
*/
+ const EVENT_MOVE_PROJECT = 'task.move.project';
const EVENT_MOVE_COLUMN = 'task.move.column';
const EVENT_MOVE_POSITION = 'task.move.position';
const EVENT_MOVE_SWIMLANE = 'task.move.swimlane';
diff --git a/app/Model/TaskCreation.php b/app/Model/TaskCreation.php
index de9f7ce1..6a2c0f9c 100644
--- a/app/Model/TaskCreation.php
+++ b/app/Model/TaskCreation.php
@@ -2,6 +2,8 @@
namespace Model;
+use Event\TaskEvent;
+
/**
* Task Creation
*
@@ -64,7 +66,7 @@ class TaskCreation extends Base
private function fireEvents($task_id, array $values)
{
$values['task_id'] = $task_id;
- $this->event->trigger(Task::EVENT_CREATE_UPDATE, $values);
- $this->event->trigger(Task::EVENT_CREATE, $values);
+ $this->container['dispatcher']->dispatch(Task::EVENT_CREATE_UPDATE, new TaskEvent($values));
+ $this->container['dispatcher']->dispatch(Task::EVENT_CREATE, new TaskEvent($values));
}
}
diff --git a/app/Model/TaskDuplication.php b/app/Model/TaskDuplication.php
index 2410213b..172edb9f 100644
--- a/app/Model/TaskDuplication.php
+++ b/app/Model/TaskDuplication.php
@@ -2,6 +2,8 @@
namespace Model;
+use Event\TaskEvent;
+
/**
* Task Duplication
*
@@ -84,7 +86,14 @@ class TaskDuplication extends Base
$this->checkDestinationProjectValues($values);
- return $this->db->table(Task::TABLE)->eq('id', $task['id'])->update($values);
+ if ($this->db->table(Task::TABLE)->eq('id', $task['id'])->update($values)) {
+ $this->container['dispatcher']->dispatch(
+ Task::EVENT_MOVE_PROJECT,
+ new TaskEvent(array_merge($task, $values, array('task_id' => $task['id'])))
+ );
+ }
+
+ return true;
}
/**
diff --git a/app/Model/TaskModification.php b/app/Model/TaskModification.php
index b165ea24..dac52334 100644
--- a/app/Model/TaskModification.php
+++ b/app/Model/TaskModification.php
@@ -2,6 +2,8 @@
namespace Model;
+use Event\TaskEvent;
+
/**
* Task Modification
*
@@ -15,17 +17,16 @@ class TaskModification extends Base
*
* @access public
* @param array $values
- * @param boolean $fire_events
* @return boolean
*/
- public function update(array $values, $fire_events = true)
+ public function update(array $values)
{
$original_task = $this->taskFinder->getById($values['id']);
$this->prepare($values);
$result = $this->db->table(Task::TABLE)->eq('id', $original_task['id'])->update($values);
- if ($result && $fire_events) {
+ if ($result) {
$this->fireEvents($original_task, $values);
}
@@ -51,7 +52,7 @@ class TaskModification extends Base
}
foreach ($events as $event) {
- $this->event->trigger($event, $event_data);
+ $this->container['dispatcher']->dispatch($event, new TaskEvent($event_data));
}
}
diff --git a/app/Model/TaskPosition.php b/app/Model/TaskPosition.php
index 9a9642e5..e5152b0b 100644
--- a/app/Model/TaskPosition.php
+++ b/app/Model/TaskPosition.php
@@ -2,6 +2,8 @@
namespace Model;
+use Event\TaskEvent;
+
/**
* Task Position
*
@@ -139,13 +141,13 @@ class TaskPosition extends Base
);
if ($task['swimlane_id'] != $new_swimlane_id) {
- $this->event->trigger(Task::EVENT_MOVE_SWIMLANE, $event_data);
+ $this->container['dispatcher']->dispatch(Task::EVENT_MOVE_SWIMLANE, new TaskEvent($event_data));
}
else if ($task['column_id'] != $new_column_id) {
- $this->event->trigger(Task::EVENT_MOVE_COLUMN, $event_data);
+ $this->container['dispatcher']->dispatch(Task::EVENT_MOVE_COLUMN, new TaskEvent($event_data));
}
else if ($task['position'] != $new_position) {
- $this->event->trigger(Task::EVENT_MOVE_POSITION, $event_data);
+ $this->container['dispatcher']->dispatch(Task::EVENT_MOVE_POSITION, new TaskEvent($event_data));
}
}
diff --git a/app/Model/TaskStatus.php b/app/Model/TaskStatus.php
index 99faffde..225b3933 100644
--- a/app/Model/TaskStatus.php
+++ b/app/Model/TaskStatus.php
@@ -2,6 +2,8 @@
namespace Model;
+use Event\TaskEvent;
+
/**
* Task Status
*
@@ -84,9 +86,9 @@ class TaskStatus extends Base
));
if ($result) {
- $this->event->trigger(
+ $this->container['dispatcher']->dispatch(
$event,
- array('task_id' => $task_id) + $this->taskFinder->getById($task_id)
+ new TaskEvent(array('task_id' => $task_id) + $this->taskFinder->getById($task_id))
);
}
diff --git a/app/Model/Webhook.php b/app/Model/Webhook.php
index 14d50684..7edffa6e 100644
--- a/app/Model/Webhook.php
+++ b/app/Model/Webhook.php
@@ -2,8 +2,6 @@
namespace Model;
-use Event\WebhookListener;
-
/**
* Webhook model
*
@@ -34,87 +32,6 @@ class Webhook extends Base
const HTTP_USER_AGENT = 'Kanboard Webhook';
/**
- * URL to call for task creation
- *
- * @access private
- * @var string
- */
- private $url_task_creation = '';
-
- /**
- * URL to call for task modification
- *
- * @access private
- * @var string
- */
- private $url_task_modification = '';
-
- /**
- * Webook token
- *
- * @access private
- * @var string
- */
- private $token = '';
-
- /**
- * Attach events
- *
- * @access public
- */
- public function attachEvents()
- {
- $this->url_task_creation = $this->config->get('webhook_url_task_creation');
- $this->url_task_modification = $this->config->get('webhook_url_task_modification');
- $this->token = $this->config->get('webhook_token');
-
- if ($this->url_task_creation) {
- $this->attachCreateEvents();
- }
-
- if ($this->url_task_modification) {
- $this->attachUpdateEvents();
- }
- }
-
- /**
- * Attach events for task modification
- *
- * @access public
- */
- public function attachUpdateEvents()
- {
- $events = array(
- Task::EVENT_UPDATE,
- Task::EVENT_CLOSE,
- Task::EVENT_OPEN,
- Task::EVENT_MOVE_COLUMN,
- Task::EVENT_MOVE_POSITION,
- Task::EVENT_ASSIGNEE_CHANGE,
- );
-
- $listener = new WebhookListener($this->container);
- $listener->setUrl($this->url_task_modification);
-
- foreach ($events as $event_name) {
- $this->event->attach($event_name, $listener);
- }
- }
-
- /**
- * Attach events for task creation
- *
- * @access public
- */
- public function attachCreateEvents()
- {
- $listener = new WebhookListener($this->container);
- $listener->setUrl($this->url_task_creation);
-
- $this->event->attach(Task::EVENT_CREATE, $listener);
- }
-
- /**
* Call the external URL
*
* @access public
@@ -123,6 +40,8 @@ class Webhook extends Base
*/
public function notify($url, array $task)
{
+ $token = $this->config->get('webhook_token');
+
$headers = array(
'Connection: close',
'User-Agent: '.self::HTTP_USER_AGENT,
@@ -140,10 +59,10 @@ class Webhook extends Base
));
if (strpos($url, '?') !== false) {
- $url .= '&token='.$this->token;
+ $url .= '&token='.$token;
}
else {
- $url .= '?token='.$this->token;
+ $url .= '?token='.$token;
}
@file_get_contents($url, false, $context);