summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-03-24 20:43:07 -0400
committerFrederic Guillot <fred@kanboard.net>2016-03-24 20:43:07 -0400
commit3a06e0ab21ef12e4193f52260e7ecf367c6bb8f0 (patch)
tree0c0498ad825ea5ee8e445877442d59f5ac87d7c0 /app
parent725b7d2a551c782b40e69ab1bdc701b5ee899646 (diff)
Improve PR #1993
Diffstat (limited to 'app')
-rw-r--r--app/Model/Metadata.php21
-rw-r--r--app/Model/Setting.php13
-rw-r--r--app/Schema/Mysql.php23
-rw-r--r--app/Schema/Postgres.php23
-rw-r--r--app/Schema/Sqlite.php25
5 files changed, 62 insertions, 43 deletions
diff --git a/app/Model/Metadata.php b/app/Model/Metadata.php
index 9b26e404..01799a40 100644
--- a/app/Model/Metadata.php
+++ b/app/Model/Metadata.php
@@ -83,16 +83,29 @@ abstract class Metadata extends Base
$results = array();
$user_id = $this->userSession->getId();
$timestamp = time();
-
+
$this->db->startTransaction();
-
+
foreach ($values as $key => $value) {
if ($this->exists($entity_id, $key)) {
- $results[] = $this->db->table(static::TABLE)->eq($this->getEntityKey(), $entity_id)->eq('name', $key)->update(array('value' => $value, 'changed_on' => $timestamp, 'changed_by' => $user_id));
+ $results[] = $this->db->table(static::TABLE)
+ ->eq($this->getEntityKey(), $entity_id)
+ ->eq('name', $key)->update(array(
+ 'value' => $value,
+ 'changed_on' => $timestamp,
+ 'changed_by' => $user_id,
+ ));
} else {
- $results[] = $this->db->table(static::TABLE)->insert(array('name' => $key, 'value' => $value, $this->getEntityKey() => $entity_id, 'changed_on' => $timestamp, 'changed_by' => $user_id));
+ $results[] = $this->db->table(static::TABLE)->insert(array(
+ 'name' => $key,
+ 'value' => $value,
+ $this->getEntityKey() => $entity_id,
+ 'changed_on' => $timestamp,
+ 'changed_by' => $user_id,
+ ));
}
}
+
$this->db->closeTransaction();
return ! in_array(false, $results, true);
}
diff --git a/app/Model/Setting.php b/app/Model/Setting.php
index 4e1c1b0b..f98d7ce1 100644
--- a/app/Model/Setting.php
+++ b/app/Model/Setting.php
@@ -88,9 +88,18 @@ abstract class Setting extends Base
foreach ($values as $option => $value) {
if ($this->exists($option)) {
- $results[] = $this->db->table(self::TABLE)->eq('option', $option)->update(array('value' => $value, 'changed_on' => $timestamp, 'changed_by' => $user_id));
+ $results[] = $this->db->table(self::TABLE)->eq('option', $option)->update(array(
+ 'value' => $value,
+ 'changed_on' => $timestamp,
+ 'changed_by' => $user_id,
+ ));
} else {
- $results[] = $this->db->table(self::TABLE)->insert(array('option' => $option, 'value' => $value, 'changed_on' => $timestamp, 'changed_by' => $user_id));
+ $results[] = $this->db->table(self::TABLE)->insert(array(
+ 'option' => $option,
+ 'value' => $value,
+ 'changed_on' => $timestamp,
+ 'changed_by' => $user_id,
+ ));
}
}
diff --git a/app/Schema/Mysql.php b/app/Schema/Mysql.php
index bf41ba29..9bfe6649 100644
--- a/app/Schema/Mysql.php
+++ b/app/Schema/Mysql.php
@@ -10,18 +10,17 @@ const VERSION = 108;
function version_108(PDO $pdo)
{
- //user_has_metadata
- $pdo->exec("ALTER TABLE user_has_metadata ADD COLUMN changed_by INT DEFAULT 0 NOT NULL");
- $pdo->exec("ALTER TABLE user_has_metadata ADD COLUMN changed_on INT DEFAULT 0 NOT NULL");
- //project_has_metadata
- $pdo->exec("ALTER TABLE project_has_metadata ADD COLUMN changed_by INT DEFAULT 0 NOT NULL");
- $pdo->exec("ALTER TABLE project_has_metadata ADD COLUMN changed_on INT DEFAULT 0 NOT NULL");
- //task_has_metadata
- $pdo->exec("ALTER TABLE task_has_metadata ADD COLUMN changed_by INT DEFAULT 0 NOT NULL");
- $pdo->exec("ALTER TABLE task_has_metadata ADD COLUMN changed_on INT DEFAULT 0 NOT NULL");
- //settings
- $pdo->exec("ALTER TABLE settings ADD COLUMN changed_by INT DEFAULT 0 NOT NULL");
- $pdo->exec("ALTER TABLE settings ADD COLUMN changed_on INT DEFAULT 0 NOT NULL");
+ $pdo->exec("ALTER TABLE user_has_metadata ADD COLUMN changed_by INT DEFAULT 0 NOT NULL");
+ $pdo->exec("ALTER TABLE user_has_metadata ADD COLUMN changed_on INT DEFAULT 0 NOT NULL");
+
+ $pdo->exec("ALTER TABLE project_has_metadata ADD COLUMN changed_by INT DEFAULT 0 NOT NULL");
+ $pdo->exec("ALTER TABLE project_has_metadata ADD COLUMN changed_on INT DEFAULT 0 NOT NULL");
+
+ $pdo->exec("ALTER TABLE task_has_metadata ADD COLUMN changed_by INT DEFAULT 0 NOT NULL");
+ $pdo->exec("ALTER TABLE task_has_metadata ADD COLUMN changed_on INT DEFAULT 0 NOT NULL");
+
+ $pdo->exec("ALTER TABLE settings ADD COLUMN changed_by INT DEFAULT 0 NOT NULL");
+ $pdo->exec("ALTER TABLE settings ADD COLUMN changed_on INT DEFAULT 0 NOT NULL");
}
function version_107(PDO $pdo)
diff --git a/app/Schema/Postgres.php b/app/Schema/Postgres.php
index 1b1996b4..28c563de 100644
--- a/app/Schema/Postgres.php
+++ b/app/Schema/Postgres.php
@@ -10,18 +10,17 @@ const VERSION = 88;
function version_88(PDO $pdo)
{
- //user_has_metadata
- $pdo->exec("ALTER TABLE user_has_metadata ADD COLUMN changed_by INTEGER DEFAULT 0 NOT NULL");
- $pdo->exec("ALTER TABLE user_has_metadata ADD COLUMN changed_on INTEGER DEFAULT 0 NOT NULL");
- //project_has_metadata
- $pdo->exec("ALTER TABLE project_has_metadata ADD COLUMN changed_by INTEGER DEFAULT 0 NOT NULL");
- $pdo->exec("ALTER TABLE project_has_metadata ADD COLUMN changed_on INTEGER DEFAULT 0 NOT NULL");
- //task_has_metadata
- $pdo->exec("ALTER TABLE task_has_metadata ADD COLUMN changed_by INTEGER DEFAULT 0 NOT NULL");
- $pdo->exec("ALTER TABLE task_has_metadata ADD COLUMN changed_on INTEGER DEFAULT 0 NOT NULL");
- //settings
- $pdo->exec("ALTER TABLE settings ADD COLUMN changed_by INTEGER DEFAULT 0 NOT NULL");
- $pdo->exec("ALTER TABLE settings ADD COLUMN changed_on INTEGER DEFAULT 0 NOT NULL");
+ $pdo->exec("ALTER TABLE user_has_metadata ADD COLUMN changed_by INTEGER DEFAULT 0 NOT NULL");
+ $pdo->exec("ALTER TABLE user_has_metadata ADD COLUMN changed_on INTEGER DEFAULT 0 NOT NULL");
+
+ $pdo->exec("ALTER TABLE project_has_metadata ADD COLUMN changed_by INTEGER DEFAULT 0 NOT NULL");
+ $pdo->exec("ALTER TABLE project_has_metadata ADD COLUMN changed_on INTEGER DEFAULT 0 NOT NULL");
+
+ $pdo->exec("ALTER TABLE task_has_metadata ADD COLUMN changed_by INTEGER DEFAULT 0 NOT NULL");
+ $pdo->exec("ALTER TABLE task_has_metadata ADD COLUMN changed_on INTEGER DEFAULT 0 NOT NULL");
+
+ $pdo->exec("ALTER TABLE settings ADD COLUMN changed_by INTEGER DEFAULT 0 NOT NULL");
+ $pdo->exec("ALTER TABLE settings ADD COLUMN changed_on INTEGER DEFAULT 0 NOT NULL");
}
function version_87(PDO $pdo)
diff --git a/app/Schema/Sqlite.php b/app/Schema/Sqlite.php
index c846eb5e..c6f60332 100644
--- a/app/Schema/Sqlite.php
+++ b/app/Schema/Sqlite.php
@@ -10,19 +10,18 @@ const VERSION = 100;
function version_100(PDO $pdo)
{
- //user_has_metadata
- $pdo->exec("ALTER TABLE user_has_metadata ADD COLUMN changed_by INTEGER DEFAULT 0 NOT NULL");
- $pdo->exec("ALTER TABLE user_has_metadata ADD COLUMN changed_on INTEGER DEFAULT 0 NOT NULL");
- //project_has_metadata
- $pdo->exec("ALTER TABLE project_has_metadata ADD COLUMN changed_by INTEGER DEFAULT 0 NOT NULL");
- $pdo->exec("ALTER TABLE project_has_metadata ADD COLUMN changed_on INTEGER DEFAULT 0 NOT NULL");
- //task_has_metadata
- $pdo->exec("ALTER TABLE task_has_metadata ADD COLUMN changed_by INTEGER DEFAULT 0 NOT NULL");
- $pdo->exec("ALTER TABLE task_has_metadata ADD COLUMN changed_on INTEGER DEFAULT 0 NOT NULL");
- //settings
- $pdo->exec("ALTER TABLE settings ADD COLUMN changed_by INTEGER DEFAULT 0 NOT NULL");
- $pdo->exec("ALTER TABLE settings ADD COLUMN changed_on INTEGER DEFAULT 0 NOT NULL");
-
+ $pdo->exec("ALTER TABLE user_has_metadata ADD COLUMN changed_by INTEGER DEFAULT 0 NOT NULL");
+ $pdo->exec("ALTER TABLE user_has_metadata ADD COLUMN changed_on INTEGER DEFAULT 0 NOT NULL");
+
+ $pdo->exec("ALTER TABLE project_has_metadata ADD COLUMN changed_by INTEGER DEFAULT 0 NOT NULL");
+ $pdo->exec("ALTER TABLE project_has_metadata ADD COLUMN changed_on INTEGER DEFAULT 0 NOT NULL");
+
+ $pdo->exec("ALTER TABLE task_has_metadata ADD COLUMN changed_by INTEGER DEFAULT 0 NOT NULL");
+ $pdo->exec("ALTER TABLE task_has_metadata ADD COLUMN changed_on INTEGER DEFAULT 0 NOT NULL");
+
+ $pdo->exec("ALTER TABLE settings ADD COLUMN changed_by INTEGER DEFAULT 0 NOT NULL");
+ $pdo->exec("ALTER TABLE settings ADD COLUMN changed_on INTEGER DEFAULT 0 NOT NULL");
+
}
function version_99(PDO $pdo)