diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-03-24 20:43:07 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-03-24 20:43:07 -0400 |
commit | 3a06e0ab21ef12e4193f52260e7ecf367c6bb8f0 (patch) | |
tree | 0c0498ad825ea5ee8e445877442d59f5ac87d7c0 /app/Model/Metadata.php | |
parent | 725b7d2a551c782b40e69ab1bdc701b5ee899646 (diff) |
Improve PR #1993
Diffstat (limited to 'app/Model/Metadata.php')
-rw-r--r-- | app/Model/Metadata.php | 21 |
1 files changed, 17 insertions, 4 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); } |