diff options
author | Julius Härtl <jus@bitgrid.net> | 2020-10-01 09:20:08 +0300 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2020-10-01 09:20:08 +0300 |
commit | 5deeb5c61a9678621967cad139ae1a3f14502458 (patch) | |
tree | a8171d817ff9a213715f5bba634ccfc0ce61729d /lib | |
parent | 72456fbe03b08ddfac6d1b637fa83ba034f42dc6 (diff) |
Do not setup appdata in constructor to avoid errors causing the whole instance to stop
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib')
-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; + } + } |