Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
85795d6
fix(backend): Reset document session and yjs file when file is deleted
mejo- Mar 13, 2024
8e741de
fix(backend): Reset document session when updated from outside editor
mejo- Mar 13, 2024
8e1ad16
fix(backend): Remove yjs file and all steps when resetting document s…
mejo- Mar 13, 2024
cc2e6c3
fix: catch expected exception in event handler
juliusknorr Mar 15, 2024
aa236cf
fix: Clean up logic to return document state file or file content
juliusknorr Mar 13, 2024
c2798f2
fix: Set base version etag to a unique id per document creation
juliusknorr Mar 13, 2024
ae78252
fix(sync): If `baseVersionEtag` changed, reset frontend
mejo- Mar 15, 2024
f72fb5b
fix(Middleware): Response with 412 if `baseVersionEtag` doesn't match
mejo- Mar 18, 2024
af37fe4
fix(DocumentStatus): Refactor and migrate to `NcNoteCard`
mejo- Mar 18, 2024
25ad80e
test(cypress): Add session API tests with non-matching baseVersionEtag
mejo- Mar 20, 2024
628e463
text(cypress): Test browser refresh warning after document session cl…
mejo- Mar 20, 2024
907d2d4
fix(response): Make sure JSONResponse returns valid data
mejo- Mar 20, 2024
261051c
fix: Create idempotent y.js doc for initial content
juliusknorr Mar 30, 2024
134106f
tests: Add tests for loading documents from different preconditions
juliusknorr Mar 30, 2024
64a6252
fix: Always return initial content when needed
juliusknorr Mar 30, 2024
d464338
tests: Adjust tests covering initial state
juliusknorr Mar 30, 2024
ddabaf0
ci: Make cypress test more stable by closing connections
juliusknorr Mar 31, 2024
499a54f
fix: Adapt to review feedback
juliusknorr Apr 2, 2024
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
Next Next commit
fix(backend): Remove yjs file and all steps when resetting document s…
…ession

Instead of just deleting the newest steps, always remove all session
data: document, sessions and steps from the database as well as the yjs
(document state) file.

Without the `--force` option, don't reset document sessions with unsaved
steps.

Signed-off-by: Jonas <[email protected]>
  • Loading branch information
mejo- committed Apr 2, 2024
commit 8e1ad169ec24ffad4468535ff6c091d994f2e26b
45 changes: 16 additions & 29 deletions lib/Command/ResetDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@

namespace OCA\Text\Command;

use OCA\Text\Db\DocumentMapper;
use OCA\Text\Db\SessionMapper;
use OCA\Text\Db\StepMapper;
use OCA\Text\Exception\DocumentHasUnsavedChangesException;
use OCA\Text\Service\DocumentService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -34,33 +32,26 @@

class ResetDocument extends Command {
protected DocumentService $documentService;
protected DocumentMapper $documentMapper;
protected StepMapper $stepMapper;
protected SessionMapper $sessionMapper;

public function __construct(DocumentService $documentService, DocumentMapper $documentMapper, StepMapper $stepMapper, SessionMapper $sessionMapper) {
public function __construct(DocumentService $documentService) {
parent::__construct();

$this->documentService = $documentService;
$this->documentMapper = $documentMapper;
$this->stepMapper = $stepMapper;
$this->sessionMapper = $sessionMapper;
}

protected function configure(): void {
$this
->setName('text:reset')
->setDescription('Reset a text document')
->setDescription('Reset a text document session to the current file content')
->addArgument(
'file-id',
InputArgument::REQUIRED,
'File id of the document to rest'
'File id of the document to reset'
)
->addOption(
'full',
'force',
'f',
null,
'Drop all existing steps and use the currently saved version'
'Reset the document session even with unsaved changes'
)
;
}
Expand All @@ -72,27 +63,23 @@ protected function configure(): void {
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
$fileId = $input->getArgument('file-id');
$fullReset = $input->getOption('full');
$fullReset = $input->getOption('force');

if ($fullReset) {
$output->writeln('Full document reset');
$output->writeln('Force-reset the document session for file ' . $fileId);
$this->documentService->resetDocument($fileId, true);

return 0;
} else {
$output->writeln('Trying to restore to last saved version');
$document = $this->documentMapper->find($fileId);
$deleted = $this->stepMapper->deleteAfterVersion($fileId, $document->getLastSavedVersion());
if ($deleted > 0) {
$this->sessionMapper->deleteByDocumentId($fileId);
$output->writeln('Reverted document to the last saved version');

return 0;
} else {
$output->writeln('Failed revert changes that are newer than the last saved version');
}
}

$output->writeln('Reset the document session for file ' . $fileId);
try {
$this->documentService->resetDocument($fileId);
} catch (DocumentHasUnsavedChangesException) {
$output->writeln('Not resetting due to unsaved changes');
return 1;
}

return 0;
}
}
15 changes: 5 additions & 10 deletions lib/Cron/Cleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

namespace OCA\Text\Cron;

use OCA\Text\Service\AttachmentService;
use OCA\Text\Exception\DocumentHasUnsavedChangesException;
use OCA\Text\Service\DocumentService;
use OCA\Text\Service\SessionService;
use OCP\AppFramework\Utility\ITimeFactory;
Expand All @@ -39,26 +39,22 @@ class Cleanup extends TimedJob {
private SessionService $sessionService;
private DocumentService $documentService;
private LoggerInterface $logger;
private AttachmentService $attachmentService;

public function __construct(ITimeFactory $time,
SessionService $sessionService,
DocumentService $documentService,
AttachmentService $attachmentService,
LoggerInterface $logger) {
parent::__construct($time);
$this->sessionService = $sessionService;
$this->documentService = $documentService;
$this->attachmentService = $attachmentService;
$this->logger = $logger;
$this->setInterval(SessionService::SESSION_VALID_TIME);
}

/**
* @param array $argument
* @return void
*/
protected function run($argument) {
protected function run($argument): void {
$this->logger->debug('Run cleanup job for text documents');
$documents = $this->documentService->getAll();
foreach ($documents as $document) {
Expand All @@ -69,11 +65,10 @@ protected function run($argument) {
continue;
}

if ($this->documentService->hasUnsavedChanges($document)) {
continue;
try {
$this->documentService->resetDocument($document->getId());
} catch (DocumentHasUnsavedChangesException) {
}

$this->documentService->resetDocument($document->getId());
}

$this->logger->debug('Run cleanup job for text sessions');
Expand Down
4 changes: 1 addition & 3 deletions lib/Service/DocumentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,8 @@ public function resetDocument(int $documentId, bool $force = false): void {
$this->stepMapper->deleteAll($documentId);
$this->sessionMapper->deleteByDocumentId($documentId);
$this->documentMapper->delete($document);
$this->getStateFile($documentId)->delete();

if ($force) {
$this->getStateFile($documentId)->delete();
}
$this->logger->debug('document reset for ' . $documentId);
} catch (DoesNotExistException|NotFoundException $e) {
// Ignore if document not found or state file not found
Expand Down