]> source.dussan.org Git - nextcloud-server.git/commitdiff
Wrap mimetype insert and getLastInsertId in a transaction 40461/head
authorLucas Azevedo <lhs_azevedo@hotmail.com>
Mon, 4 Sep 2023 11:02:35 +0000 (08:02 -0300)
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>
Sat, 16 Sep 2023 19:31:27 +0000 (19:31 +0000)
Signed-off-by: Lucas Azevedo <lhs_azevedo@hotmail.com>
lib/private/Files/Type/Loader.php

index 7ca1b677fb5911b8eaa418b183333aeeda3ba818..7032e6193850f5e1db718ce6423c6114b2997043 100644 (file)
@@ -117,13 +117,15 @@ class Loader implements IMimeTypeLoader {
         */
        protected function store($mimetype) {
                try {
-                       $insert = $this->dbConnection->getQueryBuilder();
-                       $insert->insert('mimetypes')
-                               ->values([
-                                       'mimetype' => $insert->createNamedParameter($mimetype)
-                               ])
-                               ->executeStatement();
-                       $mimetypeId = $insert->getLastInsertId();
+                       $mimetypeId = $this->atomic(function () use ($mimetype) {
+                               $insert = $this->dbConnection->getQueryBuilder();
+                               $insert->insert('mimetypes')
+                                       ->values([
+                                               'mimetype' => $insert->createNamedParameter($mimetype)
+                                       ])
+                                       ->executeStatement();
+                               return $insert->getLastInsertId();
+                       }, $this->dbConnection);
                } catch (DbalException $e) {
                        if ($e->getReason() !== DBException::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
                                throw $e;