diff --git a/lib/Listeners/BeforeNodeWrittenListener.php b/lib/Listeners/BeforeNodeWrittenListener.php index 1079d7c1b9c..73b85a3c970 100644 --- a/lib/Listeners/BeforeNodeWrittenListener.php +++ b/lib/Listeners/BeforeNodeWrittenListener.php @@ -31,6 +31,7 @@ use OCP\EventDispatcher\IEventListener; use OCP\Files\Events\Node\BeforeNodeWrittenEvent; use OCP\Files\File; +use OCP\Files\NotFoundException; /** * @template-implements IEventListener @@ -47,15 +48,19 @@ public function handle(Event $event): void { return; } $node = $event->getNode(); - if ($node instanceof File && $node->getMimeType() === 'text/markdown') { - if (!$this->documentService->isSaveFromText()) { - // Reset document session to avoid manual conflict resolution if there's no unsaved steps - try { - $this->documentService->resetDocument($node->getId()); - } catch (DocumentHasUnsavedChangesException) { - // Do not throw during event handling in this is expected to happen + try { + if ($node instanceof File && $node->getMimeType() === 'text/markdown') { + if (!$this->documentService->isSaveFromText()) { + // Reset document session to avoid manual conflict resolution if there's no unsaved steps + try { + $this->documentService->resetDocument($node->getId()); + } catch (DocumentHasUnsavedChangesException) { + // Do not throw during event handling in this is expected to happen + } } } + } catch (NotFoundException) { + // This might occur on new files when a NonExistingFile is passed and we cannot access the mimetype } } }