From 940163e16b6ee49132abfcb4177021c571e488cd Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 9 Mar 2015 19:02:34 +0100 Subject: [PATCH] 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 d7d57811a7..eaa4601e4f 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']; + } + } } }