diff --git a/modules/comment/comment.install b/modules/comment/comment.install index 1dd67f4..dc051c3 100644 --- a/modules/comment/comment.install +++ b/modules/comment/comment.install @@ -16,6 +16,7 @@ function comment_uninstall() { variable_del('comment_block_count'); $node_types = array_keys(node_type_get_types()); foreach ($node_types as $node_type) { + field_attach_delete_bundle('comment', 'comment_node_' . $node_type); variable_del('comment_' . $node_type); variable_del('comment_anonymous_' . $node_type); variable_del('comment_controls_' . $node_type); diff --git a/modules/field/field.module b/modules/field/field.module index b808e59..6e8d6cf 100644 --- a/modules/field/field.module +++ b/modules/field/field.module @@ -379,6 +379,11 @@ function field_cron() { */ function field_modules_uninstalled($modules) { module_load_include('inc', 'field', 'field.crud'); + // When modules are uninstalled they may delete bundles that have instances + // attached. Try to remove those instances. + $limit = variable_get('field_purge_batch_size', 10); + field_purge_batch($limit); + foreach ($modules as $module) { // TODO D7: field_module_delete is not yet implemented // field_module_delete($module); diff --git a/modules/taxonomy/taxonomy.install b/modules/taxonomy/taxonomy.install index 10009d6..b67f18b 100644 --- a/modules/taxonomy/taxonomy.install +++ b/modules/taxonomy/taxonomy.install @@ -12,6 +12,11 @@ function taxonomy_uninstall() { // Remove variables. variable_del('taxonomy_override_selector'); variable_del('taxonomy_terms_per_page_admin'); + // Remove taxonomy_term bundles. + $vocabularies = db_query("SELECT machine_name FROM {taxonomy_vocabulary}")->fetchCol(); + foreach ($vocabularies as $vocabulary) { + field_attach_delete_bundle('taxonomy_term', $vocabulary); + } } /** diff --git a/modules/taxonomy/taxonomy.test b/modules/taxonomy/taxonomy.test index 1fd47f5..d8e652a 100644 --- a/modules/taxonomy/taxonomy.test +++ b/modules/taxonomy/taxonomy.test @@ -350,6 +350,39 @@ class TaxonomyVocabularyUnitTest extends TaxonomyWebTestCase { // Check that the field instance is still attached to the vocabulary. $this->assertTrue(field_info_instance('taxonomy_term', 'field_test', $new_name), t('The bundle name was updated correctly.')); } + + /** + * Test uninstall and reinstall of the taxonomy module. + */ + function testUninstallReinstall() { + // Fields and field instances attached to taxonomy term bundles should be + // removed when the module is uninstalled. Attach a text field to a bundle + // to ensure this happens. + $this->field_name = drupal_strtolower($this->randomName() . '_field_name'); + $this->field = array('field_name' => $this->field_name, 'type' => 'text', 'cardinality' => 4); + $this->field = field_create_field($this->field); + $this->field_id = $this->field['id']; + $this->instance = array( + 'field_name' => $this->field_name, + 'entity_type' => 'taxonomy_term', + 'bundle' => $this->vocabulary->machine_name, + 'label' => $this->randomName() . '_label', + ); + field_create_instance($this->instance); + + module_disable(array('taxonomy')); + require_once DRUPAL_ROOT . '/includes/install.inc'; + drupal_uninstall_modules(array('taxonomy')); + field_purge_batch(10); + module_enable(array('taxonomy')); + + // Now create a vocabulary with the same name. All field instances + // connected to this vocabulary name should have been removed when the + // module was uninstalled. + unset($this->vocabulary->vid); + taxonomy_vocabulary_save($this->vocabulary); + field_create_instance($this->instance); + } } /**