You are here

function crm_core_relationship_uninstall in CRM Core 7

Same name and namespace in other branches
  1. 8.3 modules/crm_core_relationship/crm_core_relationship.install \crm_core_relationship_uninstall()
  2. 8 modules/crm_core_relationship/crm_core_relationship.install \crm_core_relationship_uninstall()
  3. 8.2 modules/crm_core_relationship/crm_core_relationship.install \crm_core_relationship_uninstall()

Implements hook_uninstall()

File

modules/crm_core_relationship/crm_core_relationship.install, line 49
Install, update and uninstall functions for the relationship module.

Code

function crm_core_relationship_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', 'crm_core_contact')
    ->distinct()
    ->execute();
  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);
  }
}