|
2 | 2 |
|
3 | 3 | namespace OCA\Text\Migration; |
4 | 4 |
|
5 | | -use OCA\Text\Db\SessionMapper; |
| 5 | +use OCA\Text\Db\Document; |
6 | 6 | use OCA\Text\Service\DocumentService; |
7 | 7 | use OCP\IConfig; |
8 | 8 | use OCP\Migration\IOutput; |
9 | 9 | use OCP\Migration\IRepairStep; |
10 | 10 |
|
11 | 11 | class ResetSessionsBeforeYjs implements IRepairStep { |
12 | 12 | private IConfig $config; |
13 | | - private SessionMapper $sessionMapper; |
14 | 13 | private DocumentService $documentService; |
15 | 14 |
|
16 | 15 | public function __construct(IConfig $config, |
17 | | - SessionMapper $sessionMapper, |
18 | 16 | DocumentService $documentService) { |
19 | 17 | $this->config = $config; |
20 | | - $this->sessionMapper = $sessionMapper; |
21 | 18 | $this->documentService = $documentService; |
22 | 19 | } |
23 | 20 |
|
24 | 21 | /** |
25 | 22 | * @return string |
26 | 23 | */ |
27 | 24 | public function getName(): string { |
28 | | - return 'Force-reset all Text sessions before Yjs migration'; |
| 25 | + return 'Force-reset all Text document sessions'; |
29 | 26 | } |
30 | 27 |
|
31 | | - /** |
32 | | - * @param IOutput $output |
33 | | - * |
34 | | - * @return void |
35 | | - */ |
36 | 28 | public function run(IOutput $output): void { |
37 | 29 | $appVersion = $this->config->getAppValue('text', 'installed_version'); |
38 | 30 |
|
39 | | - if (!$appVersion || version_compare($appVersion, '3.7.2') !== -1) { |
| 31 | + if (!$appVersion || version_compare($appVersion, '3.8.1') !== -1) { |
40 | 32 | return; |
41 | 33 | } |
42 | 34 |
|
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) { |
45 | 40 | return; |
46 | 41 | } |
47 | 42 |
|
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); |
53 | 47 | $output->advance(); |
54 | 48 | } |
55 | 49 | $output->finishProgress(); |
|
0 commit comments