Skip to content
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

Cookbook - File Uploads with Doctrine - removeUpload at PreRemove #712

Closed
sricardo opened this issue Sep 19, 2011 · 3 comments
Closed

Cookbook - File Uploads with Doctrine - removeUpload at PreRemove #712

sricardo opened this issue Sep 19, 2011 · 3 comments

Comments

@sricardo
Copy link

In the section "Using the id as the filename", it seems that the callback of the removeUpload() function should be at PreRemove instead of PostRemove, because we will not be able to retrieve the id.

@craue
Copy link
Contributor

craue commented Oct 6, 2011

Indeed, $this->id is already null when removeUpload() is called for the PostRemove event and thus the generated path is invalid. But deleting the file on PreRemove doesn't seem to be a good solution for me because the file would have been deleted even if an error occurs while removing the entity from the database, right?

@craue
Copy link
Contributor

craue commented Oct 6, 2011

One option could be to add a method for PreRemove temporarily saving the path (using the id still available) into a private variable which is then used to delete the file on PostRemove.

weaverryan added a commit that referenced this issue Apr 29, 2012
@weaverryan
Copy link
Member

Hi guys!

@craue you're absolutely right with your concern - only in PostRemove can we safely delete the file. It's not pretty, but the only responsible way to work around it is as you suggested - to store the path in PreRemove and then use it in PostRemove. I've made this change.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants