Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: Catch unique constraint violation when creating new documents
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr authored and backportbot-nextcloud[bot] committed Jun 13, 2023
commit 448f11340d4cec5a35b54d1707f269e1d442ca08
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