Allow to specifiy a path to a builtin ressource via the url field.

This commit is contained in:
Jan Böhmer 2019-09-25 16:03:22 +02:00
parent d99365f906
commit 2001680542
6 changed files with 192 additions and 10 deletions

View file

@ -66,6 +66,11 @@ class AttachmentDeleteListener
public function preUpdateHandler(Attachment $attachment, PreUpdateEventArgs $event)
{
if ($event->hasChangedField('path')) {
//Dont delete file if the attachment uses a builtin ressource:
if (Attachment::checkIfBuiltin($event->getOldValue('path'))) {
return;
}
$file = new \SplFileInfo($this->attachmentHelper->placeholderToRealPath($event->getOldValue('path')));
$this->attachmentReverseSearch->deleteIfNotUsed($file);
}
@ -81,6 +86,11 @@ class AttachmentDeleteListener
*/
public function postRemoveHandler(Attachment $attachment, LifecycleEventArgs $event)
{
//Dont delete file if the attachment uses a builtin ressource:
if (Attachment::checkIfBuiltin($event->getOldValue('path'))) {
return;
}
$file = $this->attachmentHelper->attachmentToFile($attachment);
//Only delete if the attachment has a valid file.
if ($file !== null) {