From 9769915b349edcd97bb192773b55cd8982fbd6bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Mon, 30 Mar 2020 16:29:31 +0200 Subject: [PATCH] Fixed exception when uploading a file. --- src/EntityListeners/AttachmentDeleteListener.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/EntityListeners/AttachmentDeleteListener.php b/src/EntityListeners/AttachmentDeleteListener.php index 994301da..14735384 100644 --- a/src/EntityListeners/AttachmentDeleteListener.php +++ b/src/EntityListeners/AttachmentDeleteListener.php @@ -77,12 +77,21 @@ class AttachmentDeleteListener public function preUpdateHandler(Attachment $attachment, PreUpdateEventArgs $event): void { if ($event->hasChangedField('path')) { + $old_path = $event->getOldValue('path'); + //Dont delete file if the attachment uses a builtin ressource: - if (Attachment::checkIfBuiltin($event->getOldValue('path'))) { + if (Attachment::checkIfBuiltin($old_path)) { return; } - $file = new SplFileInfo($this->pathResolver->placeholderToRealPath($event->getOldValue('path'))); + $real_path = $this->pathResolver->placeholderToRealPath($old_path); + + //If the attachment does not point to a valid file, ignore it! + if ($real_path === null) { + return; + } + + $file = new SplFileInfo($real_path); $this->attachmentReverseSearch->deleteIfNotUsed($file); } }