Skip to content

Commit 6f92136

Browse files
fix(service): handle null node id when deleting physical file
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 5dd4a30 commit 6f92136

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

lib/Service/FileService.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
use OCP\IUserManager;
4747
use Psr\Log\LoggerInterface;
4848
use stdClass;
49+
use TypeError;
4950

5051
/**
5152
* @psalm-import-type LibresignEnvelopeChildFile from ResponseDefinitions
@@ -660,22 +661,22 @@ public function delete(int $fileId, bool $deleteFile = true): void {
660661
$this->idDocsMapper->deleteByFileId($file->getId());
661662
$this->fileMapper->delete($file);
662663
if ($deleteFile) {
663-
if ($file->getSignedNodeId()) {
664-
try {
665-
$signedNextcloudFile = $this->folderService->getFileByNodeId($file->getSignedNodeId());
666-
$parentFolder = $signedNextcloudFile->getParent();
667-
$signedNextcloudFile->delete();
668-
$this->deleteEmptyFolder($parentFolder);
669-
} catch (NotFoundException) {
670-
}
671-
}
672-
try {
673-
$nextcloudFile = $this->folderService->getFileByNodeId($file->getNodeId());
674-
$parentFolder = $nextcloudFile->getParent();
675-
$nextcloudFile->delete();
676-
$this->deleteEmptyFolder($parentFolder);
677-
} catch (NotFoundException) {
678-
}
664+
$this->deletePhysicalFileIfPossible($file->getSignedNodeId());
665+
$this->deletePhysicalFileIfPossible($file->getNodeId());
666+
}
667+
}
668+
669+
private function deletePhysicalFileIfPossible(?int $nodeId): void {
670+
if ($nodeId === null) {
671+
return;
672+
}
673+
674+
try {
675+
$nextcloudFile = $this->folderService->getFileByNodeId($nodeId);
676+
$parentFolder = $nextcloudFile->getParent();
677+
$nextcloudFile->delete();
678+
$this->deleteEmptyFolder($parentFolder);
679+
} catch (NotFoundException|TypeError) {
679680
}
680681
}
681682

0 commit comments

Comments
 (0)