summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/Action/Base.php1
-rw-r--r--app/Action/TaskCreation.php2
-rw-r--r--app/Controller/Base.php1
-rw-r--r--app/Controller/Task.php2
-rw-r--r--app/Controller/Webhook.php2
-rw-r--r--app/Model/Color.php11
-rw-r--r--app/Model/Task.php53
-rw-r--r--app/Model/TaskCreation.php88
-rw-r--r--app/Schema/Mysql.php7
-rw-r--r--app/Schema/Postgres.php7
-rw-r--r--app/Schema/Sqlite.php2
11 files changed, 117 insertions, 59 deletions
diff --git a/app/Action/Base.php b/app/Action/Base.php
index c9363617..c8c589c1 100644
--- a/app/Action/Base.php
+++ b/app/Action/Base.php
@@ -15,6 +15,7 @@ use Core\Tool;
* @property \Model\Acl $acl
* @property \Model\Comment $comment
* @property \Model\Task $task
+ * @property \Model\TaskCreation $taskCreation
* @property \Model\TaskFinder $taskFinder
* @property \Model\TaskStatus $taskStatus
*/
diff --git a/app/Action/TaskCreation.php b/app/Action/TaskCreation.php
index 41d0200c..5715310f 100644
--- a/app/Action/TaskCreation.php
+++ b/app/Action/TaskCreation.php
@@ -59,7 +59,7 @@ class TaskCreation extends Base
*/
public function doAction(array $data)
{
- return $this->task->create(array(
+ return $this->taskCreation->create(array(
'project_id' => $data['project_id'],
'title' => $data['title'],
'reference' => $data['reference'],
diff --git a/app/Controller/Base.php b/app/Controller/Base.php
index 5e208009..8285f458 100644
--- a/app/Controller/Base.php
+++ b/app/Controller/Base.php
@@ -33,6 +33,7 @@ use Model\LastLogin;
* @property \Model\ProjectAnalytic $projectAnalytic
* @property \Model\SubTask $subTask
* @property \Model\Task $task
+ * @property \Model\TaskCreation $taskCreation
* @property \Model\TaskHistory $taskHistory
* @property \Model\TaskExport $taskExport
* @property \Model\TaskFinder $taskFinder
diff --git a/app/Controller/Task.php b/app/Controller/Task.php
index cad2f583..e75058d9 100644
--- a/app/Controller/Task.php
+++ b/app/Controller/Task.php
@@ -127,7 +127,7 @@ class Task extends Base
if ($valid) {
- if ($this->task->create($values)) {
+ if ($this->taskCreation->create($values)) {
$this->session->flash(t('Task created successfully.'));
if (isset($values['another_task']) && $values['another_task'] == 1) {
diff --git a/app/Controller/Webhook.php b/app/Controller/Webhook.php
index a0bf369a..dcd66a1a 100644
--- a/app/Controller/Webhook.php
+++ b/app/Controller/Webhook.php
@@ -35,7 +35,7 @@ class Webhook extends Base
list($valid,) = $this->taskValidator->validateCreation($values);
- if ($valid && $this->task->create($values)) {
+ if ($valid && $this->taskCreation->create($values)) {
$this->response->text('OK');
}
diff --git a/app/Model/Color.php b/app/Model/Color.php
index f414e837..8668cf0f 100644
--- a/app/Model/Color.php
+++ b/app/Model/Color.php
@@ -28,4 +28,15 @@ class Color extends Base
'grey' => t('Grey'),
);
}
+
+ /**
+ * Get the default color
+ *
+ * @access public
+ * @return string
+ */
+ public function getDefaultColor()
+ {
+ return 'yellow'; // TODO: make this parameter configurable
+ }
}
diff --git a/app/Model/Task.php b/app/Model/Task.php
index 1b2a66cd..93914fba 100644
--- a/app/Model/Task.php
+++ b/app/Model/Task.php
@@ -54,30 +54,6 @@ class Task extends Base
}
/**
- * Prepare data before task creation
- *
- * @access public
- * @param array $values Form values
- */
- public function prepareCreation(array &$values)
- {
- $this->prepare($values);
-
- if (empty($values['column_id'])) {
- $values['column_id'] = $this->board->getFirstColumn($values['project_id']);
- }
-
- if (empty($values['color_id'])) {
- $colors = $this->color->getList();
- $values['color_id'] = key($colors);
- }
-
- $values['date_creation'] = time();
- $values['date_modification'] = $values['date_creation'];
- $values['position'] = $this->taskFinder->countByColumnId($values['project_id'], $values['column_id']) + 1;
- }
-
- /**
* Prepare data before task modification
*
* @access public
@@ -90,35 +66,6 @@ class Task extends Base
}
/**
- * Create a task
- *
- * @access public
- * @param array $values Form values
- * @return boolean|integer
- */
- public function create(array $values)
- {
- $this->db->startTransaction();
-
- $this->prepareCreation($values);
-
- if (! $this->db->table(self::TABLE)->save($values)) {
- $this->db->cancelTransaction();
- return false;
- }
-
- $task_id = $this->db->getConnection()->getLastId();
-
- $this->db->closeTransaction();
-
- // Trigger events
- $this->event->trigger(self::EVENT_CREATE_UPDATE, array('task_id' => $task_id) + $values);
- $this->event->trigger(self::EVENT_CREATE, array('task_id' => $task_id) + $values);
-
- return $task_id;
- }
-
- /**
* Update a task
*
* @access public
diff --git a/app/Model/TaskCreation.php b/app/Model/TaskCreation.php
new file mode 100644
index 00000000..58cfa6ed
--- /dev/null
+++ b/app/Model/TaskCreation.php
@@ -0,0 +1,88 @@
+<?php
+
+namespace Model;
+
+/**
+ * Task Creation
+ *
+ * @package model
+ * @author Frederic Guillot
+ */
+class TaskCreation extends Base
+{
+ /**
+ * Create a task
+ *
+ * @access public
+ * @param array $values Form values
+ * @return integer
+ */
+ public function create(array $values)
+ {
+ $this->prepare($values);
+ $task_id = $this->persist($values);
+ $this->fireEvents($task_id, $values);
+
+ return (int) $task_id;
+ }
+
+ /**
+ * Prepare data
+ *
+ * @access public
+ * @param array $values Form values
+ */
+ public function prepare(array &$values)
+ {
+ $this->dateParser->convert($values, array('date_due', 'date_started'));
+ $this->removeFields($values, array('another_task'));
+ $this->resetFields($values, array('owner_id', 'owner_id', 'date_due', 'score', 'category_id', 'time_estimated'));
+
+ if (empty($values['column_id'])) {
+ $values['column_id'] = $this->board->getFirstColumn($values['project_id']);
+ }
+
+ if (empty($values['color_id'])) {
+ $values['color_id'] = $this->color->getDefaultColor();
+ }
+
+ $values['date_creation'] = time();
+ $values['date_modification'] = $values['date_creation'];
+ $values['position'] = $this->taskFinder->countByColumnId($values['project_id'], $values['column_id']) + 1;
+ }
+
+ /**
+ * Save the task to the database
+ *
+ * @access private
+ * @param array $values Form values
+ * @return boolean|integer
+ */
+ private function persist(array $values)
+ {
+ return $this->db->transaction(function($db) use ($values) {
+
+ if (! $db->table(Task::TABLE)->save($values)) {
+ return false;
+ }
+
+ return $db->getConnection()->getLastId();
+ });
+ }
+
+ /**
+ * Fire events
+ *
+ * @access private
+ * @param integer $task_id Task id
+ * @param array $values Form values
+ */
+ private function fireEvents($task_id, array $values)
+ {
+ if ($task_id) {
+ $values['task_id'] = $task_id;
+ $this->event->trigger(Task::EVENT_CREATE_UPDATE, $values);
+ $this->event->trigger(Task::EVENT_CREATE, $values);
+ }
+ }
+}
diff --git a/app/Schema/Mysql.php b/app/Schema/Mysql.php
index e73f6cf4..52dbea50 100644
--- a/app/Schema/Mysql.php
+++ b/app/Schema/Mysql.php
@@ -5,7 +5,12 @@ namespace Schema;
use PDO;
use Core\Security;
-const VERSION = 35;
+const VERSION = 36;
+
+function version_36($pdo)
+{
+ $pdo->exec('ALTER TABLE tasks MODIFY title VARCHAR(255) NOT NULL');
+}
function version_35($pdo)
{
diff --git a/app/Schema/Postgres.php b/app/Schema/Postgres.php
index 4ec3885c..9493e60e 100644
--- a/app/Schema/Postgres.php
+++ b/app/Schema/Postgres.php
@@ -5,7 +5,12 @@ namespace Schema;
use PDO;
use Core\Security;
-const VERSION = 16;
+const VERSION = 17;
+
+function version_17($pdo)
+{
+ $pdo->exec('ALTER TABLE tasks ALTER COLUMN title SET NOT NULL');
+}
function version_16($pdo)
{
diff --git a/app/Schema/Sqlite.php b/app/Schema/Sqlite.php
index cdc74465..82c2f41c 100644
--- a/app/Schema/Sqlite.php
+++ b/app/Schema/Sqlite.php
@@ -457,7 +457,7 @@ function version_1($pdo)
$pdo->exec("
CREATE TABLE tasks (
id INTEGER PRIMARY KEY,
- title TEXT,
+ title TEXT NOT NULL,
description TEXT,
date_creation INTEGER,
color_id TEXT,