insertIfNotExists() for storage insertion

This commit is contained in:
Joas Schilling 2015-03-09 19:02:34 +01:00 committed by Thomas Müller
parent c917ea183c
commit 940163e16b
1 changed files with 9 additions and 3 deletions

View 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'];
}
}
}
}