Skip to content

Commit

Permalink
Merge pull request #5599 from nextcloud/backport/5572/stable28
Browse files Browse the repository at this point in the history
[stable28] fix: Catch exceptions on non existing files
  • Loading branch information
mejo- authored Apr 3, 2024
2 parents d60ce8c + 79c1a4e commit 0e6fb87
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/Listeners/BeforeNodeWrittenListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<Event|BeforeNodeWrittenEvent>
Expand All @@ -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
}
}
}

0 comments on commit 0e6fb87

Please sign in to comment.