Răsfoiți Sursa

Fixed bug with upgrade problem from Tripal v1.2 to v1.3

Stephen Ficklin 8 ani în urmă
părinte
comite
b646c93885

+ 2 - 2
legacy/tripal_analysis/tripal_analysis.install

@@ -81,7 +81,7 @@ function tripal_analysis_uninstall() {
  *
  * @ingroup tripal_analysis
  */
-// This function was moved to tripal_chado/includes/tripal_chado.setup.inc
+// This function was moved to tripal_chado/includes/setup/tripal_chado.setup.inc
 /* function tripal_analysis_create_analysisfeatureprop() {
 
   // Create analysisfeatureprop table in chado.  This is needed for Chado
@@ -237,7 +237,7 @@ function tripal_analysis_schema() {
  *
  * @ingroup tripal_analysis
  */
-// This function was moved to tripal_chado/includes/tripal_chado.setup.inc
+// This function was moved to tripal_chado/includes/setup/tripal_chado.setup.inc
 /* function tripal_analysis_add_mview_analysis_organism() {
   $view_name = 'analysis_organism';
   $comment = t('This view is for associating an organism (via it\'s associated features) to an analysis.');

+ 1 - 1
legacy/tripal_contact/tripal_contact.install

@@ -172,7 +172,7 @@ function tripal_contact_schema() {
  *
  * @ingroup tripal_contact
  */
-// This function was moved to tripal_chado/includes/tripal_chado.setup.inc
+// This function was moved to tripal_chado/includes/setup/tripal_chado.setup.inc
 /* function tripal_contact_add_custom_tables(){
   $schema = array (
     'table' => 'contactprop',

+ 4 - 4
legacy/tripal_feature/tripal_feature.install

@@ -82,7 +82,7 @@ function tripal_feature_install() {
 function tripal_feature_uninstall() {
 
 }
-// This function was moved to tripal_chado/includes/tripal_chado.setup.inc
+// This function was moved to tripal_chado/includes/setup/tripal_chado.setup.inc
 /* function tripal_feature_add_tripal_gff_temp_table() {
   $schema = array(
     'table' => 'tripal_gff_temp',
@@ -121,7 +121,7 @@ function tripal_feature_uninstall() {
 /**
  *
  */
-// This function was moved to tripal_chado/includes/tripal_chado.setup.inc
+// This function was moved to tripal_chado/includes/setup/tripal_chado.setup.inc
 /* function tripal_feature_add_tripal_gffcds_temp_table($skip_recreate = TRUE) {
   $schema = array(
     'table' => 'tripal_gffcds_temp',
@@ -162,7 +162,7 @@ function tripal_feature_uninstall() {
 /**
  *
  */
-// This function was moved to tripal_chado/includes/tripal_chado.setup.inc
+// This function was moved to tripal_chado/includes/setup/tripal_chado.setup.inc
 /* function tripal_feature_add_tripal_gffprotein_temp_table() {
   $schema = array(
     'table' => 'tripal_gffprotein_temp',
@@ -245,7 +245,7 @@ function tripal_feature_schema() {
  *
  * @ingroup tripal_feature
  */
-// This function was moved to tripal_chado/includes/tripal_chado.setup.inc
+// This function was moved to tripal_chado/includes/setup/tripal_chado.setup.inc
 /* function tripal_feature_add_organism_count_mview() {
   $view_name = 'organism_feature_count';
   $comment = 'Stores the type and number of features per organism';

+ 1 - 1
legacy/tripal_featuremap/tripal_featuremap.install

@@ -309,7 +309,7 @@ function tripal_featuremap_add_cvterms() {
  *
  * @ingroup tripal_featuremap
  */
-// This function was moved to tripal_chado/includes/tripal_chado.setup.inc
+// This function was moved to tripal_chado/includes/setup/tripal_chado.setup.inc
 /* function tripal_featuremap_add_custom_tables(){
   // add the featuremaprop table to Chado
   $schema = array (

+ 1 - 1
legacy/tripal_pub/tripal_pub.install

@@ -171,7 +171,7 @@ function tripal_pub_schema() {
  *
  * @ingroup tripal_pub
  */
-// This function was moved to tripal_chado/includes/tripal_chado.setup.inc
+// This function was moved to tripal_chado/includes/setup/tripal_chado.setup.inc
 /* function tripal_pub_add_custom_tables() {
   $schema = array (
     'table' => 'pubauthor_contact',

+ 1 - 2
tripal/includes/tripal.field_storage.inc

@@ -22,8 +22,7 @@ function tripal_field_storage_info() {
 /**
  * Implements hook_field_storage_load().
  *
- * Responsible for loading the fields from the Chado database and adding
- * their values to the entity.
+ * Responsible for loading the fields and adding their values to the entity.
  */
 function tripal_field_storage_load($entity_type, $entities, $age,
     $fields, $options) {

+ 19 - 19
tripal_chado/api/tripal_chado.schema_v1.11.api.inc

@@ -1697,7 +1697,7 @@ function tripal_chado_chado_schema_v1_11_cell_line_dbxref() {
       'is_current' => array(
         'type' => 'boolean',
         'not NULL' => '1',
-        'default' => 'ru',
+        'default' => 'true',
       ),
     ),
     'primary key' => array(
@@ -2024,12 +2024,12 @@ function tripal_chado_chado_schema_v1_11_cell_line_synonym() {
       'is_current' => array(
         'type' => 'boolean',
         'not NULL' => '1',
-        'default' => 'als',
+        'default' => 'false',
       ),
       'is_internal' => array(
         'type' => 'boolean',
         'not NULL' => '1',
-        'default' => 'als',
+        'default' => 'false',
       ),
     ),
     'primary key' => array(
@@ -4113,12 +4113,12 @@ function tripal_chado_chado_schema_v1_11_feature() {
       'is_analysis' => array(
         'type' => 'boolean',
         'not NULL' => '1',
-        'default' => 'als',
+        'default' => 'false',
       ),
       'is_obsolete' => array(
         'type' => 'boolean',
         'not NULL' => '1',
-        'default' => 'als',
+        'default' => 'false',
       ),
       'timeaccessioned' => array(
         'type' => 'datetime',
@@ -4236,7 +4236,7 @@ function tripal_chado_chado_schema_v1_11_feature_cvterm() {
       'is_not' => array(
         'type' => 'boolean',
         'not NULL' => '1',
-        'default' => 'als',
+        'default' => 'false',
       ),
       'rank' => array(
         'type' => 'int',
@@ -4523,7 +4523,7 @@ function tripal_chado_chado_schema_v1_11_feature_dbxref() {
       'is_current' => array(
         'type' => 'boolean',
         'not NULL' => '1',
-        'default' => 'ru',
+        'default' => 'true',
       ),
     ),
     'primary key' => array(
@@ -5323,12 +5323,12 @@ function tripal_chado_chado_schema_v1_11_feature_synonym() {
       'is_current' => array(
         'type' => 'boolean',
         'not NULL' => '1',
-        'default' => 'als',
+        'default' => 'false',
       ),
       'is_internal' => array(
         'type' => 'boolean',
         'not NULL' => '1',
-        'default' => 'als',
+        'default' => 'false',
       ),
     ),
     'primary key' => array(
@@ -5411,7 +5411,7 @@ function tripal_chado_chado_schema_v1_11_featureloc() {
       'is_fmin_partial' => array(
         'type' => 'boolean',
         'not NULL' => '1',
-        'default' => 'als',
+        'default' => 'false',
       ),
       'fmax' => array(
         'type' => 'int',
@@ -5420,7 +5420,7 @@ function tripal_chado_chado_schema_v1_11_featureloc() {
       'is_fmax_partial' => array(
         'type' => 'boolean',
         'not NULL' => '1',
-        'default' => 'als',
+        'default' => 'false',
       ),
       'strand' => array(
         'type' => 'int',
@@ -6262,7 +6262,7 @@ function tripal_chado_chado_schema_v1_11_library_dbxref() {
       'is_current' => array(
         'type' => 'boolean',
         'not NULL' => '1',
-        'default' => 'ru',
+        'default' => 'true',
       ),
     ),
     'primary key' => array(
@@ -6463,12 +6463,12 @@ function tripal_chado_chado_schema_v1_11_library_synonym() {
       'is_current' => array(
         'type' => 'boolean',
         'not NULL' => '1',
-        'default' => 'ru',
+        'default' => 'true',
       ),
       'is_internal' => array(
         'type' => 'boolean',
         'not NULL' => '1',
-        'default' => 'als',
+        'default' => 'false',
       ),
     ),
     'primary key' => array(
@@ -8473,7 +8473,7 @@ function tripal_chado_chado_schema_v1_11_pub() {
       'is_obsolete' => array(
         'type' => 'boolean',
         'not NULL' => '',
-        'default' => 'als',
+        'default' => 'false',
       ),
       'publisher' => array(
         'type' => 'varchar',
@@ -8542,7 +8542,7 @@ function tripal_chado_chado_schema_v1_11_pub_dbxref() {
       'is_current' => array(
         'type' => 'boolean',
         'not NULL' => '1',
-        'default' => 'ru',
+        'default' => 'true',
       ),
     ),
     'primary key' => array(
@@ -8684,7 +8684,7 @@ function tripal_chado_chado_schema_v1_11_pubauthor() {
       'editor' => array(
         'type' => 'boolean',
         'not NULL' => '',
-        'default' => 'als',
+        'default' => 'false',
       ),
       'surname' => array(
         'type' => 'varchar',
@@ -9108,7 +9108,7 @@ function tripal_chado_chado_schema_v1_11_stock() {
       'is_obsolete' => array(
         'type' => 'boolean',
         'not NULL' => '1',
-        'default' => 'als',
+        'default' => 'false',
       ),
     ),
     'primary key' => array(
@@ -9271,7 +9271,7 @@ function tripal_chado_chado_schema_v1_11_stock_dbxref() {
       'is_current' => array(
         'type' => 'boolean',
         'not NULL' => '1',
-        'default' => 'ru',
+        'default' => 'true',
       ),
     ),
     'primary key' => array(

+ 20 - 20
tripal_chado/api/tripal_chado.schema_v1.2.api.inc

@@ -1969,7 +1969,7 @@ function tripal_chado_chado_schema_v1_2_cell_line_dbxref() {
         'description' => '',
         'type' => 'boolean',
         'not null' => TRUE,
-        'default' => 'ru',
+        'default' => 'true',
       ),
     ),
     'primary key' => array(
@@ -2316,13 +2316,13 @@ function tripal_chado_chado_schema_v1_2_cell_line_synonym() {
         'description' => '',
         'type' => 'boolean',
         'not null' => TRUE,
-        'default' => 'als',
+        'default' => 'false',
       ),
       'is_internal' => array(
         'description' => '',
         'type' => 'boolean',
         'not null' => TRUE,
-        'default' => 'als',
+        'default' => 'false',
       ),
     ),
     'primary key' => array(
@@ -4877,13 +4877,13 @@ function tripal_chado_chado_schema_v1_2_feature() {
         'description' => '',
         'type' => 'boolean',
         'not null' => TRUE,
-        'default' => 'als',
+        'default' => 'false',
       ),
       'is_obsolete' => array(
         'description' => '',
         'type' => 'boolean',
         'not null' => TRUE,
-        'default' => 'als',
+        'default' => 'false',
       ),
       'timeaccessioned' => array(
         'description' => '',
@@ -5010,7 +5010,7 @@ function tripal_chado_chado_schema_v1_2_feature_cvterm() {
         'description' => '',
         'type' => 'boolean',
         'not null' => TRUE,
-        'default' => 'als',
+        'default' => 'false',
       ),
       'rank' => array(
         'description' => '',
@@ -5325,7 +5325,7 @@ function tripal_chado_chado_schema_v1_2_feature_dbxref() {
         'description' => '',
         'type' => 'boolean',
         'not null' => TRUE,
-        'default' => 'ru',
+        'default' => 'true',
       ),
     ),
     'primary key' => array(
@@ -6206,13 +6206,13 @@ function tripal_chado_chado_schema_v1_2_feature_synonym() {
         'description' => '',
         'type' => 'boolean',
         'not null' => TRUE,
-        'default' => 'als',
+        'default' => 'false',
       ),
       'is_internal' => array(
         'description' => '',
         'type' => 'boolean',
         'not null' => TRUE,
-        'default' => 'als',
+        'default' => 'false',
       ),
     ),
     'primary key' => array(
@@ -6302,7 +6302,7 @@ function tripal_chado_chado_schema_v1_2_featureloc() {
         'description' => '',
         'type' => 'boolean',
         'not null' => TRUE,
-        'default' => 'als',
+        'default' => 'false',
       ),
       'fmax' => array(
         'description' => '',
@@ -6313,7 +6313,7 @@ function tripal_chado_chado_schema_v1_2_featureloc() {
         'description' => '',
         'type' => 'boolean',
         'not null' => TRUE,
-        'default' => 'als',
+        'default' => 'false',
       ),
       'strand' => array(
         'description' => '',
@@ -7317,7 +7317,7 @@ function tripal_chado_chado_schema_v1_2_library_dbxref() {
         'description' => '',
         'type' => 'boolean',
         'not null' => TRUE,
-        'default' => 'ru',
+        'default' => 'true',
       ),
     ),
     'primary key' => array(
@@ -7536,13 +7536,13 @@ function tripal_chado_chado_schema_v1_2_library_synonym() {
         'description' => '',
         'type' => 'boolean',
         'not null' => TRUE,
-        'default' => 'ru',
+        'default' => 'true',
       ),
       'is_internal' => array(
         'description' => '',
         'type' => 'boolean',
         'not null' => TRUE,
-        'default' => 'als',
+        'default' => 'false',
       ),
     ),
     'primary key' => array(
@@ -11236,7 +11236,7 @@ function tripal_chado_chado_schema_v1_2_pub() {
         'description' => '',
         'type' => 'boolean',
         'not null' => FALSE,
-        'default' => 'als',
+        'default' => 'false',
       ),
       'publisher' => array(
         'description' => '',
@@ -11354,7 +11354,7 @@ function tripal_chado_chado_schema_v1_2_pub_dbxref() {
         'description' => '',
         'type' => 'boolean',
         'not null' => TRUE,
-        'default' => 'ru',
+        'default' => 'true',
       ),
     ),
     'primary key' => array(
@@ -11508,7 +11508,7 @@ function tripal_chado_chado_schema_v1_2_pubauthor() {
         'description' => '',
         'type' => 'boolean',
         'not null' => FALSE,
-        'default' => 'als',
+        'default' => 'false',
       ),
       'surname' => array(
         'description' => '',
@@ -11970,7 +11970,7 @@ function tripal_chado_chado_schema_v1_2_stock() {
         'description' => '',
         'type' => 'boolean',
         'not null' => TRUE,
-        'default' => 'als',
+        'default' => 'false',
       ),
     ),
     'primary key' => array(
@@ -12075,7 +12075,7 @@ function tripal_chado_chado_schema_v1_2_stock_cvterm() {
         'description' => '',
         'type' => 'boolean',
         'not null' => TRUE,
-        'default' => 'als',
+        'default' => 'false',
       ),
       'rank' => array(
         'description' => '',
@@ -12250,7 +12250,7 @@ function tripal_chado_chado_schema_v1_2_stock_dbxref() {
         'description' => '',
         'type' => 'boolean',
         'not null' => TRUE,
-        'default' => 'ru',
+        'default' => 'true',
       ),
     ),
     'primary key' => array(

+ 9 - 9
tripal_chado/api/tripal_chado.schema_v1.3.api.inc

@@ -552,7 +552,7 @@ function tripal_chado_chado_schema_v1_3_analysis_dbxref() {
         'size' => 'normal',
         'type' => 'boolean',
         'not null' => TRUE,
-        'default' => 'ru',
+        'default' => 'true',
       ),
     ),
     'unique keys' => array(
@@ -2453,7 +2453,7 @@ function tripal_chado_chado_schema_v1_3_cell_line_dbxref() {
         'size' => 'normal',
         'type' => 'boolean',
         'not null' => TRUE,
-        'default' => 'ru',
+        'default' => 'true',
       ),
     ),
     'unique keys' => array(
@@ -6305,7 +6305,7 @@ function tripal_chado_chado_schema_v1_3_feature_dbxref() {
         'size' => 'normal',
         'type' => 'boolean',
         'not null' => TRUE,
-        'default' => 'ru',
+        'default' => 'true',
       ),
     ),
     'unique keys' => array(
@@ -7016,7 +7016,7 @@ function tripal_chado_chado_schema_v1_3_featuremap_dbxref() {
         'size' => 'normal',
         'type' => 'boolean',
         'not null' => TRUE,
-        'default' => 'ru',
+        'default' => 'true',
       ),
     ),
     'indexes' => array(
@@ -8856,7 +8856,7 @@ function tripal_chado_chado_schema_v1_3_library_dbxref() {
         'size' => 'normal',
         'type' => 'boolean',
         'not null' => TRUE,
-        'default' => 'ru',
+        'default' => 'true',
       ),
     ),
     'unique keys' => array(
@@ -9661,7 +9661,7 @@ function tripal_chado_chado_schema_v1_3_library_synonym() {
         'size' => 'normal',
         'type' => 'boolean',
         'not null' => TRUE,
-        'default' => 'ru',
+        'default' => 'true',
       ),
       'is_internal' => array(
         'size' => 'normal',
@@ -14034,7 +14034,7 @@ function tripal_chado_chado_schema_v1_3_project_dbxref() {
         'size' => 'normal',
         'type' => 'boolean',
         'not null' => TRUE,
-        'default' => 'ru',
+        'default' => 'true',
       ),
     ),
     'unique keys' => array(
@@ -15020,7 +15020,7 @@ function tripal_chado_chado_schema_v1_3_pub_dbxref() {
         'size' => 'normal',
         'type' => 'boolean',
         'not null' => TRUE,
-        'default' => 'ru',
+        'default' => 'true',
       ),
     ),
     'unique keys' => array(
@@ -16193,7 +16193,7 @@ function tripal_chado_chado_schema_v1_3_stock_dbxref() {
         'size' => 'normal',
         'type' => 'boolean',
         'not null' => TRUE,
-        'default' => 'ru',
+        'default' => 'true',
       ),
     ),
     'unique keys' => array(

+ 11 - 11
tripal_chado/includes/loaders/tripal_chado.pub_importers.inc

@@ -35,8 +35,8 @@ function tripal_pub_importers_list() {
 
     $rows[] = array(
       array(
-        'data' => l(t('Edit/Test'), "admin/tripal/storage/chado/loaders/pub/edit/$importer->pub_import_id") . '<br>' .
-                  l(t('Import Pubs'), "admin/tripal/storage/chado/loaders/pub/submit/$importer->pub_import_id"),
+        'data' => l(t('Edit/Test'), "admin/tripal/loaders/pub/edit/$importer->pub_import_id") . '<br>' .
+                  l(t('Import Pubs'), "admin/tripal/loaders/pub/submit/$importer->pub_import_id"),
         'nowrap' => 'nowrap'
       ),
       $importer->name,
@@ -44,13 +44,13 @@ function tripal_pub_importers_list() {
       $criteria_str,
       $importer->disabled ? 'Yes' : 'No',
       $importer->do_contact ? 'Yes' : 'No',
-      l(t('Delete'), "admin/tripal/storage/chado/loaders/pub/delete/$importer->pub_import_id"),
+      l(t('Delete'), "admin/tripal/loaders/pub/delete/$importer->pub_import_id"),
     );
   }
 
 
   $page  = "<ul class='action-links'>";
-  $page .= '  <li>' . l('New Importer', 'admin/tripal/storage/chado/loaders/pub/new') . '</li>';
+  $page .= '  <li>' . l('New Importer', 'admin/tripal/loaders/pub/new') . '</li>';
   $page .= '</ul>';
 
   $page .= '<p>' . t(
@@ -121,7 +121,7 @@ function tripal_pub_importer_setup_page($action = 'new', $pub_import_id = NULL)
   // generate the search form
   $form = drupal_get_form('tripal_pub_importer_setup_form',  $pub_import_id, $action);
 
-  $output = l("Return to publication importers list", "admin/tripal/storage/chado/loaders/pub");
+  $output = l("Return to publication importers list", "admin/tripal/loaders/pub");
   $output .= drupal_render($form);
 
   // retrieve any results
@@ -161,7 +161,7 @@ function tripal_pub_importer_setup_page($action = 'new', $pub_import_id = NULL)
           $citation = htmlspecialchars($pub['Citation']);
           $raw_link = '';
           if($pub['Publication Dbxref']) {
-            $raw_link = l('raw', 'admin/tripal/storage/chado/loaders/pub/raw/' . $pub['Publication Dbxref'], array('attributes' => array('target' => '_blank')));
+            $raw_link = l('raw', 'admin/tripal/loaders/pub/raw/' . $pub['Publication Dbxref'], array('attributes' => array('target' => '_blank')));
           }
           $rows[] = array(
             number_format($i),
@@ -707,7 +707,7 @@ function tripal_pub_importer_setup_form_submit($form, &$form_state) {
       if(drupal_write_record('tripal_pub_import', $record, 'pub_import_id')){
         unset($_SESSION['tripal_pub_import']);
         drupal_set_message('Publication import settings updated.');
-        drupal_goto('admin/tripal/storage/chado/loaders/pub');
+        drupal_goto('admin/tripal/loaders/pub');
       }
       else {
         drupal_set_message('Could not update publication import settings.', 'error');
@@ -723,7 +723,7 @@ function tripal_pub_importer_setup_form_submit($form, &$form_state) {
         if ($form_state['values']['op'] == 'Save & Import Now') {
           tripal_execute_pub_importer($record['pub_import_id']);
         }
-        drupal_goto('admin/tripal/storage/chado/loaders/pub');
+        drupal_goto('admin/tripal/loaders/pub');
       }
       else {
         drupal_set_message('Could not save publication import settings.', 'error');
@@ -735,7 +735,7 @@ function tripal_pub_importer_setup_form_submit($form, &$form_state) {
     $success = db_query($sql, array(':pub_import_id' => $pub_import_id));
     if ($success) {
       drupal_set_message('Publication importer deleted.');
-      drupal_goto('admin/tripal/storage/chado/loaders/pub');
+      drupal_goto('admin/tripal/loaders/pub');
     }
     else {
       drupal_set_message('Could not delete publication importer.', 'error');
@@ -832,7 +832,7 @@ function tripal_pub_importer_submit_job($import_id) {
   tripal_add_job("Import publications $import->name", 'tripal_chado',
     'tripal_execute_pub_importer', $args, $user->uid, 10, $includes);
 
-  drupal_goto('admin/tripal/storage/chado/loaders/pub');
+  drupal_goto('admin/tripal/loaders/pub');
 }
 /**
  * Deletes a publication importer.
@@ -846,7 +846,7 @@ function tripal_pub_importer_delete($import_id) {
 
   if ($success) {
     drupal_set_message('Publication importer deleted.');
-    drupal_goto('admin/tripal/storage/chado/loaders/pub');
+    drupal_goto('admin/tripal/loaders/pub');
   }
   else {
     drupal_set_message('Could not delete publication importer.', 'error');

+ 321 - 0
tripal_chado/includes/setup/tripal_chado.chado_v1.2.inc

@@ -0,0 +1,321 @@
+<?php
+/**
+ * Add any custom tables needed by this module.
+ * - Contactprop: keep track of properties of contact
+ *
+ * @ingroup tripal_contact
+ */
+function tripal_chado_add_contactprop_table(){
+  $schema = array (
+    'table' => 'contactprop',
+    'fields' => array (
+      'contactprop_id' => array (
+        'type' => 'serial',
+        'not null' => true,
+      ),
+      'contact_id' => array (
+        'type' => 'int',
+        'not null' => true,
+      ),
+      'type_id' => array (
+        'type' => 'int',
+        'not null' => true,
+      ),
+      'value' => array (
+        'type' => 'text',
+        'not null' => false,
+      ),
+      'rank' => array (
+        'type' => 'int',
+        'not null' => true,
+        'default' => 0,
+      ),
+    ),
+    'primary key' => array (
+      0 => 'contactprop_id',
+    ),
+    'unique keys' => array (
+      'contactprop_c1' => array (
+        0 => 'contact_id',
+        1 => 'type_id',
+        2 => 'rank',
+      ),
+    ),
+    'indexes' => array (
+      'contactprop_idx1' => array (
+        0 => 'contact_id',
+      ),
+      'contactprop_idx2' => array (
+        0 => 'type_id',
+      ),
+    ),
+    'foreign keys' => array (
+      'cvterm' => array (
+        'table' => 'cvterm',
+        'columns' => array (
+          'type_id' => 'cvterm_id',
+        ),
+      ),
+      'contact' => array (
+        'table' => 'contact',
+        'columns' => array (
+          'contact_id' => 'contact_id',
+        ),
+      ),
+    ),
+  );
+  chado_create_custom_table('contactprop', $schema, TRUE);
+}
+
+/**
+ * Adds the featuremap_dbxref table to Chado v1.2.
+ */
+function tripal_chado_add_featuremap_dbxref_table(){
+
+  // add the featuremap_dbxref table to Chado
+  $schema = array (
+    'table' => 'featuremap_dbxref',
+    'fields' => array (
+      'featuremap_dbxref_id' => array (
+        'type' => 'serial',
+        'not null' => true,
+      ),
+      'featuremap_id' => array (
+        'type' => 'int',
+        'not null' => true,
+      ),
+      'dbxref_id' => array (
+        'type' => 'int',
+        'not null' => true,
+      ),
+      'is_current' => array (
+        'type' => 'int',
+        'size' => 'tiny',
+        'not null' => true,
+        'default' => 1,
+      ),
+    ),
+    'primary key' => array (
+      0 => 'featuremap_dbxref_id',
+    ),
+    'unique keys' => array (
+      'featuremap_dbxref_c1' => array (
+        0 => 'featuremap_id',
+        1 => 'dbxref_id',
+      ),
+    ),
+    'indexes' => array (
+      'featuremap_dbxref_idx1' => array (
+        0 => 'featuremap_dbxref_id',
+      ),
+      'featuremap_dbxref_idx2' => array (
+        0 => 'dbxref_id',
+      ),
+    ),
+    'foreign keys' => array (
+      'dbxref' => array (
+        'table' => 'dbxref',
+        'columns' => array (
+          'dbxref_id' => 'dbxref_id',
+        ),
+      ),
+      'featuremap' => array (
+        'table' => 'featuremap',
+        'columns' => array (
+          'featuremap_id' => 'featuremap_id',
+        ),
+      ),
+    ),
+    'referring_tables' => NULL,
+  );
+
+  chado_create_custom_table('featuremap_dbxref', $schema, TRUE);
+
+}
+
+/**
+ * Add custom tables needed by the feature map module
+ *  - featuremapprop
+ *  - featuremap_dbxref
+ *  - featureposprop
+ *
+ * @ingroup tripal_featuremap
+ */
+function tripal_chado_add_featuremapprop_table(){
+  // add the featuremaprop table to Chado
+  $schema = array (
+    'table' => 'featuremapprop',
+    'fields' => array (
+      'featuremapprop_id' => array (
+        'type' => 'serial',
+        'not null' => true,
+      ),
+      'featuremap_id' => array (
+        'type' => 'int',
+        'not null' => true,
+      ),
+      'type_id' => array (
+        'type' => 'int',
+        'not null' => true,
+      ),
+      'value' => array (
+        'type' => 'text',
+        'not null' => false,
+      ),
+      'rank' => array (
+        'type' => 'int',
+        'not null' => true,
+        'default' => 0,
+      ),
+    ),
+    'primary key' => array (
+      0 => 'featuremapprop_id',
+    ),
+    'unique keys' => array (
+      'featuremapprop_c1' => array (
+        0 => 'featuremap_id',
+        1 => 'type_id',
+        2 => 'rank',
+      ),
+    ),
+    'indexes' => array (
+      'featuremapprop_idx1' => array (
+        0 => 'featuremap_id',
+      ),
+      'featuremapprop_idx2' => array (
+        0 => 'type_id',
+      ),
+    ),
+    'foreign keys' => array (
+      'cvterm' => array (
+        'table' => 'cvterm',
+        'columns' => array (
+          'type_id' => 'cvterm_id',
+        ),
+      ),
+      'featuremap' => array (
+        'table' => 'featuremap',
+        'columns' => array (
+          'featuremap_id' => 'featuremap_id',
+        ),
+      ),
+    ),
+  );
+  chado_create_custom_table('featuremapprop', $schema, TRUE);
+}
+
+/**
+ *
+ */
+function tripal_chado_add_featureposprop_table(){
+  $schema = array (
+    'table' => 'featureposprop',
+    'fields' => array (
+      'featureposprop_id' => array (
+        'type' => 'serial',
+        'not null' => true,
+      ),
+      'featurepos_id' => array (
+        'type' => 'int',
+        'not null' => true,
+      ),
+      'type_id' => array (
+        'type' => 'int',
+        'not null' => true,
+      ),
+      'value' => array (
+        'type' => 'text',
+        'not null' => false,
+      ),
+      'rank' => array (
+        'type' => 'int',
+        'not null' => true,
+        'default' => 0,
+      ),
+    ),
+    'primary key' => array (
+      0 => 'featureposprop_id',
+    ),
+    'unique keys' => array (
+      'featureposprop_id' => array (
+        0 => 'featurepos_id',
+        1 => 'type_id',
+        2 => 'rank',
+      ),
+    ),
+    'indexes' => array (
+      'featureposprop_c1' => array (
+        0 => 'featurepos_id',
+      ),
+      'featureposprop_idx2' => array (
+        0 => 'type_id',
+      ),
+    ),
+    'foreign keys' => array (
+      'cvterm' => array (
+        'table' => 'cvterm',
+        'columns' => array (
+          'type_id' => 'cvterm_id',
+        ),
+      ),
+      'featurepos' => array (
+        'table' => 'featurepos',
+        'columns' => array (
+          'featurepos_id' => 'featurepos_id',
+        ),
+      ),
+    ),
+  );
+  chado_create_custom_table('featureposprop', $schema, TRUE);
+}
+
+
+/**
+ * Add custom table related to publications
+ *  - pubauthor_contact
+ *
+ * @ingroup tripal_pub
+ */
+function tripal_chado_add_pubauthor_contact_table() {
+  $schema = array (
+    'table' => 'pubauthor_contact',
+    'fields' => array (
+      'pubauthor_contact_id' => array (
+        'type' => 'serial',
+        'not null' => true,
+      ),
+      'contact_id' => array (
+        'type' => 'int',
+        'not null' => true,
+      ),
+      'pubauthor_id' => array (
+        'type' => 'int',
+        'not null' => true,
+      ),
+    ),
+    'primary key' => array (
+      0 => 'pubauthor_contact_id',
+    ),
+    'unique keys' => array (
+      'pubauthor_contact_c1' => array (
+        0 => 'contact_id',
+        1 => 'pubauthor_id',
+      ),
+    ),
+    'foreign keys' => array (
+      'contact' => array (
+        'table' => 'contact',
+        'columns' => array (
+          'contact_id' => 'contact_id',
+        ),
+      ),
+      'pubauthor' => array (
+        'table' => 'pubauthor',
+        'columns' => array (
+          'pubauthor_id' => 'pubauthor_id',
+        ),
+      ),
+    ),
+  );
+  chado_create_custom_table('pubauthor_contact', $schema, TRUE);
+}

+ 27 - 0
tripal_chado/includes/setup/tripal_chado.chado_v1_1.inc

@@ -0,0 +1,27 @@
+<?php
+/**
+ * Create a legacy custom chado table (analysisfeatureprop) to store properties of
+ * analysisfeature links.
+ *
+ * @ingroup tripal_analysis
+ */
+function tripal_chado_add_analysisfeatureprop_table() {
+
+  // Create analysisfeatureprop table in chado.  This is needed for Chado
+  // version 1.11, the table exists in Chado 1.2.
+  if (!db_table_exists('chado.analysisfeatureprop')) {
+    $sql = "
+      CREATE TABLE {analysisfeatureprop} (
+        analysisfeatureprop_id SERIAL PRIMARY KEY,
+        analysisfeature_id     INTEGER NOT NULL,
+        type_id                INTEGER NOT NULL,
+        value                  TEXT,
+        rank                   INTEGER NOT NULL,
+        CONSTRAINT analysisfeature_id_type_id_rank UNIQUE (analysisfeature_id, type_id, rank),
+        CONSTRAINT analysisfeatureprop_analysisfeature_id_fkey FOREIGN KEY (analysisfeature_id) REFERENCES {analysisfeature}(analysisfeature_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
+        CONSTRAINT analysisfeatureprop_type_id_fkey FOREIGN KEY (type_id) REFERENCES {cvterm}(cvterm_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
+      )
+    ";
+    chado_query($sql);
+  }
+}

+ 463 - 0
tripal_chado/includes/setup/tripal_chado.chado_vx_x.inc

@@ -0,0 +1,463 @@
+<?php
+function tripal_chado_add_tripal_gff_temp_table() {
+  $schema = array(
+    'table' => 'tripal_gff_temp',
+    'fields' => array(
+      'feature_id' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'organism_id' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'uniquename' => array(
+        'type' => 'text',
+        'not null' => TRUE,
+      ),
+      'type_name' => array(
+        'type' => 'varchar',
+        'length' => '1024',
+        'not null' => TRUE,
+      ),
+    ),
+    'indexes' => array(
+      'tripal_gff_temp_idx0' => array('feature_id'),
+      'tripal_gff_temp_idx0' => array('organism_id'),
+      'tripal_gff_temp_idx1' => array('uniquename'),
+    ),
+    'unique keys' => array(
+      'tripal_gff_temp_uq0' => array('feature_id'),
+      'tripal_gff_temp_uq1' => array('uniquename', 'organism_id', 'type_name'),
+    ),
+  );
+  chado_create_custom_table('tripal_gff_temp', $schema, TRUE);
+}
+
+/**
+ *
+ */
+function tripal_chado_add_tripal_gffcds_temp_table() {
+  $schema = array(
+    'table' => 'tripal_gffcds_temp',
+    'fields' => array(
+      'feature_id' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'parent_id' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'phase' => array(
+        'type' => 'int',
+        'not null' => FALSE,
+      ),
+      'strand' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'fmin' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'fmax' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+    ),
+    'indexes' => array(
+      'tripal_gff_temp_idx0' => array('feature_id'),
+      'tripal_gff_temp_idx0' => array('parent_id'),
+    ),
+  );
+  chado_create_custom_table('tripal_gffcds_temp', $schema);
+}
+
+/**
+ *
+ */
+function tripal_chado_add_tripal_gffprotein_temp_table() {
+  $schema = array(
+    'table' => 'tripal_gffprotein_temp',
+    'fields' => array(
+      'feature_id' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'parent_id' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'fmin' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'fmax' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+    ),
+    'indexes' => array(
+      'tripal_gff_temp_idx0' => array('feature_id'),
+      'tripal_gff_temp_idx0' => array('parent_id'),
+    ),
+    'unique keys' => array(
+      'tripal_gff_temp_uq0' => array('feature_id'),
+    ),
+  );
+  chado_create_custom_table('tripal_gffprotein_temp', $schema, TRUE);
+}
+
+/**
+ * Creates a temporary table to store obo details while loading an obo file
+ *
+ * @ingroup tripal_cv
+ */
+function tripal_chado_add_tripal_obo_temp_table() {
+  // the tripal_obo_temp table is used for temporary housing of records when loading OBO files
+  // we create it here using plain SQL because we want it to be in the chado schema but we
+  // do not want to use the Tripal Custom Table API because we don't want it to appear in the
+  // list of custom tables.  It needs to be available for the Tripal Chado API so we create it
+  // here and then define it in the tripal_cv/api/tripal_cv.schema.api.inc
+  if (!chado_table_exists('tripal_obo_temp')) {
+    $sql = "
+      CREATE TABLE {tripal_obo_temp} (
+        id character varying(255) NOT NULL,
+        stanza text NOT NULL,
+        type character varying(50) NOT NULL,
+        CONSTRAINT tripal_obo_temp_uq0 UNIQUE (id)
+      );
+    ";
+    chado_query($sql);
+    $sql = "CREATE INDEX tripal_obo_temp_idx0 ON {tripal_obo_temp} USING btree (id)";
+    chado_query($sql);
+    $sql = "CREATE INDEX tripal_obo_temp_idx1 ON {tripal_obo_temp} USING btree (type)";
+    chado_query($sql);
+  }
+}
+
+
+
+/**
+ * Creates a materialized view that stores the type & number of stocks per organism
+ *
+ * @ingroup tripal_stock
+ */
+function tripal_chado_add_organism_stock_count_mview() {
+  $view_name = 'organism_stock_count';
+  $comment = 'Stores the type and number of stocks per organism';
+
+  $schema = array(
+    'description' => $comment,
+    'table' => $view_name,
+    'fields' => array(
+      'organism_id' => array(
+        'size' => 'big',
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'genus' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+      ),
+      'species' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+      ),
+      'common_name' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => FALSE,
+      ),
+      'num_stocks' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'cvterm_id' => array(
+        'size' => 'big',
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'stock_type' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+      ),
+    ),
+    'indexes' => array(
+      'organism_stock_count_idx1' => array('organism_id'),
+      'organism_stock_count_idx2' => array('cvterm_id'),
+      'organism_stock_count_idx3' => array('stock_type'),
+    ),
+  );
+
+  $sql = "
+    SELECT
+        O.organism_id, O.genus, O.species, O.common_name,
+        count(S.stock_id) as num_stocks,
+        CVT.cvterm_id, CVT.name as stock_type
+     FROM organism O
+        INNER JOIN stock S  ON O.Organism_id = S.organism_id
+        INNER JOIN cvterm CVT ON S.type_id     = CVT.cvterm_id
+     GROUP BY
+        O.Organism_id, O.genus, O.species, O.common_name, CVT.cvterm_id, CVT.name
+  ";
+
+  tripal_add_mview($view_name, 'tripal_stock', $schema, $sql, $comment);
+}
+
+
+
+
+/**
+ * Adds a materialized view keeping track of the type of features associated with each library
+ *
+ * @ingroup tripal_library
+ */
+function tripal_chado_add_library_feature_count_mview(){
+  $view_name = 'library_feature_count';
+  $comment = 'Provides count of feature by type that are associated with all libraries';
+
+  $schema = array(
+    'table' => $view_name,
+    'description' => $comment,
+    'fields' => array(
+      'library_id' => array(
+        'size' => 'big',
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'name' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+      ),
+      'num_features' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'feature_type' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+      ),
+    ),
+    'indexes' => array(
+      'library_feature_count_idx1' => array('library_id'),
+    ),
+  );
+
+  $sql = "
+    SELECT
+      L.library_id, L.name,
+      count(F.feature_id) as num_features,
+      CVT.name as feature_type
+    FROM library L
+      INNER JOIN library_feature LF  ON LF.library_id = L.library_id
+      INNER JOIN feature F           ON LF.feature_id = F.feature_id
+      INNER JOIN cvterm CVT          ON F.type_id     = CVT.cvterm_id
+    GROUP BY L.library_id, L.name, CVT.name
+  ";
+
+  tripal_add_mview($view_name, 'tripal_library', $schema, $sql, $comment);
+}
+
+
+
+
+
+
+/**
+ *
+ */
+
+
+
+
+
+/**
+ * Creates a materialized view that stores the type & number of features per organism
+ *
+ * @ingroup tripal_feature
+ */
+function tripal_chado_add_organism_feature_count_mview() {
+  $view_name = 'organism_feature_count';
+  $comment = 'Stores the type and number of features per organism';
+
+  $schema = array(
+    'description' => $comment,
+    'table' => $view_name,
+    'fields' => array(
+      'organism_id' => array(
+        'size' => 'big',
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'genus' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+      ),
+      'species' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+      ),
+      'common_name' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => FALSE,
+      ),
+      'num_features' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'cvterm_id' => array(
+        'size' => 'big',
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'feature_type' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+      ),
+    ),
+    'indexes' => array(
+      'organism_feature_count_idx1' => array('organism_id'),
+      'organism_feature_count_idx2' => array('cvterm_id'),
+      'organism_feature_count_idx3' => array('feature_type'),
+    ),
+  );
+
+  $sql = "
+    SELECT
+        O.organism_id, O.genus, O.species, O.common_name,
+        count(F.feature_id) as num_features,
+        CVT.cvterm_id, CVT.name as feature_type
+     FROM organism O
+        INNER JOIN feature F  ON O.Organism_id = F.organism_id
+        INNER JOIN cvterm CVT ON F.type_id     = CVT.cvterm_id
+     GROUP BY
+        O.Organism_id, O.genus, O.species, O.common_name, CVT.cvterm_id, CVT.name
+  ";
+
+  tripal_add_mview($view_name, 'tripal_feature', $schema, $sql, $comment);
+}
+
+
+/**
+ * Creates a view showing the link between an organism & it's analysis through associated features.
+ *
+ * @ingroup tripal_analysis
+ */
+function tripal_chado_add_analysis_organism_mview() {
+  $view_name = 'analysis_organism';
+  $comment = t('This view is for associating an organism (via it\'s associated features) to an analysis.');
+
+  // this is the SQL used to identify the organism to which an analsysis
+  // has been used.  This is obtained though the analysisfeature -> feature -> organism
+  // joins
+  $sql = "
+    SELECT DISTINCT A.analysis_id, O.organism_id
+    FROM analysis A
+      INNER JOIN analysisfeature AF ON A.analysis_id = AF.analysis_id
+      INNER JOIN feature F          ON AF.feature_id = F.feature_id
+      INNER JOIN organism O         ON O.organism_id = F.organism_id
+  ";
+
+  // the schema array for describing this view
+  $schema = array(
+    'table' => $view_name,
+    'description' => $comment,
+    'fields' => array(
+      'analysis_id' => array(
+        'size' => 'big',
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'organism_id' => array(
+        'size' => 'big',
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+    ),
+    'indexes' => array(
+      'networkmod_qtl_indx0' => array('analysis_id'),
+      'networkmod_qtl_indx1' => array('organism_id'),
+    ),
+    'foreign keys' => array(
+      'analysis' => array(
+        'table' => 'analysis',
+        'columns' => array(
+          'analysis_id' => 'analysis_id',
+        ),
+      ),
+      'organism' => array(
+        'table' => 'organism',
+        'columns' => array(
+          'organism_id' => 'organism_id',
+        ),
+      ),
+    ),
+  );
+
+  // add the view
+  tripal_add_mview($view_name, 'tripal_analysis', $schema, $sql, $comment);
+}
+
+/**
+ * Add a materialized view of root terms for all chado cvs. This is needed for viewing cv trees
+ *
+ * @ingroup tripal_cv
+ */
+function tripal_chado_add_cv_root_mview_mview() {
+  $mv_name = 'cv_root_mview';
+  $comment = 'A list of the root terms for all controlled vocabularies. This is needed for viewing CV trees';
+  $schema = array(
+    'table' => $mv_name,
+    'description' => $comment,
+    'fields' => array(
+      'name' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+      ),
+      'cvterm_id' => array(
+        'size' => 'big',
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'cv_id' => array(
+        'size' => 'big',
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'cv_name' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+      ),
+    ),
+    'indexes' => array(
+      'cv_root_mview_indx1' => array('cvterm_id'),
+      'cv_root_mview_indx2' => array('cv_id'),
+    ),
+  );
+
+  $sql = "
+    SELECT DISTINCT CVT.name,CVT.cvterm_id, CV.cv_id, CV.name
+    FROM cvterm_relationship CVTR
+      INNER JOIN cvterm CVT on CVTR.object_id = CVT.cvterm_id
+      INNER JOIN cv CV on CV.cv_id = CVT.cv_id
+    WHERE CVTR.object_id not in
+      (SELECT subject_id FROM cvterm_relationship)
+  ";
+
+  // Create the MView
+  tripal_add_mview($mv_name, 'tripal_cv', $schema, $sql, $comment);
+}
+

+ 396 - 0
tripal_chado/includes/setup/tripal_chado.setup.inc

@@ -0,0 +1,396 @@
+<?php
+/**
+ * @file
+ * Functions to install chado schema through Drupal
+ */
+
+/**
+ * Prepares Chado for Tripal use
+ */
+function tripal_chado_prepare_form($form, $form_state) {
+  $form = array();
+
+  if (variable_get('tripal_chado_is_prepared') == TRUE) {
+    drupal_set_message('Your site is prepared.');
+  }
+  $form['instructions'] = array(
+    '#type' => 'item',
+    '#title' => 'Prepare Drupal for Chado.',
+    '#description' => t("Before a Drupal site can use Chado (via Tripal), both
+        Chado and Drupal must be prepared a bit more.  Tripal will add some new
+        materialized views, custom tables and controlled vocabularies to Chado.
+        It will also add some management tables to Drupal. You only are
+        required to prepare your Drupal site if this is a brand-new Drupal
+        installation or if Chado was installed outside of Tripal.  If you
+        installed Chado using Tripal then you do not need to run this step.
+        If you are upgrading from a previous version of Tripal, you do not
+        need to prepare your site, and you can click the 'Skip' button."),
+  );
+
+  $form['prepare-button'] = array(
+    '#type' => 'submit',
+    '#value' => t('Prepare this site'),
+    '#name' => 'prepare-chado',
+  );
+  $form['skip-button'] = array(
+    '#type' => 'submit',
+    '#value' => t('Skip'),
+    '#name' => 'prepare-skip',
+  );
+  return $form;
+}
+
+/**
+ * Submit function for the tripal_chado_prepare_form().
+ *
+ * @param $form
+ * @param $form_state
+ */
+function tripal_chado_prepare_form_submit($form, $form_state) {
+   if ($form_state['clicked_button']['#name'] == "prepare-chado") {
+     global $user;
+     $args = array();
+     $includes = array(
+        module_load_include('inc', 'tripal_chado', 'includes/setup/tripal_chado.setup'),
+        module_load_include('inc', 'tripal_chado', 'includes/loaders/tripal_chado.obo_loader'),
+     );
+     tripal_add_job('Prepare Chado', 'tripal_chado',
+       'tripal_chado_prepare_chado', $args,
+       $user->uid, 10, $includes);
+   }
+   if ($form_state['clicked_button']['#name'] == "prepare-skip") {
+     variable_set('tripal_chado_is_prepared', TRUE);
+   }
+}
+
+/**
+ *
+ */
+function tripal_chado_load_ontologies() {
+
+  // Insert commonly used ontologies into the tables.
+  $ontologies = array(
+    array(
+      'name' => 'Relationship Ontology (legacy)',
+      'path' => '{tripal_chado}/files/legacy_ro.obo',
+      'auto_load' => FALSE,
+      'cv_name' => 'ro'
+    ),
+    array(
+      'name' => 'Gene Ontology',
+      'path' => 'http://purl.obolibrary.org/obo/go.obo',
+      'auto_load' => FALSE,
+      'cv_name' => 'cellualar_component'
+    ),
+    array(
+      'name' => 'Taxonomic Rank',
+      'path' => 'http://purl.obolibrary.org/obo/taxrank.obo',
+      'auto_load' => TRUE,
+      'cv_name' => 'taxonomic_rank'
+    ),
+    array(
+      'name' => 'Tripal Contact',
+      'path' => '{tripal_chado}/files/tcontact.obo',
+      'auto_load' => TRUE,
+      'cv_name' => 'tripal_contact'
+    ),
+    array(
+      'name' => 'Tripal Publication',
+      'path' => '{tripal_chado}/files/tpub.obo',
+      'auto_load' => TRUE,
+      'cv_name' => 'tripal_pub'
+    ),
+     array(
+       'name' => 'Sequence Ontology',
+       'path' => 'http://purl.obolibrary.org/obo/so.obo',
+       'auto_load' => TRUE,
+       'cv_name' => 'sequence'
+     ),
+
+  );
+  for ($i = 0; $i < count($ontologies); $i++) {
+    $obo_id = tripal_insert_obo($ontologies[$i]['name'], $ontologies[$i]['path']);
+    if ($ontologies[$i]['auto_load'] == TRUE) {
+      // Only load ontologies that are not already in the cv table.
+      $cv = tripal_get_cv(array('name' => $ontologies[$i]['cv_name']));
+      if (!$cv) {
+        tripal_chado_load_obo_v1_2_id($obo_id);
+      }
+    }
+  }
+}
+/**
+ * Prepares Chado for use by Tripal.
+ */
+function tripal_chado_prepare_chado() {
+
+  try {
+
+    // We want to provide a set of commonly used entity types by default. This
+    // way when a user first installs Tripal there are some commonly used
+    // formats.
+    module_load_include('inc', 'tripal', 'api/tripal.api');
+    module_load_include('inc', 'tripal', 'includes/tripal.admin');
+    module_load_include('inc', 'tripal_chado', 'includes/tripal_chado.semweb');
+
+    // Get the effective version.  Pass true as second argument
+    // to warn the user if the current version is not compatible.
+    $version = chado_get_version(FALSE, FALSE);
+
+    // We want to force the version of Chado to be set properly.
+    $real_version = chado_get_version(TRUE);
+
+    // Create the temp table we will use for loading OBO files.
+    tripal_chado_add_tripal_obo_temp_table();
+
+    // Import commonly used ontologies if needed.
+    tripal_chado_load_ontologies();
+
+    // Populate the semantic web associations for Chado tables/fields.
+    tripal_chado_populate_chado_semweb_table();
+
+    // Initialize the population of the chado_cvterm_mapping table.  This will
+    // map existing data types already in Chado so that when users want to
+    // add new content types it simplifies the form for them.
+    tripal_chado_map_cvterms();
+
+    // Create the 'Organism' entity type. This uses the obi:organism term.
+    $error = '';
+    $args = array(
+      'vocabulary' => 'OBI',
+      'accession' => '0100026',
+      'term_name' => 'organism',
+      'storage_args' => array(
+        'data_table' => 'organism',
+      )
+    );
+    $term = tripal_load_term_entity(array('vocabulary' => 'OBI', 'accession' => '0100026'));
+    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
+    if (!$term or !$bundle) {
+      if (!tripal_create_bundle($args, $error)) {
+        throw new Exception($error['!message']);
+      }
+    }
+
+    // Create the 'Analysis' entity type. This uses the local:analysis term.
+    $error = '';
+    $args = array(
+      'vocabulary' => 'local',
+      'accession' => 'analysis',
+      'term_name' => 'analysis',
+      'storage_args' => array(
+        'data_table' => 'analysis',
+      )
+    );
+    $term = tripal_load_term_entity(array('vocabulary' => 'local', 'accession' => 'analysis'));
+    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
+    if (!$term or !$bundle) {
+      if (!tripal_create_bundle($args, $error)) {
+        throw new Exception($error['!message']);
+      }
+    }
+
+    // Create the 'Project' entity type. This uses the local:project term.
+    $error = '';
+    $args = array(
+      'vocabulary' => 'local',
+      'accession' => 'project',
+      'term_name' => 'project',
+      'storage_args' => array(
+        'data_table' => 'project',
+      )
+    );
+    $term = tripal_load_term_entity(array('vocabulary' => 'local', 'accession' => 'project'));
+    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
+    if (!$term or !$bundle) {
+      if (!tripal_create_bundle($args, $error)) {
+        throw new Exception($error['!message']);
+      }
+    }
+
+    // Create the 'Map' entity type. This uses the local:project term.
+    $error = '';
+    $args = array(
+      'vocabulary' => 'data',
+      'accession' => '1274',
+      'term_name' => 'Map',
+      'storage_args' => array(
+        'data_table' => 'featuremap',
+      )
+    );
+    $term = tripal_load_term_entity(array('vocabulary' => 'data', 'accession' => '1274'));
+    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
+    if (!$term or !$bundle) {
+      if (!tripal_create_bundle($args, $error)) {
+        throw new Exception($error['!message']);
+      }
+    }
+
+    // Import a publication so we get all of the properties before
+    // creating the content type.
+    tripal_import_pub_by_dbxref('PMID:24163125');
+
+    // Create the 'Publication' entity type.
+    $error = '';
+    $args = array(
+      'vocabulary' => 'TPUB',
+      'accession' => '0000002',
+      'term_name' => 'Publication',
+      'storage_args' => array(
+        'data_table' => 'pub',
+      )
+    );
+    $term = tripal_load_term_entity(array('vocabulary' => 'TPUB', 'accession' => '0000002'));
+    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
+    if (!$term or !$bundle) {
+      if (!tripal_create_bundle($args, $error)) {
+        throw new Exception($error['!message']);
+      }
+    }
+
+    // Now remove the publication that was added above.
+    $values = array(
+      'dbxref_id' => array(
+        'accession' => '24163125',
+        'db_id' => array(
+          'name' => 'PMID',
+        ),
+      ),
+    );
+    $result = chado_select_record('pub_dbxref', array('pub_id'), $values);
+    chado_delete_record('pub', array('pub_id' => $result[0]->pub_id));
+
+    // Create the 'Gene' entity type.
+    $error = '';
+    $args = array(
+      'vocabulary' => 'SO',
+      'accession' => '0000704',
+      'term_name' => 'gene',
+      'storage_args' => array(
+        'data_table' => 'feature',
+        'type_column' => 'type_id',
+      )
+    );
+    $term = tripal_load_term_entity(array('vocabulary' => 'SO', 'accession' => '0000704'));
+    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
+    if (!$term or !$bundle) {
+      if (!tripal_create_bundle($args, $error)) {
+        throw new Exception($error['!message']);
+      }
+    }
+
+    // Create the 'mRNA' entity type.
+    $error = '';
+    $args = array(
+      'vocabulary' => 'SO',
+      'accession' => '0000234',
+      'term_name' => 'mRNA',
+      'storage_args' => array(
+        'data_table' => 'feature',
+        'type_column' => 'type_id',
+      )
+    );
+    $term = tripal_load_term_entity(array('vocabulary' => 'SO', 'accession' => '0000234'));
+    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
+    if (!$term or !$bundle) {
+      if (!tripal_create_bundle($args, $error)) {
+        throw new Exception($error['!message']);
+      }
+    }
+
+    // Create custom tables depending on the Chado version installed.
+    $chado_version = chado_get_version();
+    if ($chado_version == '1.1') {
+      tripal_chado_add_v1_1_custom_tables();
+      tripal_chado_add_vx_x_custom_tables();
+    }
+    if ($chado_version == '1.2') {
+      tripal_chado_add_v1_2_custom_tables();
+      tripal_chado_add_vx_x_custom_tables();
+    }
+    if ($chado_version == '1.3') {
+      tripal_chado_add_vx_x_custom_tables();
+      tripal_chado_fix_v1_3_custom_tables();
+    }
+
+    // Add the supported loaders
+    variable_set('tripal_pub_supported_dbs', array('PMID', 'AGL'));
+
+    // Set a variable to indicate the site is prepared.
+    variable_set('tripal_chado_is_prepared', TRUE);
+  }
+  catch (Exception $e) {
+    throw new Exception($e);
+  }
+}
+
+/**
+ * For Chado v1.1 Tripal provides some new custom tables.
+ *
+ * For Chado v1.2 or greater these tables are not needed as they are part of the
+ * schema update.
+ */
+function tripal_chado_add_v1_1_custom_tables(){
+  module_load_include('inc', 'tripal_chado', 'includes/setup/tripal_chado.chado_v1_1');
+  tripal_chado_add_analysisfeatureprop_table();
+}
+
+/**
+ * For Chado v1.2 Tripal provides some new custom tables.
+ *
+ * For Chado v1.3 these tables are not needed as they are part of the
+ * schema update.
+ */
+function tripal_chado_add_v1_2_custom_tables(){
+  module_load_include('inc', 'tripal_chado', 'includes/setup/tripal_chado.chado_v1_2');
+  tripal_chado_add_contactprop_table();
+  tripal_chado_add_featuremap_dbxref_table();
+  tripal_chado_add_featuremapprop_table();
+  tripal_chado_add_featureposprop_table();
+  tripal_chado_add_pubauthor_contact_table();
+}
+
+/**
+ * Add custom tables for any version of Chado.
+ *
+ * These are tables that Chado uses to manage the site (i.e. temporary
+ * loading tables) and not for primary data storage.
+ */
+function tripal_chado_add_vx_x_custom_tables(){
+  module_load_include('inc', 'tripal_chado', 'includes/setup/tripal_chado.chado_vx_x');
+
+  // Add in custom tables.
+  tripal_chado_add_tripal_gff_temp_table();
+  tripal_chado_add_tripal_gffcds_temp_table();
+  tripal_chado_add_tripal_gffprotein_temp_table();
+  tripal_chado_add_tripal_obo_temp_table();
+
+  // Add in materialized views.
+  tripal_chado_add_organism_stock_count_mview();
+  tripal_chado_add_library_feature_count_mview();
+  tripal_chado_add_organism_feature_count_mview();
+  tripal_chado_add_analysis_organism_mview();
+  tripal_chado_add_cv_root_mview_mview();
+}
+
+/**
+ * Many of the custom tables created for Chado v1.2 are now in Chado v1.3.
+ *
+ * These tables need not be tracked by Tripal anymore as custom tables and
+ * in some cases the Chado version has different columns so we need to
+ * adjust them.
+ */
+function tripal_chado_fix_v1_3_custom_tables() {
+
+
+  // Update the featuremap_dbxref table by adding an is_current field.
+  if (!chado_column_exists('featuremap_dbxref', 'is_current')) {
+    chado_query("ALTER TABLE {featuremap_dbxref} ADD COLUMN is_current boolean DEFAULT true NOT NULL,;");
+  }
+
+  // Remove the previously managed custom tables from the
+  // tripal_custom_tables table.
+  db_delete('tripal_custom_tables')
+    ->condition('table_name', array('analysisfeatureprop', 'featuremap_dbxref', 'contactprop', 'featuremapprop', 'featureposprop', 'pubauthor_contact'))
+    ->execute();
+}

+ 47 - 18
tripal_chado/includes/tripal_chado.field_storage.inc

@@ -175,20 +175,24 @@ function tripal_chado_field_storage_write_table($table_name, $values) {
 }
 
 /**
- * Implements hook_field_storage_load().
+ * Implements hook_field_storage_pre_load().
  *
- * Responsible for loading the fields from the Chado database and adding
- * their values to the entity.
+ * Adds a 'chado_record' object containing the base record for the
+ * entity.
  */
-function tripal_chado_field_storage_load($entity_type, $entities, $age,
+function tripal_chado_field_storage_pre_load($entity_type, $entities, $age,
     $fields, $options) {
 
-  $load_current = $age == FIELD_LOAD_CURRENT;
-  global $language;
-  $langcode = $language->language;
 
+  // Itereate through the entities and add in the Chado record.
   foreach ($entities as $id => $entity) {
 
+    // Only deal with Tripal Entities.
+    if ($entity_type != 'TripalEntity') {
+      continue;
+    }
+
+    $record_id = NULL;
     if (property_exists($entity, 'chado_table')) {
       // Get the base table and record id for the fields of this entity.
       $base_table = $entity->chado_table;
@@ -207,21 +211,46 @@ function tripal_chado_field_storage_load($entity_type, $entities, $age,
         ->condition('entity_id', $entity->id)
         ->execute()
         ->fetchObject();
-      if (!$details) {
-        // TODO: what to do if record is missing!
+      if ($details) {
+        $record_id  = isset($details->record_id) ? $details->record_id : '';
       }
-      $record_id  = isset($details->record_id) ? $details->record_id : '';
+      $entity->chado_table = $base_table;
+      $entity->chado_record_id = $record_id;
+      $entity->chado_column = $type_field;
+    }
+    if ($record_id) {
+      // Get this table's schema.
+      $schema = chado_get_schema($base_table);
+      $pkey_field = $schema['primary key'][0];
+
+      // Get the base record if one exists
+      $columns = array('*');
+      $match = array($pkey_field => $record_id);
+      $record = chado_generate_var($base_table, $match);
+      $entity->chado_record = $record;
     }
+  }
+}
 
-    // Get this table's schema.
-    $schema = chado_get_schema($base_table);
-    $pkey_field = $schema['primary key'][0];
+/**
+ * Implements hook_field_storage_load().
+ *
+ * Responsible for loading the fields from the Chado database and adding
+ * their values to the entity.
+ */
+function tripal_chado_field_storage_load($entity_type, $entities, $age,
+    $fields, $options) {
 
-    // Get the base record if one exists
-    $columns = array('*');
-    $match = array($pkey_field => $record_id);
-    $record = chado_generate_var($base_table, $match);
-    $entity->chado_record = $record;
+  $load_current = $age == FIELD_LOAD_CURRENT;
+  global $language;
+  $langcode = $language->language;
+
+  foreach ($entities as $id => $entity) {
+    $base_table = $entity->chado_table;
+    $type_field = $entity->chado_column;
+    $record_id  = $entity->chado_record_id;
+    $record = $entity->chado_record;
+    $schema = chado_get_schema($base_table);
 
     // Iterate through the entity's fields so we can get the column names
     // that need to be selected from each of the tables represented.

+ 0 - 1129
tripal_chado/includes/tripal_chado.setup.inc

@@ -1,1129 +0,0 @@
-<?php
-/**
- * @file
- * Functions to install chado schema through Drupal
- */
-
-/**
- * Prepares Chado for Tripal use
- */
-function tripal_chado_prepare_form($form, $form_state) {
-  $form = array();
-
-  if (variable_get('tripal_chado_is_prepared') == TRUE) {
-    drupal_set_message('Your site is prepared.');
-  }
-  $form['instructions'] = array(
-    '#type' => 'item',
-    '#title' => 'Prepare Drupal for Chado.',
-    '#description' => t("Before a Drupal site can use Chado (via Tripal), both
-        Chado and Drupal must be prepared a bit more.  Tripal will add some new
-        materialized views, custom tables and controlled vocabularies to Chado.
-        It will also add some management tables to Drupal. You only are
-        required to prepare your Drupal site if this is a brand-new Drupal
-        installation or if Chado was installed outside of Tripal.  If you
-        installed Chado using Tripal then you do not need to run this step.
-        If you are upgrading from a previous version of Tripal, you do not
-        need to prepare your site, and you can click the 'Skip' button."),
-  );
-
-  $form['prepare-button'] = array(
-    '#type' => 'submit',
-    '#value' => t('Prepare this site'),
-    '#name' => 'prepare-chado',
-  );
-  $form['skip-button'] = array(
-    '#type' => 'submit',
-    '#value' => t('Skip'),
-    '#name' => 'prepare-skip',
-  );
-  return $form;
-}
-
-/**
- * Submit function for the tripal_chado_prepare_form().
- *
- * @param $form
- * @param $form_state
- */
-function tripal_chado_prepare_form_submit($form, $form_state) {
-   if ($form_state['clicked_button']['#name'] == "prepare-chado") {
-     global $user;
-     $args = array();
-     $includes = array(
-        module_load_include('inc', 'tripal_chado', 'includes/tripal_chado.setup'),
-        module_load_include('inc', 'tripal_chado', 'includes/loaders/tripal_chado.obo_loader'),
-     );
-     tripal_add_job('Prepare Chado', 'tripal_chado',
-       'tripal_chado_prepare_chado', $args,
-       $user->uid, 10, $includes);
-   }
-   if ($form_state['clicked_button']['#name'] == "prepare-skip") {
-     variable_set('tripal_chado_is_prepared', TRUE);
-   }
-}
-
-/**
- *
- */
-function tripal_chado_load_ontologies() {
-
-  // Insert commonly used ontologies into the tables.
-  $ontologies = array(
-    array(
-      'name' => 'Relationship Ontology (legacy)',
-      'path' => '{tripal_chado}/files/legacy_ro.obo',
-      'auto_load' => FALSE,
-      'cv_name' => 'ro'
-    ),
-    array(
-      'name' => 'Gene Ontology',
-      'path' => 'http://purl.obolibrary.org/obo/go.obo',
-      'auto_load' => FALSE,
-      'cv_name' => 'cellualar_component'
-    ),
-    array(
-      'name' => 'Taxonomic Rank',
-      'path' => 'http://purl.obolibrary.org/obo/taxrank.obo',
-      'auto_load' => TRUE,
-      'cv_name' => 'taxonomic_rank'
-    ),
-    array(
-      'name' => 'Tripal Contact',
-      'path' => '{tripal_chado}/files/tcontact.obo',
-      'auto_load' => TRUE,
-      'cv_name' => 'tripal_contact'
-    ),
-    array(
-      'name' => 'Tripal Publication',
-      'path' => '{tripal_chado}/files/tpub.obo',
-      'auto_load' => TRUE,
-      'cv_name' => 'tripal_pub'
-    ),
-     array(
-       'name' => 'Sequence Ontology',
-       'path' => 'http://purl.obolibrary.org/obo/so.obo',
-       'auto_load' => TRUE,
-       'cv_name' => 'sequence'
-     ),
-
-  );
-  for ($i = 0; $i < count($ontologies); $i++) {
-    $obo_id = tripal_insert_obo($ontologies[$i]['name'], $ontologies[$i]['path']);
-    if ($ontologies[$i]['auto_load'] == TRUE) {
-      // Only load ontologies that are not already in the cv table.
-      $cv = tripal_get_cv(array('name' => $ontologies[$i]['cv_name']));
-      if (!$cv) {
-        tripal_chado_load_obo_v1_2_id($obo_id);
-      }
-    }
-  }
-}
-/**
- * Prepares Chado for use by Tripal.
- */
-function tripal_chado_prepare_chado() {
-
-  try {
-
-    // We want to provide a set of commonly used entity types by default. This
-    // way when a user first installs Tripal there are some commonly used
-    // formats.
-    module_load_include('inc', 'tripal', 'api/tripal.api');
-    module_load_include('inc', 'tripal', 'includes/tripal.admin');
-    module_load_include('inc', 'tripal_chado', 'includes/tripal_chado.semweb');
-
-    // Get the effective version.  Pass true as second argument
-    // to warn the user if the current version is not compatible.
-    $version = chado_get_version(FALSE, FALSE);
-
-    // We want to force the version of Chado to be set properly.
-    $real_version = chado_get_version(TRUE);
-
-    // Create the temp table we will use for loading OBO files.
-    tripal_chado_add_tripal_obo_temp_table();
-
-    // Import commonly used ontologies if needed.
-    tripal_chado_load_ontologies();
-
-    // Populate the semantic web associations for Chado tables/fields.
-    tripal_chado_populate_chado_semweb_table();
-
-    // Initialize the population of the chado_cvterm_mapping table.  This will
-    // map existing data types already in Chado so that when users want to
-    // add new content types it simplifies the form for them.
-    tripal_chado_map_cvterms();
-
-    // Create the 'Organism' entity type. This uses the obi:organism term.
-    $error = '';
-    $args = array(
-      'vocabulary' => 'OBI',
-      'accession' => '0100026',
-      'term_name' => 'organism',
-      'storage_args' => array(
-        'data_table' => 'organism',
-      )
-    );
-    $term = tripal_load_term_entity(array('vocabulary' => 'OBI', 'accession' => '0100026'));
-    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
-    if (!$term or !$bundle) {
-      if (!tripal_create_bundle($args, $error)) {
-        throw new Exception($error['!message']);
-      }
-    }
-
-    // Create the 'Analysis' entity type. This uses the local:analysis term.
-    $error = '';
-    $args = array(
-      'vocabulary' => 'local',
-      'accession' => 'analysis',
-      'term_name' => 'analysis',
-      'storage_args' => array(
-        'data_table' => 'analysis',
-      )
-    );
-    $term = tripal_load_term_entity(array('vocabulary' => 'local', 'accession' => 'analysis'));
-    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
-    if (!$term or !$bundle) {
-      if (!tripal_create_bundle($args, $error)) {
-        throw new Exception($error['!message']);
-      }
-    }
-
-    // Create the 'Project' entity type. This uses the local:project term.
-    $error = '';
-    $args = array(
-      'vocabulary' => 'local',
-      'accession' => 'project',
-      'term_name' => 'project',
-      'storage_args' => array(
-        'data_table' => 'project',
-      )
-    );
-    $term = tripal_load_term_entity(array('vocabulary' => 'local', 'accession' => 'project'));
-    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
-    if (!$term or !$bundle) {
-      if (!tripal_create_bundle($args, $error)) {
-        throw new Exception($error['!message']);
-      }
-    }
-
-    // Create the 'Map' entity type. This uses the local:project term.
-    $error = '';
-    $args = array(
-      'vocabulary' => 'data',
-      'accession' => '1274',
-      'term_name' => 'Map',
-      'storage_args' => array(
-        'data_table' => 'featuremap',
-      )
-    );
-    $term = tripal_load_term_entity(array('vocabulary' => 'data', 'accession' => '1274'));
-    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
-    if (!$term or !$bundle) {
-      if (!tripal_create_bundle($args, $error)) {
-        throw new Exception($error['!message']);
-      }
-    }
-
-    // Import a publication so we get all of the properties before
-    // creating the content type.
-    tripal_import_pub_by_dbxref('PMID:24163125');
-
-    // Create the 'Publication' entity type.
-    $error = '';
-    $args = array(
-      'vocabulary' => 'TPUB',
-      'accession' => '0000002',
-      'term_name' => 'Publication',
-      'storage_args' => array(
-        'data_table' => 'pub',
-      )
-    );
-    $term = tripal_load_term_entity(array('vocabulary' => 'TPUB', 'accession' => '0000002'));
-    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
-    if (!$term or !$bundle) {
-      if (!tripal_create_bundle($args, $error)) {
-        throw new Exception($error['!message']);
-      }
-    }
-
-    // Now remove the publication that was added above.
-    $values = array(
-      'dbxref_id' => array(
-        'accession' => '24163125',
-        'db_id' => array(
-          'name' => 'PMID',
-        ),
-      ),
-    );
-    $result = chado_select_record('pub_dbxref', array('pub_id'), $values);
-    chado_delete_record('pub', array('pub_id' => $result[0]->pub_id));
-
-    // Create the 'Gene' entity type.
-    $error = '';
-    $args = array(
-      'vocabulary' => 'SO',
-      'accession' => '0000704',
-      'term_name' => 'gene',
-      'storage_args' => array(
-        'data_table' => 'feature',
-        'type_column' => 'type_id',
-      )
-    );
-    $term = tripal_load_term_entity(array('vocabulary' => 'SO', 'accession' => '0000704'));
-    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
-    if (!$term or !$bundle) {
-      if (!tripal_create_bundle($args, $error)) {
-        throw new Exception($error['!message']);
-      }
-    }
-
-    // Create the 'mRNA' entity type.
-    $error = '';
-    $args = array(
-      'vocabulary' => 'SO',
-      'accession' => '0000234',
-      'term_name' => 'mRNA',
-      'storage_args' => array(
-        'data_table' => 'feature',
-        'type_column' => 'type_id',
-      )
-    );
-    $term = tripal_load_term_entity(array('vocabulary' => 'SO', 'accession' => '0000234'));
-    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
-    if (!$term or !$bundle) {
-      if (!tripal_create_bundle($args, $error)) {
-        throw new Exception($error['!message']);
-      }
-    }
-
-    // Add the cv_root_mview.
-    tripal_chado_add_cv_root_mview_mview();
-
-    // Support for Analyses
-    // we may need the analysisfeatureprop table if it doesn't already exist
-    tripal_chado_add_analysisfeatureprop_table();
-
-    // add materialized views
-    tripal_chado_add_analysis_organism_mview();
-
-    // Support for Contacts
-    // Add the contactprop table to Chado.
-    tripal_chado_add_contactprop_table();
-
-    // Support for Features
-    // Add the materialized view.
-    tripal_chado_add_organism_feature_count_mview();
-
-    // Add the custom tables for the GFF loader.
-    tripal_chado_add_tripal_gff_temp_table();
-    tripal_chado_add_tripal_gffcds_temp_table();
-    tripal_chado_add_tripal_gffprotein_temp_table();
-
-    // Support for FeatureMaps.
-    // add the featuremapprop table to Chado
-    tripal_chado_add_featuremap_dbxref_table();
-    tripal_chado_add_featuremapprop_table();
-    //tripal_chado_add_featuremappos_table();
-
-    // Support for Libraries.
-    // add the materialized view
-    tripal_chado_add_library_feature_count_mview();
-
-    // Support for Pubs.
-    // add the custom tables
-    tripal_chado_add_pubauthor_contact_table();
-    // Add the supported loaders
-    variable_set('tripal_pub_supported_dbs', array('PMID', 'AGL'));
-
-    // Support for Stocks.
-    // add the materialized view
-    tripal_chado_add_organism_stock_count_mview();
-
-    // Set a variable to indicate the site is prepared.
-    variable_set('tripal_chado_is_prepared', TRUE);
-  }
-  catch (Exception $e) {
-    throw new Exception($e);
-  }
-}
-
-/**
- * Creates a materialized view that stores the type & number of stocks per organism
- *
- * @ingroup tripal_stock
- */
-function tripal_chado_add_organism_stock_count_mview() {
-  $view_name = 'organism_stock_count';
-  $comment = 'Stores the type and number of stocks per organism';
-
-  $schema = array(
-    'description' => $comment,
-    'table' => $view_name,
-    'fields' => array(
-      'organism_id' => array(
-        'size' => 'big',
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-      'genus' => array(
-        'type' => 'varchar',
-        'length' => '255',
-        'not null' => TRUE,
-      ),
-      'species' => array(
-        'type' => 'varchar',
-        'length' => '255',
-        'not null' => TRUE,
-      ),
-      'common_name' => array(
-        'type' => 'varchar',
-        'length' => '255',
-        'not null' => FALSE,
-      ),
-      'num_stocks' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-      'cvterm_id' => array(
-        'size' => 'big',
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-      'stock_type' => array(
-        'type' => 'varchar',
-        'length' => '255',
-        'not null' => TRUE,
-      ),
-    ),
-    'indexes' => array(
-      'organism_stock_count_idx1' => array('organism_id'),
-      'organism_stock_count_idx2' => array('cvterm_id'),
-      'organism_stock_count_idx3' => array('stock_type'),
-    ),
-  );
-
-  $sql = "
-    SELECT
-        O.organism_id, O.genus, O.species, O.common_name,
-        count(S.stock_id) as num_stocks,
-        CVT.cvterm_id, CVT.name as stock_type
-     FROM organism O
-        INNER JOIN stock S  ON O.Organism_id = S.organism_id
-        INNER JOIN cvterm CVT ON S.type_id     = CVT.cvterm_id
-     GROUP BY
-        O.Organism_id, O.genus, O.species, O.common_name, CVT.cvterm_id, CVT.name
-  ";
-
-  tripal_add_mview($view_name, 'tripal_stock', $schema, $sql, $comment);
-}
-
-/**
- * Add custom table related to publications
- *  - pubauthor_contact
- *
- * @ingroup tripal_pub
- */
-function tripal_chado_add_pubauthor_contact_table() {
-  $schema = array (
-    'table' => 'pubauthor_contact',
-    'fields' => array (
-      'pubauthor_contact_id' => array (
-        'type' => 'serial',
-        'not null' => true,
-      ),
-      'contact_id' => array (
-        'type' => 'int',
-        'not null' => true,
-      ),
-      'pubauthor_id' => array (
-        'type' => 'int',
-        'not null' => true,
-      ),
-    ),
-    'primary key' => array (
-      0 => 'pubauthor_contact_id',
-    ),
-    'unique keys' => array (
-      'pubauthor_contact_c1' => array (
-        0 => 'contact_id',
-        1 => 'pubauthor_id',
-      ),
-    ),
-    'foreign keys' => array (
-      'contact' => array (
-        'table' => 'contact',
-        'columns' => array (
-          'contact_id' => 'contact_id',
-        ),
-      ),
-      'pubauthor' => array (
-        'table' => 'pubauthor',
-        'columns' => array (
-          'pubauthor_id' => 'pubauthor_id',
-        ),
-      ),
-    ),
-  );
-  chado_create_custom_table('pubauthor_contact', $schema, TRUE);
-}
-
-
-/**
- * Adds a materialized view keeping track of the type of features associated with each library
- *
- * @ingroup tripal_library
- */
-function tripal_chado_add_library_feature_count_mview(){
-  $view_name = 'library_feature_count';
-  $comment = 'Provides count of feature by type that are associated with all libraries';
-
-  $schema = array(
-    'table' => $view_name,
-    'description' => $comment,
-    'fields' => array(
-      'library_id' => array(
-        'size' => 'big',
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-      'name' => array(
-        'type' => 'varchar',
-        'length' => 255,
-        'not null' => TRUE,
-      ),
-      'num_features' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-      'feature_type' => array(
-        'type' => 'varchar',
-        'length' => 255,
-        'not null' => TRUE,
-      ),
-    ),
-    'indexes' => array(
-      'library_feature_count_idx1' => array('library_id'),
-    ),
-  );
-
-  $sql = "
-    SELECT
-      L.library_id, L.name,
-      count(F.feature_id) as num_features,
-      CVT.name as feature_type
-    FROM library L
-      INNER JOIN library_feature LF  ON LF.library_id = L.library_id
-      INNER JOIN feature F           ON LF.feature_id = F.feature_id
-      INNER JOIN cvterm CVT          ON F.type_id     = CVT.cvterm_id
-    GROUP BY L.library_id, L.name, CVT.name
-  ";
-
-  tripal_add_mview($view_name, 'tripal_library', $schema, $sql, $comment);
-}
-
-/**
- * Add custom tables needed by the feature map module
- *  - featuremapprop
- *  - featuremap_dbxref
- *  - featureposprop
- *
- * @ingroup tripal_featuremap
- */
-function tripal_chado_add_featuremapprop_table(){
-  // add the featuremaprop table to Chado
-  $schema = array (
-    'table' => 'featuremapprop',
-    'fields' => array (
-      'featuremapprop_id' => array (
-        'type' => 'serial',
-        'not null' => true,
-      ),
-      'featuremap_id' => array (
-        'type' => 'int',
-        'not null' => true,
-      ),
-      'type_id' => array (
-        'type' => 'int',
-        'not null' => true,
-      ),
-      'value' => array (
-        'type' => 'text',
-        'not null' => false,
-      ),
-      'rank' => array (
-        'type' => 'int',
-        'not null' => true,
-        'default' => 0,
-      ),
-    ),
-    'primary key' => array (
-      0 => 'featuremapprop_id',
-    ),
-    'unique keys' => array (
-      'featuremapprop_c1' => array (
-        0 => 'featuremap_id',
-        1 => 'type_id',
-        2 => 'rank',
-      ),
-    ),
-    'indexes' => array (
-      'featuremapprop_idx1' => array (
-        0 => 'featuremap_id',
-      ),
-      'featuremapprop_idx2' => array (
-        0 => 'type_id',
-      ),
-    ),
-    'foreign keys' => array (
-      'cvterm' => array (
-        'table' => 'cvterm',
-        'columns' => array (
-          'type_id' => 'cvterm_id',
-        ),
-      ),
-      'featuremap' => array (
-        'table' => 'featuremap',
-        'columns' => array (
-          'featuremap_id' => 'featuremap_id',
-        ),
-      ),
-    ),
-  );
-  chado_create_custom_table('featuremapprop', $schema, TRUE);
-}
-/**
- *
- */
-function tripal_chado_add_featuremap_dbxref_table(){
-  // add the featuremap_dbxref table to Chado
-  $schema = array (
-    'table' => 'featuremap_dbxref',
-    'fields' => array (
-      'featuremap_dbxref_id' => array (
-        'type' => 'serial',
-        'not null' => true,
-      ),
-      'featuremap_id' => array (
-        'type' => 'int',
-        'not null' => true,
-      ),
-      'dbxref_id' => array (
-        'type' => 'int',
-        'not null' => true,
-      ),
-    ),
-    'primary key' => array (
-      0 => 'featuremap_dbxref_id',
-    ),
-    'unique keys' => array (
-      'featuremap_dbxref_c1' => array (
-        0 => 'featuremap_id',
-        1 => 'dbxref_id',
-      ),
-    ),
-    'indexes' => array (
-      'featuremap_dbxref_idx1' => array (
-        0 => 'featuremap_dbxref_id',
-      ),
-      'featuremap_dbxref_idx2' => array (
-        0 => 'dbxref_id',
-      ),
-    ),
-    'foreign keys' => array (
-      'dbxref' => array (
-        'table' => 'dbxref',
-        'columns' => array (
-          'dbxref_id' => 'dbxref_id',
-        ),
-      ),
-      'featuremap' => array (
-        'table' => 'featuremap',
-        'columns' => array (
-          'featuremap_id' => 'featuremap_id',
-        ),
-      ),
-    ),
-    'referring_tables' => NULL,
-  );
-  chado_create_custom_table('featuremap_dbxref', $schema, TRUE);
-}
-/**
- *
- */
-function tripal_chado_add_featureposprop_table(){
-  $schema = array (
-    'table' => 'featureposprop',
-    'fields' => array (
-      'featureposprop_id' => array (
-        'type' => 'serial',
-        'not null' => true,
-      ),
-      'featurepos_id' => array (
-        'type' => 'int',
-        'not null' => true,
-      ),
-      'type_id' => array (
-        'type' => 'int',
-        'not null' => true,
-      ),
-      'value' => array (
-        'type' => 'text',
-        'not null' => false,
-      ),
-      'rank' => array (
-        'type' => 'int',
-        'not null' => true,
-        'default' => 0,
-      ),
-    ),
-    'primary key' => array (
-      0 => 'featureposprop_id',
-    ),
-    'unique keys' => array (
-      'featureposprop_id' => array (
-        0 => 'featurepos_id',
-        1 => 'type_id',
-        2 => 'rank',
-      ),
-    ),
-    'indexes' => array (
-      'featureposprop_c1' => array (
-        0 => 'featurepos_id',
-      ),
-      'featureposprop_idx2' => array (
-        0 => 'type_id',
-      ),
-    ),
-    'foreign keys' => array (
-      'cvterm' => array (
-        'table' => 'cvterm',
-        'columns' => array (
-          'type_id' => 'cvterm_id',
-        ),
-      ),
-      'featurepos' => array (
-        'table' => 'featurepos',
-        'columns' => array (
-          'featurepos_id' => 'featurepos_id',
-        ),
-      ),
-    ),
-  );
-  chado_create_custom_table('featureposprop', $schema, TRUE);
-}
-
-/**
- *
- */
-function tripal_chado_add_tripal_gff_temp_table() {
-  $schema = array(
-    'table' => 'tripal_gff_temp',
-    'fields' => array(
-      'feature_id' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-      'organism_id' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-      'uniquename' => array(
-        'type' => 'text',
-        'not null' => TRUE,
-      ),
-      'type_name' => array(
-        'type' => 'varchar',
-        'length' => '1024',
-        'not null' => TRUE,
-      ),
-    ),
-    'indexes' => array(
-      'tripal_gff_temp_idx0' => array('feature_id'),
-      'tripal_gff_temp_idx0' => array('organism_id'),
-      'tripal_gff_temp_idx1' => array('uniquename'),
-    ),
-    'unique keys' => array(
-      'tripal_gff_temp_uq0' => array('feature_id'),
-      'tripal_gff_temp_uq1' => array('uniquename', 'organism_id', 'type_name'),
-    ),
-  );
-  chado_create_custom_table('tripal_gff_temp', $schema, TRUE);
-}
-
-/**
- *
- */
-function tripal_chado_add_tripal_gffcds_temp_table($skip_recreate = TRUE) {
-  $schema = array(
-    'table' => 'tripal_gffcds_temp',
-    'fields' => array(
-      'feature_id' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-      'parent_id' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-      'phase' => array(
-        'type' => 'int',
-        'not null' => FALSE,
-      ),
-      'strand' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-      'fmin' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-      'fmax' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-    ),
-    'indexes' => array(
-      'tripal_gff_temp_idx0' => array('feature_id'),
-      'tripal_gff_temp_idx0' => array('parent_id'),
-    ),
-  );
-  chado_create_custom_table('tripal_gffcds_temp', $schema, $skip_recreate);
-}
-
-/**
- *
- */
-function tripal_chado_add_tripal_gffprotein_temp_table() {
-  $schema = array(
-    'table' => 'tripal_gffprotein_temp',
-    'fields' => array(
-      'feature_id' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-      'parent_id' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-      'fmin' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-      'fmax' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-    ),
-    'indexes' => array(
-      'tripal_gff_temp_idx0' => array('feature_id'),
-      'tripal_gff_temp_idx0' => array('parent_id'),
-    ),
-    'unique keys' => array(
-      'tripal_gff_temp_uq0' => array('feature_id'),
-    ),
-  );
-  chado_create_custom_table('tripal_gffprotein_temp', $schema, TRUE);
-}
-/**
- * Creates a materialized view that stores the type & number of features per organism
- *
- * @ingroup tripal_feature
- */
-function tripal_chado_add_organism_feature_count_mview() {
-  $view_name = 'organism_feature_count';
-  $comment = 'Stores the type and number of features per organism';
-
-  $schema = array(
-    'description' => $comment,
-    'table' => $view_name,
-    'fields' => array(
-      'organism_id' => array(
-        'size' => 'big',
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-      'genus' => array(
-        'type' => 'varchar',
-        'length' => '255',
-        'not null' => TRUE,
-      ),
-      'species' => array(
-        'type' => 'varchar',
-        'length' => '255',
-        'not null' => TRUE,
-      ),
-      'common_name' => array(
-        'type' => 'varchar',
-        'length' => '255',
-        'not null' => FALSE,
-      ),
-      'num_features' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-      'cvterm_id' => array(
-        'size' => 'big',
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-      'feature_type' => array(
-        'type' => 'varchar',
-        'length' => '255',
-        'not null' => TRUE,
-      ),
-    ),
-    'indexes' => array(
-      'organism_feature_count_idx1' => array('organism_id'),
-      'organism_feature_count_idx2' => array('cvterm_id'),
-      'organism_feature_count_idx3' => array('feature_type'),
-    ),
-  );
-
-  $sql = "
-    SELECT
-        O.organism_id, O.genus, O.species, O.common_name,
-        count(F.feature_id) as num_features,
-        CVT.cvterm_id, CVT.name as feature_type
-     FROM organism O
-        INNER JOIN feature F  ON O.Organism_id = F.organism_id
-        INNER JOIN cvterm CVT ON F.type_id     = CVT.cvterm_id
-     GROUP BY
-        O.Organism_id, O.genus, O.species, O.common_name, CVT.cvterm_id, CVT.name
-  ";
-
-  tripal_add_mview($view_name, 'tripal_feature', $schema, $sql, $comment);
-}
-/**
- * Add any custom tables needed by this module.
- * - Contactprop: keep track of properties of contact
- *
- * @ingroup tripal_contact
- */
-function tripal_chado_add_contactprop_table(){
-  $schema = array (
-    'table' => 'contactprop',
-    'fields' => array (
-      'contactprop_id' => array (
-        'type' => 'serial',
-        'not null' => true,
-      ),
-      'contact_id' => array (
-        'type' => 'int',
-        'not null' => true,
-      ),
-      'type_id' => array (
-        'type' => 'int',
-        'not null' => true,
-      ),
-      'value' => array (
-        'type' => 'text',
-        'not null' => false,
-      ),
-      'rank' => array (
-        'type' => 'int',
-        'not null' => true,
-        'default' => 0,
-      ),
-    ),
-    'primary key' => array (
-      0 => 'contactprop_id',
-    ),
-    'unique keys' => array (
-      'contactprop_c1' => array (
-        0 => 'contact_id',
-        1 => 'type_id',
-        2 => 'rank',
-      ),
-    ),
-    'indexes' => array (
-      'contactprop_idx1' => array (
-        0 => 'contact_id',
-      ),
-      'contactprop_idx2' => array (
-        0 => 'type_id',
-      ),
-    ),
-    'foreign keys' => array (
-      'cvterm' => array (
-        'table' => 'cvterm',
-        'columns' => array (
-          'type_id' => 'cvterm_id',
-        ),
-      ),
-      'contact' => array (
-        'table' => 'contact',
-        'columns' => array (
-          'contact_id' => 'contact_id',
-        ),
-      ),
-    ),
-  );
-  chado_create_custom_table('contactprop', $schema, TRUE);
-}
-/**
- * Create a legacy custom chado table (analysisfeatureprop) to store properties of
- * analysisfeature links.
- *
- * @ingroup tripal_analysis
- */
-function tripal_chado_add_analysisfeatureprop_table() {
-
-  // Create analysisfeatureprop table in chado.  This is needed for Chado
-  // version 1.11, the table exists in Chado 1.2.
-  if (!db_table_exists('chado.analysisfeatureprop')) {
-    $sql = "
-      CREATE TABLE {analysisfeatureprop} (
-        analysisfeatureprop_id SERIAL PRIMARY KEY,
-        analysisfeature_id     INTEGER NOT NULL,
-        type_id                INTEGER NOT NULL,
-        value                  TEXT,
-        rank                   INTEGER NOT NULL,
-        CONSTRAINT analysisfeature_id_type_id_rank UNIQUE (analysisfeature_id, type_id, rank),
-        CONSTRAINT analysisfeatureprop_analysisfeature_id_fkey FOREIGN KEY (analysisfeature_id) REFERENCES {analysisfeature}(analysisfeature_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
-        CONSTRAINT analysisfeatureprop_type_id_fkey FOREIGN KEY (type_id) REFERENCES {cvterm}(cvterm_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
-      )
-    ";
-    chado_query($sql);
-  }
-}
-/**
- * Creates a view showing the link between an organism & it's analysis through associated features.
- *
- * @ingroup tripal_analysis
- */
-function tripal_chado_add_analysis_organism_mview() {
-  $view_name = 'analysis_organism';
-  $comment = t('This view is for associating an organism (via it\'s associated features) to an analysis.');
-
-  // this is the SQL used to identify the organism to which an analsysis
-  // has been used.  This is obtained though the analysisfeature -> feature -> organism
-  // joins
-  $sql = "
-    SELECT DISTINCT A.analysis_id, O.organism_id
-    FROM analysis A
-      INNER JOIN analysisfeature AF ON A.analysis_id = AF.analysis_id
-      INNER JOIN feature F          ON AF.feature_id = F.feature_id
-      INNER JOIN organism O         ON O.organism_id = F.organism_id
-  ";
-
-  // the schema array for describing this view
-  $schema = array(
-    'table' => $view_name,
-    'description' => $comment,
-    'fields' => array(
-      'analysis_id' => array(
-        'size' => 'big',
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-      'organism_id' => array(
-        'size' => 'big',
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-    ),
-    'indexes' => array(
-      'networkmod_qtl_indx0' => array('analysis_id'),
-      'networkmod_qtl_indx1' => array('organism_id'),
-    ),
-    'foreign keys' => array(
-      'analysis' => array(
-        'table' => 'analysis',
-        'columns' => array(
-          'analysis_id' => 'analysis_id',
-        ),
-      ),
-      'organism' => array(
-        'table' => 'organism',
-        'columns' => array(
-          'organism_id' => 'organism_id',
-        ),
-      ),
-    ),
-  );
-
-  // add the view
-  tripal_add_mview($view_name, 'tripal_analysis', $schema, $sql, $comment);
-}
-
-/**
- * Add a materialized view of root terms for all chado cvs. This is needed for viewing cv trees
- *
- * @ingroup tripal_cv
- */
-function tripal_chado_add_cv_root_mview_mview() {
-  $mv_name = 'cv_root_mview';
-  $comment = 'A list of the root terms for all controlled vocabularies. This is needed for viewing CV trees';
-  $schema = array(
-    'table' => $mv_name,
-    'description' => $comment,
-    'fields' => array(
-      'name' => array(
-        'type' => 'varchar',
-        'length' => 255,
-        'not null' => TRUE,
-      ),
-      'cvterm_id' => array(
-        'size' => 'big',
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-      'cv_id' => array(
-        'size' => 'big',
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-      'cv_name' => array(
-        'type' => 'varchar',
-        'length' => 255,
-        'not null' => TRUE,
-      ),
-    ),
-    'indexes' => array(
-      'cv_root_mview_indx1' => array('cvterm_id'),
-      'cv_root_mview_indx2' => array('cv_id'),
-    ),
-  );
-
-  $sql = "
-    SELECT DISTINCT CVT.name,CVT.cvterm_id, CV.cv_id, CV.name
-    FROM cvterm_relationship CVTR
-      INNER JOIN cvterm CVT on CVTR.object_id = CVT.cvterm_id
-      INNER JOIN cv CV on CV.cv_id = CVT.cv_id
-    WHERE CVTR.object_id not in
-      (SELECT subject_id FROM cvterm_relationship)
-  ";
-
-  // Create the MView
-  tripal_add_mview($mv_name, 'tripal_cv', $schema, $sql, $comment);
-}
-/**
- * Creates a temporary table to store obo details while loading an obo file
- *
- * @ingroup tripal_cv
- */
-function tripal_chado_add_tripal_obo_temp_table() {
-  // the tripal_obo_temp table is used for temporary housing of records when loading OBO files
-  // we create it here using plain SQL because we want it to be in the chado schema but we
-  // do not want to use the Tripal Custom Table API because we don't want it to appear in the
-  // list of custom tables.  It needs to be available for the Tripal Chado API so we create it
-  // here and then define it in the tripal_cv/api/tripal_cv.schema.api.inc
-  if (!chado_table_exists('tripal_obo_temp')) {
-    $sql = "
-      CREATE TABLE {tripal_obo_temp} (
-        id character varying(255) NOT NULL,
-        stanza text NOT NULL,
-        type character varying(50) NOT NULL,
-        CONSTRAINT tripal_obo_temp_uq0 UNIQUE (id)
-      );
-    ";
-    chado_query($sql);
-    $sql = "CREATE INDEX tripal_obo_temp_idx0 ON {tripal_obo_temp} USING btree (id)";
-    chado_query($sql);
-    $sql = "CREATE INDEX tripal_obo_temp_idx1 ON {tripal_obo_temp} USING btree (type)";
-    chado_query($sql);
-  }
-}
-

+ 18 - 0
tripal_chado/tripal_chado.install

@@ -791,3 +791,21 @@ function tripal_chado_update_7302(){
     throw new DrupalUpdateException('Could not perform update: '. $error);
   }
 }
+
+/**
+ * Fixes inconsistency with Chado v1.3 update if was applied.
+ */
+function tripal_chado_update_7303() {
+  try {
+    $chado_version = chado_get_version();
+    if ($chado_version == '1.3') {
+      module_load_include('inc', 'tripal_chado', 'includes/setup/tripal_chado.setup');
+      tripal_chado_fix_v1_3_custom_tables();
+    }
+  }
+  catch (\PDOException $e) {
+    $transaction->rollback();
+    $error = $e->getMessage();
+    throw new DrupalUpdateException('Could not perform update: '. $error);
+  }
+}

+ 25 - 27
tripal_chado/tripal_chado.module

@@ -144,7 +144,7 @@ function tripal_chado_menu() {
     'page arguments' => array('tripal_chado_prepare_form'),
     'type' => MENU_NORMAL_ITEM,
     'access arguments' => array('install chado'),
-    'file' => 'includes/tripal_chado.setup.inc',
+    'file' => 'includes/setup/tripal_chado.setup.inc',
     'file path' => drupal_get_path('module', 'tripal_chado'),
     'weight' => -99
   );
@@ -350,15 +350,15 @@ function tripal_chado_menu() {
   //////////////////////////////////////////////////////////////////////////////
   //                           Data Loaders
   //////////////////////////////////////////////////////////////////////////////
-  $items['admin/tripal/storage/chado/loaders'] = array(
+  $items['admin/tripal/loaders'] = array(
     'title' => 'Data Loaders',
     'description' => t('Tools facilitating data import.'),
     'access arguments' => array('administer tripal'),
     'type' => MENU_NORMAL_ITEM,
     'weight' => 6
   );
-  $items['admin/tripal/storage/chado/loaders/fasta_loader'] = array(
-    'title' => 'FASTA file Loader',
+  $items['admin/tripal/loaders/fasta_loader'] = array(
+    'title' => 'Chado FASTA File Loader',
     'description' => 'Load sequences from a multi-FASTA file into Chado',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('tripal_feature_fasta_load_form'),
@@ -367,8 +367,8 @@ function tripal_chado_menu() {
     'file path' => drupal_get_path('module', 'tripal_chado'),
     'type' => MENU_NORMAL_ITEM,
   );
-  $items['admin/tripal/storage/chado/loaders/gff3_load'] = array(
-    'title' => 'GFF3 file Loader',
+  $items['admin/tripal/loaders/gff3_load'] = array(
+    'title' => 'Chado GFF3 File Loader',
     'description' => 'Import a GFF3 file into Chado',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('tripal_feature_gff3_load_form'),
@@ -377,8 +377,8 @@ function tripal_chado_menu() {
     'file path' => drupal_get_path('module', 'tripal_chado'),
     'type' => MENU_NORMAL_ITEM,
   );
-  $items['admin/tripal/storage/chado/loaders/ncbi_taxonomy_loader'] = array(
-    'title' => 'NCBI Taxonomy Loader',
+  $items['admin/tripal/loaders/ncbi_taxonomy_loader'] = array(
+    'title' => 'Chado NCBI Taxonomy Loader',
     'description' => 'Loads taxonomic details about installed organisms.',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('tripal_chado_taxonomy_load_form'),
@@ -389,8 +389,8 @@ function tripal_chado_menu() {
   );
 
   // Data Loaders
-  $items['admin/tripal/storage/chado/loaders/newic_phylotree_loader'] = array(
-    'title' => 'Phylogenetic Trees (Newic format)',
+  $items['admin/tripal/loaders/newic_phylotree_loader'] = array(
+    'title' => 'Chado Phylogenetic Trees (Newic format)',
     'description' => 'Loads phylogenetic trees in Newic format.',
     'page callback' => 'drupal_goto',
     'page arguments' => array('node/add/chado-phylotree'),
@@ -398,8 +398,8 @@ function tripal_chado_menu() {
     'type' => MENU_NORMAL_ITEM,
   );
 
-  $items['admin/tripal/storage/chado/loaders/pub'] = array(
-    'title' => t('Publication Importers'),
+  $items['admin/tripal/loaders/pub'] = array(
+    'title' => t('Chado Publication Importers'),
     'description' => t('Create and modify importers that can connect to and retreive publications from remote databases.'),
     'page callback' => 'tripal_pub_importers_list',
     'access arguments' => array('administer tripal'),
@@ -409,7 +409,7 @@ function tripal_chado_menu() {
     'weight' => 0
   );
 
-  $items['admin/tripal/storage/chado/loaders/pub/new'] = array(
+  $items['admin/tripal/loaders/pub/new'] = array(
     'title' => t('Add an Importer'),
     'description' => t('Add a new publication importer.'),
     'page callback' => 'tripal_pub_importer_setup_page',
@@ -418,18 +418,17 @@ function tripal_chado_menu() {
     'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
     'file path' => drupal_get_path('module', 'tripal_chado'),
   );
-  $items['admin/tripal/storage/chado/loaders/pub/edit/%'] = array(
+  $items['admin/tripal/loaders/pub/edit/%'] = array(
     'page callback' => 'tripal_pub_importer_setup_page',
-    'page arguments' => array(6, 7),
+    'page arguments' => array(5),
     'access arguments' => array('administer tripal'),
     'type ' => MENU_CALLBACK,
     'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
     'file path' => drupal_get_path('module', 'tripal_chado'),
   );
-  $items['admin/tripal/storage/chado/loaders/pub/raw/%'] = array(
-    'title' => t('Raw Data From Publication Import'),
+  $items['admin/tripal/loaders/pub/raw/%'] = array(
     'page callback' => 'tripal_get_remote_pub_raw_page',
-    'page arguments' => array(6),
+    'page arguments' => array(5),
     'access arguments' => array('administer tripal'),
     'type ' => MENU_CALLBACK,
     'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
@@ -437,8 +436,7 @@ function tripal_chado_menu() {
   );
 
   // add a second link for the importer on the data loaders page
-  $items['admin/tripal/storage/chado/loaders/pub/import'] = array(
-    'title' => t('Publication Importers'),
+  $items['admin/tripal/loaders/pub/import'] = array(
     'page callback' => 'tripal_pub_importers_list',
     'access arguments' => array('administer tripal'),
     'type' => MENU_CALLBACK,
@@ -446,24 +444,24 @@ function tripal_chado_menu() {
     'file path' => drupal_get_path('module', 'tripal_chado'),
   );
 
-  $items['admin/tripal/storage/chado/loaders/pub/submit/%'] = array(
+  $items['admin/tripal/loaders/pub/submit/%'] = array(
     'page callback' => 'tripal_pub_importer_submit_job',
-    'page arguments' => array(7),
+    'page arguments' => array(5),
     'access arguments' => array('administer tripal'),
     'type ' => MENU_CALLBACK,
     'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
     'file path' => drupal_get_path('module', 'tripal_chado'),
   );
 
-  $items['admin/tripal/storage/chado/loaders/pub/delete/%'] = array(
+  $items['admin/tripal/loaders/pub/delete/%'] = array(
     'page callback' => 'tripal_pub_importer_delete',
-    'page arguments' => array(7),
+    'page arguments' => array(5),
     'access arguments' => array('administer tripal'),
     'type ' => MENU_CALLBACK,
     'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
     'file path' => drupal_get_path('module', 'tripal_chado'),
   );
-  $items['admin/tripal/storage/chado/loaders/pub/changedb'] = array(
+  $items['admin/tripal/loaders/pub/changedb'] = array(
     'page callback' => 'tripal_pub_importer_setup_page_update_remotedb',
     'page arguments' => array(),
     'access arguments' => array('administer tripal'),
@@ -472,9 +470,9 @@ function tripal_chado_menu() {
     'file path' => drupal_get_path('module', 'tripal_chado'),
   );
 
-  $items['admin/tripal/storage/chado/loaders/pub/criteria/%/%'] = array(
+  $items['admin/tripal/loaders/pub/criteria/%/%'] = array(
     'page callback' => 'tripal_pub_importer_setup_page_update_criteria',
-    'page arguments' => array(7, 8),
+    'page arguments' => array(5, 6),
     'access arguments' => array('administer tripal'),
     'type ' => MENU_CALLBACK,
     'file' => 'includes/loaders/tripal_chado.pub_importers.inc',