Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The subject says it all.
- Create a webform with a file upload component
- Submit the form specifying a file to be uploaded
- Go to the submission to confirm the file is there
- Delete the submission
- Watch the file being kept on the webform
files
directory
Comment | File | Size | Author |
---|---|---|---|
#8 | webform_file_delete_update-7x-3x.patch | 1.26 KB | quicksketch |
#7 | webform_file_delete_update_1305308.patch | 1.06 KB | Liam Morland |
#6 | webform_file_delete_1305308.patch | 448 bytes | Liam Morland |
Comments
Comment #1
quicksketchI can't confirm this problem on either Drupal 6 or Drupal 7. Both properly delete a file when the submission is deleted. Do you have any other webform-related modules installed?
This is the code that does the deletion, looks like it's working properly:
Comment #2
quicksketchComment #3
meerkat CreditAttribution: meerkat commentedI've got the same problem in 7.x-3.15.
The delete file function below definitely being called when the submission is deleted:
However, file_delete() uses file_usage_list() to check if the file is in use, if it is then an array is returned and the file is not deleted.
In my test case file_delete() is returning
and the file is not deleted.
If my observation is correct I think there two solutions - bludgeon file_delete() into deleting the file by using the $force parameter or get webform to release the file before calling file delete.
btw, I'm very much liking the Ajax file upload in the latest dev version.
Comment #4
overtune CreditAttribution: overtune commentedIt's the same problem with 7.x-4.0-alpha2.
Uploaded files doesnt gets deleted when deleting the submission. I have tested both with public and private files.
(The files arent used anywhere else then in just that submission).
Comment #5
quicksketchThanks guys, I think you're correct. Ever since we switched to using the managed_file element we haven't been removing records from the file_usage table, and therefor files aren't getting deleted. :(
Fortunately we can clean up our records with an update hook and clean up all the ones that have been lingering.
Comment #6
Liam MorlandThe attached patch adds a call to file_usage_delete() so that uploaded files get deleted when their submission is deleted or results are cleared. This does not clean-up files left over from submissions already deleted.
Comment #7
Liam MorlandThe attached patch creates an update hook to clean up files left over from submissions that have been deleted. This patch must be applied along with the patch in #6.
Comment #8
quicksketchThanks Liam! This patch needs to be applied to 3.x also, so I applied this backport also. Committed.