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
30 changes: 23 additions & 7 deletions lib/Service/DocumentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ public function __construct(DocumentMapper $documentMapper, StepMapper $stepMapp
$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) {
Expand Down Expand Up @@ -149,8 +144,12 @@ public function createDocument(File $file): Document {
} 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());
}
Expand All @@ -174,6 +173,9 @@ public function createDocument(File $file): Document {
* @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);
}

Expand Down Expand Up @@ -343,7 +345,7 @@ public function resetDocument($documentId, $force = false): void {
$this->documentMapper->delete($document);

try {
$this->appData->getFolder('documents')->getFile((string)$documentId)->delete();
$this->getBaseFile($documentId)->delete();
} catch (NotFoundException $e) {
} catch (NotPermittedException $e) {
}
Expand Down Expand Up @@ -457,4 +459,18 @@ public function hasUnsavedChanges(Document $document) {
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;
}

}