From: Joas Schilling Date: Mon, 9 Mar 2015 18:02:34 +0000 (+0100) Subject: insertIfNotExists() for storage insertion X-Git-Tag: v8.1.0alpha1~280^2~8 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=940163e16b6ee49132abfcb4177021c571e488cd;p=nextcloud-server.git insertIfNotExists() for storage insertion --- 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']; + } + } } }