diff --git a/appinfo/info.xml b/appinfo/info.xml index 4109aed012e..720cc8a9d8f 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.7.1 + 3.7.2 agpl Julius Hรคrtl Text @@ -40,4 +40,9 @@ OCA\Text\DAV\WorkspacePlugin + + + OCA\Text\Migration\ResetSessionsBeforeYjs + + diff --git a/composer/composer/autoload_classmap.php b/composer/composer/autoload_classmap.php index cc802bb9408..6db47ec2d86 100644 --- a/composer/composer/autoload_classmap.php +++ b/composer/composer/autoload_classmap.php @@ -39,6 +39,7 @@ 'OCA\\Text\\Listeners\\LoadViewerListener' => $baseDir . '/../lib/Listeners/LoadViewerListener.php', 'OCA\\Text\\Listeners\\NodeCopiedListener' => $baseDir . '/../lib/Listeners/NodeCopiedListener.php', 'OCA\\Text\\Listeners\\RegisterDirectEditorEventListener' => $baseDir . '/../lib/Listeners/RegisterDirectEditorEventListener.php', + 'OCA\\Text\\Migration\\ResetSessionsBeforeYjs' => $baseDir . '/../lib/Migration/ResetSessionsBeforeYjs.php', 'OCA\\Text\\Migration\\Version010000Date20190617184535' => $baseDir . '/../lib/Migration/Version010000Date20190617184535.php', 'OCA\\Text\\Migration\\Version030001Date20200402075029' => $baseDir . '/../lib/Migration/Version030001Date20200402075029.php', 'OCA\\Text\\Migration\\Version030201Date20201116110353' => $baseDir . '/../lib/Migration/Version030201Date20201116110353.php', diff --git a/composer/composer/autoload_static.php b/composer/composer/autoload_static.php index 315f6e2b87e..5246ab8c713 100644 --- a/composer/composer/autoload_static.php +++ b/composer/composer/autoload_static.php @@ -54,6 +54,7 @@ class ComposerStaticInitText 'OCA\\Text\\Listeners\\LoadViewerListener' => __DIR__ . '/..' . '/../lib/Listeners/LoadViewerListener.php', 'OCA\\Text\\Listeners\\NodeCopiedListener' => __DIR__ . '/..' . '/../lib/Listeners/NodeCopiedListener.php', 'OCA\\Text\\Listeners\\RegisterDirectEditorEventListener' => __DIR__ . '/..' . '/../lib/Listeners/RegisterDirectEditorEventListener.php', + 'OCA\\Text\\Migration\\ResetSessionsBeforeYjs' => __DIR__ . '/..' . '/../lib/Migration/ResetSessionsBeforeYjs.php', 'OCA\\Text\\Migration\\Version010000Date20190617184535' => __DIR__ . '/..' . '/../lib/Migration/Version010000Date20190617184535.php', 'OCA\\Text\\Migration\\Version030001Date20200402075029' => __DIR__ . '/..' . '/../lib/Migration/Version030001Date20200402075029.php', 'OCA\\Text\\Migration\\Version030201Date20201116110353' => __DIR__ . '/..' . '/../lib/Migration/Version030201Date20201116110353.php', diff --git a/lib/Db/SessionMapper.php b/lib/Db/SessionMapper.php index 91c0674b6f5..62851b85969 100644 --- a/lib/Db/SessionMapper.php +++ b/lib/Db/SessionMapper.php @@ -35,6 +35,17 @@ public function __construct(IDBConnection $db) { parent::__construct($db, 'text_sessions', Session::class); } + /** + * @return array + */ + public function findAllDocuments(): array { + $qb = $this->db->getQueryBuilder(); + $qb->select('*') + ->from($this->getTableName()); + + return $this->findEntities($qb); + } + /** * @param $documentId * @param $sessionId diff --git a/lib/Migration/ResetSessionsBeforeYjs.php b/lib/Migration/ResetSessionsBeforeYjs.php new file mode 100644 index 00000000000..f52d005dc0e --- /dev/null +++ b/lib/Migration/ResetSessionsBeforeYjs.php @@ -0,0 +1,57 @@ +config = $config; + $this->sessionMapper = $sessionMapper; + $this->documentService = $documentService; + } + + /** + * @return string + */ + public function getName(): string { + return 'Force-reset all Text sessions before Yjs migration'; + } + + /** + * @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) { + return; + } + + $sessions = $this->sessionMapper->findAllDocuments(); + if (!$sessions) { + return; + } + + $output->startProgress(count($sessions)); + foreach ($sessions as $session) { + $documentId = $session->getDocumentId(); + $this->documentService->unlock($documentId); + $this->documentService->resetDocument($documentId, true); + $output->advance(); + } + $output->finishProgress(); + } +} diff --git a/lib/Service/DocumentService.php b/lib/Service/DocumentService.php index a6f5d612c97..ddd085f65c6 100644 --- a/lib/Service/DocumentService.php +++ b/lib/Service/DocumentService.php @@ -339,7 +339,7 @@ public function autosave(?File $file, int $documentId, int $version, ?string $au * @param bool $force * @throws DocumentHasUnsavedChangesException */ - public function resetDocument(int $documentId, $force = false): void { + public function resetDocument(int $documentId, bool $force = false): void { try { $this->unlock($documentId);