You are here

function redhen_relation_uninstall in RedHen CRM 7

Implements hook_uninstall().

File

modules/redhen_relation/redhen_relation.install, line 184
Install, update and uninstall functions for the redhen relations module.

Code

function redhen_relation_uninstall() {

  // Get all the relationship_types (bundles), find all fields
  // delete them.
  $query = db_select('relation_bundles', 'rb')
    ->fields('rb', array(
    'relation_type',
  ))
    ->condition('rb.entity_type', 'redhen_contact')
    ->distinct()
    ->execute();
  $relationship_type = array();
  while ($record = $query
    ->fetchAssoc()) {
    $relationship_type[] = $record['relation_type'];
  }
  foreach ($relationship_type as $type) {

    // Look into the database for each type.
    $relationship_query = db_select('relation', 'r')
      ->fields('r', array(
      'rid',
    ))
      ->condition('r.relation_type', $type)
      ->execute();
    while ($result = $relationship_query
      ->fetchAssoc()) {

      // Delete all the relationships of that type.
      relation_delete($result['rid']);
    }

    // Finally delete the relationshp_type.
    relation_type_delete($type);
  }

  // Delete status field.
  field_delete_field('redhen_relation_status');

  // Delete Roles field:
  field_delete_field('redhen_relation_roles');

  // Delete relation role field.
  field_delete_field(REDHEN_RELATION_ROLES_FIELD);
  entity_info_cache_clear();
}