From c587f684bd18b2572249d46cd9ffe45e43f9c98f Mon Sep 17 00:00:00 2001 From: Lucas Azevedo Date: Mon, 4 Sep 2023 08:02:35 -0300 Subject: [PATCH] Wrap mimetype insert and getLastInsertId in a transaction Signed-off-by: Lucas Azevedo --- lib/private/Files/Type/Loader.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/private/Files/Type/Loader.php b/lib/private/Files/Type/Loader.php index 7ca1b677fb591..7032e6193850f 100644 --- a/lib/private/Files/Type/Loader.php +++ b/lib/private/Files/Type/Loader.php @@ -117,13 +117,15 @@ public function reset() { */ 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;