Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.3k
[cookbook] fixed file uploads with Doctrine samples to upload the file wh#564
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
cookbook/doctrine/file_uploads.rst Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
probably meant "updated" :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thanks fixed.
weaverryan commentedJul 27, 2011
Hey Hugo! Ok, so you're definitely correct with this PR, but to be a truly functional system, should we also include something that would handle unlinking the old file when a new file is updated? I believe with this, each time you "update" the record by uploading a new file, the old file will still remain on the filesystem. Thoughts? |
…e when the object is both persisted and updated. Added a note about PrePersist, PreUpdate, PostPersist and PostUpdate lifecycle callback events.
hhamon commentedJul 27, 2011
Hi Ryan, I'm ready with this PR. I have fixed it and tested it while I was giving a training. We were trying the file uploads with Doctrine and we noticed the update was not proceeded because of the missing @PreUpdate and@postupdate lifecycle callbacks. You can merge the PR and then I will open a new PR to remove the old file on the filesystem in case of the entity is updated with a new file upload with a different name. Cheers. |
hhamon commentedJul 28, 2011
In fact, don't merge it now... I need to recheck the code. |
hhamon commentedJul 28, 2011
So I rechecked and the code is good but there is a "bug" in Doctrine2. The pre and post update callbacks are only called if at least one property of the object has changed. If we try to only change the uploaded file without changing the other properties, the callbacks are not called... and that sucks... I will add a note in the PR. |
stof commentedJul 28, 2011
it is not a bug but a feature. The update event is dispatched only if the entity is updated, not for all entities that were queried during the request. |
hhamon commentedJul 28, 2011
Yes it's a feature and a quite logic behavior. Nevertheless, if we want to trigger the callbacks we have to use a hack. For example, we can rely on an updatedAt field in the entity that is changed everytime the file is uploaded. But it's still a hack and it's probably not the best solution to consider the lifecycle callbacks when dealing with file uploads and doctrine entities... |
[cookbook] fixed file uploads with Doctrine samples to upload the file wh
weaverryan commentedJul 30, 2011
Hi Hugo! Thanks for the good research, I understand the problem. I've merged in this PR - the entry is obviously not perfect yet, but it's better. I've added a caution message temporarily:808da21 Perhaps this is a conversation for the dev-board. What we need is an agreed-upon "best practice" for this situation. So far, the example in this entry really doesn't fully solve the problem. Thanks! |
weaverryan commentedJul 30, 2011
Also see#600, so we can keep this on our radar. |
hhamon commentedJul 31, 2011
Great! Thanks Ryan ;) |
lancergr commentedJul 11, 2012
I think that another solution that may be included in the documentation is to update the already existing path field instead of using "updatedAt": |
murilolobato commentedMay 26, 2014
I'm having a problem with the following situation: On the edit screen of a entity that has OneToOne association to documents, if I click save without adding an image a register is created at the database on document, but path stays null, because i did not selected the image. What I want is dont create any entry on the 'document' table. Is there a way to do this? |
[cookbook] fixed file uploads with Doctrine samples to upload the file when the object is both persisted and updated. Added a note about PrePersist, PreUpdate, PostPersist and PostUpdate lifecycle callback events.