Skip to content

Commit

Permalink
Merge pull request #6170 from nextcloud/backport/6167/stable29
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusknorr authored Aug 5, 2024
2 parents 2e3d4a6 + 32c2fc1 commit 2ddc6a4
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/Listeners/BeforeNodeWrittenListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@
use OCP\EventDispatcher\IEventListener;
use OCP\Files\Events\Node\BeforeNodeWrittenEvent;
use OCP\Files\File;
use OCP\Files\NotFoundException;
use Psr\Log\LoggerInterface;

/**
* @template-implements IEventListener<Event|BeforeNodeWrittenEvent>
*/
class BeforeNodeWrittenListener implements IEventListener {
private DocumentService $documentService;

public function __construct(DocumentService $documentService) {
$this->documentService = $documentService;
public function __construct(
private LoggerInterface $logger,
private DocumentService $documentService
) {
}

public function handle(Event $event): void {
Expand All @@ -56,8 +58,11 @@ public function handle(Event $event): void {
// Reset document session to avoid manual conflict resolution if there's no unsaved steps
try {
$this->documentService->resetDocument($node->getId());
} catch (DocumentHasUnsavedChangesException) {
} catch (DocumentHasUnsavedChangesException|NotFoundException $e) {
// Do not throw during event handling in this is expected to happen
// DocumentHasUnsavedChangesException: A document editing session is likely ongoing, someone can resolve the conflict
// NotFoundException: The event was called oin a file that was just created so a NonExistingFile object is used that has no id yet
$this->logger->debug('Reset document skipped in BeforeNodeWrittenEvent', ['exception' => $e]);
}
}
}

0 comments on commit 2ddc6a4

Please sign in to comment.