diff --git a/lib/Service/ApiService.php b/lib/Service/ApiService.php index 436ddc73eee..bcd89e4ded6 100644 --- a/lib/Service/ApiService.php +++ b/lib/Service/ApiService.php @@ -37,6 +37,7 @@ use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\Constants; +use OCP\Files\AlreadyExistsException; use OCP\Files\InvalidPathException; use OCP\Files\Lock\ILock; use OCP\Files\NotFoundException; @@ -117,7 +118,12 @@ public function create(?int $fileId = null, ?string $filePath = null, ?string $t if ($freshSession) { $this->logger->info('Create new document of ' . $file->getId()); - $document = $this->documentService->createDocument($file); + try { + $document = $this->documentService->createDocument($file); + } catch (AlreadyExistsException) { + $freshSession = false; + $document = $this->documentService->getDocument($file->getId()); + } } else { $this->logger->info('Keep previous document of ' . $file->getId()); } diff --git a/lib/Service/DocumentService.php b/lib/Service/DocumentService.php index 1241f324588..6291cb706a9 100644 --- a/lib/Service/DocumentService.php +++ b/lib/Service/DocumentService.php @@ -41,6 +41,7 @@ use OCP\Constants; use OCP\DB\Exception; use OCP\DirectEditing\IManager; +use OCP\Files\AlreadyExistsException; use OCP\Files\Config\IUserMountCache; use OCP\Files\File; use OCP\Files\Folder; @@ -157,7 +158,7 @@ public function createDocument(File $file): Document { } catch (Exception $e) { if ($e->getReason() === Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) { // Document might have been created in the meantime - return $this->documentMapper->find($file->getId()); + throw new AlreadyExistsException(); } throw $e;