From 3a06e0ab21ef12e4193f52260e7ecf367c6bb8f0 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Thu, 24 Mar 2016 20:43:07 -0400 Subject: Improve PR #1993 --- app/Model/Metadata.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'app/Model/Metadata.php') 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); } -- cgit v1.2.3