You are here

function social_content_twitter_uninstall in Social Content 7

Implements hook_uninstall().

Remove variables and content type.

File

modules/twitter/social_content_twitter.install, line 85
Install/uninstall code for Social Content: Twitter.

Code

function social_content_twitter_uninstall() {

  // Remove variables.
  variable_del('social_content_twitter_account');
  variable_del('social_content_twitter_hashtag');

  // Machine name of the content type.
  $name = 'tweet';

  // Gather all tweet nodes created.
  $sql = 'SELECT nid FROM {node} n WHERE n.type = :type';
  $result = db_query($sql, array(
    ':type' => $name,
  ));
  $nids = array();
  foreach ($result as $row) {
    $nids[] = $row->nid;
  }

  // Delete all the tweet nodes at once.
  node_delete_multiple($nids);

  // Remove persistant variables that control settings.
  variable_del('additional_settings__active_tab_' . $name);
  variable_del('node_preview_' . $name);
  variable_del('node_options_' . $name);
  variable_del('node_submitted_' . $name);
  variable_del('menu_options_' . $name);
  variable_del('menu_parent_' . $name);

  // Delete our content type.
  node_type_delete($name);

  // Find all fields and delete them.
  module_load_include('inc', 'social_content_twitter', 'social_content_twitter.fields');
  foreach (array_keys(social_content_twitter_create_fields()) as $field) {
    field_delete_field($field);
  }

  // Find all fields and delete instance.
  $instances = field_info_instances('node', $name);
  foreach ($instances as $instance_name => $instance) {
    field_delete_instance($instance);
  }

  // Purge all field info.
  field_purge_batch(1000);
}