From a5aa15b13847fa823965ca0133d5cf480d30f5ce Mon Sep 17 00:00:00 2001 From: Matthew Thomas Date: Fri, 19 Jan 2018 11:04:34 +0000 Subject: [PATCH 1/3] Post Load Event Listener I've noticed a scenario (a bit of an edge case when uploading imagery). If you have an entity (say a brochure) but you can give it a title and an image and the image title can be updated without the image being updated (the file type is not an UploadedFile but a File on save it'll persist the full file path instead of the desired filename. The above is a safety measure to ensure the above. --- controller/upload_file.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/controller/upload_file.rst b/controller/upload_file.rst index dda7491124d..797285ee561 100644 --- a/controller/upload_file.rst +++ b/controller/upload_file.rst @@ -321,6 +321,7 @@ automatically upload the file when persisting the entity:: namespace App\EventListener; use Symfony\Component\HttpFoundation\File\UploadedFile; + use Symfony\Component\HttpFoundation\File\File; use Doctrine\ORM\Event\LifecycleEventArgs; use Doctrine\ORM\Event\PreUpdateEventArgs; use App\Entity\Product; @@ -362,6 +363,10 @@ automatically upload the file when persisting the entity:: if ($file instanceof UploadedFile) { $fileName = $this->uploader->upload($file); $entity->setBrochure($fileName); + } elseif($file instanceof File) { + // prevents the full file path being saved on updates + // as the path is set on the postLoad listener + $entity->setBrocure($file->getFilename()); } } } From 8f67315c82c931ae46092ef8c47ed04f3b04537b Mon Sep 17 00:00:00 2001 From: Matthew Thomas Date: Fri, 19 Jan 2018 14:04:21 +0000 Subject: [PATCH 2/3] Pr feedback --- controller/upload_file.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controller/upload_file.rst b/controller/upload_file.rst index 797285ee561..80f67ec5f4a 100644 --- a/controller/upload_file.rst +++ b/controller/upload_file.rst @@ -363,7 +363,7 @@ automatically upload the file when persisting the entity:: if ($file instanceof UploadedFile) { $fileName = $this->uploader->upload($file); $entity->setBrochure($fileName); - } elseif($file instanceof File) { + } elseif ($file instanceof File) { // prevents the full file path being saved on updates // as the path is set on the postLoad listener $entity->setBrocure($file->getFilename()); From caf5455a9ab60a60132c8c315a9e9f3fd0e52261 Mon Sep 17 00:00:00 2001 From: Matthew Thomas Date: Sat, 20 Jan 2018 16:47:09 +0000 Subject: [PATCH 3/3] Pr feedback --- controller/upload_file.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controller/upload_file.rst b/controller/upload_file.rst index 80f67ec5f4a..405f57631fd 100644 --- a/controller/upload_file.rst +++ b/controller/upload_file.rst @@ -366,7 +366,7 @@ automatically upload the file when persisting the entity:: } elseif ($file instanceof File) { // prevents the full file path being saved on updates // as the path is set on the postLoad listener - $entity->setBrocure($file->getFilename()); + $entity->setBrochure($file->getFilename()); } } }