function tripal_contact_update_7200

2.x tripal_contact.install tripal_contact_update_7200()

This is the required update for tripal_contact when upgrading from Drupal core API 6.x.

File

tripal_contact/tripal_contact.install, line 241
Handles install, uninstall, disable and enable functionality including database tables.

Code

function tripal_contact_update_7200() {

  // Make sure we have the full API loaded this will help during a
  // site upgrade when the tripal_core module is disabled.
  module_load_include('module', 'tripal_core', 'tripal_core');
  tripal_core_import_api();
  module_load_include('inc', 'tripal_cv', 'api/tripal_cv.api');


  // Add the contact_type CV
  try {
    // First we add the cv.
    // Notice that tripal_insert_cv() will only add it if it doesn't exist already.
    $cv = tripal_insert_cv(
    'tripal_contact', 
    'A heirarchical set of terms for describing a contact. It is intended to be used as the default vocabularies in Tripal for contact types and contact properties.'
    );
    if ($cv) {
      $cv_id = $cv->cv_id;

      // Set as Default CV for contact types.
      $is_set = tripal_get_default_cv('contact', 'type_id');
      if (!$is_set) {
        tripal_set_default_cv('contact', 'type_id', 'tripal_contact', $cv_id);
      }

      // Set as Default CV for contact properties.
      $is_set = tripal_get_default_cv('contactprop', 'type_id');
      if (!$is_set) {
        tripal_set_default_cv('contactprop', 'type_id', 'tripal_contact', $cv_id);
      }
    }
    else {
      throw new DrupalUpdateException('Failed to add tripal_contact vocabulary.');
    }
  }
  catch (\PDOException $e) {
    $error = $e->getMessage();
    throw new DrupalUpdateException('Failed to add tripal_contact vocabulary: ' . $error);
  }


  // Add the contact_relationship CV
  try {
    // First we add the cv.
    // Notice that tripal_insert_cv() will only add it if it doesn't exist already.
    $cv = tripal_insert_cv(
    'contact_relationship', 
    'Contains types of relationships between contacts.'
    );
    if ($cv) {
      $cv_id = $cv->cv_id;

      // Set as Default CV for contact relationships.
      $is_set = tripal_get_default_cv('contact_relationship', 'type_id');
      if (!$is_set) {
        tripal_set_default_cv('contact_relationship', 'type_id', 'contact_relationship', $cv_id);
      }
    }
    else {
      throw new DrupalUpdateException('Failed to add contact_relationship vocabulary.');
    }
  }
  catch (\PDOException $e) {
    $error = $e->getMessage();
    throw new DrupalUpdateException('Failed to add contact_relationship vocabulary: ' . $error);
  }

  // Add the contact_type CV (not default).
  try {
    $cv = tripal_insert_cv(
    'contact_type', 
    'Contains types of contacts. This can be used if the tripal_contact vocabulary (which is default for contacts in Tripal) is not desired.'
    );
  }
  catch (\PDOException $e) {
    $error = $e->getMessage();
    throw new DrupalUpdateException('Failed to add contact_type vocabulary: ' . $error);
  }

  // Add the contact_property CV (not default).
  try {
    $cv = tripal_insert_cv(
    'contact_property', 
    'Contains properties for contacts. This can be used if the tripal_contact vocabulary (which is default for contacts in Tripal) is not desired.'
    );
  }
  catch (\PDOException $e) {
    $error = $e->getMessage();
    throw new DrupalUpdateException('Failed to add contact_property vocabulary: ' . $error);
  }
}