VichUploaderBundle
VichUploaderBundle copied to clipboard
Uploaded file not registered in Doctrine changeset (onFlush event)
I'm having a problem when uploading a file and trying to get the changeset from the changed entity.
So I've got an Entity where you can upload a file through Vich. Uploading works fine. But I also want to save all the changes made to this entity, since I have 2 websites running that can exchange their content (I need to know what changed on one site to update the other with). I've created an onFlush Listener and in this listener I get the Doctrine UnitOfWork Object to retrieve the entity's changeset with the "getEntityChangeSet" method. I was suprised to see that the uploaded file is not registered in the changeset. I figured the @uploadableField wouldn't be registered, but the I thought the fileNameProperty field would (since this one is saved).
So how does the Vich uploader avoid the onFlush event while the filename is actually saved in the database?
I see that the problem for me was that the 'fileNameProperty' field is not updated until the preUpdate event. I'm going to see if i can get it to work with the preUpdate event. Sorry for this post. Hope my comment can help anyone else.
I found out I do still have a problem, in the preUpdate event i cannot save a field that is not in the changeset. This means i cannot save my changeset in a separate field.
The changeset should be recomputed once the upload is performed by the bundle (see the UploadListener and the Adapter doing the job)
I'll try do do a few tests to see if I can reproduce your issue but any help on this would be appreciated :)