From 2988485b0685dd922f16f1dafd6440e11fa0ca90 Mon Sep 17 00:00:00 2001 From: Jonas Date: Tue, 11 Jun 2024 16:49:47 +0200 Subject: [PATCH] fix(reset): Reset all document sessions on upgrades from 3.8.0 or below Fixes: #5420 Fixes: nextcloud/collectives#1270 Signed-off-by: Jonas --- appinfo/info.xml | 2 +- lib/Migration/ResetSessionsBeforeYjs.php | 30 ++++++++++-------------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index c1d56579945..1d5e9dec3d1 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -11,7 +11,7 @@ - **๐Ÿ’พ Open format:** Files are saved as [Markdown](https://en.wikipedia.org/wiki/Markdown), so you can edit them from any other text app too. - **โœŠ Strong foundation:** We use [๐Ÿˆ tiptap](https://tiptap.scrumpy.io) which is based on [๐Ÿฆ‰ ProseMirror](https://prosemirror.net) โ€“ huge thanks to them! ]]> - 3.8.0 + 3.8.1 agpl Julius Hรคrtl Text diff --git a/lib/Migration/ResetSessionsBeforeYjs.php b/lib/Migration/ResetSessionsBeforeYjs.php index a9ad5d451c9..ded1c8bdf3e 100644 --- a/lib/Migration/ResetSessionsBeforeYjs.php +++ b/lib/Migration/ResetSessionsBeforeYjs.php @@ -2,7 +2,7 @@ namespace OCA\Text\Migration; -use OCA\Text\Db\SessionMapper; +use OCA\Text\Db\Document; use OCA\Text\Service\DocumentService; use OCP\IConfig; use OCP\Migration\IOutput; @@ -10,14 +10,11 @@ class ResetSessionsBeforeYjs implements IRepairStep { private IConfig $config; - private SessionMapper $sessionMapper; private DocumentService $documentService; public function __construct(IConfig $config, - SessionMapper $sessionMapper, DocumentService $documentService) { $this->config = $config; - $this->sessionMapper = $sessionMapper; $this->documentService = $documentService; } @@ -25,31 +22,28 @@ public function __construct(IConfig $config, * @return string */ public function getName(): string { - return 'Force-reset all Text sessions before Yjs migration'; + return 'Force-reset all Text document sessions'; } - /** - * @param IOutput $output - * - * @return void - */ public function run(IOutput $output): void { $appVersion = $this->config->getAppValue('text', 'installed_version'); - if (!$appVersion || version_compare($appVersion, '3.7.2') !== -1) { + if (!$appVersion || version_compare($appVersion, '3.8.1') !== -1) { return; } - $sessions = $this->sessionMapper->findAllDocuments(); - if (!$sessions) { + $fileIds = array_map(static function (Document $document) { + return $document->getId(); + }, $this->documentService->getAll()); + + if (!$fileIds) { return; } - $output->startProgress(count($sessions)); - foreach ($sessions as $session) { - $documentId = $session->getDocumentId(); - $this->documentService->unlock($documentId); - $this->documentService->resetDocument($documentId, true); + $output->startProgress(count($fileIds)); + foreach ($fileIds as $fileId) { + $this->documentService->unlock($fileId); + $this->documentService->resetDocument($fileId, true); $output->advance(); } $output->finishProgress();