Skip to content

Commit fd7ae93

Browse files
authored
Merge pull request #6948 from nextcloud/backport/6918/stable31
2 parents d53e23a + 88a7300 commit fd7ae93

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

lib/AppInfo/Application.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use OCA\Files\Event\LoadAdditionalScriptsEvent;
1212
use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent;
1313
use OCA\Text\Event\LoadEditor;
14+
use OCA\Text\Exception\DocumentHasUnsavedChangesException;
1415
use OCA\Text\Listeners\AddMissingIndicesListener;
1516
use OCA\Text\Listeners\BeforeAssistantNotificationListener;
1617
use OCA\Text\Listeners\BeforeNodeDeletedListener;
@@ -25,6 +26,7 @@
2526
use OCA\Text\Listeners\RegisterTemplateCreatorListener;
2627
use OCA\Text\Middleware\SessionMiddleware;
2728
use OCA\Text\Notification\Notifier;
29+
use OCA\Text\Service\DocumentService;
2830
use OCA\TpAssistant\Event\BeforeAssistantNotificationEvent;
2931
use OCA\Viewer\Event\LoadViewer;
3032
use OCP\AppFramework\App;
@@ -37,7 +39,11 @@
3739
use OCP\Files\Events\Node\BeforeNodeRenamedEvent;
3840
use OCP\Files\Events\Node\BeforeNodeWrittenEvent;
3941
use OCP\Files\Events\Node\NodeCopiedEvent;
42+
use OCP\Files\File;
43+
use OCP\Files\NotFoundException;
4044
use OCP\Files\Template\RegisterTemplateCreatorEvent;
45+
use OCP\Server;
46+
use OCP\Util;
4147

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

6470
$context->registerNotifierService(Notifier::class);
6571
$context->registerMiddleware(SessionMiddleware::class);
72+
73+
/** @psalm-suppress DeprecatedMethod */
74+
Util::connectHook('\OCP\Versions', 'rollback', $this, 'resetSessionsAfterRestoreFile');
6675
}
6776

6877
public function boot(IBootContext $context): void {
6978
}
79+
80+
public function resetSessionsAfterRestoreFile(array $params): void {
81+
$node = $params['node'];
82+
if (!$node instanceof File) {
83+
return;
84+
}
85+
86+
$documentService = Server::get(DocumentService::class);
87+
// Reset document session to avoid manual conflict resolution if there's no unsaved steps
88+
try {
89+
$documentService->resetDocument($node->getId());
90+
} catch (DocumentHasUnsavedChangesException|NotFoundException $e) {
91+
// Do not throw during event handling in this is expected to happen
92+
// DocumentHasUnsavedChangesException: A document editing session is likely ongoing, someone can resolve the conflict
93+
// NotFoundException: The event was called oin a file that was just created so a NonExistingFile object is used that has no id yet
94+
}
95+
}
7096
}

0 commit comments

Comments
 (0)