mirror of
https://github.com/nextcloud/server.git
synced 2026-06-10 09:13:19 -04:00
Merge pull request #40461 from nextcloud/backport/40203/stable27
[stable27] fix(mimetype): Fix aborted transaction on PostgreSQL when storing mimetype
This commit is contained in:
commit
91a7538bec
1 changed files with 17 additions and 19 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue