You are here

function classified_uninstall in Classified Ads 7.3

Same name and namespace in other branches
  1. 6.3 classified.install \classified_uninstall()

Implements hook_uninstall().

  • remove vocabulary and its terms,
  • remove fields,
  • remove nodes,
  • remove module variables.

Permissions/role mapping removal is handled by core in D7: http://drupal.org/node/306027

File

./classified.install, line 245
Install file for the Classified Ads module.

Code

function classified_uninstall() {
  drupal_load('module', 'classified');
  $vid = _classified_get('vid');
  $t = get_t();
  if ($vid) {

    // In some broken situations, the vocabulary may be already deleted, so we
    // avoid choking on its failed deletion.
    $vocabulary = taxonomy_vocabulary_load($vid);
    if ($vocabulary !== FALSE) {
      taxonomy_vocabulary_delete($vid);
      drupal_set_message($t('Removed Classified Ads vocabulary and terms.'));
    }
    else {
      drupal_set_message($t('Classified Ads vocabulary was already removed.'));
    }
  }
  else {
    drupal_set_message($t('Could not find a Classified Ads vocabulary to remove.'), 'warning');
  }

  // Delete our fields.
  field_delete_instance(array(
    'field_name' => 'body',
    'entity_type' => 'node',
    'bundle' => 'classified',
  ), TRUE);
  field_delete_instance(array(
    'field_name' => _classified_get('field-category'),
    'entity_type' => 'node',
    'bundle' => 'classified',
  ), TRUE);
  drupal_set_message($t('Removed Classified Ads fields.'));

  // Delete our nodes.
  $q = new EntityFieldQuery();
  $light_nodes = $q
    ->entityCondition('entity_type', 'node')
    ->entityCondition('bundle', 'classified')
    ->execute();
  if (isset($light_nodes['node']) && !empty($light_nodes['node'])) {
    $nids = array_keys($light_nodes['node']);
    node_delete_multiple($nids);
    drupal_set_message($t('Removed Classified Ads nodes.'));
  }
  else {
    drupal_set_message($t('Could not find nodes to remove.'));
  }

  // Delete our variables.
  foreach (array_keys(_classified_get_vars()) as $var_name) {
    variable_del($var_name);
  }
  drupal_set_message($t('Removed Classified Ads variables.'));
  cache_clear_all('classified:overview', 'cache');
  field_cron();
  drupal_flush_all_caches();
}