Merge pull request #10618 from nextcloud/mimetype-insert-if-not-exists
use insertIfNotExists to store new mimetypes.
This commit is contained in:
commit
a080c425cd
|
@ -114,20 +114,9 @@ class Loader implements IMimeTypeLoader {
|
||||||
* @param int inserted ID
|
* @param int inserted ID
|
||||||
*/
|
*/
|
||||||
protected function store($mimetype) {
|
protected function store($mimetype) {
|
||||||
try {
|
$this->dbConnection->insertIfNotExist('*PREFIX*mimetypes', [
|
||||||
$qb = $this->dbConnection->getQueryBuilder();
|
'mimetype' => $mimetype
|
||||||
$qb->insert('mimetypes')
|
]);
|
||||||
->values([
|
|
||||||
'mimetype' => $qb->createNamedParameter($mimetype)
|
|
||||||
]);
|
|
||||||
$qb->execute();
|
|
||||||
} catch (UniqueConstraintViolationException $e) {
|
|
||||||
if ($this->dbConnection->inTransaction()) {
|
|
||||||
// if we're inside a transaction we can't recover safely
|
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
// something inserted it before us
|
|
||||||
}
|
|
||||||
|
|
||||||
$fetch = $this->dbConnection->getQueryBuilder();
|
$fetch = $this->dbConnection->getQueryBuilder();
|
||||||
$fetch->select('id')
|
$fetch->select('id')
|
||||||
|
@ -137,6 +126,10 @@ class Loader implements IMimeTypeLoader {
|
||||||
));
|
));
|
||||||
$row = $fetch->execute()->fetch();
|
$row = $fetch->execute()->fetch();
|
||||||
|
|
||||||
|
if (!$row) {
|
||||||
|
throw new \Exception("Failed to get mimetype id for $mimetype after trying to store it");
|
||||||
|
}
|
||||||
|
|
||||||
$this->mimetypes[$row['id']] = $mimetype;
|
$this->mimetypes[$row['id']] = $mimetype;
|
||||||
$this->mimetypeIds[$mimetype] = $row['id'];
|
$this->mimetypeIds[$mimetype] = $row['id'];
|
||||||
return $row['id'];
|
return $row['id'];
|
||||||
|
|
Loading…
Reference in New Issue