Skip to content
Prev Previous commit
Next Next commit
chore: Make resetDocument more readable
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliusknorr authored and backportbot-nextcloud[bot] committed Mar 9, 2023
commit dba594d564d4485c84aabe8ca1ac452865ba2b9c
30 changes: 13 additions & 17 deletions lib/Service/DocumentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,30 +375,26 @@ public function autosave(?File $file, int $documentId, int $version, ?string $au
}

/**
* @param $documentId
* @param bool $force
* @throws DocumentHasUnsavedChangesException
* @throws Exception
* @throws NotPermittedException
*/
public function resetDocument(int $documentId, bool $force = false): void {
try {
$this->unlock($documentId);

$document = $this->documentMapper->find($documentId);

if ($force || !$this->hasUnsavedChanges($document)) {
$this->stepMapper->deleteAll($documentId);
$this->sessionMapper->deleteByDocumentId($documentId);
$this->documentMapper->delete($document);

try {
$this->getStateFile($documentId)->delete();
} catch (NotFoundException $e) {
} catch (NotPermittedException $e) {
}
} elseif ($this->hasUnsavedChanges($document)) {
if (!$force && $this->hasUnsavedChanges($document)) {
throw new DocumentHasUnsavedChangesException('Did not reset document, as it has unsaved changes');
}
} catch (DoesNotExistException $e) {

$this->unlock($documentId);

$this->stepMapper->deleteAll($documentId);
$this->sessionMapper->deleteByDocumentId($documentId);
$this->documentMapper->delete($document);

$this->getStateFile($documentId)->delete();
} catch (DoesNotExistException|NotFoundException $e) {
// Ignore if document not found or state file not found
}
}

Expand Down