@@ -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