Skip to content

Commit c1715e8

Browse files
committed
chore: Make resetDocument more readable
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1 parent 4277d5c commit c1715e8

1 file changed

Lines changed: 13 additions & 17 deletions

File tree

lib/Service/DocumentService.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -375,30 +375,26 @@ public function autosave(?File $file, int $documentId, int $version, ?string $au
375375
}
376376

377377
/**
378-
* @param $documentId
379-
* @param bool $force
380378
* @throws DocumentHasUnsavedChangesException
379+
* @throws Exception
380+
* @throws NotPermittedException
381381
*/
382382
public function resetDocument(int $documentId, bool $force = false): void {
383383
try {
384-
$this->unlock($documentId);
385-
386384
$document = $this->documentMapper->find($documentId);
387-
388-
if ($force || !$this->hasUnsavedChanges($document)) {
389-
$this->stepMapper->deleteAll($documentId);
390-
$this->sessionMapper->deleteByDocumentId($documentId);
391-
$this->documentMapper->delete($document);
392-
393-
try {
394-
$this->getStateFile($documentId)->delete();
395-
} catch (NotFoundException $e) {
396-
} catch (NotPermittedException $e) {
397-
}
398-
} elseif ($this->hasUnsavedChanges($document)) {
385+
if (!$force && $this->hasUnsavedChanges($document)) {
399386
throw new DocumentHasUnsavedChangesException('Did not reset document, as it has unsaved changes');
400387
}
401-
} catch (DoesNotExistException $e) {
388+
389+
$this->unlock($documentId);
390+
391+
$this->stepMapper->deleteAll($documentId);
392+
$this->sessionMapper->deleteByDocumentId($documentId);
393+
$this->documentMapper->delete($document);
394+
395+
$this->getStateFile($documentId)->delete();
396+
} catch (DoesNotExistException|NotFoundException $e) {
397+
// Ignore if document not found or state file not found
402398
}
403399
}
404400

0 commit comments

Comments
 (0)