You are here

function event_calendar_uninstall in Event Calendar 7

Implements hook_uninstall().

We are using hook_uninstall() to delete our node content type and its fields

See also

field_delete_instance()

field_delete_field()

taxonomy_term_delete()

variable_del()

File

./event_calendar.install, line 56
install file for Event Calendar module.

Code

function event_calendar_uninstall() {
  $node_type = variable_get('event_calendar_node_type', 'event_calendar');

  // Delete content type and all fields.
  $instances = field_info_instances('node', $node_type);
  foreach ($instances as $instance_name => $instance) {
    field_delete_instance($instance);
  }
  $instances = field_info_instances('node', $node_type);
  foreach ($instances as $instance_name => $instance) {
    field_delete_field($instance);
  }
  $result = db_query("SELECT nid FROM {node} AS n WHERE n.type = '{$node_type}'");
  foreach ($result as $record) {
    node_delete($record->nid);
  }
  node_type_delete($node_type);

  // Delete peristant variables that control settings.
  variable_del('node_preview_' . $node_type);
  variable_del('node_options_' . $node_type);
  variable_del('node_submitted_' . $node_type);
  variable_del('comment_' . $node_type);
  variable_del('event_calendar_node_type');

  // Delete all terms associated with status vocabulary.
  $vid = db_query('SELECT vid FROM {taxonomy_vocabulary} WHERE machine_name = ' . ':machine_name', array(
    ':machine_name' => TAXONOMY_TYPE,
  ))
    ->fetchField();
  $terms = taxonomy_get_tree($vid);
  if ($terms) {
    foreach ($terms as $key => $tid) {
      taxonomy_term_delete($tid->tid);
    }
  }

  // Delete vocabulary.
  taxonomy_vocabulary_delete($vid);

  // Rebuild database cache of node types.
  node_types_rebuild();

  // Rebuild database cache of menus.
  menu_rebuild();
}