The subject says it all.

  1. Create a webform with a file upload component
  2. Submit the form specifying a file to be uploaded
  3. Go to the submission to confirm the file is there
  4. Delete the submission
  5. Watch the file being kept on the webform files directory
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

Status: Active » Postponed (maintainer needs more info)

I 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:

/**
 * Implements _webform_delete_component().
 */
function _webform_delete_file($component, $value) {
  // Delete an individual submission file.
  if (!empty($value[0]) && ($file = webform_get_file($value[0]))) {
    unlink($file->filepath);
    db_query("DELETE FROM {files} WHERE fid = '%d'", $file->fid);
  }
}
quicksketch’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)
meerkat’s picture

I've got the same problem in 7.x-3.15.

The delete file function below definitely being called when the submission is deleted:

function _webform_delete_file($component, $value) {
  // Delete an individual submission file.
  if (!empty($value[0]) && ($file = webform_get_file($value[0]))) {
    file_delete($file);
  }
}

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

[webform] => Array
        (
            [submission] => Array
                (
                    [8] => 1
                )

        )

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.

overtune’s picture

Version: 6.x-3.14 » 7.x-4.0-alpha2
Status: Closed (cannot reproduce) » Active

It'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).

quicksketch’s picture

Thanks 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.

Liam Morland’s picture

Version: 7.x-4.0-alpha2 » 7.x-4.x-dev
Component: User interface » Code
Status: Active » Needs review
FileSize
448 bytes

The 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.

Liam Morland’s picture

The 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.

quicksketch’s picture

Status: Needs review » Fixed
FileSize
1.26 KB

Thanks Liam! This patch needs to be applied to 3.x also, so I applied this backport also. Committed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.