diff options
author | Robin Appelman <robin@icewind.nl> | 2018-08-09 15:19:23 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2018-08-09 15:31:47 +0200 |
commit | 706813ab0805f1c40ad6f9f1d355f4b4d0412c68 (patch) | |
tree | 0ba392c3018e8701e01ac0d2c2d27d231109ce71 /lib/private | |
parent | a5985ad0f4697249f42c95cc5241a69df7acef09 (diff) | |
download | nextcloud-server-706813ab0805f1c40ad6f9f1d355f4b4d0412c68.tar.gz nextcloud-server-706813ab0805f1c40ad6f9f1d355f4b4d0412c68.zip |
use insertIfNotExists to store new mimetypes.
Also throw an error if we can't find the mimetype after insert
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Files/Type/Loader.php | 21 |
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']; |