Skip to content

Commit 4965d20

Browse files
committed
fix(hooks): resetDocument gets a fileId use it as such
File ids used to be document ids. But not anymore. In all current calls to `resetDocument` the parameter send actually is a file id. Follow up: Make this generic for all context types.--signoff Signed-off-by: Max <max@nextcloud.com>
1 parent e1c83f3 commit 4965d20

3 files changed

Lines changed: 18 additions & 11 deletions

File tree

cypress/e2e/api/SessionApi.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ describe('The session Api', function() {
289289
.its('status')
290290
.should('eql', 412)
291291

292-
293292
connection.baseVersionEtag = 'wrongBaseVersionEtag'
294293

295294
cy.failToPushSteps({ connection, steps: [messages.update], version })

cypress/support/sessions.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import { push, sync } from '../../src/apis/sync.ts'
1010

1111
const url = Cypress.config('baseUrl').replace(/\/index.php\/?$/g, '')
1212

13-
const expectFailure = () => {
13+
/**
14+
* Callback for requests that are expected to fail.
15+
*/
16+
function expectFailure() {
1417
throw new Error('Expected request to fail - but it succeeded!')
1518
}
1619

lib/Service/DocumentService.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -424,38 +424,43 @@ public function autosave(Document $document, IContext $context, int $version, st
424424
* @throws Exception
425425
* @throws NotPermittedException
426426
*/
427-
public function resetDocument(int $documentId, bool $force = false): void {
427+
public function resetDocument(int $fileId, bool $force = false): void {
428428
try {
429429
$userId = $this->userId;
430430
// If no user is provided we need to get any file from existing mounts for cleanup jobs
431431
if ($userId === null) {
432-
$mounts = $this->userMountCache->getMountsForFileId($documentId);
432+
$mounts = $this->userMountCache->getMountsForFileId($fileId);
433433
$anyMount = array_shift($mounts);
434434
if ($anyMount === null) {
435435
throw new NotFoundException('Could not fallback to file from mounts');
436436
}
437437
$userId = $anyMount->getUser()->getUID();
438438
}
439439

440-
$document = $this->documentMapper->find($documentId);
440+
$document = $this->documentMapper->load('file', $fileId);
441+
if (!$document) {
442+
// no document found for the file in question - so nothing to reset.
443+
$this->logger->info('did not find document for file with id - document not reset.' . $fileId);
444+
return;
445+
}
441446
if (!$force && $this->hasUnsavedChanges($document)) {
442-
$this->logger->debug('did not reset document for ' . $documentId);
447+
$this->logger->debug('did not reset document for file with id' . $fileId);
443448
throw new DocumentHasUnsavedChangesException('Did not reset document, as it has unsaved changes');
444449
}
445450

446451
try {
447-
$file = $this->fileService->getFileById($documentId, $userId);
452+
$file = $this->fileService->getFileById($fileId, $userId);
448453
$this->lockService->unlock($file);
449454
} catch (NotFoundException) {
450455
// Continue with the cleanup even if the file does not exist.
451456
}
452457

453-
$this->stepMapper->deleteAll($documentId);
454-
$this->sessionMapper->deleteByDocumentId($documentId);
458+
$this->stepMapper->deleteAll($document->id);
459+
$this->sessionMapper->deleteByDocumentId($document->id);
455460
$this->documentMapper->delete($document);
456-
$this->getStateFile($documentId)->delete();
461+
$this->getStateFile($document->id)->delete();
457462

458-
$this->logger->debug('document reset for ' . $documentId);
463+
$this->logger->debug('document reset for file with id ' . $fileId);
459464
} catch (DoesNotExistException|NotFoundException) {
460465
// Ignore if document not found or state file not found
461466
}

0 commit comments

Comments
 (0)