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
26 changes: 26 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent;
use OCA\Text\Event\LoadEditor;
use OCA\Text\Exception\DocumentHasUnsavedChangesException;
use OCA\Text\Listeners\AddMissingIndicesListener;
use OCA\Text\Listeners\BeforeAssistantNotificationListener;
use OCA\Text\Listeners\BeforeNodeDeletedListener;
Expand All @@ -25,6 +26,7 @@
use OCA\Text\Listeners\RegisterTemplateCreatorListener;
use OCA\Text\Middleware\SessionMiddleware;
use OCA\Text\Notification\Notifier;
use OCA\Text\Service\DocumentService;
use OCA\TpAssistant\Event\BeforeAssistantNotificationEvent;
use OCA\Viewer\Event\LoadViewer;
use OCP\AppFramework\App;
Expand All @@ -37,7 +39,11 @@
use OCP\Files\Events\Node\BeforeNodeRenamedEvent;
use OCP\Files\Events\Node\BeforeNodeWrittenEvent;
use OCP\Files\Events\Node\NodeCopiedEvent;
use OCP\Files\File;
use OCP\Files\NotFoundException;
use OCP\Files\Template\RegisterTemplateCreatorEvent;
use OCP\Server;
use OCP\Util;

class Application extends App implements IBootstrap {
public const APP_NAME = 'text';
Expand All @@ -63,8 +69,28 @@ public function register(IRegistrationContext $context): void {

$context->registerNotifierService(Notifier::class);
$context->registerMiddleware(SessionMiddleware::class);

/** @psalm-suppress DeprecatedMethod */
Util::connectHook('\OCP\Versions', 'rollback', $this, 'resetSessionsAfterRestoreFile');
}

public function boot(IBootContext $context): void {
}

public function resetSessionsAfterRestoreFile(array $params): void {
$node = $params['node'];
if (!$node instanceof File) {
return;
}

$documentService = Server::get(DocumentService::class);
// Reset document session to avoid manual conflict resolution if there's no unsaved steps
try {
$documentService->resetDocument($node->getId());
} 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
}
}
}
Loading