Skip to content

Commit

Permalink
fix: resolve file version conflict during restore
Browse files Browse the repository at this point in the history
Signed-off-by: ailkiv <[email protected]>
  • Loading branch information
AIlkiv committed Feb 26, 2025
1 parent 0bea5f4 commit 7b44a34
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,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 +38,10 @@
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\Template\RegisterTemplateCreatorEvent;
use OCP\Server;
use OCP\Util;

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

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

Util::connectHook('\OCP\Versions', 'rollback', $this, 'resetSessionsAfterRestoreFile');

Check failure on line 71 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

DeprecatedMethod

lib/AppInfo/Application.php:71:3: DeprecatedMethod: The method OCP\Util::connectHook has been marked as deprecated (see https://psalm.dev/001)
}

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

public function resetSessionsAfterRestoreFile($params) {

Check failure on line 77 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

MissingReturnType

lib/AppInfo/Application.php:77:18: MissingReturnType: Method OCA\Text\AppInfo\Application::resetSessionsAfterRestoreFile does not have a return type, expecting void (see https://psalm.dev/050)

Check failure on line 77 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

MissingParamType

lib/AppInfo/Application.php:77:48: MissingParamType: Parameter $params has no provided type (see https://psalm.dev/154)
$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) {

Check failure on line 87 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedClass

lib/AppInfo/Application.php:87:12: UndefinedClass: Class, interface or enum named OCA\Text\AppInfo\DocumentHasUnsavedChangesException does not exist (see https://psalm.dev/019)

Check failure on line 87 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedClass

lib/AppInfo/Application.php:87:47: UndefinedClass: Class, interface or enum named OCA\Text\AppInfo\NotFoundException does not exist (see https://psalm.dev/019)
// 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
}
}
}

0 comments on commit 7b44a34

Please sign in to comment.