Skip to content

Commit 62dba61

Browse files
juliusknorrbackportbot-nextcloud[bot]
authored andcommittedJun 13, 2023
fix: Catch unique constraint violation when creating new documents
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1 parent 7f0e402 commit 62dba61

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed
 

‎lib/Service/DocumentService.php

+11-2
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,17 @@ public function createDocument(File $file): Document {
154154
$document->setLastSavedVersionTime($file->getFileInfo()->getMtime());
155155
$document->setLastSavedVersionEtag($file->getEtag());
156156
$document->setBaseVersionEtag($file->getEtag());
157-
$document = $this->documentMapper->insert($document);
158-
$this->cache->set('document-version-'.$document->getId(), 0);
157+
try {
158+
$document = $this->documentMapper->insert($document);
159+
$this->cache->set('document-version-'.$document->getId(), 0);
160+
} catch (Exception $e) {
161+
if ($e->getReason() === Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
162+
// Document might have been created in the meantime
163+
return $this->documentMapper->find($file->getFileInfo()->getId());
164+
}
165+
166+
throw $e;
167+
}
159168
return $document;
160169
}
161170

0 commit comments

Comments
 (0)