|
@@ -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;
|