function merci_uninstall in MERCI (Manage Equipment Reservations, Checkout and Inventory) 6.2
Same name and namespace in other branches
- 6 merci.install \merci_uninstall()
- 7.2 merci.install \merci_uninstall()
Implementation of hook_uninstall().
File
- ./merci.install, line 23 
- merci Installer / Uninstaller
Code
function merci_uninstall() {
  // Delete the vocabulary.
  $vid = variable_get('merci_equipment_grouping_vid', '');
  taxonomy_del_vocabulary($vid);
  // Need to load the CCK include file where content_field_instance_create() is defined.
  module_load_include('inc', 'content', 'includes/content.crud');
  $results = db_query("SELECT field_name,type_name FROM {" . content_instance_tablename() . "} WHERE type_name = 'merci_reservation'");
  while ($field = db_fetch_array($results)) {
    content_field_instance_delete($field['field_name'], $field['type_name'], FALSE);
  }
  // Force the caches and static arrays to update to the new info.
  content_clear_type_cache(TRUE);
  // Remove all MERCI variables.
  $variables = db_query("SELECT name FROM {variable} WHERE name LIKE 'merci_%'");
  while ($variable = db_fetch_object($variables)) {
    variable_del($variable->name);
  }
  // Remove all MERCI all associated nodes
  //No longer removes content types
  $content_types = db_query("SELECT type FROM {merci_node_type} WHERE merci_type_setting <> 'disabled'");
  while ($content_type = db_fetch_object($content_types)) {
    $nodes = db_query(db_rewrite_sql("SELECT nid FROM {node} n WHERE type = '%s'"), $content_type->type);
    while ($node = db_fetch_object($nodes)) {
      node_delete($node->nid);
    }
    //node_type_delete($content_type->type);
  }
  // Remove the programatically created reservation node type
  // and all associated nodes.
  $nodes = db_query(db_rewrite_sql("SELECT nid FROM {node} n WHERE type = 'merci_reservation'"));
  while ($node = db_fetch_object($nodes)) {
    node_delete($node->nid);
  }
  node_type_delete('merci_reservation');
  // You'd think the uninstall submit function would take care of this
  // but it doesn't look like it.
  node_types_rebuild();
  menu_rebuild();
  // Remove tables.
  drupal_uninstall_schema('merci');
}