Skip to content

Commit cf14604

Browse files
committed
fix(reset): Reset all document sessions on upgrades from 3.8.0 or below
Fixes: #5420 Fixes: nextcloud/collectives#1270 Signed-off-by: Jonas <jonas@freesources.org>
1 parent 490fddf commit cf14604

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

lib/Migration/ResetSessionsBeforeYjs.php

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,48 @@
22

33
namespace OCA\Text\Migration;
44

5-
use OCA\Text\Db\SessionMapper;
5+
use OCA\Text\Db\Document;
66
use OCA\Text\Service\DocumentService;
77
use OCP\IConfig;
88
use OCP\Migration\IOutput;
99
use OCP\Migration\IRepairStep;
1010

1111
class ResetSessionsBeforeYjs implements IRepairStep {
1212
private IConfig $config;
13-
private SessionMapper $sessionMapper;
1413
private DocumentService $documentService;
1514

1615
public function __construct(IConfig $config,
17-
SessionMapper $sessionMapper,
1816
DocumentService $documentService) {
1917
$this->config = $config;
20-
$this->sessionMapper = $sessionMapper;
2118
$this->documentService = $documentService;
2219
}
2320

2421
/**
2522
* @return string
2623
*/
2724
public function getName(): string {
28-
return 'Force-reset all Text sessions before Yjs migration';
25+
return 'Force-reset all Text document sessions';
2926
}
3027

31-
/**
32-
* @param IOutput $output
33-
*
34-
* @return void
35-
*/
3628
public function run(IOutput $output): void {
3729
$appVersion = $this->config->getAppValue('text', 'installed_version');
3830

39-
if (!$appVersion || version_compare($appVersion, '3.7.2') !== -1) {
31+
if (!$appVersion || version_compare($appVersion, '3.8.1') !== -1) {
4032
return;
4133
}
4234

43-
$sessions = $this->sessionMapper->findAllDocuments();
44-
if (!$sessions) {
35+
$fileIds = array_map(static function (Document $document) {
36+
return $document->getId();
37+
}, $this->documentService->getAll());
38+
39+
if (!$fileIds) {
4540
return;
4641
}
4742

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);
43+
$output->startProgress(count($fileIds));
44+
foreach ($fileIds as $fileId) {
45+
$this->documentService->unlock($fileId);
46+
$this->documentService->resetDocument($fileId, true);
5347
$output->advance();
5448
}
5549
$output->finishProgress();

0 commit comments

Comments
 (0)