Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-03-09 21:02:34 +0300
committerJoas Schilling <nickvergessen@owncloud.com>2015-03-16 13:44:14 +0300
commit9383856ca520414fc8194e69cee7202c7fbb764a (patch)
treebf93152ffa717c58d6694a7f566a66d054e2f0bd /lib
parent78b2c8b0be29be11929d04da80235fff0fe85751 (diff)
insertIfNotExists() for storage insertion
Diffstat (limited to 'lib')
-rw-r--r--lib/private/files/cache/storage.php12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/private/files/cache/storage.php b/lib/private/files/cache/storage.php
index d7d57811a7d..eaa4601e4fa 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'];
+ }
+ }
}
}