Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions lib/private/db/connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,16 +265,12 @@ private function getType($value) {
* @throws PreconditionNotMetException
*/
public function setValues($table, array $keys, array $values, array $updatePreconditionValues = []) {
try {
$insertQb = $this->getQueryBuilder();
$insertQb->insert($table)
->values(
array_map(function($value) use ($insertQb) {
return $insertQb->createNamedParameter($value, $this->getType($value));
}, array_merge($keys, $values))
);
return $insertQb->execute();
} catch (\Doctrine\DBAL\Exception\ConstraintViolationException $e) {
$toInsert = array_merge($keys, $values);
$compare = array_keys($keys);
$tableName = $this->tablePrefix . $table;
$affected = $this->adapter->insertIfNotExist($tableName, $toInsert, $compare);

if ($affected === 0) {
// value already exists, try update
$updateQb = $this->getQueryBuilder();
$updateQb->update($table);
Expand All @@ -297,8 +293,10 @@ public function setValues($table, array $keys, array $values, array $updatePreco
throw new PreconditionNotMetException();
}

return 0;
}

return $affected;

}

/**
Expand Down