If a field or instance is inactive, the normal CCK crud function used by update_api_content_field_delete() won't delete it. This can be an issue when using the Features module, for instance, where a field that is removed from a feature gets marked inactive but not totally deleted, especially if you have changed your mind about a field and added, but then removed, it from a feature.
You could get around this by adding the following code to update_api_content_field_delete before attempting to delete the field which will re-active the field and instance before attempting to delete them. If it is already active it won't hurt anything, but if it is inactive it will ensure the delete will work as you expect it to. You have to clear the content type cache after updating the database or the new values won't get used:
db_query("UPDATE {content_node_field} SET active=1 WHERE field_name='%s'", $field_name);
db_query("UPDATE {content_node_field_instance} SET widget_active=1 WHERE field_name='%s' and type_name='%s'", $field_name, $type_name);
content_clear_type_cache();
Comments
Comment #1
wojtha commentedI had to solve the same problem yesterday, but without knowledge that any Update API exists. Here is my approach. The code is bit ugly since I needed to fix the site asap and I was writing it just for internal use.
The code is bit safer than just updating the "active property". It checks if the field's and widget's modules exists before reactivation and deletion.