summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwebchick <webchick@24967.no-reply.drupal.org>2011-06-14 04:27:14 -0400
committerwebchick <webchick@24967.no-reply.drupal.org>2011-06-14 04:27:14 -0400
commit6bca3db38b7baa8e1e1340ca8cb5bda1ff67e2e5 (patch)
tree877dab4958ada7b2dc3c84bf0f61850867e82ebf
parent078dc10b2ac4b6d4edbc1c73cb9834f521b0b762 (diff)
downloadbrdo-6bca3db38b7baa8e1e1340ca8cb5bda1ff67e2e5.tar.gz
brdo-6bca3db38b7baa8e1e1340ca8cb5bda1ff67e2e5.tar.bz2
Issue #1115510 by catch, barbi, amateescu: Fixed Entity providing modules must call field_attach_delete_bundle() in hook_uninstall().
-rw-r--r--modules/comment/comment.install1
-rw-r--r--modules/field/field.attach.inc6
-rw-r--r--modules/taxonomy/taxonomy.install5
-rw-r--r--modules/taxonomy/taxonomy.test34
4 files changed, 44 insertions, 2 deletions
diff --git a/modules/comment/comment.install b/modules/comment/comment.install
index d64b3acde..120467fd0 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.attach.inc b/modules/field/field.attach.inc
index 4ca15f543..6ec95c73a 100644
--- a/modules/field/field.attach.inc
+++ b/modules/field/field.attach.inc
@@ -1333,8 +1333,10 @@ function field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new) {
* The bundle to delete.
*/
function field_attach_delete_bundle($entity_type, $bundle) {
- // First, delete the instances themseves.
- $instances = field_info_instances($entity_type, $bundle);
+ // First, delete the instances themselves. field_read_instances() must be
+ // used here since field_info_instances() does not return instances for
+ // disabled entity types or bundles.
+ $instances = field_read_instances(array('entity_type' => $entity_type, 'bundle' => $bundle), array('include_inactive' => 1));
foreach ($instances as $instance) {
field_delete_instance($instance);
}
diff --git a/modules/taxonomy/taxonomy.install b/modules/taxonomy/taxonomy.install
index f28ffedf4..56b7e01c6 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 1fd47f5ea..97cfe448f 100644
--- a/modules/taxonomy/taxonomy.test
+++ b/modules/taxonomy/taxonomy.test
@@ -350,6 +350,40 @@ 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.
+ $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'));
+ 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. Creating a new field with the same name and
+ // an instance of this field on the same bundle name should be successful.
+ unset($this->vocabulary->vid);
+ taxonomy_vocabulary_save($this->vocabulary);
+ unset($this->field['id']);
+ field_create_field($this->field);
+ field_create_instance($this->instance);
+ }
}
/**