From 28ff8dad91c9e3c25f6a3b5398ae15f2a1ef95cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?=
Date: Wed, 10 Sep 2014 16:21:47 +0200
Subject: [PATCH] Add subtasks and comments history
---
app/Controller/Base.php | 30 +++-
app/Controller/Project.php | 1 -
app/Core/Translator.php | 61 ++++----
app/Event/CommentHistoryListener.php | 62 ++++++++
app/Event/SubtaskHistoryListener.php | 62 ++++++++
app/Event/TaskHistoryListener.php | 4 +-
app/Model/BaseHistory.php | 70 +++++++++
app/Model/CommentHistory.php | 152 +++++++++++++++++++
app/Model/Notification.php | 26 ++--
app/Model/Project.php | 22 ++-
app/Model/SubtaskHistory.php | 161 +++++++++++++++++++++
app/Model/Task.php | 32 ++--
app/Model/TaskHistory.php | 64 ++------
app/Schema/Mysql.php | 54 ++++++-
app/Schema/Postgres.php | 54 ++++++-
app/Schema/Sqlite.php | 37 ++++-
app/Templates/event_comment_create.php | 7 +
app/Templates/event_comment_update.php | 7 +
app/Templates/event_subtask_create.php | 12 ++
app/Templates/event_subtask_update.php | 12 ++
app/Templates/event_task_close.php | 2 +-
app/Templates/event_task_create.php | 2 +-
app/Templates/event_task_move_column.php | 2 +-
app/Templates/event_task_move_position.php | 2 +-
app/Templates/event_task_open.php | 4 +-
app/Templates/event_task_update.php | 2 +-
app/Templates/project_activity.php | 4 +
app/translator.php | 7 +
tests/units/Base.php | 3 +
29 files changed, 822 insertions(+), 136 deletions(-)
create mode 100644 app/Event/CommentHistoryListener.php
create mode 100644 app/Event/SubtaskHistoryListener.php
create mode 100644 app/Model/BaseHistory.php
create mode 100644 app/Model/CommentHistory.php
create mode 100644 app/Model/SubtaskHistory.php
create mode 100644 app/Templates/event_comment_create.php
create mode 100644 app/Templates/event_comment_update.php
create mode 100644 app/Templates/event_subtask_create.php
create mode 100644 app/Templates/event_subtask_update.php
diff --git a/app/Controller/Base.php b/app/Controller/Base.php
index 4f920ab08..00bfb79b5 100644
--- a/app/Controller/Base.php
+++ b/app/Controller/Base.php
@@ -28,6 +28,8 @@ use Model\LastLogin;
* @property \Model\SubTask $subTask
* @property \Model\Task $task
* @property \Model\TaskHistory $taskHistory
+ * @property \Model\CommentHistory $commentHistory
+ * @property \Model\SubtaskHistory $subtaskHistory
* @property \Model\User $user
* @property \Model\Webhook $webhook
*/
@@ -131,11 +133,29 @@ abstract class Base
}
// Attach events
- $this->action->attachEvents();
- $this->project->attachEvents();
- $this->webhook->attachEvents();
- $this->notification->attachEvents();
- $this->taskHistory->attachEvents();
+ $this->attachEvents();
+ }
+
+ /**
+ * Attach events
+ *
+ * @access private
+ */
+ private function attachEvents()
+ {
+ $models = array(
+ 'action',
+ 'project',
+ 'webhook',
+ 'notification',
+ 'taskHistory',
+ 'commentHistory',
+ 'subtaskHistory',
+ );
+
+ foreach ($models as $model) {
+ $this->$model->attachEvents();
+ }
}
/**
diff --git a/app/Controller/Project.php b/app/Controller/Project.php
index 26b241b92..6356a9c6a 100644
--- a/app/Controller/Project.php
+++ b/app/Controller/Project.php
@@ -72,7 +72,6 @@ class Project extends Base
$to = $this->request->getStringParam('to');
if ($from && $to) {
- Translator::disableEscaping();
$data = $this->task->export($project['id'], $from, $to);
$this->response->forceDownload('Export_'.date('Y_m_d_H_i_S').'.csv');
$this->response->csv($data);
diff --git a/app/Core/Translator.php b/app/Core/Translator.php
index c34a40ba4..43e934a95 100644
--- a/app/Core/Translator.php
+++ b/app/Core/Translator.php
@@ -26,44 +26,13 @@ class Translator
*/
private static $locales = array();
- /**
- * Flag to enable HTML escaping
- *
- * @static
- * @access private
- * @var boolean
- */
- private static $enable_escaping = true;
-
- /**
- * Disable HTML escaping for translations
- *
- * @static
- * @access public
- */
- public static function disableEscaping()
- {
- self::$enable_escaping = false;
- }
-
- /**
- * Enable HTML escaping for translations
- *
- * @static
- * @access public
- */
- public static function enableEscaping()
- {
- self::$enable_escaping = true;
- }
-
/**
* Get a translation
*
* $translator->translate('I have %d kids', 5);
*
* @access public
- * @param $identifier
+ * @param string $identifier Default string
* @return string
*/
public function translate($identifier)
@@ -73,10 +42,8 @@ class Translator
array_shift($args);
array_unshift($args, $this->get($identifier, $identifier));
- if (self::$enable_escaping) {
- foreach ($args as &$arg) {
- $arg = htmlspecialchars($arg, ENT_QUOTES, 'UTF-8', false);
- }
+ foreach ($args as &$arg) {
+ $arg = htmlspecialchars($arg, ENT_QUOTES, 'UTF-8', false);
}
return call_user_func_array(
@@ -85,6 +52,28 @@ class Translator
);
}
+ /**
+ * Get a translation with no HTML escaping
+ *
+ * $translator->translateNoEscaping('I have %d kids', 5);
+ *
+ * @access public
+ * @param string $identifier Default string
+ * @return string
+ */
+ public function translateNoEscaping($identifier)
+ {
+ $args = func_get_args();
+
+ array_shift($args);
+ array_unshift($args, $this->get($identifier, $identifier));
+
+ return call_user_func_array(
+ 'sprintf',
+ $args
+ );
+ }
+
/**
* Get a formatted number
*
diff --git a/app/Event/CommentHistoryListener.php b/app/Event/CommentHistoryListener.php
new file mode 100644
index 000000000..a89ecbaeb
--- /dev/null
+++ b/app/Event/CommentHistoryListener.php
@@ -0,0 +1,62 @@
+model = $model;
+ }
+
+ /**
+ * 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)
+ {
+ $creator_id = $this->model->acl->getUserId();
+
+ if ($creator_id && isset($data['task_id']) && isset($data['id'])) {
+
+ $task = $this->model->task->getById($data['task_id']);
+
+ $this->model->create(
+ $task['project_id'],
+ $data['task_id'],
+ $data['id'],
+ $creator_id,
+ $this->model->event->getLastTriggeredEvent(),
+ $data['comment']
+ );
+ }
+
+ return false;
+ }
+}
diff --git a/app/Event/SubtaskHistoryListener.php b/app/Event/SubtaskHistoryListener.php
new file mode 100644
index 000000000..e859828c2
--- /dev/null
+++ b/app/Event/SubtaskHistoryListener.php
@@ -0,0 +1,62 @@
+model = $model;
+ }
+
+ /**
+ * 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)
+ {
+ $creator_id = $this->model->acl->getUserId();
+
+ if ($creator_id && isset($data['task_id']) && isset($data['id'])) {
+
+ $task = $this->model->task->getById($data['task_id']);
+
+ $this->model->create(
+ $task['project_id'],
+ $data['task_id'],
+ $data['id'],
+ $creator_id,
+ $this->model->event->getLastTriggeredEvent(),
+ ''
+ );
+ }
+
+ return false;
+ }
+}
diff --git a/app/Event/TaskHistoryListener.php b/app/Event/TaskHistoryListener.php
index d6709f6e7..c8a880e80 100644
--- a/app/Event/TaskHistoryListener.php
+++ b/app/Event/TaskHistoryListener.php
@@ -14,7 +14,7 @@ use Model\TaskHistory;
class TaskHistoryListener implements Listener
{
/**
- * TaskHistory model
+ * Task History model
*
* @accesss private
* @var \Model\TaskHistory
@@ -25,7 +25,7 @@ class TaskHistoryListener implements Listener
* Constructor
*
* @access public
- * @param \Model\TaskHistory $model TaskHistory model instance
+ * @param \Model\TaskHistory $model Task History model instance
*/
public function __construct(TaskHistory $model)
{
diff --git a/app/Model/BaseHistory.php b/app/Model/BaseHistory.php
new file mode 100644
index 000000000..31578a3bc
--- /dev/null
+++ b/app/Model/BaseHistory.php
@@ -0,0 +1,70 @@
+db->table($this->table)->count() > $max) {
+
+ $this->db->execute('
+ DELETE FROM '.$this->table.'
+ WHERE id <= (
+ SELECT id FROM (
+ SELECT id FROM '.$this->table.' ORDER BY id DESC LIMIT 1 OFFSET '.$max.'
+ ) foo
+ )');
+ }
+ }
+
+ /**
+ * Get all events for a given project
+ *
+ * @access public
+ * @return array
+ */
+ public function getAllByProjectId($project_id)
+ {
+ return $this->db->table($this->table)
+ ->eq('project_id', $project_id)
+ ->desc('id')
+ ->findAll();
+ }
+
+ /**
+ * Get the event html content
+ *
+ * @access public
+ * @param array $params Event properties
+ * @return string
+ */
+ public function getContent(array $params)
+ {
+ $tpl = new Template;
+ return $tpl->load('event_'.str_replace('.', '_', $params['event_name']), $params);
+ }
+}
diff --git a/app/Model/CommentHistory.php b/app/Model/CommentHistory.php
new file mode 100644
index 000000000..5b94729cd
--- /dev/null
+++ b/app/Model/CommentHistory.php
@@ -0,0 +1,152 @@
+table = self::TABLE;
+ }
+
+ /**
+ * Create a new event
+ *
+ * @access public
+ * @param integer $project_id Project id
+ * @param integer $task_id Task id
+ * @param integer $comment_id Comment id
+ * @param integer $creator_id Author of the event (user id)
+ * @param string $event_name Task event name
+ * @param string $data Current comment
+ * @return boolean
+ */
+ public function create($project_id, $task_id, $comment_id, $creator_id, $event_name, $data)
+ {
+ $values = array(
+ 'project_id' => $project_id,
+ 'task_id' => $task_id,
+ 'comment_id' => $comment_id,
+ 'creator_id' => $creator_id,
+ 'event_name' => $event_name,
+ 'date_creation' => time(),
+ 'data' => $data,
+ );
+
+ $this->db->startTransaction();
+
+ $this->cleanup(self::MAX_EVENTS - 1);
+ $result = $this->db->table(self::TABLE)->insert($values);
+
+ $this->db->closeTransaction();
+
+ return $result;
+ }
+
+ /**
+ * Get all necessary content to display activity feed
+ *
+ * $author_name
+ * $author_username
+ * $task['id', 'title', 'position', 'column_name']
+ */
+ public function getAllContentByProjectId($project_id, $limit = 50)
+ {
+ $sql = '
+ SELECT
+ comment_has_events.id,
+ comment_has_events.date_creation,
+ comment_has_events.event_name,
+ comment_has_events.data as comment,
+ comment_has_events.task_id,
+ tasks.title as task_title,
+ users.username as author_username,
+ users.name as author_name
+ FROM comment_has_events
+ LEFT JOIN users ON users.id=comment_has_events.creator_id
+ LEFT JOIN tasks ON tasks.id=comment_has_events.task_id
+ WHERE comment_has_events.project_id = ?
+ ORDER BY comment_has_events.id DESC
+ LIMIT 0, '.$limit.'
+ ';
+
+ $rq = $this->db->execute($sql, array($project_id));
+ $events = $rq->fetchAll(PDO::FETCH_ASSOC);
+
+ foreach ($events as &$event) {
+ $event['author'] = $event['author_name'] ?: $event['author_username'];
+ $event['event_title'] = $this->getTitle($event);
+ $event['event_content'] = $this->getContent($event);
+ $event['event_type'] = 'comment';
+ }
+
+ return $events;
+ }
+
+ /**
+ * Get the event title (translated)
+ *
+ * @access public
+ * @param array $event Event properties
+ * @return string
+ */
+ public function getTitle(array $event)
+ {
+ $titles = array(
+ Comment::EVENT_UPDATE => t('%s updated a comment on the task #%d', $event['author'], $event['task_id']),
+ Comment::EVENT_CREATE => t('%s commented on the task #%d', $event['author'], $event['task_id']),
+ );
+
+ return isset($titles[$event['event_name']]) ? $titles[$event['event_name']] : '';
+ }
+
+ /**
+ * Attach events to be able to record the history
+ *
+ * @access public
+ */
+ public function attachEvents()
+ {
+ $events = array(
+ Comment::EVENT_UPDATE,
+ Comment::EVENT_CREATE,
+ );
+
+ $listener = new CommentHistoryListener($this);
+
+ foreach ($events as $event_name) {
+ $this->event->attach($event_name, $listener);
+ }
+ }
+}
diff --git a/app/Model/Notification.php b/app/Model/Notification.php
index a92ce73ef..0cb170766 100644
--- a/app/Model/Notification.php
+++ b/app/Model/Notification.php
@@ -115,45 +115,41 @@ class Notification extends Base
*/
public function getMailSubject($template, array $data)
{
- Translator::disableEscaping();
-
switch ($template) {
case 'notification_file_creation':
- $subject = t('[%s][New attachment] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
+ $subject = e('[%s][New attachment] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
break;
case 'notification_comment_creation':
- $subject = t('[%s][New comment] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
+ $subject = e('[%s][New comment] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
break;
case 'notification_comment_update':
- $subject = t('[%s][Comment updated] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
+ $subject = e('[%s][Comment updated] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
break;
case 'notification_subtask_creation':
- $subject = t('[%s][New subtask] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
+ $subject = e('[%s][New subtask] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
break;
case 'notification_subtask_update':
- $subject = t('[%s][Subtask updated] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
+ $subject = e('[%s][Subtask updated] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
break;
case 'notification_task_creation':
- $subject = t('[%s][New task] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
+ $subject = e('[%s][New task] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
break;
case 'notification_task_update':
- $subject = t('[%s][Task updated] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
+ $subject = e('[%s][Task updated] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
break;
case 'notification_task_close':
- $subject = t('[%s][Task closed] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
+ $subject = e('[%s][Task closed] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
break;
case 'notification_task_open':
- $subject = t('[%s][Task opened] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
+ $subject = e('[%s][Task opened] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
break;
case 'notification_task_due':
- $subject = t('[%s][Due tasks]', $data['project']);
+ $subject = e('[%s][Due tasks]', $data['project']);
break;
default:
- $subject = t('[Kanboard] Notification');
+ $subject = e('[Kanboard] Notification');
}
- Translator::enableEscaping();
-
return $subject;
}
diff --git a/app/Model/Project.php b/app/Model/Project.php
index 1da5c164e..9aef3c7e7 100644
--- a/app/Model/Project.php
+++ b/app/Model/Project.php
@@ -720,7 +720,25 @@ class Project extends Base
*/
public function getActivity($project_id)
{
- // TODO: merge comments and subtasks activity
- return $this->taskHistory->getAllContentByProjectId($project_id);
+ $activity = array();
+ $tasks = $this->taskHistory->getAllContentByProjectId($project_id, 25);
+ $comments = $this->commentHistory->getAllContentByProjectId($project_id, 25);
+ $subtasks = $this->subtaskHistory->getAllContentByProjectId($project_id, 25);
+
+ foreach ($tasks as &$task) {
+ $activity[$task['date_creation'].'-'.$task['id']] = $task;
+ }
+
+ foreach ($subtasks as &$subtask) {
+ $activity[$subtask['date_creation'].'-'.$subtask['id']] = $subtask;
+ }
+
+ foreach ($comments as &$comment) {
+ $activity[$comment['date_creation'].'-'.$comment['id']] = $comment;
+ }
+
+ krsort($activity);
+
+ return $activity;
}
}
diff --git a/app/Model/SubtaskHistory.php b/app/Model/SubtaskHistory.php
new file mode 100644
index 000000000..bbf6ce3d8
--- /dev/null
+++ b/app/Model/SubtaskHistory.php
@@ -0,0 +1,161 @@
+table = self::TABLE;
+ }
+
+ /**
+ * Create a new event
+ *
+ * @access public
+ * @param integer $project_id Project id
+ * @param integer $task_id Task id
+ * @param integer $subtask_id Subtask id
+ * @param integer $creator_id Author of the event (user id)
+ * @param string $event_name Task event name
+ * @param string $data Current comment
+ * @return boolean
+ */
+ public function create($project_id, $task_id, $subtask_id, $creator_id, $event_name, $data)
+ {
+ $values = array(
+ 'project_id' => $project_id,
+ 'task_id' => $task_id,
+ 'subtask_id' => $subtask_id,
+ 'creator_id' => $creator_id,
+ 'event_name' => $event_name,
+ 'date_creation' => time(),
+ 'data' => $data,
+ );
+
+ $this->db->startTransaction();
+
+ $this->cleanup(self::MAX_EVENTS - 1);
+ $result = $this->db->table(self::TABLE)->insert($values);
+
+ $this->db->closeTransaction();
+
+ return $result;
+ }
+
+ /**
+ * Get all necessary content to display activity feed
+ *
+ * $author_name
+ * $author_username
+ * $task['id', 'title', 'position', 'column_name']
+ */
+ public function getAllContentByProjectId($project_id, $limit = 50)
+ {
+ $sql = '
+ SELECT
+ subtask_has_events.id,
+ subtask_has_events.date_creation,
+ subtask_has_events.event_name,
+ subtask_has_events.task_id,
+ tasks.title as task_title,
+ users.username as author_username,
+ users.name as author_name,
+ assignees.name as subtask_assignee_name,
+ assignees.username as subtask_assignee_username,
+ task_has_subtasks.title as subtask_title,
+ task_has_subtasks.status as subtask_status,
+ task_has_subtasks.time_spent as subtask_time_spent,
+ task_has_subtasks.time_estimated as subtask_time_estimated
+ FROM subtask_has_events
+ LEFT JOIN users ON users.id=subtask_has_events.creator_id
+ LEFT JOIN tasks ON tasks.id=subtask_has_events.task_id
+ LEFT JOIN task_has_subtasks ON task_has_subtasks.id=subtask_has_events.subtask_id
+ LEFT JOIN users AS assignees ON assignees.id=task_has_subtasks.user_id
+ WHERE subtask_has_events.project_id = ?
+ ORDER BY subtask_has_events.id DESC
+ LIMIT 0, '.$limit.'
+ ';
+
+ $rq = $this->db->execute($sql, array($project_id));
+ $events = $rq->fetchAll(PDO::FETCH_ASSOC);
+
+ foreach ($events as &$event) {
+ $event['author'] = $event['author_name'] ?: $event['author_username'];
+ $event['subtask_assignee'] = $event['subtask_assignee_name'] ?: $event['subtask_assignee_username'];
+ $event['subtask_status_list'] = $this->subTask->getStatusList();
+ $event['event_title'] = $this->getTitle($event);
+ $event['event_content'] = $this->getContent($event);
+ $event['event_type'] = 'subtask';
+ }
+
+ return $events;
+ }
+
+ /**
+ * Get the event title (translated)
+ *
+ * @access public
+ * @param array $event Event properties
+ * @return string
+ */
+ public function getTitle(array $event)
+ {
+ $titles = array(
+ SubTask::EVENT_UPDATE => t('%s updated a subtask for the task #%d', $event['author'], $event['task_id']),
+ SubTask::EVENT_CREATE => t('%s created a subtask for the task #%d', $event['author'], $event['task_id']),
+ );
+
+ return isset($titles[$event['event_name']]) ? $titles[$event['event_name']] : '';
+ }
+
+ /**
+ * Attach events to be able to record the history
+ *
+ * @access public
+ */
+ public function attachEvents()
+ {
+ $events = array(
+ SubTask::EVENT_UPDATE,
+ SubTask::EVENT_CREATE,
+ );
+
+ $listener = new SubtaskHistoryListener($this);
+
+ foreach ($events as $event_name) {
+ $this->event->attach($event_name, $listener);
+ }
+ }
+}
diff --git a/app/Model/Task.php b/app/Model/Task.php
index 7ebb46413..10d125d47 100644
--- a/app/Model/Task.php
+++ b/app/Model/Task.php
@@ -936,21 +936,21 @@ class Task extends Base
$tasks = $rq->fetchAll(PDO::FETCH_ASSOC);
$columns = array(
- t('Task Id'),
- t('Project'),
- t('Status'),
- t('Category'),
- t('Column'),
- t('Position'),
- t('Color'),
- t('Due date'),
- t('Creator'),
- t('Assignee'),
- t('Complexity'),
- t('Title'),
- t('Creation date'),
- t('Modification date'),
- t('Completion date'),
+ e('Task Id'),
+ e('Project'),
+ e('Status'),
+ e('Category'),
+ e('Column'),
+ e('Position'),
+ e('Color'),
+ e('Due date'),
+ e('Creator'),
+ e('Assignee'),
+ e('Complexity'),
+ e('Title'),
+ e('Creation date'),
+ e('Modification date'),
+ e('Completion date'),
);
$results = array($columns);
@@ -973,7 +973,7 @@ class Task extends Base
{
$colors = $this->getColors();
$task['score'] = $task['score'] ?: '';
- $task['is_active'] = $task['is_active'] == self::STATUS_OPEN ? t('Open') : t('Closed');
+ $task['is_active'] = $task['is_active'] == self::STATUS_OPEN ? e('Open') : e('Closed');
$task['color_id'] = $colors[$task['color_id']];
$task['date_creation'] = date('Y-m-d', $task['date_creation']);
$task['date_due'] = $task['date_due'] ? date('Y-m-d', $task['date_due']) : '';
diff --git a/app/Model/TaskHistory.php b/app/Model/TaskHistory.php
index 181e41810..35b7cb278 100644
--- a/app/Model/TaskHistory.php
+++ b/app/Model/TaskHistory.php
@@ -3,7 +3,7 @@
namespace Model;
use PDO;
-use Core\Template;
+use Core\Registry;
use Event\TaskHistoryListener;
/**
@@ -12,7 +12,7 @@ use Event\TaskHistoryListener;
* @package model
* @author Frederic Guillot
*/
-class TaskHistory extends Base
+class TaskHistory extends BaseHistory
{
/**
* SQL table name
@@ -28,6 +28,18 @@ class TaskHistory extends Base
*/
const MAX_EVENTS = 5000;
+ /**
+ * Constructor
+ *
+ * @access public
+ * @param \Core\Registry $registry Registry instance
+ */
+ public function __construct(Registry $registry)
+ {
+ parent::__construct($registry);
+ $this->table = self::TABLE;
+ }
+
/**
* Create a new event
*
@@ -58,40 +70,6 @@ class TaskHistory extends Base
return $result;
}
- /**
- * Remove old event entries to avoid a large table
- *
- * @access public
- * @param integer $max Maximum number of items to keep in the table
- */
- public function cleanup($max)
- {
- if ($this->db->table(self::TABLE)->count() > $max) {
-
- $this->db->execute('
- DELETE FROM '.self::TABLE.'
- WHERE id <= (
- SELECT id FROM (
- SELECT id FROM '.self::TABLE.' ORDER BY id DESC LIMIT 1 OFFSET '.$max.'
- ) foo
- )');
- }
- }
-
- /**
- * Get all events for a given project
- *
- * @access public
- * @return array
- */
- public function getAllByProjectId($project_id)
- {
- return $this->db->table(self::TABLE)
- ->eq('project_id', $project_id)
- ->desc('id')
- ->findAll();
- }
-
/**
* Get all necessary content to display activity feed
*
@@ -103,6 +81,7 @@ class TaskHistory extends Base
{
$sql = '
SELECT
+ task_has_events.id,
task_has_events.date_creation,
task_has_events.event_name,
task_has_events.task_id,
@@ -154,19 +133,6 @@ class TaskHistory extends Base
return isset($titles[$event['event_name']]) ? $titles[$event['event_name']] : '';
}
- /**
- * Get the event html content
- *
- * @access public
- * @param array $params Event properties
- * @return string
- */
- public function getContent(array $params)
- {
- $tpl = new Template;
- return $tpl->load('event_'.str_replace('.', '_', $params['event_name']), $params);
- }
-
/**
* Attach events to be able to record the history
*
diff --git a/app/Schema/Mysql.php b/app/Schema/Mysql.php
index 9b202a695..9ab12a1a5 100644
--- a/app/Schema/Mysql.php
+++ b/app/Schema/Mysql.php
@@ -4,7 +4,59 @@ namespace Schema;
use Core\Security;
-const VERSION = 24;
+const VERSION = 25;
+
+function version_25($pdo)
+{
+ $pdo->exec("
+ CREATE TABLE task_has_events (
+ id INT NOT NULL AUTO_INCREMENT,
+ date_creation INT NOT NULL,
+ event_name TEXT NOT NULL,
+ creator_id INT,
+ project_id INT,
+ task_id INT,
+ data TEXT,
+ FOREIGN KEY(creator_id) REFERENCES users(id) ON DELETE CASCADE,
+ FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
+ FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE
+ );
+ ");
+
+ $pdo->exec("
+ CREATE TABLE subtask_has_events (
+ id INT NOT NULL AUTO_INCREMENT,
+ date_creation INT NOT NULL,
+ event_name TEXT NOT NULL,
+ creator_id INT,
+ project_id INT,
+ subtask_id INT,
+ task_id INT,
+ data TEXT,
+ FOREIGN KEY(creator_id) REFERENCES users(id) ON DELETE CASCADE,
+ FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
+ FOREIGN KEY(subtask_id) REFERENCES task_has_subtasks(id) ON DELETE CASCADE,
+ FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE
+ );
+ ");
+
+ $pdo->exec("
+ CREATE TABLE comment_has_events (
+ id INT NOT NULL AUTO_INCREMENT,
+ date_creation INT NOT NULL,
+ event_name TEXT NOT NULL,
+ creator_id INT,
+ project_id INT,
+ comment_id INT,
+ task_id INT,
+ data TEXT,
+ FOREIGN KEY(creator_id) REFERENCES users(id) ON DELETE CASCADE,
+ FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
+ FOREIGN KEY(comment_id) REFERENCES comments(id) ON DELETE CASCADE,
+ FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE
+ );
+ ");
+}
function version_24($pdo)
{
diff --git a/app/Schema/Postgres.php b/app/Schema/Postgres.php
index 99774a555..b58b9bb34 100644
--- a/app/Schema/Postgres.php
+++ b/app/Schema/Postgres.php
@@ -4,7 +4,59 @@ namespace Schema;
use Core\Security;
-const VERSION = 5;
+const VERSION = 6;
+
+function version_6($pdo)
+{
+ $pdo->exec("
+ CREATE TABLE task_has_events (
+ id SERIAL PRIMARY KEY,
+ date_creation INTEGER NOT NULL,
+ event_name TEXT NOT NULL,
+ creator_id INTEGER,
+ project_id INTEGER,
+ task_id INTEGER,
+ data TEXT,
+ FOREIGN KEY(creator_id) REFERENCES users(id) ON DELETE CASCADE,
+ FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
+ FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE
+ );
+ ");
+
+ $pdo->exec("
+ CREATE TABLE subtask_has_events (
+ id SERIAL PRIMARY KEY,
+ date_creation INTEGER NOT NULL,
+ event_name TEXT NOT NULL,
+ creator_id INTEGER,
+ project_id INTEGER,
+ subtask_id INTEGER,
+ task_id INTEGER,
+ data TEXT,
+ FOREIGN KEY(creator_id) REFERENCES users(id) ON DELETE CASCADE,
+ FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
+ FOREIGN KEY(subtask_id) REFERENCES task_has_subtasks(id) ON DELETE CASCADE,
+ FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE
+ );
+ ");
+
+ $pdo->exec("
+ CREATE TABLE comment_has_events (
+ id SERIAL PRIMARY KEY,
+ date_creation INTEGER NOT NULL,
+ event_name TEXT NOT NULL,
+ creator_id INTEGER,
+ project_id INTEGER,
+ comment_id INTEGER,
+ task_id INTEGER,
+ data TEXT,
+ FOREIGN KEY(creator_id) REFERENCES users(id) ON DELETE CASCADE,
+ FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
+ FOREIGN KEY(comment_id) REFERENCES comments(id) ON DELETE CASCADE,
+ FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE
+ );
+ ");
+}
function version_5($pdo)
{
diff --git a/app/Schema/Sqlite.php b/app/Schema/Sqlite.php
index e18d35e96..ecd62c97b 100644
--- a/app/Schema/Sqlite.php
+++ b/app/Schema/Sqlite.php
@@ -11,16 +11,51 @@ function version_25($pdo)
$pdo->exec("
CREATE TABLE task_has_events (
id INTEGER PRIMARY KEY,
- date_creation INTEGER,
+ date_creation INTEGER NOT NULL,
event_name TEXT NOT NULL,
creator_id INTEGER,
project_id INTEGER,
task_id INTEGER,
+ data TEXT,
FOREIGN KEY(creator_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE
);
");
+
+ $pdo->exec("
+ CREATE TABLE subtask_has_events (
+ id INTEGER PRIMARY KEY,
+ date_creation INTEGER NOT NULL,
+ event_name TEXT NOT NULL,
+ creator_id INTEGER,
+ project_id INTEGER,
+ subtask_id INTEGER,
+ task_id INTEGER,
+ data TEXT,
+ FOREIGN KEY(creator_id) REFERENCES users(id) ON DELETE CASCADE,
+ FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
+ FOREIGN KEY(subtask_id) REFERENCES task_has_subtasks(id) ON DELETE CASCADE,
+ FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE
+ );
+ ");
+
+ $pdo->exec("
+ CREATE TABLE comment_has_events (
+ id INTEGER PRIMARY KEY,
+ date_creation INTEGER NOT NULL,
+ event_name TEXT NOT NULL,
+ creator_id INTEGER,
+ project_id INTEGER,
+ comment_id INTEGER,
+ task_id INTEGER,
+ data TEXT,
+ FOREIGN KEY(creator_id) REFERENCES users(id) ON DELETE CASCADE,
+ FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
+ FOREIGN KEY(comment_id) REFERENCES comments(id) ON DELETE CASCADE,
+ FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE
+ );
+ ");
}
function version_24($pdo)
diff --git a/app/Templates/event_comment_create.php b/app/Templates/event_comment_create.php
new file mode 100644
index 000000000..09d45ed08
--- /dev/null
+++ b/app/Templates/event_comment_create.php
@@ -0,0 +1,7 @@
+
+ = e('%s commented the task #%d', Helper\escape($author), $task_id, $task_id) ?>
+
+
+ = Helper\escape($task_title) ?>
+
= Helper\parse($comment) ?>
+
\ No newline at end of file
diff --git a/app/Templates/event_comment_update.php b/app/Templates/event_comment_update.php
new file mode 100644
index 000000000..a42e5daba
--- /dev/null
+++ b/app/Templates/event_comment_update.php
@@ -0,0 +1,7 @@
+
+ = e('%s updated a comment on the task #%d', Helper\escape($author), $task_id, $task_id) ?>
+
+
+ = Helper\escape($task_title) ?>
+
= Helper\parse($comment) ?>
+
\ No newline at end of file
diff --git a/app/Templates/event_subtask_create.php b/app/Templates/event_subtask_create.php
new file mode 100644
index 000000000..81268449a
--- /dev/null
+++ b/app/Templates/event_subtask_create.php
@@ -0,0 +1,12 @@
+
+ = e('%s created a subtask for the task #%d', Helper\escape($author), $task_id, $task_id) ?>
+
+
+ = Helper\escape($task_title) ?>
+
= Helper\escape($subtask_title) ?> (= Helper\in_list($subtask_status, $subtask_status_list) ?>)
+
+ = t('Assigned to %s with estimate of %s/%sh', $subtask_assignee, $subtask_time_spent, $subtask_time_estimated) ?>
+
+ = t('Not assigned, estimate of %sh', $subtask_time_estimated) ?>
+
+
\ No newline at end of file
diff --git a/app/Templates/event_subtask_update.php b/app/Templates/event_subtask_update.php
new file mode 100644
index 000000000..9862f997b
--- /dev/null
+++ b/app/Templates/event_subtask_update.php
@@ -0,0 +1,12 @@
+
+ = e('%s updated a subtask for the task #%d', Helper\escape($author), $task_id, $task_id) ?>
+
+
+ = Helper\escape($task_title) ?>
+
= Helper\escape($subtask_title) ?> (= Helper\in_list($subtask_status, $subtask_status_list) ?>)
+
+ = t('Assigned to %s with estimate of %s/%sh', $subtask_assignee, $subtask_time_spent, $subtask_time_estimated) ?>
+
+ = t('Not assigned, estimate of %sh', $subtask_time_estimated) ?>
+
+
\ No newline at end of file
diff --git a/app/Templates/event_task_close.php b/app/Templates/event_task_close.php
index d5952d748..9d92ea553 100644
--- a/app/Templates/event_task_close.php
+++ b/app/Templates/event_task_close.php
@@ -1,5 +1,5 @@
- = t('%s closed the task #%d', $author, $task_id) ?>
+ = e('%s closed the task #%d', Helper\escape($author), $task_id, $task_id) ?>
= Helper\escape($task_title) ?>
diff --git a/app/Templates/event_task_create.php b/app/Templates/event_task_create.php
index f0dcf2d7f..7ceab4bb2 100644
--- a/app/Templates/event_task_create.php
+++ b/app/Templates/event_task_create.php
@@ -1,5 +1,5 @@
- = t('%s created the task #%d', $author, $task_id) ?>
+ = e('%s created the task #%d', Helper\escape($author), $task_id, $task_id) ?>
= Helper\escape($task_title) ?>
diff --git a/app/Templates/event_task_move_column.php b/app/Templates/event_task_move_column.php
index 0ccad655c..a674f80a9 100644
--- a/app/Templates/event_task_move_column.php
+++ b/app/Templates/event_task_move_column.php
@@ -1,5 +1,5 @@
- = t('%s moved the task #%d to the column %s', $author, $task_id, $task_column_name) ?>
+ = e('%s moved the task #%d to the column "%s"', Helper\escape($author), $task_id, $task_id, Helper\escape($task_column_name)) ?>
= Helper\escape($task_title) ?>
diff --git a/app/Templates/event_task_move_position.php b/app/Templates/event_task_move_position.php
index e7d6b2443..0b7e9615f 100644
--- a/app/Templates/event_task_move_position.php
+++ b/app/Templates/event_task_move_position.php
@@ -1,5 +1,5 @@
- = t('%s moved the task #%d to the position %d in the column %s', $author, $task_id, $task_position, $task_column_name) ?>
+ = e('%s moved the task #%d to the position #%d in the column "%s"', Helper\escape($author), $task_id, $task_id, $task_position, Helper\escape($task_column_name)) ?>
= Helper\escape($task_title) ?>
diff --git a/app/Templates/event_task_open.php b/app/Templates/event_task_open.php
index b3bc595a9..763b0dfc0 100644
--- a/app/Templates/event_task_open.php
+++ b/app/Templates/event_task_open.php
@@ -1,6 +1,6 @@
- = t('%s open the task #%d', $author, $task_id) ?>
+ = e('%s open the task #%d', Helper\escape($author), $task_id, $task_id) ?>
- = Helper\escape($task_title ?>
+ = Helper\escape($task_title) ?>
\ No newline at end of file
diff --git a/app/Templates/event_task_update.php b/app/Templates/event_task_update.php
index e2af6776b..313e79cb4 100644
--- a/app/Templates/event_task_update.php
+++ b/app/Templates/event_task_update.php
@@ -1,5 +1,5 @@
- = t('%s updated the task #%d', $author, $task_id) ?>
+ = e('%s updated the task #%d', Helper\escape($author), $task_id, $task_id) ?>
= Helper\escape($task_title) ?>
diff --git a/app/Templates/project_activity.php b/app/Templates/project_activity.php
index 7886cfa4c..b79d97f9a 100644
--- a/app/Templates/project_activity.php
+++ b/app/Templates/project_activity.php
@@ -17,6 +17,10 @@
+
+
+
+
= dt('%B %e, %Y at %k:%M %p', $event['date_creation']) ?>
diff --git a/app/translator.php b/app/translator.php
index 338821d3d..ac4d72e20 100644
--- a/app/translator.php
+++ b/app/translator.php
@@ -9,6 +9,13 @@ function t()
return call_user_func_array(array($t, 'translate'), func_get_args());
}
+// translate with no html escaping
+function e()
+{
+ $t = new Translator;
+ return call_user_func_array(array($t, 'translateNoEscaping'), func_get_args());
+}
+
// Get a locale currency
function c($value)
{
diff --git a/tests/units/Base.php b/tests/units/Base.php
index c1702c614..c566ce9ab 100644
--- a/tests/units/Base.php
+++ b/tests/units/Base.php
@@ -43,7 +43,10 @@ require_once __DIR__.'/../../app/Model/Action.php';
require_once __DIR__.'/../../app/Model/Category.php';
require_once __DIR__.'/../../app/Model/SubTask.php';
require_once __DIR__.'/../../app/Model/File.php';
+require_once __DIR__.'/../../app/Model/BaseHistory.php';
require_once __DIR__.'/../../app/Model/TaskHistory.php';
+require_once __DIR__.'/../../app/Model/SubtaskHistory.php';
+require_once __DIR__.'/../../app/Model/CommentHistory.php';
require_once __DIR__.'/../../app/Action/Base.php';
require_once __DIR__.'/../../app/Action/TaskClose.php';