function tripal_analysis_update_7200

2.x tripal_analysis.install tripal_analysis_update_7200()

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

File

tripal_analysis/tripal_analysis.install, line 298
Implements hooks from the Schema API.

Code

function tripal_analysis_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');

  // Set the analysis_property as default.
  try {
    $is_set = tripal_get_default_cv('analysisprop', 'type_id');
    if (!$is_set) {
      tripal_set_default_cv('analysisprop', 'type_id', 'analysis_property');
    }
  }
  catch (\PDOException $e) {
    $error = $e->getMessage();
    throw new DrupalUpdateException('Failed to add analysis_property vocabulary: ' . $error);
  }


  // During the upgrade from D6 to D7 the vocabulary terms assigned to organisms were
  // copied to the field_data_taxonomyextra table rather than to the correct
  // field_data_taxonomy_vocabulary_[vid] table. We'll move them.
  $vid = db_query("SELECT vid FROM {taxonomy_vocabulary} WHERE name = 'Analysis'")->fetchField();
  if ($vid) {
    try {
      if (db_table_exists('field_data_taxonomyextra')) {
        // first move from the field_data_taxonomyextra table
        $sql = "
          INSERT INTO {field_data_taxonomy_vocabulary_$vid}
            (entity_type, bundle, deleted, entity_id, revision_id, language, delta, taxonomy_vocabulary_" . $vid . "_tid)
          (SELECT entity_type, bundle, deleted, entity_id, revision_id, language, delta, taxonomyextra_tid
           FROM field_data_taxonomyextra
           WHERE bundle = 'chado_feature')
        ";
        db_query($sql);
        $sql = "DELETE FROM field_data_taxonomyextra WHERE bundle = 'chado_analysis'";
        db_query($sql);

        // next move from the field_revision_taxonomyextra table
        $sql = "
          INSERT INTO {field_revision_taxonomy_vocabulary_$vid}
            (entity_type, bundle, deleted, entity_id, revision_id, language, delta, taxonomy_vocabulary_" . $vid . "_tid)
          (SELECT entity_type, bundle, deleted, entity_id, revision_id, language, delta, taxonomyextra_tid
           FROM field_revision_taxonomyextra
           WHERE bundle = 'chado_feature')
        ";
        db_query($sql);
        $sql = "DELETE FROM field_revision_taxonomyextra WHERE bundle = 'chado_analysis'";
        db_query($sql);
      }
    }
    catch (\PDOException $e) {
      $error = $e->getMessage();
      throw new DrupalUpdateException('Could not move organism taxonomy terms: ' . $error);
    }
  }
}