Skip to content

Commit

Permalink
fix: Catch unique constraint violation when creating new documents
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliushaertl committed Jun 13, 2023
1 parent b9ca139 commit cfd0aa6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/Service/DocumentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,17 @@ public function createDocument(File $file): Document {
$document->setLastSavedVersionTime($file->getFileInfo()->getMtime());
$document->setLastSavedVersionEtag($file->getEtag());
$document->setBaseVersionEtag($file->getEtag());
$document = $this->documentMapper->insert($document);
$this->cache->set('document-version-'.$document->getId(), 0);
try {
$document = $this->documentMapper->insert($document);
$this->cache->set('document-version-'.$document->getId(), 0);
} catch (Exception $e) {
if ($e->getReason() === Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
// Document might have been created in the meantime
return $this->documentMapper->find($file->getFileInfo()->getId());
}

throw $e;
}
return $document;
}

Expand Down

0 comments on commit cfd0aa6

Please sign in to comment.