]> source.dussan.org Git - nextcloud-server.git/commitdiff
insertIfNotExists() for storage insertion
authorJoas Schilling <nickvergessen@owncloud.com>
Mon, 9 Mar 2015 18:02:34 +0000 (19:02 +0100)
committerThomas Müller <thomas.mueller@tmit.eu>
Mon, 9 Mar 2015 21:37:49 +0000 (22:37 +0100)
lib/private/files/cache/storage.php

index d7d57811a7dd01eef715d260cf08b04ab69d9e49..eaa4601e4fa34c06b4ab6446b1b959e4287b9f2f 100644 (file)
@@ -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'];
+                               }
+                       }
                }
        }