Skip to content

Commit ca75353

Browse files
committed
Add repair step to reset all sessions before Yjs migration
Text sessions with data from our old collaboration backend cause issues after the upgrade to Text with the new Yjs backend. Therefore let's force-reset all sessions when upgrading from a Text version smaller than 3.7.1. Signed-off-by: Jonas <jonas@freesources.org>
1 parent 7a9b452 commit ca75353

File tree

6 files changed

+77
-2
lines changed

6 files changed

+77
-2
lines changed

appinfo/info.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
- **💾 Open format:** Files are saved as [Markdown](https://en.wikipedia.org/wiki/Markdown), so you can edit them from any other text app too.
1212
- **✊ Strong foundation:** We use [🐈 tiptap](https://tiptap.scrumpy.io) which is based on [🦉 ProseMirror](https://prosemirror.net) – huge thanks to them!
1313
]]></description>
14-
<version>3.7.1</version>
14+
<version>3.7.2</version>
1515
<licence>agpl</licence>
1616
<author mail="jus@bitgrid.net">Julius Härtl</author>
1717
<namespace>Text</namespace>
@@ -40,4 +40,9 @@
4040
<plugin>OCA\Text\DAV\WorkspacePlugin</plugin>
4141
</plugins>
4242
</sabre>
43+
<repair-steps>
44+
<post-migration>
45+
<step>OCA\Text\Migration\ResetSessionsBeforeYjs</step>
46+
</post-migration>
47+
</repair-steps>
4348
</info>

composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
'OCA\\Text\\Listeners\\LoadViewerListener' => $baseDir . '/../lib/Listeners/LoadViewerListener.php',
4040
'OCA\\Text\\Listeners\\NodeCopiedListener' => $baseDir . '/../lib/Listeners/NodeCopiedListener.php',
4141
'OCA\\Text\\Listeners\\RegisterDirectEditorEventListener' => $baseDir . '/../lib/Listeners/RegisterDirectEditorEventListener.php',
42+
'OCA\\Text\\Migration\\ResetSessionsBeforeYjs' => $baseDir . '/../lib/Migration/ResetSessionsBeforeYjs.php',
4243
'OCA\\Text\\Migration\\Version010000Date20190617184535' => $baseDir . '/../lib/Migration/Version010000Date20190617184535.php',
4344
'OCA\\Text\\Migration\\Version030001Date20200402075029' => $baseDir . '/../lib/Migration/Version030001Date20200402075029.php',
4445
'OCA\\Text\\Migration\\Version030201Date20201116110353' => $baseDir . '/../lib/Migration/Version030201Date20201116110353.php',

composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class ComposerStaticInitText
5454
'OCA\\Text\\Listeners\\LoadViewerListener' => __DIR__ . '/..' . '/../lib/Listeners/LoadViewerListener.php',
5555
'OCA\\Text\\Listeners\\NodeCopiedListener' => __DIR__ . '/..' . '/../lib/Listeners/NodeCopiedListener.php',
5656
'OCA\\Text\\Listeners\\RegisterDirectEditorEventListener' => __DIR__ . '/..' . '/../lib/Listeners/RegisterDirectEditorEventListener.php',
57+
'OCA\\Text\\Migration\\ResetSessionsBeforeYjs' => __DIR__ . '/..' . '/../lib/Migration/ResetSessionsBeforeYjs.php',
5758
'OCA\\Text\\Migration\\Version010000Date20190617184535' => __DIR__ . '/..' . '/../lib/Migration/Version010000Date20190617184535.php',
5859
'OCA\\Text\\Migration\\Version030001Date20200402075029' => __DIR__ . '/..' . '/../lib/Migration/Version030001Date20200402075029.php',
5960
'OCA\\Text\\Migration\\Version030201Date20201116110353' => __DIR__ . '/..' . '/../lib/Migration/Version030201Date20201116110353.php',

lib/Db/SessionMapper.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ public function __construct(IDBConnection $db) {
3535
parent::__construct($db, 'text_sessions', Session::class);
3636
}
3737

38+
/**
39+
* @return array
40+
*/
41+
public function findAllDocuments(): array {
42+
$qb = $this->db->getQueryBuilder();
43+
$qb->select('*')
44+
->from($this->getTableName());
45+
46+
return $this->findEntities($qb);
47+
}
48+
3849
/**
3950
* @param $documentId
4051
* @param $sessionId
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace OCA\Text\Migration;
4+
5+
use OCA\Text\Db\SessionMapper;
6+
use OCA\Text\Service\DocumentService;
7+
use OCP\IConfig;
8+
use OCP\Migration\IOutput;
9+
use OCP\Migration\IRepairStep;
10+
11+
class ResetSessionsBeforeYjs implements IRepairStep {
12+
private IConfig $config;
13+
private SessionMapper $sessionMapper;
14+
private DocumentService $documentService;
15+
16+
public function __construct(IConfig $config,
17+
SessionMapper $sessionMapper,
18+
DocumentService $documentService) {
19+
$this->config = $config;
20+
$this->sessionMapper = $sessionMapper;
21+
$this->documentService = $documentService;
22+
}
23+
24+
/**
25+
* @return string
26+
*/
27+
public function getName(): string {
28+
return 'Force-reset all Text sessions before Yjs migration';
29+
}
30+
31+
/**
32+
* @param IOutput $output
33+
*
34+
* @return void
35+
*/
36+
public function run(IOutput $output): void {
37+
$appVersion = $this->config->getAppValue('text', 'installed_version');
38+
39+
if (!$appVersion || version_compare($appVersion, '3.7.2') !== -1) {
40+
return;
41+
}
42+
43+
$sessions = $this->sessionMapper->findAllDocuments();
44+
if (!$sessions) {
45+
return;
46+
}
47+
48+
$output->startProgress(count($sessions));
49+
foreach ($sessions as $session) {
50+
$documentId = $session->getDocumentId();
51+
$this->documentService->unlock($documentId);
52+
$this->documentService->resetDocument($documentId, true);
53+
$output->advance();
54+
}
55+
$output->finishProgress();
56+
}
57+
}

lib/Service/DocumentService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public function autosave(?File $file, int $documentId, int $version, ?string $au
339339
* @param bool $force
340340
* @throws DocumentHasUnsavedChangesException
341341
*/
342-
public function resetDocument(int $documentId, $force = false): void {
342+
public function resetDocument(int $documentId, bool $force = false): void {
343343
try {
344344
$this->unlock($documentId);
345345

0 commit comments

Comments
 (0)