diff options
author | Simon L <szaimen@e.mail.de> | 2023-09-16 21:17:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-16 21:17:24 +0200 |
commit | 7bba5ec71ef00b68a27a861b0d7a0f4ce83bcc2e (patch) | |
tree | 67142ab0c8e80645a18296630d47cf7e797e4312 | |
parent | 006f5d096cbb883ffefd93fc1329e2c5e61cb780 (diff) | |
parent | c587f684bd18b2572249d46cd9ffe45e43f9c98f (diff) | |
download | nextcloud-server-7bba5ec71ef00b68a27a861b0d7a0f4ce83bcc2e.tar.gz nextcloud-server-7bba5ec71ef00b68a27a861b0d7a0f4ce83bcc2e.zip |
Merge pull request #40203 from lhsazevedo/fix/mimetype-40064
-rw-r--r-- | lib/private/Files/Type/Loader.php | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/lib/private/Files/Type/Loader.php b/lib/private/Files/Type/Loader.php index 20c298f21b3..7032e619385 100644 --- a/lib/private/Files/Type/Loader.php +++ b/lib/private/Files/Type/Loader.php @@ -116,8 +116,8 @@ class Loader implements IMimeTypeLoader { * @return int inserted ID */ protected function store($mimetype) { - $mimetypeId = $this->atomic(function () use ($mimetype) { - try { + try { + $mimetypeId = $this->atomic(function () use ($mimetype) { $insert = $this->dbConnection->getQueryBuilder(); $insert->insert('mimetypes') ->values([ @@ -125,26 +125,24 @@ class Loader implements IMimeTypeLoader { ]) ->executeStatement(); return $insert->getLastInsertId(); - } catch (DbalException $e) { - if ($e->getReason() !== DBException::REASON_UNIQUE_CONSTRAINT_VIOLATION) { - throw $e; - } - $qb = $this->dbConnection->getQueryBuilder(); - $qb->select('id') - ->from('mimetypes') - ->where($qb->expr()->eq('mimetype', $qb->createNamedParameter($mimetype))); - $result = $qb->executeQuery(); - $id = $result->fetchOne(); - $result->closeCursor(); - if ($id !== false) { - return (int) $id; - } + }, $this->dbConnection); + } catch (DbalException $e) { + if ($e->getReason() !== DBException::REASON_UNIQUE_CONSTRAINT_VIOLATION) { + throw $e; + } + + $qb = $this->dbConnection->getQueryBuilder(); + $qb->select('id') + ->from('mimetypes') + ->where($qb->expr()->eq('mimetype', $qb->createNamedParameter($mimetype))); + $result = $qb->executeQuery(); + $id = $result->fetchOne(); + $result->closeCursor(); + if ($id === false) { throw new \Exception("Database threw an unique constraint on inserting a new mimetype, but couldn't return the ID for this very mimetype"); } - }, $this->dbConnection); - if (!$mimetypeId) { - throw new \Exception("Failed to get mimetype id for $mimetype after trying to store it"); + $mimetypeId = (int) $id; } $this->mimetypes[$mimetypeId] = $mimetype; |