From 9f19ce6cb46969fcb9344ddadbc3be879857aae8 Mon Sep 17 00:00:00 2001 From: Loulier Guillaume Date: Fri, 13 Jan 2017 10:40:14 +0100 Subject: [PATCH 1/4] [Validations] Check if the entity contains the files After many tests, it seems that if the entity does not contains the files, the event throw a Exception, by checking the presence of files, the exception isn't thrown and the process can continue, this can be usefull if the entity isn't linked with file or if the file was stored into an array but not needed at this time. The return isn't needed after the if statement. --- controller/upload_file.rst | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/controller/upload_file.rst b/controller/upload_file.rst index 8971c6f5806..5be48e1273d 100644 --- a/controller/upload_file.rst +++ b/controller/upload_file.rst @@ -442,10 +442,17 @@ controller. public function postLoad(LifecycleEventArgs $args) { $entity = $args->getEntity(); - - $fileName = $entity->getBrochure(); - - $entity->setBrochure(new File($this->targetPath.'/'.$fileName)); + + // Only for tests purpose and proper object validation + if (!$entity instanceof ObjectWanted) { + return; + } + + if ($entity->getBrochure()) { + $fileName = $entity->getBrochure(); + + $entity->setBrochure(new File($this->targetPath.'/'.$fileName)); + } } } From 0b779f9817f4fa804aa1eeb682f9b10e8dfc7031 Mon Sep 17 00:00:00 2001 From: Loulier Guillaume Date: Sun, 15 Jan 2017 09:40:47 +0100 Subject: [PATCH 2/4] Update upload_file.rst --- controller/upload_file.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/controller/upload_file.rst b/controller/upload_file.rst index 5be48e1273d..66e455c5fe4 100644 --- a/controller/upload_file.rst +++ b/controller/upload_file.rst @@ -443,8 +443,7 @@ controller. { $entity = $args->getEntity(); - // Only for tests purpose and proper object validation - if (!$entity instanceof ObjectWanted) { + if (!$entity instanceof Product) { return; } From 13908eb3cb464eb63dcd80be38ae5665c7b23b5a Mon Sep 17 00:00:00 2001 From: Loulier Guillaume Date: Sun, 15 Jan 2017 09:56:19 +0100 Subject: [PATCH 3/4] Update upload_file.rst --- controller/upload_file.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/controller/upload_file.rst b/controller/upload_file.rst index 66e455c5fe4..5278ff55ce2 100644 --- a/controller/upload_file.rst +++ b/controller/upload_file.rst @@ -444,13 +444,13 @@ controller. $entity = $args->getEntity(); if (!$entity instanceof Product) { - return; + return; } if ($entity->getBrochure()) { - $fileName = $entity->getBrochure(); + $fileName = $entity->getBrochure(); - $entity->setBrochure(new File($this->targetPath.'/'.$fileName)); + $entity->setBrochure(new File($this->targetPath.'/'.$fileName)); } } } From f9ee895e841be38dcd782cee96d6b17c2544ecde Mon Sep 17 00:00:00 2001 From: Loulier Guillaume Date: Fri, 20 Jan 2017 15:25:04 +0100 Subject: [PATCH 4/4] Update upload_file.rst --- controller/upload_file.rst | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/controller/upload_file.rst b/controller/upload_file.rst index 5278ff55ce2..1c3ed682c1d 100644 --- a/controller/upload_file.rst +++ b/controller/upload_file.rst @@ -447,9 +447,7 @@ controller. return; } - if ($entity->getBrochure()) { - $fileName = $entity->getBrochure(); - + if ($fileName = $entity->getBrochure()) { $entity->setBrochure(new File($this->targetPath.'/'.$fileName)); } }