function tripal_pub_update_7200

2.x tripal_pub.install tripal_pub_update_7200()
3.x tripal_pub.install tripal_pub_update_7200()

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

File

tripal_pub/tripal_pub.install, line 283
Installation of the publication module

Code

function tripal_pub_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 tripal_pub CV and set it to be the default for pub types and pub properties
  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_pub', 
    'A heirarchical set of terms for describing a publication. It is intended to be used as the default vocabularies in Tripal for publication types and contact properties.'
    );
    if ($cv) {
      $cv_id = $cv->cv_id;

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

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

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

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

  // add the pub_relationship CV
  try {
    $cv = tripal_insert_cv(
    'pub_relationship', 
    'Contains types of relationships between publications.'
    );
    if ($cv) {
      $cv_id = $cv->cv_id;

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