summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2018-08-10 10:31:55 +0200
committerGitHub <noreply@github.com>2018-08-10 10:31:55 +0200
commita080c425cd364019067c503a2f17c490722233b7 (patch)
tree181dcbf52678554eec5abf361769883f417ee3c8 /lib/private
parent3254b85c123d84276dca3c66883343d7af45a851 (diff)
parent5e9d6b1585535baf1024d75ce26246b489140a7f (diff)
downloadnextcloud-server-a080c425cd364019067c503a2f17c490722233b7.tar.gz
nextcloud-server-a080c425cd364019067c503a2f17c490722233b7.zip
Merge pull request #10618 from nextcloud/mimetype-insert-if-not-exists
use insertIfNotExists to store new mimetypes.
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Files/Type/Loader.php21
1 files changed, 7 insertions, 14 deletions
diff --git a/lib/private/Files/Type/Loader.php b/lib/private/Files/Type/Loader.php
index 2b15c9b6e13..41c561dcd22 100644
--- a/lib/private/Files/Type/Loader.php
+++ b/lib/private/Files/Type/Loader.php
@@ -114,20 +114,9 @@ class Loader implements IMimeTypeLoader {
* @param int inserted ID
*/
protected function store($mimetype) {
- try {
- $qb = $this->dbConnection->getQueryBuilder();
- $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
- }
+ $this->dbConnection->insertIfNotExist('*PREFIX*mimetypes', [
+ 'mimetype' => $mimetype
+ ]);
$fetch = $this->dbConnection->getQueryBuilder();
$fetch->select('id')
@@ -137,6 +126,10 @@ class Loader implements IMimeTypeLoader {
));
$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->mimetypeIds[$mimetype] = $row['id'];
return $row['id'];