Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix(reset): Reset all document sessions on upgrades from 3.10.0 or below
Fixes: #5420
Fixes: nextcloud/collectives#1270

Signed-off-by: Jonas <[email protected]>
  • Loading branch information
mejo- committed Jun 12, 2024
commit 3f722aba6f81dac483fb66e551d4251be9769bb0
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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!
]]></description>
<version>3.10.0</version>
<version>3.10.1</version>
<licence>agpl</licence>
<author mail="[email protected]">Julius Härtl</author>
<namespace>Text</namespace>
Expand Down
39 changes: 14 additions & 25 deletions lib/Migration/ResetSessionsBeforeYjs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,43 @@

namespace OCA\Text\Migration;

use OCA\Text\Db\SessionMapper;
use OCA\Text\Db\Document;
use OCA\Text\Service\DocumentService;
use OCP\IAppConfig;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;

class ResetSessionsBeforeYjs implements IRepairStep {
private IAppConfig $config;
private SessionMapper $sessionMapper;
private DocumentService $documentService;

public function __construct(IAppConfig $config,
SessionMapper $sessionMapper,
DocumentService $documentService) {
$this->config = $config;
$this->sessionMapper = $sessionMapper;
$this->documentService = $documentService;
public function __construct(private IAppConfig $config,
private DocumentService $documentService) {
}

/**
* @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->getValueString('text', 'installed_version');

if (!$appVersion || version_compare($appVersion, '3.7.2') !== -1) {
if (!$appVersion || version_compare($appVersion, '3.10.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();
Expand Down