In the install hook, my module installs a vocabulary and attaches an image field to any of the terms. That works fine.

However when I run hook_uninstall, images created along with terms for my vocabulary don't get deleted. When I delete a term via the taxonomy admin UI, the (non-temporary) managed image file gets removed from the files directory as well as the file_managed table as expected.

I tried the following sequences in my hook_uninstall:

  • 1. Iterate through terms for my vocabulary
    2. file_load the image
    3. file_delete the image
    4. field_delete_field any of the fields installed in hook_install
    5. field_delete_instance any of the fields installed in hook_install
    6. taxonomy_vocabulary_delete my vocabulary

    Result: the vocabulary terms get deleted but not the files uploaded to the files directory. The file_managed table entries don't get removed either.

  • 1. Iterate through terms for my vocabulary
    2. taxonomy_term_delete the terms
    3. field_delete_field any of the fields installed in hook_install
    4. field_delete_instance any of the fields installed in hook_install
    5. taxonomy_vocabulary_delete my vocabulary

    Result: the vocabulary terms as well as the managed files get deleted as expected.

So the second sequence does the job for me. It still strikes me as the wrong behaviour though. Why do I need to explicitly call taxonomy_term_delete when this should be handled as part of taxonomy_vocabulary_delete? What is different between me calling taxonomy_term_delete and taxonomy_vocabulary_delete doing exactly the same thing?

The first approach works for me for uninstalling image fields attached to a node (aka bundle). Why shouldn't this work exactly the same way for fields attached to a taxonomy term?

It's probably not a major issue at all just some inconsistency which I noticed (unless I'm doing something wrong) which would be good to get clarified.

Comments

aspilicious’s picture

A lot has changed with regards to fields and uninstallation. Could you try to reproduce your problem with latest dev version of drupal. (you also can wait for the new release that will come to you in a week)

xjm’s picture

I believe this is a duplicate of another issue, though I am not able to find it right now.

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.