Skip to content

Commit

Permalink
Wrap mimetype insert and getLastInsertId in a transaction
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas Azevedo <[email protected]>
  • Loading branch information
lhsazevedo committed Sep 4, 2023
1 parent 5de021c commit c587f68
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/private/Files/Type/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c587f68

Please sign in to comment.