[Pkg-owncloud-commits] [owncloud] 47/118: insertIfNotExists() for storage insertion

David Prévot taffit at moszumanska.debian.org
Fri Mar 27 22:13:11 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit 9383856ca520414fc8194e69cee7202c7fbb764a
Author: Joas Schilling <nickvergessen at owncloud.com>
Date:   Mon Mar 9 19:02:34 2015 +0100

    insertIfNotExists() for storage insertion
---
 lib/private/files/cache/storage.php | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lib/private/files/cache/storage.php b/lib/private/files/cache/storage.php
index d7d5781..eaa4601 100644
--- a/lib/private/files/cache/storage.php
+++ b/lib/private/files/cache/storage.php
@@ -35,9 +35,15 @@ class Storage {
 		if ($row = $result->fetchRow()) {
 			$this->numericId = $row['numeric_id'];
 		} else {
-			$sql = 'INSERT INTO `*PREFIX*storages` (`id`) VALUES(?)';
-			\OC_DB::executeAudited($sql, array($this->storageId));
-			$this->numericId = \OC_DB::insertid('*PREFIX*storages');
+			$connection = \OC_DB::getConnection();
+			if ($connection->insertIfNotExist('*PREFIX*storages', ['id' => $this->storageId])) {
+				$this->numericId = \OC_DB::insertid('*PREFIX*storages');
+			} else {
+				$result = \OC_DB::executeAudited($sql, array($this->storageId));
+				if ($row = $result->fetchRow()) {
+					$this->numericId = $row['numeric_id'];
+				}
+			}
 		}
 	}
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list