function tripal_stock_update_7200

2.x tripal_stock.install tripal_stock_update_7200()

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

File

tripal_stock/tripal_stock.install, line 215
Install the tripal stock module including it's content type

Code

function tripal_stock_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 stock_relationshp 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(
    'stock_relationship', 
    'Contains types of relationships between stocks.'
    );
    if ($cv) {
      $cv_id = $cv->cv_id;

      // for backwards compatibility, get the previously set stock relationship CV, otherwise
      // use the new stock_relationship CV we just added
      $default_stockrel_cv = variable_get('chado_stock_relationship_cv', $cv_id);

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

  // add the stock_property 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(
    'stock_property', 
    'Contains properties for stocks.'
    );
    if ($cv) {
      $cv_id = $cv->cv_id;

      // for backwards compatibility, get the previously set stock property CV, otherwise
      // use the new stock_property CV we just added
      $default_stockprop_cv = variable_get('chado_stock_prop_types_cv', $cv_id);

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


  // add the stock_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(
    'stock_type', 
    'Contains a list of types for stocks.'
    );
    if ($cv) {
      $cv_id = $cv->cv_id;

      // for backwards compatibility, get the previously set stock types CV, otherwise
      // use the new stock_type CV we just added
      $default_stocktype_cv = variable_get('chado_stock_types_cv', $cv_id);

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

}