File tree Expand file tree Collapse file tree 1 file changed +21
-3
lines changed
Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -164,9 +164,10 @@ controller to specify the directory in which the brochures should be stored:
164164
165165.. code-block :: yaml
166166
167- # app/config/parameters.yml
167+ # app/config/config.yml
168+
169+ # ...
168170 parameters :
169- # ...
170171 brochures_directory : ' %kernel.root_dir%/../web/uploads/brochures'
171172
172173 There are some important things to consider in the code of the above controller:
@@ -320,14 +321,31 @@ automatically upload the file when persisting the entity::
320321 {
321322 $entity = $args->getEntity();
322323
324+ $this->uploadFile($entity);
325+ }
326+
327+ public function preUpdate(LifecycleEventArs $args)
328+ {
329+ $entity = $args->getEntity();
330+
331+ $this->uploadFile($entity);
332+ }
333+
334+ private function uploadFile($entity)
335+ {
323336 // upload only works for Product entities
324337 if (!$entity instanceof Product) {
325338 return;
326339 }
327340
328341 $file = $entity->getBrochure();
329- $fileName = $this->uploader->upload($file);
330342
343+ // only upload new files
344+ if (!$file instanceof UploadedFile) {
345+ return;
346+ }
347+
348+ $fileName = $this->uploader->upload($file);
331349 $entity->setBrochure($fileName);
332350 }
333351 }
You can’t perform that action at this time.
0 commit comments