-
Notifications
You must be signed in to change notification settings - Fork 518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upload is not performed if there is no change in the entity #297
Comments
I personnaly use FormEvents to achieve this change automatically. Example: class ApplicationType extends AbstractType
{
...
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name')
->add('icon', 'file', array(
'required' => false,
));
$builder->get('icon')->addEventListener(FormEvents::POST_SUBMIT, function(FormEvent $e){
if(!empty($e->getData())){
/** @var Application $app */
$app = $e->getForm()->getParent()->getData();
$app->setUpdateAt(new \DateTime());
}
});
}
...
} This code simply checks if the I guess it will be possible to consider the creation of a dedicated form type Another and complementary form type could also check if the form entity implements a given interface, in charge to update the |
The thing is I don't want to rely on this kind of "hack". We should not have to ask the user to write boilerplate code/implement an interface/add a "updated at" field. |
if we use update date in entity setter as in example
this is execute in each time where entity is loaded. if after call $em->flush() updatedAt field will be updated in db - one query for each entity. |
@rik43 you must check if File is an UploadedFile. See #8 (comment) |
good idea, thanks |
Add 'instanceof' check as written here: dustin10#8 (comment) to avoid this issue dustin10#297 (comment)
Is there a chance you fix this issue one day ? Reproduced using :
|
This is the wrong question. |
Ok, but this issue was opened 5 years ago... I you (we) don't manage to fix it, maybe you (we) should change this part of documentation :
|
@acantepie it's already documented just 4 lines after |
just ran into this issue. bundle version: 1.19.1 wanting to add in that if the update/created blamable/timestampable values are managed by something like doctrine extensions, that is not enough to trigger the uploader/clean-listener. ended up making a "dummy" column in the table to just always update as part of the request processing
|
That's probably a matter of priority in Doctrine listeners |
Hi, I want to add a comment after having been through the issue of file not uploaded for new entity. It may affect you if you're using translatable in any of the field on the entity. After further checking it seems that translatable will trigger a persist early on the form lifecycle (the |
When using doctrine, event listeners are not called if there have been no column changed. It's a problem because we precisely depend on these events to be fired to handle the uploads.
Right now, we use some boilerplate code to artificially trigger a change in the entity whenever a file is uploaded (by updating the
created_at
column for instance).I'd like to find an other way to fix this issue.
The text was updated successfully, but these errors were encountered: