diff options
-rw-r--r-- | lib/Service/DocumentService.php | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/lib/Service/DocumentService.php b/lib/Service/DocumentService.php index 73eb53688..ccccfae59 100644 --- a/lib/Service/DocumentService.php +++ b/lib/Service/DocumentService.php @@ -108,11 +108,6 @@ class DocumentService { $this->logger = $logger; $this->shareManager = $shareManager; $this->lockingProvider = $lockingProvider; - try { - $this->appData->getFolder('documents'); - } catch (NotFoundException $e) { - $this->appData->newFolder('documents'); - } $token = $request->getParam('token'); if ($this->userId === null && $token !== null) { @@ -149,8 +144,12 @@ class DocumentService { } catch (NotFoundException $e) { } + if (!$this->ensureDocumentsFolder()) { + throw new NotFoundException('No app data folder present for text documents'); + } + try { - $documentBaseFile = $this->appData->getFolder('documents')->getFile((string)$file->getFileInfo()->getId()); + $documentBaseFile = $this->getBaseFile((string)$file->getFileInfo()->getId()); } catch (NotFoundException $e) { $documentBaseFile = $this->appData->getFolder('documents')->newFile((string)$file->getFileInfo()->getId()); } @@ -174,6 +173,9 @@ class DocumentService { * @throws NotFoundException */ public function getBaseFile($document): ISimpleFile { + if (!$this->ensureDocumentsFolder()) { + throw new NotFoundException('No app data folder present for text documents'); + } return $this->appData->getFolder('documents')->getFile((string) $document); } @@ -343,7 +345,7 @@ class DocumentService { $this->documentMapper->delete($document); try { - $this->appData->getFolder('documents')->getFile((string)$documentId)->delete(); + $this->getBaseFile($documentId)->delete(); } catch (NotFoundException $e) { } catch (NotPermittedException $e) { } @@ -457,4 +459,18 @@ class DocumentService { return $document->getCurrentVersion() !== $document->getLastSavedVersion(); } + private function ensureDocumentsFolder(): bool { + try { + $this->appData->getFolder('documents'); + } catch (NotFoundException $e) { + $this->appData->newFolder('documents'); + } catch (\RuntimeException $e) { + // Do not fail hard + $this->logger->logException($e); + return false; + } + + return true; + } + } |