You are here

function advpoll_uninstall in Advanced Poll 7

Same name and namespace in other branches
  1. 8 advpoll.install \advpoll_uninstall()
  2. 5 advpoll.install \advpoll_uninstall()
  3. 6.3 advpoll.install \advpoll_uninstall()
  4. 6 advpoll.install \advpoll_uninstall()
  5. 6.2 advpoll.install \advpoll_uninstall()
  6. 7.3 advpoll.install \advpoll_uninstall()
  7. 7.2 advpoll.install \advpoll_uninstall()

Implements hook_uninstall().

File

./advpoll.install, line 93
Install file for Advanced Poll Much thanks to the example modules. MW

Code

function advpoll_uninstall() {

  // Gather all the example content that might have been created while this
  // module was enabled.  Simple selects still use db_query().
  // http://api.drupal.org/api/function/db_query/7
  $sql = 'SELECT nid FROM {node} n WHERE n.type = :type';
  $result = db_query($sql, array(
    ':type' => 'advpoll',
  ));
  $nid = array();
  foreach ($result as $row) {
    $nid[] = $row->nid;
  }
  if ($nid) {
    db_delete('votingapi_vote')
      ->condition('entity_id', $nid, 'IN')
      ->execute();

    // Delete all the nodes at once
    // http://api.drupal.org/api/function/node_delete_multiple/7
    node_delete_multiple($nid);
  }

  // Loop over each of the fields defined by this module and delete
  // all instances of the field, their data, and the field itself.
  // http://api.drupal.org/api/function/field_delete_field/7
  foreach (array_keys(_advpoll_installed_fields()) as $field) {
    field_delete_field($field);
  }

  // Loop over any remaining field instances attached to the node_example
  // content type (such as the body field) and delete them individually.
  // http://api.drupal.org/api/function/field_delete_field/7
  $instances = field_info_instances('node', 'advpoll');
  foreach ($instances as $instance_name => $instance) {
    field_delete_instance($instance);
  }

  // Delete our content type
  // http://api.drupal.org/api/function/node_type_delete/7
  node_type_delete('advpoll');

  // Purge all field infromation
  // http://api.drupal.org/api/function/field_purge_batch/7
  field_purge_batch(1000);
}