diff options
author | Joas Schilling <nickvergessen@owncloud.com> | 2015-03-09 19:02:34 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-03-09 22:37:49 +0100 |
commit | 940163e16b6ee49132abfcb4177021c571e488cd (patch) | |
tree | d241863ac0225111cfc3c2896b62ab19d57fed58 /lib | |
parent | c917ea183ce0acf7c49f8c7104c9ffa54f2b804f (diff) | |
download | nextcloud-server-940163e16b6ee49132abfcb4177021c571e488cd.tar.gz nextcloud-server-940163e16b6ee49132abfcb4177021c571e488cd.zip |
insertIfNotExists() for storage insertion
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/files/cache/storage.php | 12 |
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']; + } + } } } |