From 167e46fea46c1ae54527db70398eab4faaa2344a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sat, 13 Jun 2020 21:55:20 +0200 Subject: [PATCH] Do not delete an file if there is an other attachment remaining after deletion. Fixes issue #71. --- src/EntityListeners/AttachmentDeleteListener.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/EntityListeners/AttachmentDeleteListener.php b/src/EntityListeners/AttachmentDeleteListener.php index ab033e7e..bf17a1fc 100644 --- a/src/EntityListeners/AttachmentDeleteListener.php +++ b/src/EntityListeners/AttachmentDeleteListener.php @@ -131,7 +131,9 @@ class AttachmentDeleteListener $file = $this->attachmentHelper->attachmentToFile($attachment); //Only delete if the attachment has a valid file. if (null !== $file) { - $this->attachmentReverseSearch->deleteIfNotUsed($file); + /* The original file has already been removed, so we have to decrease the threshold to zero, + as any remaining attachment depends on this attachment, and we must not delete this file! */ + $this->attachmentReverseSearch->deleteIfNotUsed($file, 0); } } }