summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2023-05-04 10:25:09 +0200
committerThomas Citharel <tcit@tcit.fr>2023-05-04 11:15:50 +0200
commit375466819e41f24f8c813c8ebdebb940a1850127 (patch)
tree623e57f8a64f78b542480e90d5700356865ec702 /lib
parentb44de9ccb8395dcaacbf1a8ceee31868188e63e6 (diff)
downloadnextcloud-server-375466819e41f24f8c813c8ebdebb940a1850127.tar.gz
nextcloud-server-375466819e41f24f8c813c8ebdebb940a1850127.zip
fix(mimetype): Fix returning value when finding existing mimetype in MimeType Loader
Also, only return the ID from the transaction as the mimetype string is already used from the function argument value Fixes https://github.com/nextcloud/server/pull/35744/files#r1184644610 Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Files/Type/Loader.php26
1 files changed, 10 insertions, 16 deletions
diff --git a/lib/private/Files/Type/Loader.php b/lib/private/Files/Type/Loader.php
index 32013bc3786..20c298f21b3 100644
--- a/lib/private/Files/Type/Loader.php
+++ b/lib/private/Files/Type/Loader.php
@@ -116,7 +116,7 @@ class Loader implements IMimeTypeLoader {
* @return int inserted ID
*/
protected function store($mimetype) {
- $row = $this->atomic(function () use ($mimetype) {
+ $mimetypeId = $this->atomic(function () use ($mimetype) {
try {
$insert = $this->dbConnection->getQueryBuilder();
$insert->insert('mimetypes')
@@ -124,34 +124,28 @@ class Loader implements IMimeTypeLoader {
'mimetype' => $insert->createNamedParameter($mimetype)
])
->executeStatement();
- return [
- 'mimetype' => $mimetype,
- 'id' => $insert->getLastInsertId(),
- ];
+ return $insert->getLastInsertId();
} catch (DbalException $e) {
if ($e->getReason() !== DBException::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
throw $e;
}
$qb = $this->dbConnection->getQueryBuilder();
- $row = $qb->select('id')
+ $qb->select('id')
->from('mimetypes')
- ->where($qb->expr()->eq('mimetype', $qb->createNamedParameter($mimetype)))
- ->executeQuery()
- ->fetchOne();
- if ($row) {
- return [
- 'mimetype' => $mimetype,
- 'id' => $row['id'],
- ];
+ ->where($qb->expr()->eq('mimetype', $qb->createNamedParameter($mimetype)));
+ $result = $qb->executeQuery();
+ $id = $result->fetchOne();
+ $result->closeCursor();
+ if ($id !== false) {
+ return (int) $id;
}
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 (!$row) {
+ if (!$mimetypeId) {
throw new \Exception("Failed to get mimetype id for $mimetype after trying to store it");
}
- $mimetypeId = (int) $row['id'];
$this->mimetypes[$mimetypeId] = $mimetype;
$this->mimetypeIds[$mimetype] = $mimetypeId;