Images attached to content are not being cleaned up upon delete. One line patch here fixes it.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dries’s picture

Status: Needs review » Reviewed & tested by the community

Care to provide a bit more context? That would help the review process.

moshe weitzman’s picture

Status: Reviewed & tested by the community » Needs review

if you delete an article that has an uploaded image, the image is not deleted. the cause is a check in file_get_file_reference_count() that should be true but it is comparing image == file. the attached patch skips that check as it is not needed.

i asked quicksketch to review this.

Status: Needs review » Needs work

The last submitted patch, image_del.diff, failed testing.

quicksketch’s picture

Status: Needs work » Needs review

So this has a bit of a long function chain, but here's the basic idea: Image module depends on File module and pretty much just reuses all File module's hook_field_* functions exactly. Unfortunately File module has a small bias that assumes that you're going to be working with fields of type "file" as opposed to other types (like "image"), causing images to not be deleted when the parent node is deleted.

As a sort of stack trace:
image_field_delete() ->
file_field_delete() ->
file_field_delete_file() ->
file_get_file_reference_count()

Since file_get_file_reference_count() defaults to restricting $field_type == 'file', it doesn't count references of other field types properly. As an alternative to changing the function signature though, we could simply pass NULL into file_get_file_reference_count() from file_field_delete_file().

quicksketch’s picture

Status: Needs review » Needs work

Crosspost. Maybe altering the call in file_field_delete_file() would be a safer change, since it doesn't modify the function signature.

quicksketch’s picture

Status: Needs work » Needs review
FileSize
945 bytes

Updates the one call to file_get_file_reference_count() that was working off the assumption of $field_type = 'file'.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

works for me.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the clarifications. That helps me focus on investigating the surrounding/affected code. Committed to CVS HEAD.

Status: Fixed » Closed (fixed)

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