Эх сурвалжийг харах

Merge branch '7.x-2.x' of git.drupal.org:sandbox/spficklin/1337878 into 7.x-2.x

Stephen Ficklin 10 жил өмнө
parent
commit
395de50b36
29 өөрчлөгдсөн 616 нэмэгдсэн , 337 устгасан
  1. 29 13
      tripal_analysis/tripal_analysis.install
  2. 1 1
      tripal_bulk_loader/api/tripal_bulk_loader.api.templates.inc
  3. 12 12
      tripal_bulk_loader/includes/tripal_bulk_loader.admin.templates.inc
  4. 20 3
      tripal_contact/api/tripal_contact.api.inc
  5. 18 7
      tripal_contact/includes/tripal_contact.chado_node.inc
  6. 6 6
      tripal_contact/tripal_contact.install
  7. 26 23
      tripal_core/api/tripal_core.chado_nodes.dbxrefs.api.inc
  8. 18 1
      tripal_core/api/tripal_core.jobs.api.inc
  9. 11 5
      tripal_cv/api/tripal_cv.api.inc
  10. 10 4
      tripal_cv/includes/tripal_cv.cvterm_form.inc
  11. 110 86
      tripal_cv/includes/tripal_cv.obo_loader.inc
  12. 2 2
      tripal_db/api/tripal_db.api.inc
  13. 9 9
      tripal_example/tripal_example.install
  14. 8 2
      tripal_feature/includes/tripal_feature.chado_node.inc
  15. 6 2
      tripal_feature/includes/tripal_feature.gff_loader.inc
  16. 3 3
      tripal_feature/tripal_feature.install
  17. 1 1
      tripal_feature/tripal_feature.module
  18. 114 64
      tripal_featuremap/tripal_featuremap.install
  19. 17 6
      tripal_library/includes/tripal_library.chado_node.inc
  20. 46 24
      tripal_library/tripal_library.install
  21. 31 6
      tripal_natural_diversity/tripal_natural_diversity.install
  22. 1 1
      tripal_organism/tripal_organism.install
  23. 15 4
      tripal_project/includes/tripal_project.chado_node.inc
  24. 8 5
      tripal_project/tripal_project.install
  25. 60 33
      tripal_pub/includes/tripal_pub.chado_node.inc
  26. 7 2
      tripal_pub/includes/tripal_pub.pub_importers.inc
  27. 23 8
      tripal_pub/tripal_pub.install
  28. 1 1
      tripal_stock/includes/tripal_stock.chado_node.inc
  29. 3 3
      tripal_stock/tripal_stock.install

+ 29 - 13
tripal_analysis/tripal_analysis.install

@@ -124,32 +124,48 @@ function tripal_analysis_add_cvs() {
  */
 function tripal_analysis_add_cvterms() {
 
-  tripal_cv_add_cv('tripal_analysis', 'Terms used for managing analyses in Tripal');
+  tripal_insert_cv('tripal_analysis', 'Terms used for managing analyses in Tripal');
 
   // add analysis_date.  This is no longer used (as far as we can tell) but we don't
   // get rid of it in case it is used, so just keep it in the Tripal CV
-  $term = array(
-    'name' => 'analysis_date',
-    'def' => 'The date that an analysis was performed.'
+  tripal_insert_cvterm(
+    array(
+      'name' => 'analysis_date',
+      'definition' => 'The date that an analysis was performed.',
+      'cv_name' => 'tripal',
+      'is_relationship' => 0,
+      'db_name' => 'tripal'
+    ),
+    array('update_existing' => TRUE)
   );
-  tripal_cv_add_cvterm($term, 'tripal', 0, 1, 'tripal');
 
   // add analysis_short_name.  This is no longer used (as far as we can tell) but we don't
   // get rid of it in case it is used, so just keep it in the Tripal CV
-  $term = array(
-    'name' => 'analysis_short_name',
-    'def' => 'A computer legible (no spaces or special characters) abbreviation for the analysis.'
+  tripal_insert_cvterm(
+    array(
+      'name' => 'analysis_short_name',
+      'definition' => 'A computer legible (no spaces or special characters) '
+        . 'abbreviation for the analysis.',
+      'cv_name' => 'tripal',
+      'is_relationship' => 0,
+      'db_name' => 'tripal'
+    ),
+    array('update_existing' => TRUE)
   );
-  tripal_cv_add_cvterm($term, 'tripal', 0, 1 , 'tripal');
 
 
   // the 'analysis_property' vocabulary is for user definable properties wo we
   // will add an 'Analysis Type' to this vocubulary
-  $term = array(
-    'name' => 'Analysis Type',
-    'def' => 'The type of analysis that was performed.'
+  tripal_insert_cvterm(
+    array(
+      'name' => 'Analysis Type',
+      'definition' => 'The type of analysis that was performed.',
+      'cv_name' => 'analysis_property',
+      'is_relationship' => 0,
+      'db_name' => 'tripal'
+    ),
+    array('update_existing' => TRUE)
   );
-  tripal_cv_add_cvterm($term, 'analysis_property', 0, 1, 'tripal');
 }
 
 /**

+ 1 - 1
tripal_bulk_loader/api/tripal_bulk_loader.api.templates.inc

@@ -127,7 +127,7 @@ function tripal_delete_bulk_loader_field($priority, $delete_field_index, $templa
 
   // If this field was the only one in the current record, also delete the record
   if (empty($new_template_array[$priority]['fields'])) {
-    $new_template_array = tripal_bulk_loader_delete_record($priority, $new_template_array);
+    $new_template_array = tripal_delete_bulk_loader_record($priority, $new_template_array);
   }
 
   return $new_template_array;

+ 12 - 12
tripal_bulk_loader/includes/tripal_bulk_loader.admin.templates.inc

@@ -53,7 +53,7 @@ function tripal_bulk_loader_modify_template_base_form($form, &$form_state = NULL
       $form_state['storage']['record2priority'] = array();
       foreach ($form_state['storage']['template'] as $priority => $record_array) {
         if (!is_array($record_array)) {
-          continue; 
+          continue;
         }
         $form_state['storage']['record2priority'][$record_array['record_id']] = $priority;
       }
@@ -205,11 +205,11 @@ function tripal_bulk_loader_modify_template_base_form($form, &$form_state = NULL
 
     // List Current Fields -------------------------------------------------------------
     $num_fields=0;
-    
+
     // pre-create the URLs for dealing with records & fields. We will substitute values as needed
     $record_href_template = 'admin/tripal/loaders/bulk/template/%template/%action/%priority';
     $field_href_template  = 'admin/tripal/loaders/bulk/template/%template/%action/%priority/%field';
-    
+
     foreach ($form_state['storage']['template'] as $priority => $table_array) {
       if (!is_array($table_array)) {
       continue; }
@@ -875,7 +875,7 @@ function tripal_bulk_loader_edit_template_record_form($form, &$form_state) {
   else {
     $template = $form_state['storage']['template'];
   }
-  
+
   // Tables and default table
   $tables = chado_get_table_names(TRUE);
   if (isset($form_state['values']['chado_table'])) {
@@ -1082,7 +1082,7 @@ function tripal_bulk_loader_edit_template_record_form_validate($form, &$form_sta
 
   // Don't worry about validation when Cancel button is clicked
   if ($form_state['clicked_button']['#value'] == 'Save Record') {
-    $is_unique = tripal_bulk_loader_is_record_name_unique(
+    $is_unique = tripal_is_bulk_loader_record_name_unique(
       $form_state['values']['record_name'],
       $form_state['values']['template_id'],
       $form_state['storage']['template_array'],
@@ -1282,7 +1282,7 @@ function tripal_bulk_loader_delete_template_record_form_submit($form, &$form_sta
   $form_state['storage']['template'] = unserialize($result->template_array);
 
   $form_state['storage']['record2priority'] = array();
-  $new_template = tripal_bulk_loader_delete_record($form_state['storage']['record_id'], $form_state['storage']['template']);
+  $new_template = tripal_delete_bulk_loader_record($form_state['storage']['record_id'], $form_state['storage']['template']);
   if (!empty($new_template)) {
     $form_state['storage']['template'] = $new_template;
   }
@@ -1432,7 +1432,7 @@ function tripal_bulk_loader_duplicate_template_record_form_submit($form, &$form_
  */
 function tripal_bulk_loader_template_field_form_default_values($mode, &$form_state) {
   $v = array();
-  
+
   // mode can be 'create' or 'edit'
   $v['mode'] = $mode;
 
@@ -1450,7 +1450,7 @@ function tripal_bulk_loader_template_field_form_default_values($mode, &$form_sta
   $v['no_field_index'] = (isset($form_state['build_info']['args'][3])) ? FALSE : TRUE;
   $form_state['storage']['field_index'] = $v['field_index'];
   $field_index = $v['field_index'];
-  
+
   if (!array_key_exists('values', $form_state)) {
     $form_state['values'] = array();
   }
@@ -1476,7 +1476,7 @@ function tripal_bulk_loader_template_field_form_default_values($mode, &$form_sta
       $template = $form_state['storage']['template'];
     }
   }
-  
+
   // initialize the record2priority array which keeps track of the order by
   // copying the priority information about each record from the template array
   // into the $form_state['storage']['record2priority'] array
@@ -1487,7 +1487,7 @@ function tripal_bulk_loader_template_field_form_default_values($mode, &$form_sta
     }
     $form_state['storage']['record2priority'][$record_array['record_id']] = $priority;
   }
-  
+
 
   // If we are editing then get the original values
   if ($mode == 'edit' && !$v['no_field_index']) {
@@ -2185,7 +2185,7 @@ function tripal_bulk_loader_template_field_form_validate($form, &$form_state) {
 
   // Don't worry about validation when Cancel button is clicked
   if ($form_state['clicked_button']['#value'] == 'Save Changes') {
-    $is_unique = tripal_bulk_loader_is_record_name_unique(
+    $is_unique = tripal_is_bulk_loader_record_name_unique(
       $form_state['values']['record_name'],
       $form_state['values']['template_id'],
       $form_state['storage']['template_array']
@@ -2459,7 +2459,7 @@ function tripal_bulk_loader_delete_template_field_form_submit($form, &$form_stat
   $result = db_query($sql, array(':template' => $form_state['storage']['template_id']))->fetchObject();
   $form_state['storage']['template'] = unserialize($result->template_array);
 
-  $new_template = tripal_bulk_loader_delete_field(
+  $new_template = tripal_delete_bulk_loader_field(
     $form_state['storage']['record_id'],
     $form_state['storage']['field_id'],
     $form_state['storage']['template']

+ 20 - 3
tripal_contact/api/tripal_contact.api.inc

@@ -46,7 +46,10 @@ function tripal_insert_contact($values) {
   $contact = chado_select_record('contact', array('contact_id'), $values, $options);
 
   if (count($contact) == 0) {
-    $cvterm = tripal_cv_get_cvterm_by_name($type, NULL, 'tripal_contact');
+    $cvterm = tripal_get_cvterm(array(
+      'name' => $type,
+      'cv_id' => array('name' => 'tripal_contact')
+    ));
     if (!$cvterm) {
       tripal_report_error('tripal_contact', TRIPAL_ERROR, "Cannot find contact type '%type'",
         array('%type' => $type));
@@ -71,12 +74,26 @@ function tripal_insert_contact($values) {
   // add the description property. We don't store this in the contact.description
   // field because it is only 255 characters long and may not be enough
   if ($description) {
-    tripal_contact_insert_property($contact['contact_id'], 'contact_description', $description, TRUE);
+    chado_insert_property(
+      'contact',
+      $contact['contact_id'],
+      'contact_description',
+      'tripal_contact',
+      $description,
+      TRUE
+    );
   }
 
   // add in the other properties provided
   foreach ($properties as $key => $value) {
-    $success = tripal_contact_insert_property($contact['contact_id'], $key,$value, TRUE);
+    $success = chado_insert_property(
+      'contact',
+      $contact['contact_id'],
+      $key,
+      'tripal_contact',
+      $value,
+      TRUE
+    );
     if (!$success) {
       tripal_report_error('tripal_contact', TRIPAL_ERROR,
         "Could not add the contact property '%prop'", array('%prop' => $key));

+ 18 - 7
tripal_contact/includes/tripal_contact.chado_node.inc

@@ -95,7 +95,12 @@ function chado_contact_form(&$node, $form_state) {
       $description = $contact->description;
     }
     if (!$description) {
-      $contactprop = tripal_contact_get_property($contact->contact_id, 'contact_description');
+      $contactprop = chado_get_property(
+        'contact',
+        $contact->contact_id,
+        'contact_description',
+        'tripal_contact'
+      );
       $description = (isset($contactprop->value)) ? $contactprop->value : '';
     }
 
@@ -388,7 +393,10 @@ function chado_contact_insert($node) {
 
       // Add the description property
     $properties = chado_retrieve_node_form_properties($node);
-    $contact_descrip_id = tripal_cv_get_cvterm_by_name('contact_description', NULL, 'tripal_contact');
+    $contact_descrip_id = tripal_get_cvterm(array(
+      'name' => 'contact_description',
+      'cv_id' => array('name' =>  'tripal_contact')
+    ));
     $properties[$contact_descrip_id->cvterm_id][0] = $node->description;
 
     // * Properties Form *
@@ -462,7 +470,10 @@ function chado_contact_update($node) {
 
   // Add the description property
   $properties = chado_retrieve_node_form_properties($node);
-  $contact_descrip_id = tripal_cv_get_cvterm_by_name('contact_description', NULL, 'tripal_contact');
+  $contact_descrip_id = tripal_get_cvterm(array(
+    'name' => 'contact_description',
+    'cv_id' => array('name' => 'tripal_contact')
+  ));
   $properties[$contact_descrip_id->cvterm_id][0] = $node->description;
 
   // now add in the properties by first removing any the contact
@@ -649,12 +660,12 @@ function tripal_contact_node_insert($node) {
 
       // find the contact and add in the details
       $contact_id = chado_get_id_from_nid('contact', $node->nid);
-     
+
       // get the contact
       $values = array('contact_id' => $contact_id);
       $contact = chado_generate_var('contact', $values);
       $node->contact = $contact;
-      
+
       // Now get the title
       $node->title = chado_get_node_title($node);
 
@@ -675,12 +686,12 @@ function tripal_contact_node_update($node) {
 
       // find the contact and add in the details
       $contact_id = chado_get_id_from_nid('contact', $node->nid);
-       
+
       // get the contact
       $values = array('contact_id' => $contact_id);
       $contact = chado_generate_var('contact', $values);
       $node->contact = $contact;
-      
+
       // Now get the title
       $node->title = chado_get_node_title($node);
 

+ 6 - 6
tripal_contact/tripal_contact.install

@@ -59,8 +59,8 @@ function tripal_contact_install() {
 
   // add loading of the the tripal contact ontology to the job queue
   $obo_path = drupal_realpath(drupal_get_path('module', 'tripal_contact') . '/files/tcontact.obo');
-  $obo_id = tripal_cv_add_obo_ref('Tripal Contacts', $obo_path);
-  tripal_cv_submit_obo_job($obo_id);
+  $obo_id = tripal_insert_obo('Tripal Contacts', $obo_path);
+  tripal_submit_obo_job(array('ob_id' => $obo_id));
 
   // Add cvterms for relationship types
   tripal_contact_add_cvs();
@@ -96,26 +96,26 @@ function tripal_contact_add_cvs() {
 
   // Add the cv for contact properties. This is a default vocabulary in the event
   // that a user does not want to use the tripal_contact vocabulary
-  tripal_cv_add_cv(
+  tripal_insert_cv(
     'contact_property',
     'Contains properties for contacts. This can be used if the tripal_contact vocabulary (which is default for contacts in Tripal) is not desired.'
   );
 
   // add the cv for the contact type. This is a default vocabulary in the event
   // that a user does not want to use the tripal_contact vocabulary
-  tripal_cv_add_cv(
+  tripal_insert_cv(
     'contact_type',
     'Contains types of contacts. This can be used if the tripal_contact vocabulary (which is default for contacts in Tripal) is not desired.'
   );
 
   // Add the cv for the tripal_contact vocabulary which is loaded via the OBO
-  tripal_cv_add_cv(
+  tripal_insert_cv(
    'tripal_contact',
    'A heirarchical set of terms for describing a contact. It is intended to be used as the default vocabularies in Tripal for contact types and contact properties.'
   );
 
   // add the cv for contact relationships
-  tripal_cv_add_cv(
+  tripal_insert_cv(
     'contact_relationship',
     'Contains types of relationships between contacts.'
   );

+ 26 - 23
tripal_core/api/tripal_core.chado_nodes.dbxrefs.api.inc

@@ -128,7 +128,7 @@ function chado_add_node_form_dbxrefs(&$form, &$form_state, $details) {
   $details['fieldset_title'] = 'Additional Database References';
   $details['additional_instructions'] = '';
 
-  // Get the list of databases to display in the dropdown. 
+  // Get the list of databases to display in the dropdown.
   if (isset($details['select_options'])) {
     // the callee has provided a list
     $db_options = $details['select_options'];
@@ -199,9 +199,9 @@ function chado_add_node_form_dbxrefs(&$form, &$form_state, $details) {
   }
   else {
     $existing_dbxrefs = chado_query(
-      "SELECT 
+      "SELECT
          db.name as db_name, db.db_id as db_id,
-         dbxref.dbxref_id, dbxref.accession as accession, 
+         dbxref.dbxref_id, dbxref.accession as accession,
          dbxref.description as description, dbxref.version
        FROM {dbxref} dbxref
          LEFT JOIN {db} db ON db.db_id = dbxref.db_id
@@ -243,14 +243,14 @@ function chado_add_node_form_dbxrefs(&$form, &$form_state, $details) {
    * an element to the form for each one.
    */
   foreach ($existing_dbxrefs as $dbxref) {
-    
+
     if (array_key_exists($dbxref->db_id, $db_options)) {
 
-      /* Since the dbxref version is part of the unique constraint, when it is 
-       * empty we need to use something in the key to indicate this case. Otherwise, 
-       * you wouldn't be able to select those elements from the array 
-       * (ie: $form['addtl_dbxrefs']['dbxref_table'][9999][''] doesn't work as 
-       * expected whereas $form['addtl_dbxrefs']['dbxref_table'][9999][NONE] 
+      /* Since the dbxref version is part of the unique constraint, when it is
+       * empty we need to use something in the key to indicate this case. Otherwise,
+       * you wouldn't be able to select those elements from the array
+       * (ie: $form['addtl_dbxrefs']['dbxref_table'][9999][''] doesn't work as
+       * expected whereas $form['addtl_dbxrefs']['dbxref_table'][9999][NONE]
        * is much better)
        */
       $version = (!empty($dbxref->version)) ? $dbxref->version : 'NONE';
@@ -434,13 +434,13 @@ function chado_add_node_form_dbxrefs_add_button_submit(&$form, &$form_state) {
   $key = $dbxref['db_id'] . '-' . $version;
   $form_state['chado_additional_dbxrefs'][$key] = (object) $dbxref;
 
-  
+
   // we don't want the new element to pick up the values from the previous element so wipe them out
   unset($form_state['input']['dbxref_table']['new']['db']);
   unset($form_state['input']['dbxref_table']['new']['db_name']);
   unset($form_state['input']['dbxref_table']['new']['dbxref_version']);
   unset($form_state['input']['dbxref_table']['new']['dbxref_accession']);
-  
+
   $form_state['rebuild'] = TRUE;
 }
 
@@ -649,12 +649,12 @@ function chado_update_node_form_dbxrefs($node, $details, $retrieved_dbxrefs = FA
           // If there is no dbxref then we have to create that first
           if ($dbxref_id == 'NONE') {
             $version = ($version == 'NONE') ? '' : $version;
-            $success = tripal_db_add_dbxref(
-              $db_id,
-              $accession,
-              $version,
-              NULL
-            );
+            $success = tripal_insert_dbxref(array(
+              'db_id' => $db_id,
+              'accession' => $accession,
+              'version' => $version,
+              'description' => NULL
+            ));
             if ($success) {
               $dbxref_id = $success->dbxref_id;
             }
@@ -665,12 +665,15 @@ function chado_update_node_form_dbxrefs($node, $details, $retrieved_dbxrefs = FA
 
           // add _dbxref linker
           if ($dbxref_id) {
-            $success_link = tripal_db_add_dbxref_link(
-              $linking_table,
-              $dbxref_id,
-              $foreignkey_name,
-              $foreignkey_value
-            );
+            if (preg_match('/(\w+)_dbxref/',$linking_table,$matches)) {
+              $base_table = $matches[1];
+
+              $success_link = tripal_associate_dbxref(
+                $base_table,
+                $foreignkey_value,
+                array('dbxref_id' => $dbxref_id)
+              );
+            }
           }
         }
       }

+ 18 - 1
tripal_core/api/tripal_core.jobs.api.inc

@@ -327,7 +327,24 @@ function tripal_launch_job($do_parallel = 0, $job_id = NULL) {
       $args = explode("::", $job->arguments);
     }
     $args[] = $job->job_id;
-    print "Calling: $callback(" . implode(", ", $args) . ")\n";
+
+    // We need to do some additional processing for printing since the switch
+    // to serialized arrays now allows nested arrays which cause errors when
+    // printed using implode alone.
+    $string_args = array();
+    foreach ($args as $k => $a) {
+      if (is_array($a)) {
+        $string_args[$k] = 'Array';
+      }
+      elseif (is_object($a)) {
+        $string_args[$k] = 'Object';
+      }
+      else {
+        $string_args[$k] = $a;
+      }
+    }
+
+    print "Calling: $callback(" . implode(", ", $string_args) . ")\n";
     call_user_func_array($callback, $args);
     // set the end time for this job
     $record->end_time = REQUEST_TIME;

+ 11 - 5
tripal_cv/api/tripal_cv.api.inc

@@ -523,9 +523,9 @@ function tripal_insert_cvterm($term, $options = array()) {
   }
 
   // make sure the CV name exists
-  $cv = tripal_cv_get_cv_by_name($cvname);
+  $cv = tripal_get_cv(array('name' => $cvname));
   if (!$cv) {
-    $cv = tripal_cv_add_cv($cvname, '');
+    $cv = tripal_insert_cv($cvname, '');
   }
   if (!$cv) {
     tripal_report_error('tripal_cv', TRIPAL_WARNING, "Cannot find namespace '$cvname' when adding/updating $id", NULL);
@@ -550,7 +550,7 @@ function tripal_insert_cvterm($term, $options = array()) {
   // database already exists.
   $db = tripal_get_db(array('name' => $dbname));
   if (!$db) {
-    $db = tripal_db_add_db($dbname);
+    $db = tripal_insert_db(array('name' => $dbname));
   }
   if (!$db) {
     tripal_report_error('tripal_cv', TRIPAL_WARNING, "Cannot find database '$dbname' in Chado.", NULL);
@@ -630,7 +630,10 @@ function tripal_insert_cvterm($term, $options = array()) {
     if ($dbxref->accession != $accession) {
 
       // get/add the dbxref fort his term
-      $dbxref_new =  tripal_db_add_dbxref($db->db_id, $accession);
+      $dbxref_new =  tripal_insert_dbxref(array(
+        'db_id' => $db->db_id,
+        'accession' => $accession
+      ));
       if (!$dbxref_new) {
         tripal_report_error('tripal_cv', TRIPAL_WARNING, "Failed to find or insert the dbxref record for cvterm, " .
           "$name (id: $accession), for database $dbname", NULL);
@@ -675,7 +678,10 @@ function tripal_insert_cvterm($term, $options = array()) {
   if (!$cvterm) {
 
     // check to see if the dbxref exists if not, add it
-    $dbxref =  tripal_db_add_dbxref($db->db_id, $accession);
+    $dbxref =  tripal_insert_dbxref(array(
+      'db_id' => $db->db_id,
+      'accession' => $accession
+    ));
     if (!$dbxref) {
       tripal_report_error('tripal_cv', TRIPAL_WARNING, "Failed to find or insert the dbxref record for cvterm, " .
         "$name (id: $accession), for database $dbname", NULL);

+ 10 - 4
tripal_cv/includes/tripal_cv.cvterm_form.inc

@@ -378,11 +378,14 @@ function tripal_cv_cvterm_edit_form_submit($form, &$form_state) {
           'name' => $name,
           'namespace' => $cv->name,
           'id' => $accession,
-          'def' => $definition,
+          'definition' => $definition,
           'is_obsolete' => $is_obsolete,
+          'cv_name' => $cv->name,
+          'is_relationship' => $is_relationship,
+          'db_name' => $db_name
         );
 
-        $cvterm = tripal_cv_add_cvterm($term, $cv->name, $is_relationship, TRUE, $db->name);
+        $cvterm = tripal_insert_cvterm($term, array('update_existing' => TRUE));
         if ($cvterm) {
           drupal_set_message('Term updated successfully.');
         }
@@ -434,11 +437,14 @@ function tripal_cv_cvterm_add_form_submit($form, &$form_state) {
     'name' => $name,
     'namespace' => $cv->name,
     'id' => $accession,
-    'def' => $definition,
+    'definition' => $definition,
     'is_obsolete' => $is_obsolete,
+    'cv_name' => $cv->name,
+    'is_relationship' => $is_relationship,
+    'db_name' => $db->name
   );
 
-  $cvterm = tripal_cv_add_cvterm($term, $cv->name, $is_relationship, TRUE, $db->name);
+  $cvterm = tripal_insert_cvterm($term, array('update_existing' => TRUE));
   if ($cvterm) {
     drupal_set_message('Term added successfully.');
   }

+ 110 - 86
tripal_cv/includes/tripal_cv.obo_loader.inc

@@ -15,12 +15,12 @@
 /**
  * Provides the form to load an already existing controlled
  *  Vocabulary into chado
- *  
+ *
  * @param $form
- *   The form array 
+ *   The form array
  * @param $form_state
  *   The form state array
- *   
+ *
  * @return
  *   The form array with new additions
  *
@@ -104,13 +104,13 @@ function tripal_cv_obo_form($form, &$form_state) {
 /**
  * The submit function for the load ontology form. It registers a
  *   tripal job to import the user specified ontology file
- *   
+ *
  * @param $form
- *   The form array 
+ *   The form array
  * @param $form_state
  *   The form state array
- *   
- * 
+ *
+ *
  * @ingroup tripal_obo_loader
  */
 function tripal_cv_obo_form_submit($form, &$form_state) {
@@ -119,19 +119,24 @@ function tripal_cv_obo_form_submit($form, &$form_state) {
   $obo_url   = trim($form_state['values']['obo_url']);
   $obo_file  = trim($form_state['values']['obo_file']);
 
-  tripal_cv_submit_obo_job($obo_id, $obo_name, $obo_url, $obo_file);
+  tripal_submit_obo_job(array(
+    'ob_id' => $obo_id,
+    'name' => $obo_name,
+    'url' => $obo_url,
+    'file' => $obo_file
+  ));
 }
 
 /**
- * A wrapper function for importing the user specified OBO file into Chado by 
- * specifying the obo_id of the OBO. It requires that the file be in OBO v1.2 
- * compatible format.  This function is typically executed via the Tripal jobs 
+ * A wrapper function for importing the user specified OBO file into Chado by
+ * specifying the obo_id of the OBO. It requires that the file be in OBO v1.2
+ * compatible format.  This function is typically executed via the Tripal jobs
  * management after a user submits a job via the Load Onotloies form.
- * 
+ *
  * @param $obo_id
  *   An obo_id from the tripal_cv_obo file that specifies which OBO file to import
  * @param $job_id
- *   The job_id of the job from the Tripal jobs management system. 
+ *   The job_id of the job from the Tripal jobs management system.
  *
  * @ingroup tripal_obo_loader
  */
@@ -166,19 +171,19 @@ function tripal_cv_load_obo_v1_2_id($obo_id, $jobid = NULL) {
 }
 
 /**
- * A wrapper function for importing the user specified OBO file into Chado by 
- * specifying the filename and path of the OBO. It requires that the file be in OBO v1.2 
- * compatible format.  This function is typically executed via the Tripal jobs 
+ * A wrapper function for importing the user specified OBO file into Chado by
+ * specifying the filename and path of the OBO. It requires that the file be in OBO v1.2
+ * compatible format.  This function is typically executed via the Tripal jobs
  * management after a user submits a job via the Load Onotloies form.
- * 
+ *
  * @param $obo_name
  *   The name of the OBO (typially the ontology or controlled vocabulary name)
  * @param $file
  *   The path on the file system where the ontology can be found
  * @param $job_id
- *   The job_id of the job from the Tripal jobs management system. 
+ *   The job_id of the job from the Tripal jobs management system.
  * @param $is_new
- *   Set to TRUE if this is a new ontology that does not yet exist in the 
+ *   Set to TRUE if this is a new ontology that does not yet exist in the
  *   tripal_cv_obo table.  If TRUE the OBO will be added to the table.
  *
  * @ingroup tripal_obo_loader
@@ -187,7 +192,7 @@ function tripal_cv_load_obo_v1_2_file($obo_name, $file, $jobid = NULL, $is_new =
   $newcvs = array();
 
   if ($is_new) {
-    tripal_cv_add_obo_ref($obo_name, $file);
+    tripal_insert_obo($obo_name, $file);
   }
 
   $success = tripal_cv_load_obo_v1_2($file, $jobid, $newcvs);
@@ -199,19 +204,19 @@ function tripal_cv_load_obo_v1_2_file($obo_name, $file, $jobid = NULL, $is_new =
 }
 
 /**
- * A wrapper function for importing the user specified OBO file into Chado by 
- * specifying the remote URL of the OBO. It requires that the file be in OBO v1.2 
- * compatible format.  This function is typically executed via the Tripal jobs 
+ * A wrapper function for importing the user specified OBO file into Chado by
+ * specifying the remote URL of the OBO. It requires that the file be in OBO v1.2
+ * compatible format.  This function is typically executed via the Tripal jobs
  * management after a user submits a job via the Load Onotloies form.
- * 
+ *
  * @param $obo_name
  *   The name of the OBO (typially the ontology or controlled vocabulary name)
  * @param $url
  *   The remote URL of the OBO file.
  * @param $job_id
- *   The job_id of the job from the Tripal jobs management system. 
+ *   The job_id of the job from the Tripal jobs management system.
  * @param $is_new
- *   Set to TRUE if this is a new ontology that does not yet exist in the 
+ *   Set to TRUE if this is a new ontology that does not yet exist in the
  *   tripal_cv_obo table.  If TRUE the OBO will be added to the table.
  *
  * @ingroup tripal_obo_loader
@@ -236,15 +241,15 @@ function tripal_cv_load_obo_v1_2_url($obo_name, $url, $jobid = NULL, $is_new = T
   }
   fclose($url_fh);
   fclose($obo_fh);
-  
+
   if ($is_new) {
-    tripal_cv_add_obo_ref($obo_name, $url);
+    tripal_insert_obo($obo_name, $url);
   }
 
   // second, parse the OBO
   $success = tripal_cv_load_obo_v1_2($temp, $jobid, $newcvs);
   if ($success) {
-    
+
     // update the cvtermpath table
     tripal_cv_load_update_cvtermpath($newcvs, $jobid);
     print "Done\n";
@@ -255,42 +260,42 @@ function tripal_cv_load_obo_v1_2_url($obo_name, $url, $jobid = NULL, $is_new = T
 
 /**
  * A function for executing the cvtermpath function of Chado.  This function
- * populates the cvtermpath table of Chado for quick lookup of term 
+ * populates the cvtermpath table of Chado for quick lookup of term
  * relationships
- * 
+ *
  * @param $newcvs
  *   An associative array of controlled vocabularies to update.  The key must be
  *   the name of the vocabulary and the value the cv_id from the cv table of chado.
  * @param $jobid
- *   The job_id of the job from the Tripal jobs management system. 
- * 
+ *   The job_id of the job from the Tripal jobs management system.
+ *
  * @ingroup tripal_obo_loader
  */
 function tripal_cv_load_update_cvtermpath($newcvs, $jobid) {
 
   print "\nUpdating cvtermpath table.  This may take a while...\n";
   foreach ($newcvs as $namespace => $cvid) {
-    tripal_cv_update_cvtermpath($cvid, $jobid);
+    tripal_update_cvtermpath($cvid, $jobid);
   }
 }
 
 /**
  * Imports a given OBO file into Chado.  This function is usually called by
- * one of three wrapper functions:  tripal_cv_load_obo_v1_2_id, 
+ * one of three wrapper functions:  tripal_cv_load_obo_v1_2_id,
  * tripal_cv_load_obo_v1_2_file or tirpal_cv_load_obo_v1_2_url. But, it can
- * be called directly if the full path to an OBO file is available on the 
+ * be called directly if the full path to an OBO file is available on the
  * file system.
- * 
+ *
  * @param $flie
  *   The full path to the OBO file on the file system
  * @param $jobid
  *   The job_id of the job from the Tripal jobs management system.
  * @param $newcvs
- *   An empty array passed by reference that upon return will contain the list 
+ *   An empty array passed by reference that upon return will contain the list
  *   of newly added vocabularies.  The key will contain the CV name and the
  *   value the new cv_id
- * 
- * 
+ *
+ *
  * @ingroup tripal_obo_loader
  */
 function tripal_cv_load_obo_v1_2($file, $jobid = NULL, &$newcvs) {
@@ -312,10 +317,10 @@ function tripal_cv_load_obo_v1_2($file, $jobid = NULL, &$newcvs) {
     print "Step 1: Preloading File $file\n";
 
     // make sure we have an 'internal' and a '_global' database
-    if (!tripal_db_add_db('internal')) {
+    if (!tripal_insert_db(array('name' => 'internal'))) {
       tripal_cv_obo_quiterror("Cannot add 'internal' database");
     }
-    if (!tripal_db_add_db('_global')) {
+    if (!tripal_insert_db(array('name' => '_global'))) {
       tripal_cv_obo_quiterror("Cannot add '_global' database");
     }
 
@@ -327,7 +332,7 @@ function tripal_cv_load_obo_v1_2($file, $jobid = NULL, &$newcvs) {
     // present for each stanza.  Some ontologies have adopted the v1.4 method
     // in their v1.2 files and not including it.
     if (array_key_exists('default-namespace', $header)) {
-      $defaultcv = tripal_cv_add_cv($header['default-namespace'][0], '');
+      $defaultcv = tripal_insert_cv($header['default-namespace'][0], '');
       if (!$defaultcv) {
         tripal_cv_obo_quiterror('Cannot add namespace ' . $header['default-namespace'][0]);
       }
@@ -335,21 +340,21 @@ function tripal_cv_load_obo_v1_2($file, $jobid = NULL, &$newcvs) {
     }
     // if the 'default-namespace' is missing
     else {
-      
-      // look to see if an 'ontology' key is present.  It is part of the v1.4 
+
+      // look to see if an 'ontology' key is present.  It is part of the v1.4
       // specification so it shouldn't be in the file, but just in case
       if (array_key_exists('ontology', $header)) {
-        $defaultcv = tripal_cv_add_cv(strtoupper($header['ontology'][0]), '');
+        $defaultcv = tripal_insert_cv(strtoupper($header['ontology'][0]), '');
         if (!$defaultcv) {
           tripal_cv_obo_quiterror('Cannot add namespace ' . strtoupper($header['ontology'][0]));
         }
         $newcvs[strtoupper(strtoupper($header['ontology'][0]))] = $defaultcv->cv_id;
       }
       else {
-        $defaultcv = tripal_cv_add_cv('_global', '');
+        $defaultcv = tripal_insert_cv('_global', '');
         $newcvs['_global'] = $defaultcv->cv_id;
       }
-      watchdog('t_obo_loader', "This OBO is missing the 'default-namespace' header. It is not possible to determine which vocabulary terms without a 'namespace' key should go.  Instead, those terms will be placed in the '%vocab' vocabulary.", 
+      watchdog('t_obo_loader', "This OBO is missing the 'default-namespace' header. It is not possible to determine which vocabulary terms without a 'namespace' key should go.  Instead, those terms will be placed in the '%vocab' vocabulary.",
         array('%vocab' => $defaultcv->name), WATCHDOG_WARNING);
     }
 
@@ -376,10 +381,10 @@ function tripal_cv_load_obo_v1_2($file, $jobid = NULL, &$newcvs) {
 
 /**
  * Immediately terminates loading of the OBO file.
- * 
+ *
  * @param $message
  *   The error message to present to the user
- *   
+ *
  * @ingroup tripal_obo_loader
  */
 function tripal_cv_obo_quiterror($message) {
@@ -390,11 +395,11 @@ function tripal_cv_obo_quiterror($message) {
 }
 
 /**
- * OBO files are divided into a typedefs terms section and vocabulary terms section.  
+ * OBO files are divided into a typedefs terms section and vocabulary terms section.
  * This function loads the typedef terms from the OBO.
- * 
+ *
  * @param $defaultcv
- *   A database object containing a record from the cv table for the 
+ *   A database object containing a record from the cv table for the
  *   default controlled vocabulary
  * @param $newcvs
  *   An associative array of controlled vocabularies for this OBO.  The key must be
@@ -403,7 +408,7 @@ function tripal_cv_obo_quiterror($message) {
  *   The name of the default database.
  * @param $jobid
  *   The job_id of the job from the Tripal jobs management system.
- *   
+ *
  * @ingroup tripal_obo_loader
  */
 function tripal_cv_obo_load_typedefs($defaultcv, $newcvs, $default_db, $jobid) {
@@ -453,11 +458,11 @@ function tripal_cv_obo_load_typedefs($defaultcv, $newcvs, $default_db, $jobid) {
 }
 
 /**
- * OBO files are divided into a typedefs section and a terms section.  This 
+ * OBO files are divided into a typedefs section and a terms section.  This
  * function loads the typedef terms from the OBO.
- * 
+ *
  * @param $defaultcv
- *   A database object containing a record from the cv table for the 
+ *   A database object containing a record from the cv table for the
  *   default controlled vocabulary
  * @param $jobid
  *  The job_id of the job from the Tripal jobs management system.
@@ -527,18 +532,18 @@ function tripal_cv_obo_process_terms($defaultcv, $jobid = NULL, &$newcvs, $defau
 }
 
 /**
- * Uses the provided term array to add/update information to Chado about the 
+ * Uses the provided term array to add/update information to Chado about the
  * term including the term, dbxref, synonyms, properties, and relationships.
- * 
+ *
  * @param $term
- *   An array representing the cvterm. 
+ *   An array representing the cvterm.
  * @param $defaultcv
  *   The name of the default controlled vocabulary
  * @is_relationship
  *   Set to 1 if this term is a relationship term
  * @default_db
  *   The name of the default database.
- * 
+ *
  * @ingroup tripal_obo_loader
  */
 function tripal_cv_obo_process_term($term, $defaultcv, $is_relationship = 0, &$newcvs, $default_db) {
@@ -547,14 +552,14 @@ function tripal_cv_obo_process_term($term, $defaultcv, $is_relationship = 0, &$n
   if (!array_key_exists('namespace', $term) and !($defaultcv or $defaultcv == '')) {
     tripal_cv_obo_quiterror("Cannot add the term: no namespace defined. " . $term['id'][0]);
   }
-  
+
   // construct the term array for sending to the tripal_cv_add_cvterm function
   // for adding a new cvterm
   $t = array();
   $t['id'] = $term['id'][0];
   $t['name'] = $term['name'][0];
   if (array_key_exists('def', $term)) {
-    $t['def'] = $term['def'][0];
+    $t['definition'] = $term['def'][0];
   }
   if (array_key_exists('subset', $term)) {
     $t['subset'] = $term['subset'][0];
@@ -566,8 +571,12 @@ function tripal_cv_obo_process_term($term, $defaultcv, $is_relationship = 0, &$n
     $t['is_obsolete'] = $term['is_obsolete'][0];
   }
 
+  $t['cv_name'] = $defaultcv;
+  $t['is_relationship'] = $is_relationship;
+  $t['db_name'] = $default_db;
+
   // add the cvterm
-  $cvterm = tripal_cv_add_cvterm($t, $defaultcv, $is_relationship, 1, $default_db);
+  $cvterm = tripal_insert_cvterm($t, array('update_existing' => TRUE));
   if (!$cvterm) {
     tripal_cv_obo_quiterror("Cannot add the term " . $term['id'][0]);
   }
@@ -705,15 +714,15 @@ function tripal_cv_obo_process_term($term, $defaultcv, $is_relationship = 0, &$n
 
 /**
  * Adds a cvterm relationship
- * 
+ *
  * @param $cvterm
- *   A database object for the cvterm 
+ *   A database object for the cvterm
  * @param $rel
  *   The relationship name
  * @param $objname
  *   The relationship term name
  * @param $defaultcv
- *   A database object containing a record from the cv table for the 
+ *   A database object containing a record from the cv table for the
  *   default controlled vocabulary
  * @object_is_relationship
  *   Set to 1 if this term is a relationship term
@@ -731,8 +740,11 @@ function tripal_cv_obo_add_relationship($cvterm, $defaultcv, $rel,
     'id' => "$default_db:$rel",
     'definition' => '',
     'is_obsolete' => 0,
+    'cv_name' => $defaultcv,
+    'is_relationship' => TRUE,
+    'db_naame' => $default_db
   );
-  $relcvterm = tripal_cv_add_cvterm($term, $defaultcv, 1, 0, $default_db);
+  $relcvterm = tripal_insert_cvterm($term, array('update_existing' => FALSE));
 
   if (!$relcvterm) {
     // if the relationship term couldn't be found in the default_db provided
@@ -742,8 +754,11 @@ function tripal_cv_obo_add_relationship($cvterm, $defaultcv, $rel,
       'id' => "OBO_REL:$rel",
       'definition' => '',
       'is_obsolete' => 0,
+      'cv_name' => $defaultcv,
+      'is_relationship' => TRUE,
+      'db_name' => 'OBO_REL'
     );
-    $relcvterm = tripal_cv_add_cvterm($term, $defaultcv, 1, 0, 'OBO_REL');
+    $relcvterm = tripal_insert_cvterm($term, array('update_existing' => FALSE));
     if (!$relcvterm) {
       tripal_cv_obo_quiterror("Cannot find the relationship term in the current ontology or in the relationship ontology: $rel\n");
     }
@@ -759,7 +774,7 @@ function tripal_cv_obo_add_relationship($cvterm, $defaultcv, $rel,
   $objterm['id']            = $oterm['id'][0];
   $objterm['name']          = $oterm['name'][0];
   if (array_key_exists('def', $oterm)) {
-    $objterm['def']           = $oterm['def'][0];
+    $objterm['definition']           = $oterm['def'][0];
   }
   if (array_key_exists('subset', $oterm)) {
     $objterm['subset']      = $oterm['subset'][0];
@@ -770,7 +785,12 @@ function tripal_cv_obo_add_relationship($cvterm, $defaultcv, $rel,
   if (array_key_exists('is_obsolete', $oterm)) {
     $objterm['is_obsolete'] = $oterm['is_obsolete'][0];
   }
-  $objcvterm = tripal_cv_add_cvterm($objterm, $defaultcv, $object_is_relationship, 1, $default_db);
+
+  $objterm['cv_name' ] = $defaultcv;
+  $objterm['is_relationship'] = $object_is_relationship;
+  $objterm['db_name'] = $default_db;
+
+  $objcvterm = tripal_insert_cvterm($objterm, array('update_existing' => TRUE));
   if (!$objcvterm) {
     tripal_cv_obo_quiterror("Cannot add cvterm " . $oterm['name'][0]);
   }
@@ -799,10 +819,10 @@ function tripal_cv_obo_add_relationship($cvterm, $defaultcv, $rel,
 
 /**
  * Retreives the term array from the temp loading table for a given term id.
- * 
+ *
  * @param id
  *   The id of the term to retrieve
- *   
+ *
  * @ingroup tripal_obo_loader
  */
 function tripal_cv_obo_get_term($id) {
@@ -817,18 +837,18 @@ function tripal_cv_obo_get_term($id) {
 
 /**
  * Adds the synonyms to a term
- * 
+ *
  * @param term
  *   An array representing the cvterm. It must have a 'synonym' key/value pair.
  * @param cvterm
  *   The database object of the cvterm to which the synonym will be added.
- * 
+ *
  * @ingroup tripal_obo_loader
  */
 function tripal_cv_obo_add_synonyms($term, $cvterm) {
 
   // make sure we have a 'synonym_type' vocabulary
-  $syncv = tripal_cv_add_cv('synonym_type', 'A vocabulary added by the Tripal CV module OBO loader for storing synonym types.');
+  $syncv = tripal_insert_cv('synonym_type', 'A vocabulary added by the Tripal CV module OBO loader for storing synonym types.');
 
   // now add the synonyms
   if (array_key_exists('synonym', $term)) {
@@ -860,8 +880,10 @@ function tripal_cv_obo_add_synonyms($term, $cvterm) {
            'id' => "internal:$scope",
            'definition' => '',
            'is_obsolete' => 0,
+           'cv_name' => $syncv->name,
+           'is_relationship' => FALSE
         );
-        $syntype = tripal_cv_add_cvterm($term, $syncv->name, 0, 1);
+        $syntype = tripal_insert_cvterm($term, array('update_existing' => TRUE));
         if (!$syntype) {
           tripal_cv_obo_quiterror("Cannot add synonym type: internal:$scope");
         }
@@ -917,13 +939,13 @@ function tripal_cv_obo_add_synonyms($term, $cvterm) {
  * Parse the OBO file and populate the templ loading table
  *
  * @param $file
- *   The path on the file system where the ontology can be found 
+ *   The path on the file system where the ontology can be found
  * @param $header
  *   An array passed by reference that will be populated with the header
  *   information from the OBO file
  * @param $jobid
  *   The job_id of the job from the Tripal jobs management system.
- * 
+ *
  * @ingroup tripal_obo_loader
  */
 function tripal_cv_obo_parse($obo_file, &$header, $jobid) {
@@ -1048,7 +1070,7 @@ function tripal_cv_obo_parse($obo_file, &$header, $jobid) {
 
 /**
  * Adds a database reference to a cvterm
- * 
+ *
  * @param cvterm
  *   The database object of the cvterm to which the synonym will be added.
  * @param xref
@@ -1076,7 +1098,7 @@ function tripal_cv_obo_add_cvterm_dbxref($cvterm, $xref) {
   }
 
   // add the database
-  $db = tripal_db_add_db($dbname);
+  $db = tripal_insert_db(array('name' => $dbname));
   if (!$db) {
     tripal_cv_obo_quiterror("Cannot find database '$dbname' in Chado.");
   }
@@ -1111,12 +1133,12 @@ function tripal_cv_obo_add_cvterm_dbxref($cvterm, $xref) {
 
 /**
  * Adds a property to a cvterm
- * 
+ *
  * @param cvterm
  *   A database object for the cvterm to which properties will be added
  * @param $property
  *   The name of the property to add
- * @param $value 
+ * @param $value
  *   The value of the property
  * @param rank
  *   The rank of the property
@@ -1126,7 +1148,7 @@ function tripal_cv_obo_add_cvterm_dbxref($cvterm, $xref) {
 function tripal_cv_obo_add_cvterm_prop($cvterm, $property, $value, $rank) {
 
   // make sure the 'cvterm_property_type' CV exists
-  $cv = tripal_cv_add_cv('cvterm_property_type', '');
+  $cv = tripal_insert_cv('cvterm_property_type', '');
   if (!$cv) {
     tripal_cv_obo_quiterror("Cannot add/find cvterm_property_type cvterm");
   }
@@ -1144,8 +1166,10 @@ function tripal_cv_obo_add_cvterm_prop($cvterm, $property, $value, $rank) {
       'id' => "internal:$property",
       'definition' => '',
       'is_obsolete' => 0,
+      'cv_name' => $cv->name,
+      'is_relationship' => FALSE,
     );
-    $cvproptype = tripal_cv_add_cvterm($term, $cv->name, 0, 0);
+    $cvproptype = tripal_insert_cvterm($term, array('update_existing' => FALSE));
     if (!$cvproptype) {
       tripal_cv_obo_quiterror("Cannot add cvterm property: internal:$property");
       return FALSE;
@@ -1187,7 +1211,7 @@ function tripal_cv_obo_add_cvterm_prop($cvterm, $property, $value, $rank) {
 
 /**
  * Adds a database cross reference to a cvterm
- * 
+ *
  * @param db_id
  *   The database ID of the cross reference
  * @param accession

+ 2 - 2
tripal_db/api/tripal_db.api.inc

@@ -21,7 +21,7 @@
     $select_values = array(
       'name' => 'SOFP'
     );
-    $db_object = tripal_db_get_db($select_values);
+    $db_object = tripal_get_db($select_values);
  * @endcode
  *  The above code selects the SOFP db and returns the following object:
  * @code
@@ -159,7 +159,7 @@ function tripal_get_db_select_options() {
         'name' => 'SOFP'
       )
     );
-    $dbxref_object = tripal_db_get_dbxref($identifiers);
+    $dbxref_object = tripal_get_dbxref($identifiers);
  * @endcode
  *  The above code selects the synonym database reference and returns the following object:
  * @code

+ 9 - 9
tripal_example/tripal_example.install

@@ -208,14 +208,14 @@ function tripal_example_add_mviews() {
  * @ingroup tripal_example
  */
 function tripal_example_add_dbs() {
-  // EXPLANATION: use the tripal_db_add_db() function to add any
+  // EXPLANATION: use the tripal_insert_db() function to add any
   // external databases needed by your module.  If the database already
   // exists then the function will gracefully return.
 
-  tripal_db_add_db(
-    'example_db',
-    'An example database.'
-  );
+  tripal_insert_db(array(
+    'name' => 'example_db',
+    'description' => 'An example database.'
+  ));
 }
 /**
  * Add cvs related to publications
@@ -224,22 +224,22 @@ function tripal_example_add_dbs() {
  */
 function tripal_example_add_cvs() {
 
-  // EXPLANATION: use the tripal_cv_add_cv() function to add any
+  // EXPLANATION: use the tripal_insert_cv() function to add any
   // controlled vocabularies needed by your module.  If the vocabulary already
   // exists then the function will gracefully return.  Chado convensions
   // use a singluar name for CV names (not plural)/
 
-  tripal_cv_add_cv(
+  tripal_insert_cv(
     'example_property',
     'Contains property terms for examples.'
   );
 
-  tripal_cv_add_cv(
+  tripal_insert_cv(
     'example_type',
     'Contains terms describing types of examples.'
   );
 
-  tripal_cv_add_cv(
+  tripal_insert_cv(
    'example_relationship',
    'Contains terms for describing relationship types between examples.'
   );

+ 8 - 2
tripal_feature/includes/tripal_feature.chado_node.inc

@@ -285,7 +285,10 @@ function chado_feature_validate($node, $form, &$form_state) {
   if (property_exists($node, 'nid')) {
 
     // make sure the feature type is a real sequence ontology term
-    $type = tripal_cv_get_cvterm_by_name($node->feature_type, NULL, 'sequence');
+    $type = tripal_get_cvterm(array(
+      'name' => $node->feature_type,
+      'cv_id' => array('name' =>'sequence')
+    ));
     if (!$type) {
       form_set_error('feature_type', t("The feature type is not a valid name from the Sequence Ontology."));
     }
@@ -316,7 +319,10 @@ function chado_feature_validate($node, $form, &$form_state) {
   else {
 
     // make sure the feature type is a real sequence ontology term
-    $type = tripal_cv_get_cvterm_by_name($node->feature_type, NULL, 'sequence');
+    $type = tripal_get_cvterm(array(
+      'name' => $node->feature_type,
+      'cv_id' => array('name' => 'sequence')
+    ));
     if (!$type) {
       form_set_error('feature_type', t("The feature type is not a valid name from the Sequence Ontology."));
     }

+ 6 - 2
tripal_feature/includes/tripal_feature.gff_loader.inc

@@ -1358,8 +1358,10 @@ function tripal_feature_load_gff3_alias($feature, $aliases) {
       'id' => "internal:exact",
       'definition' => '',
       'is_obsolete' => 0,
+      'cv_name' => $syncv->name,
+      'is_relationship' => FALSE
     );
-    $syntype = tripal_cv_add_cvterm($term, $syncv->name, 0, 1);
+    $syntype = tripal_insert_cvterm($term, array('update_existing' => TRUE));
     if (!$syntype) {
       tripal_report_error("T_gff3_loader", TRIPAL_WARNING, "Cannot add synonym type: internal:$type", array());
       return 0;
@@ -1805,8 +1807,10 @@ function tripal_feature_load_gff3_property($feature, $property, $value) {
       'name' => $property,
       'namespace' => 'feature_property',
       'is_obsolete' => 0,
+      'cv_name' => 'feature_property',
+      'is_relationship' => FALSE
     );
-    $cvterm = (object) tripal_cv_add_cvterm($term, 'feature_property', 0, 0);
+    $cvterm = (object) tripal_insert_cvterm($term, array('update_existing' => FALSE));
     if (!$cvterm) {
       tripal_report_error("T_gff3_loader", TRIPAL_WARNING, "Cannot add cvterm, $property", array());
       return 0;

+ 3 - 3
tripal_feature/tripal_feature.install

@@ -227,14 +227,14 @@ function tripal_feature_add_organism_count_mview() {
 function tripal_feature_add_cvs() {
 
   // Add cv for relationship types
-  tripal_cv_add_cv(
+  tripal_insert_cv(
     'feature_relationship',
     'Contains types of relationships between features.'
   );
 
   // the feature_property CV already exists... it comes with chado, but we need to
   // add it just in case it doesn't get added before the feature module is installed
-  tripal_cv_add_cv(
+  tripal_insert_cv(
     'feature_property',
     'Stores properties about features'
   );
@@ -242,7 +242,7 @@ function tripal_feature_add_cvs() {
   // the feature type vocabulary should be the sequence ontology, and even though
   // this ontology should get loaded we will create it here just so that we can
   // set the default vocabulary for the feature.type_id field
-  tripal_cv_add_cv(
+  tripal_insert_cv(
     'sequence',
     'The Sequence Ontology'
   );

+ 1 - 1
tripal_feature/tripal_feature.module

@@ -390,7 +390,7 @@ function tripal_feature_cv_tree($tree_id) {
 
   $organism_id = preg_replace("/^tripal_feature_cv_tree_(\d+)$/", "$1", $tree_id);
   $options = array(
-    cv_id            => tripal_cv_get_cv_id('sequence'),
+    cv_id            => tripal_get_cv(array('name' => 'sequence')),
     count_mview      => 'organism_feature_count',
     cvterm_id_column => 'cvterm_id',
     count_column     => 'num_features',

+ 114 - 64
tripal_featuremap/tripal_featuremap.install

@@ -117,17 +117,17 @@ function tripal_featuremap_schema() {
  */
 function tripal_featuremap_add_cvs() {
 
-  tripal_cv_add_cv(
+  tripal_insert_cv(
     'featuremap_units',
     'Contains map unit types for the unittype_id column of the featuremap table.'
   );
 
-  tripal_cv_add_cv(
+  tripal_insert_cv(
     'featurepos_property',
     'Contains terms map properties.'
   );
 
-  tripal_cv_add_cv(
+  tripal_insert_cv(
     'featuremap_property',
     'Contains positional types for the feature positions'
   );
@@ -141,115 +141,165 @@ function tripal_featuremap_add_cvs() {
 function tripal_featuremap_add_cvterms() {
 
    // add cvterms for the map unit types
-   tripal_cv_add_cvterm(
+   tripal_insert_cvterm(
      array(
        'name' => 'cM',
-       'def' => 'Centimorgan units'
-     ),
-     'featuremap_units', 0, 1, 'tripal'
+       'definition' => 'Centimorgan units',
+       'cv_name' => 'featuremap_units',
+       'is_relationship' => 0,
+       'db_name' => 'tripal'
+      ),
+      array('update_existing' => TRUE)
    );
-   tripal_cv_add_cvterm(
+   tripal_insert_cvterm(
      array(
        'name' => 'bp',
-       'def' => 'Base pairs units'
-     ),
-     'featuremap_units', 0, 1, 'tripal'
+       'definition' => 'Base pairs units',
+       'cv_name' => 'featuremap_units',
+       'is_relationship' => 0,
+       'db_name' => 'tripal'
+      ),
+      array('update_existing' => TRUE)
    );
-   tripal_cv_add_cvterm(
+   tripal_insert_cvterm(
      array(
        'name' => 'bin_unit',
-       'def' => 'The bin unit'
-     ),
-     'featuremap_units', 0, 1, 'tripal'
+       'definition' => 'The bin unit',
+       'cv_name' => 'featuremap_units',
+       'is_relationship' => 0,
+       'db_name' => 'tripal'
+      ),
+      array('update_existing' => TRUE)
    );
-   tripal_cv_add_cvterm(
+   tripal_insert_cvterm(
      array(
        'name' => 'marker_order',
-       'def' => 'Units simply to define marker order.'
-     ),
-     'featuremap_units', 0, 1, 'tripal'
+       'definition' => 'Units simply to define marker order.',
+       'cv_name' => 'featuremap_units',
+       'is_relationship' => 0,
+       'db_name' => 'tripal'
+      ),
+      array('update_existing' => TRUE)
    );
-   tripal_cv_add_cvterm(
+   tripal_insert_cvterm(
      array(
        'name' => 'undefined',
-       'def' => 'A catch-all for an undefined unit type'
-     ),
-     'featuremap_units', 0, 1, 'tripal'
+       'definition' => 'A catch-all for an undefined unit type',
+       'cv_name' => 'featuremap_units',
+       'is_relationship' => 0,
+       'db_name' => 'tripal'
+      ),
+      array('update_existing' => TRUE)
    );
 
    // featurepos properties
-   tripal_cv_add_cvterm(
+   tripal_insert_cvterm(
      array(
        'name' => 'start',
-       'def' => 'The start coordinate for a map feature.'
-     ),
-     'featurepos_property', 0, 1, 'tripal'
+       'definition' => 'The start coordinate for a map feature.',
+       'cv_name' => 'featurepos_property',
+       'is_relationship' => 0,
+       'db_name' => 'tripal'
+      ),
+      array('update_existing' => TRUE)
    );
-   tripal_cv_add_cvterm(
+   tripal_insert_cvterm(
      array(
        'name' => 'stop',
-       'def' => 'The end coordinate for a map feature'
-     ),
-     'featurepos_property', 0, 1, 'tripal'
+       'definition' => 'The end coordinate for a map feature',
+       'cv_name' => 'featurepos_property',
+       'is_relationship' => 0,
+       'db_name' => 'tripal'
+      ),
+      array('update_existing' => TRUE)
    );
 
    // add cvterms for map properties
-   tripal_cv_add_cvterm(
+   tripal_insert_cvterm(
      array(
        'name' => 'Map Dbxref',
-       'def' => 'A unique identifer for the map in a remote database.  The format is a database abbreviation and a unique accession separated by a colon.  (e.g. Gramene:tsh1996a)'
-     ),
-     'featuremap_property', 0, 1, 'tripal'
+       'definition' => 'A unique identifer for the map in a remote database.  The '
+        . 'format is a database abbreviation and a unique accession separated '
+        . 'by a colon.  (e.g. Gramene:tsh1996a)',
+       'cv_name' => 'featuremap_property',
+       'is_relationship' => 0,
+       'db_name' => 'tripal'
+      ),
+      array('update_existing' => TRUE)
    );
-   tripal_cv_add_cvterm(
+   tripal_insert_cvterm(
      array(
        'name' => 'Map Type',
-       'def' => 'The type of Map (e.g. QTL, Physical, etc.)'
-     ),
-     'featuremap_property', 0, 1, 'tripal'
+       'definition' => 'The type of Map (e.g. QTL, Physical, etc.)',
+       'cv_name' => 'featuremap_property',
+       'is_relationship' => 0,
+       'db_name' => 'tripal'
+      ),
+      array('update_existing' => TRUE)
    );
-   tripal_cv_add_cvterm(
+   tripal_insert_cvterm(
      array(
        'name' => 'Genome Group',
-       'def' => ''
-     ),
-     'featuremap_property', 0, 1, 'tripal'
+       'definition' => '',
+       'cv_name' => 'featuremap_property',
+       'is_relationship' => 0,
+       'db_name' => 'tripal'
+      ),
+      array('update_existing' => TRUE)
    );
-   tripal_cv_add_cvterm(
+   tripal_insert_cvterm(
      array(
        'name' => 'URL',
-       'def' => 'A univeral resource locator (URL) reference where the publication can be found.  For maps found online, this would be the web address for the map.'
-     ),
-     'featuremap_property', 0, 1, 'tripal'
+       'definition' => 'A univeral resource locator (URL) reference where the '
+        . 'publication can be found.  For maps found online, this would be '
+        . 'the web address for the map.',
+       'cv_name' => 'featuremap_property',
+       'is_relationship' => 0,
+       'db_name' => 'tripal'
+      ),
+      array('update_existing' => TRUE)
    );
-   tripal_cv_add_cvterm(
+   tripal_insert_cvterm(
      array(
        'name' => 'Population Type',
-       'def' => 'A brief description of the population type used to generate the map (e.g. RIL, F2, BC1, etc).'
-     ),
-     'featuremap_property', 0, 1, 'tripal'
+       'definition' => 'A brief description of the population type used to generate '
+        . 'the map (e.g. RIL, F2, BC1, etc).',
+       'cv_name' => 'featuremap_property',
+       'is_relationship' => 0,
+       'db_name' => 'tripal'
+      ),
+      array('update_existing' => TRUE)
    );
-   tripal_cv_add_cvterm(
+   tripal_insert_cvterm(
      array(
        'name' => 'Population Size',
-       'def' => 'The size of the population used to construct the map.'
-     ),
-     'featuremap_property', 0, 1, 'tripal'
+       'definition' => 'The size of the population used to construct the map.',
+       'cv_name' => 'featuremap_property',
+       'is_relationship' => 0,
+       'db_name' => 'tripal'
+      ),
+      array('update_existing' => TRUE)
    );
-   tripal_cv_add_cvterm(
+   tripal_insert_cvterm(
      array(
        'name' => 'Methods',
-       'def' => 'A brief description of the methods used to construct the map.'
-     ),
-     'featuremap_property', 0, 1, 'tripal'
+       'definition' => 'A brief description of the methods used to construct the map.',
+       'cv_name' => 'featuremap_property',
+       'is_relationship' => 0,
+       'db_name' => 'tripal'
+      ),
+      array('update_existing' => TRUE)
    );
-   tripal_cv_add_cvterm(
+   tripal_insert_cvterm(
      array(
        'name' => 'Software',
-       'def' => 'The software used to construct the map.'
-     ),
-     'featuremap_property', 0, 1, 'tripal'
-   );
+       'definition' => 'The software used to construct the map.',
+       'cv_name' => 'featuremap_property',
+       'is_relationship' => 0,
+       'db_name' => 'tripal'
+      ),
+      array('update_existing' => TRUE)
+    );
 
 }
 

+ 17 - 6
tripal_library/includes/tripal_library.chado_node.inc

@@ -73,7 +73,12 @@ function chado_library_form($node, &$form_state) {
     $library_type = $library->type_id->cvterm_id;
     $organism_id  = $library->organism_id->organism_id;
 
-    $libprop = tripal_library_get_property($library->library_id, 'Library Description');
+    $libprop = chado_get_property(
+      'library',
+      $library->library_id,
+      'Library Description',
+      'library_property'
+    );
     $description = $libprop->value;
 
     // keep track of the library id if we have.  If we do have one then
@@ -170,7 +175,7 @@ function chado_library_form($node, &$form_state) {
     // Generate our own select list so we can exclude the description element
     $cv_result = chado_select_record('cv',array('cv_id'),array('name' => 'library_property'));
     $cv_id = $cv_result[0]->cv_id;
-    $select_options = tripal_cv_get_cvterm_options($cv_id);
+    $select_options = tripal_get_cvterm_select_options($cv_id);
     $descrip_id = array_search('Library Description', $select_options);
     unset($select_options[$descrip_id]);
   }
@@ -277,7 +282,10 @@ function chado_library_insert($node) {
     // * Properties Form *
     // add the description property
     $properties = chado_retrieve_node_form_properties($node);
-    $descrip_id = tripal_cv_get_cvterm_by_name('Library Description', NULL, 'library_property');
+    $descrip_id = tripal_get_cvterm(array(
+      'name' => 'Library Description',
+      'cv_id' => array('name' => 'library_property')
+    ));
     $properties[$descrip_id->cvterm_id][0] = $node->description;
 
     $details = array(
@@ -346,7 +354,10 @@ function chado_library_update($node) {
   // * Properties Form *
   // add the description property
   $properties = chado_retrieve_node_form_properties($node);
-  $descrip_id = tripal_cv_get_cvterm_by_name('Library Description', NULL, 'library_property');
+  $descrip_id = tripal_get_cvterm(array(
+    'name' => 'Library Description',
+    'cv_id' => array('name' => 'library_property')
+  ));
   $properties[$descrip_id->cvterm_id][0] = $node->description;
 
   $details = array(
@@ -592,7 +603,7 @@ function tripal_library_node_insert($node) {
 
   switch ($node->type) {
     case 'chado_library':
-      
+
       $library_id = chado_get_id_from_nid('library', $node->nid);
       $values = array('library_id' => $library_id);
       $library = chado_generate_var('library', $values);
@@ -616,7 +627,7 @@ function tripal_library_node_update($node) {
 
   switch ($node->type) {
     case 'chado_library':
-      
+
       $library_id = chado_get_id_from_nid('library', $node->nid);
       $values = array('library_id' => $library_id);
       $library = chado_generate_var('library', $values);

+ 46 - 24
tripal_library/tripal_library.install

@@ -168,11 +168,11 @@ function tripal_library_add_mview_library_feature_count(){
  * @ingroup tripal_library
  */
 function tripal_library_add_cvs(){
-  tripal_cv_add_cv(
+  tripal_insert_cv(
     'library_property',
     'Contains properties for libraries.'
   );
-  tripal_cv_add_cv(
+  tripal_insert_cv(
     'library_type',
     'Contains terms for types of libraries (e.g. BAC, cDNA, FOSMID, etc).'
   );
@@ -188,55 +188,77 @@ function tripal_library_add_cvterms() {
   // Insert cvterm 'library_description' into cvterm table of chado
   // database. This CV term is used to keep track of the library
   // description in the libraryprop table.
-  tripal_cv_add_cvterm(
+  tripal_insert_cvterm(
      array(
        'name' => 'Library Description',
-       'def' => 'Description of a library'
-     ),
-    'library_property', 0, 1, 'tripal'
+       'definition' => 'Description of a library',
+       'cv_name' => 'library_property',
+       'is_relationship' => 0,
+       'db_name' => 'tripal'
+      ),
+      array('update_existing' => TRUE)
    );
 
   // add cvterms for the map unit types
-  tripal_cv_add_cvterm(
+  tripal_insert_cvterm(
     array(
       'name' => 'cdna_library',
-      'def' => 'cDNA library'
+      'definition' => 'cDNA library',
+      'cv_name' => 'library_type',
+      'is_relationship' => 0,
+      'db_name' => 'tripal'
     ),
-    'library_type', 0, 1, 'tripal'
+    array('update_existing' => TRUE)
   );
-  tripal_cv_add_cvterm(
+  tripal_insert_cvterm(
     array(
       'name' => 'bac_library',
-      'def' => 'Bacterial Artifical Chromsome (BAC) library'
+      'definition' => 'Bacterial Artifical Chromsome (BAC) library',
+      'cv_name' => 'library_type',
+      'is_relationship' => 0,
+      'db_name' => 'tripal'
     ),
-    'library_type', 0, 1, 'tripal'
+    array('update_existing' => TRUE)
   );
-  tripal_cv_add_cvterm(
+  tripal_insert_cvterm(
     array(
       'name' => 'fosmid_library',
-      'def' => 'Fosmid library'
+      'definition' => 'Fosmid library',
+      'cv_name' => 'library_type',
+      'is_relationship' => 0,
+      'db_name' => 'tripal'
     ),
-    'library_type', 0, 1, 'tripal'
+    array('update_existing' => TRUE)
   );
-  tripal_cv_add_cvterm(
+  tripal_insert_cvterm(
     array(
       'name' => 'cosmid_library',
-      'def' => 'Cosmid library'
+      'definition' => 'Cosmid library',
+      'cv_name' => 'library_type',
+      'is_relationship' => 0,
+      'db_name' => 'tripal'
     ),
-    'library_type', 0, 1, 'tripal'
+    array('update_existing' => TRUE)
   );
-  tripal_cv_add_cvterm(
+  tripal_insert_cvterm(
     array(
       'name' => 'yac_library',
-      'def' => 'Yeast Artificial Chromosome (YAC) library'
+      'definition' => 'Yeast Artificial Chromosome (YAC) library',
+      'cv_name' => 'library_type',
+      'is_relationship' => 0,
+      'db_name' => 'tripal'
     ),
-    'library_type', 0, 1, 'tripal'
+    array('update_existing' => TRUE)
   );
-  tripal_cv_add_cvterm(
+  tripal_insert_cvterm(
     array(
       'name' => 'genomic_library',
-      'def' => 'Genomic Library'),
-    'library_type', 0, 1, 'tripal'
+      'definition' => 'Genomic Library',
+      'cv_name' => 'library_type',
+      'is_relationship' => 0,
+      'db_name' => 'tripal'
+    ),
+    array('update_existing' => TRUE)
   );
 }
 

+ 31 - 6
tripal_natural_diversity/tripal_natural_diversity.install

@@ -73,11 +73,36 @@ function tripal_natural_diversity_uninstall() {
 function tripal_natural_diversity_add_cvterms(){
 
   // add cvterms for the nd_experiment_types
-  tripal_cv_add_cvterm(array('name' => 'Genotyping','def' => 'An experiment where genotypes of individuals are identified.'),
-    'nd_experiment_types', 0, 1, 'tripal');
-  tripal_cv_add_cvterm(array('name' => 'Phenotyping','def' => 'An experiment where phenotypes of individuals are identified.'),
-    'nd_experiment_types', 0, 1, 'tripal');
+  tripal_insert_cvterm(
+    array(
+     'name' => 'Genotyping',
+     'definition' => 'An experiment where genotypes of individuals are identified.',
+     'cv_name' => 'nd_experiment_types',
+     'is_relationship' => 0,
+     'db_name' => 'tripal'
+    ),
+    array('update_existing' => TRUE)
+  );
 
-  tripal_cv_add_cvterm(array('name' => 'Location','def' => 'The name of the location.'),
-    'nd_geolocation_property', 0, 1, 'tripal');
+  tripal_insert_cvterm(
+    array(
+      'name' => 'Phenotyping',
+      'definition' => 'An experiment where phenotypes of individuals are identified.',
+      'cv_name' => 'nd_experiment_types',
+      'is_relationship' => 0,
+      'db_name' => 'tripal'
+    ),
+    array('update_existing' => TRUE)
+  );
+
+  tripal_insert_cvterm(
+    array(
+      'name' => 'Location',
+      'definition' => 'The name of the location.',
+      'cv_name' => 'nd_geolocation_property',
+      'is_relationship' => 0,
+      'db_name' => 'tripal'
+    ),
+    array('update_existing' => TRUE)
+  );
 }

+ 1 - 1
tripal_organism/tripal_organism.install

@@ -116,7 +116,7 @@ function tripal_organism_requirements($phase) {
  * @ingroup tripal_organism
  */
 function tripal_organism_add_cvs() {
-  tripal_cv_add_cv(
+  tripal_insert_cv(
     'organism_property',
     'Contains properties for organisms'
   );

+ 15 - 4
tripal_project/includes/tripal_project.chado_node.inc

@@ -91,7 +91,12 @@ function chado_project_form(&$node, $form_state) {
       $description = $project->description;
     }
     if (!$description) {
-      $projectprop = tripal_project_get_property($project->project_id, 'Project Description');
+      $projectprop = chado_get_property(
+        'project',
+        $project->project_id,
+        'Project Description',
+        'project_property'
+      );
       $description = $projectprop->value;
     }
 
@@ -148,7 +153,7 @@ function chado_project_form(&$node, $form_state) {
     // as a property even though it will be stored as a property.
     $cv_result = chado_select_record('cv',array('cv_id'),array('name' => 'project_property'));
     $cv_id = $cv_result[0]->cv_id;
-    $select_options = tripal_cv_get_cvterm_options($cv_id);
+    $select_options = tripal_get_cvterm_select_options($cv_id);
     $descrip_id = array_search('Project Description', $select_options);
     unset($select_options[$descrip_id]);
   }
@@ -258,7 +263,10 @@ function chado_project_insert($node) {
     // * Properties Form *
     // Add the description property
     $properties = chado_retrieve_node_form_properties($node);
-    $descrip_id = tripal_cv_get_cvterm_by_name('Project Description', NULL, 'project_property');
+    $descrip_id = tripal_get_cvterm(array(
+      'name' => 'Project Description',
+      'cv_id' => array('name' => 'project_property')
+    ));
     $properties[$descrip_id->cvterm_id][0] = $node->description;
 
     $details = array(
@@ -357,7 +365,10 @@ function chado_project_update($node) {
   // * Properties Form *
   // Add the description property
   $properties = chado_retrieve_node_form_properties($node);
-  $descrip_id = tripal_cv_get_cvterm_by_name('Project Description', NULL, 'project_property');
+  $descrip_id = tripal_get_cvterm(array(
+    'name' => 'Project Description',
+    'cv_id' => array('name' => 'project_property')
+  ));
   $properties[$descrip_id->cvterm_id][0] = $node->description;
 
   $details = array(

+ 8 - 5
tripal_project/tripal_project.install

@@ -103,13 +103,13 @@ function tripal_project_schema() {
  */
 function tripal_project_add_cvs() {
   // Add the cv for project properties
-  tripal_cv_add_cv(
+  tripal_insert_cv(
     'project_property',
     'Contains properties for projects'
   );
 
   // Add cv for relationship types
-  tripal_cv_add_cv(
+  tripal_insert_cv(
     'project_relationship',
     'Contains Types of relationships between projects.'
   );
@@ -125,12 +125,15 @@ function tripal_project_add_cvterms() {
   // Insert cvterm 'Project Description' into cvterm table of chado
   // database. This CV term is used to keep track of the project
   // description in the projectprop table.
-  tripal_cv_add_cvterm(
+  tripal_insert_cvterm(
     array(
       'name' => 'Project Description',
-      'def'  => 'Description of a project'
+      'definition'  => 'Description of a project',
+      'cv_name' => 'project_property',
+      'is_relationship' => 0,
+      'db_name' => 'tripal'
     ),
-    'project_property', 0, 1, 'tripal'
+    array('update_existing' => TRUE)
   );
 }
 

+ 60 - 33
tripal_pub/includes/tripal_pub.chado_node.inc

@@ -91,45 +91,72 @@ function chado_pub_form($node, $form_state) {
     // get fields from the pub table and convert them to properties. We will add these to the $more_props
     // array which gets passed in to the tripal_core_properties_form() API call further down
     if ($pub->volumetitle) {
-      $cvterm = tripal_cv_get_cvterm_by_name('Volume Title', NULL, 'tripal_pub');
+      $cvterm = tripal_get_cvterm(array(
+        'name' => 'Volume Title',
+        'cv_id' => array('name' => 'tripal_pub')
+      ));
       $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->volumetitle);
     }
     if ($pub->volume) {
-      $cvterm = tripal_cv_get_cvterm_by_name('Volume', NULL, 'tripal_pub');
+      $cvterm = tripal_get_cvterm(array(
+        'name' => 'Volume',
+        'cv_id' => array('name' => 'tripal_pub')
+      ));
       $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->volume);
     }
     if ($pub->series_name) {
       switch ($pub->type_id->name) {
         case 'Journal Article':
-          $cvterm = tripal_cv_get_cvterm_by_name('Journal Name', NULL, 'tripal_pub');
+          $cvterm = tripal_get_cvterm(array(
+            'name' => 'Journal Name',
+            'cv_id' => array('name' => 'tripal_pub')
+          ));
           $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->series_name);
           break;
         case 'Conference Proceedings':
-          $cvterm = tripal_cv_get_cvterm_by_name('Conference Name', NULL, 'tripal_pub');
+          $cvterm = tripal_get_cvterm(array(
+            'name' => 'Conference Name',
+            'cv_id' => array('name' => 'tripal_pub')
+          ));
           $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->series_name);
           break;
         default:
-          $cvterm = tripal_cv_get_cvterm_by_name('Series Name', NULL, 'tripal_pub');
+          $cvterm = tripal_get_cvterm(array(
+            'name' => 'Series Name',
+            'cv_id' => array('tripal_pub')
+          ));
           $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->series_name);
       }
     }
     if ($pub->issue) {
-      $cvterm = tripal_cv_get_cvterm_by_name('Issue', NULL, 'tripal_pub');
+      $cvterm = tripal_get_cvterm(array(
+        'name' => 'Issue',
+        'cv_id' => array('name' => 'tripal_pub')
+      ));
       $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->issue);
     }
     if ($pub->pages) {
-      $cvterm = tripal_cv_get_cvterm_by_name('Pages', NULL, 'tripal_pub');
+      $cvterm = tripal_get_cvterm(array(
+        'name' => 'Pages',
+        'cv_id' => array('name' => 'tripal_pub')
+      ));
       $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->pages);
     }
     if ($pub->miniref) {
       // not sure what to do with this one
     }
     if ($pub->publisher) {
-      $cvterm = tripal_cv_get_cvterm_by_name('Publisher', NULL, 'tripal_pub');
+      $cvterm = tripal_get_cvterm(array(
+        'name' => 'Publisher',
+        'cv_id' => array('name' => 'tripal_pub')
+      ));
       $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->publisher);
     }
     if ($pub->pubplace) {
-      $cvterm = tripal_cv_get_cvterm_by_name('Published Location', NULL, 'tripal_pub');
+      $cvterm = tripal_get_cvterm(array(
+        'name' => 'Published Location',
+        'cv_id' => array('name' => 'tripal_pub')
+      ));
       $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->pages);
     }
   }
@@ -157,10 +184,10 @@ function chado_pub_form($node, $form_state) {
     '#default_value' => $title,
     '#required' => TRUE,
   );
-  
+
   $type_cv = tripal_get_default_cv('pub', 'type_id');
   if ($type_cv->name == 'tripal_pub') {
-   
+
     // get the list of publication types.  In the Tripal publication
     // ontologies these are all grouped under the term 'Publication Type'
     // we want the default to be 'Journal Article'
@@ -188,7 +215,7 @@ function chado_pub_form($node, $form_state) {
   }
   else {
     $pub_types = tripal_get_cvterm_default_select_options('pub', 'type_id', 'publication types');
-    $pub_types[0] = 'Select a Type'; 
+    $pub_types[0] = 'Select a Type';
   }
 
   $form['type_id'] = array(
@@ -229,8 +256,8 @@ function chado_pub_form($node, $form_state) {
   $select_options = array();
   $prop_cv = tripal_get_default_cv('pubprop', 'type_id');
   $cv_id = $prop_cv ? $prop_cv->cv_id : NULL;
-  // if the poperty cv is 'tripal_pub' then we need to pass in our own select_options 
-  // for only a subset of the vocabulary  
+  // if the poperty cv is 'tripal_pub' then we need to pass in our own select_options
+  // for only a subset of the vocabulary
   if ($prop_cv->name == 'tripal_pub') {
     $select_options[] = 'Select a Property';
     $sql = "
@@ -285,7 +312,7 @@ function chado_pub_form($node, $form_state) {
   // Adds the form elements to your current form
   chado_add_node_form_relationships($form, $form_state, $details);
 
-  
+
   // ADDITIONAL DBXREFS FORM
   //---------------------------------------------
   $details = array(
@@ -324,7 +351,7 @@ function chado_pub_validate($node, $form, &$form_state) {
   $uniquename   = trim($node->uniquename);
   $is_obsolete  = $node->is_obsolete;
   $type_id      = $node->type_id;
-  
+
   $pub = array();
 
   // make sure the year is four digits
@@ -348,7 +375,7 @@ function chado_pub_validate($node, $form, &$form_state) {
   foreach ($properties as $key => $prop_values) {
     $values = array('cvterm_id' => $key);
     $prop_type = chado_select_record('cvterm', array('name'), $values);
-    if ($prop_type[0]->name == 'Conference Name' or 
+    if ($prop_type[0]->name == 'Conference Name' or
         $prop_type[0]->name == 'Journal Name' or
         $prop_type[0]->name == 'Series Name') {
       $series_name = $prop_values[0];
@@ -417,7 +444,7 @@ function chado_pub_validate_check_uniquename($uniquename, $pub_id = NULL) {
   $pub = chado_get_publication(array('uniquename' => $uniquename));
   if ($pub) {
     // if a $pub_id is provided to the function then this is an update
-    // if the pub_id's don't match then a different pub with the same 
+    // if the pub_id's don't match then a different pub with the same
     // uniquename already exists.
     if ($pub->pub_id != $pub_id) {
       $message = t('A publication with this unique citation already exists.');
@@ -440,7 +467,7 @@ function chado_pub_validate_check_uniquename($uniquename, $pub_id = NULL) {
  *   The type of publication
  * @param $pub_id
  *   the unique id of the publication
- *   
+ *
  *
  * @ingroup tripal_pub
  */
@@ -454,7 +481,7 @@ function chado_pub_validate_check_duplicate($title, $pyear, $series_name, $cvter
   );
   // TODO: need to include the Publication Dbxref in the $pub_details as well
   $pub_ids = tripal_publication_exists($pub_details);
-  
+
   // if we found only one publication and it is our publication then return, we're good.
   if (count($pub_ids) == 1 and in_array($pub_id, $pub_ids)) {
     return;
@@ -463,7 +490,7 @@ function chado_pub_validate_check_duplicate($title, $pyear, $series_name, $cvter
     // there is no match so return
     return;
   }
-  
+
   // return an appropriate message based on the unique constraint settings
   $import_dups_check = variable_get('tripal_pub_import_duplicate_check', 'title_year_media');
   switch ($import_dups_check) {
@@ -510,7 +537,7 @@ function chado_pub_node_access($node, $op, $account) {
   if (is_object($node)) {
     $node_type = $node->type;
   }
-  
+
   if($node_type == 'chado_pub') {
     if ($op == 'create') {
       if (!user_access('create chado_pub', $account)) {
@@ -647,7 +674,7 @@ function chado_pub_insert($node) {
     }
     // generate a citation for this pub if one doesn't already exist
     if (!$node->uniquename and !array_key_exists($citation_id, $properties)) {
-      $pub_type = tripal_cv_get_cvterm_by_id($node->type_id);
+      $pub_type = tripal_get_cvterm(array('cvterm_id' => $node->type_id));
       $pub_arr['Title'] = $node->pubtitle;
       $pub_arr['Publication Type'][0] = $pub_type->name;
       $pub_arr['Year'] = $node->pyear;
@@ -697,7 +724,7 @@ function chado_pub_insert($node) {
     chado_update_node_form_relationships($node, $details);
 
     // add in any database cross-references
-    foreach ($cross_refs as $index => $ref) { 
+    foreach ($cross_refs as $index => $ref) {
       $dbxref = array();
       if(preg_match('/^(.*?):(.*?)$/', trim($ref), $matches)) {
         $dbxref['db_name']   = $matches[1];
@@ -851,7 +878,7 @@ function chado_pub_update($node) {
   }
   // generate a citation for this pub if one doesn't already exist
   if (!$node->uniquename) {
-    $pub_type = tripal_cv_get_cvterm_by_id($node->type_id);
+    $pub_type = tripal_get_cvterm(array('cvterm_id' => $node->type_id));
     $pub_arr['Title'] = $node->pubtitle;
     $pub_arr['Publication Type'][0] = $pub_type->name;
     $pub_arr['Year'] = $node->pyear;
@@ -943,9 +970,9 @@ function chado_pub_load($nodes) {
   foreach ($nodes as $nid => $node) {
     // find the pub and add in the details
     $pub_id = chado_get_id_from_nid('pub', $nid);
-    
+
     // if the nid does not have a matching record then skip this node.
-    // this can happen with orphaned nodes. 
+    // this can happen with orphaned nodes.
     if (!$pub_id) {
       continue;
     }
@@ -1091,7 +1118,7 @@ function tripal_pub_node_view($node, $view_mode, $langcode) {
 function tripal_pub_node_insert($node) {
 
   if ($node->type == 'chado_pub') {
-    
+
     // get the pub
     $pub_id = chado_get_id_from_nid('pub', $node->nid);
     $values = array('pub_id' => $pub_id);
@@ -1103,7 +1130,7 @@ function tripal_pub_node_insert($node) {
     $pub = chado_expand_var($pub, 'field', 'pub.volumetitle');
     $pub = chado_expand_var($pub, 'field', 'pub.uniquename');
     $node->pub = $pub;
-    
+
     // Now get the title
     $node->title = chado_get_node_title($node);
 
@@ -1155,14 +1182,14 @@ function tripal_pub_node_update($node) {
     $pub_id = chado_get_id_from_nid('pub', $node->nid);
     $values = array('pub_id' => $pub_id);
     $pub = chado_generate_var('pub', $values);
-    
+
     // expand the 'text' fields as those aren't included by default
     // and they really shouldn't be so large to cause problems
     $pub = chado_expand_var($pub, 'field', 'pub.title');
     $pub = chado_expand_var($pub, 'field', 'pub.volumetitle');
     $pub = chado_expand_var($pub, 'field', 'pub.uniquename');
     $node->pub = $pub;
-            
+
     // Now get the title
     $node->title = chado_get_node_title($node);
 
@@ -1206,12 +1233,12 @@ function chado_pub_chado_node_default_title_format() {
 
 /**
  * Implements [content_type]_chado_node_sync_select_query().
- * 
+ *
  * Adds a where clause to the query to exclude the NULL pub.
  */
 function chado_pub_chado_node_sync_select_query($query) {
   $query['where_clauses']['title'][] = 'pub.title <> :pub_title_null';
   $query['where_args']['title'][':pub_title_null'] = 'NULL';
-  
+
   return $query;
 }

+ 7 - 2
tripal_pub/includes/tripal_pub.pub_importers.inc

@@ -1069,7 +1069,7 @@ function tripal_pub_add_publication($pub_details, &$action, $do_contact = FALSE,
     $cvterm = tripal_get_cvterm($identifiers);
 
     // if we could not find the cvterm by name then try by synonym
-    //$cvterm = tripal_cv_get_cvterm_by_name($key, NULL, 'tripal_pub');
+    //$cvterm = tripal_get_cvterm(array('name' => $key, 'cv_id' => array('name' => 'tripal_pub')));
     if (!$cvterm) {
       $identifiers = array(
         'synonym' => array(
@@ -1184,7 +1184,12 @@ function tripal_pub_add_authors($pub_id, $authors, $do_contact) {
     // if the user wants us to create a contact for each author then do it.
     if ($do_contact) {
       // Add the contact
-      $contact = tripal_contact_add_contact($name, '', $type, $author);
+      $contact = tripal_insert_contact(array(
+        'name' => $name,
+        'description' => '',
+        'type_name' => $type,
+        'properties' => $author
+      ));
 
       // if we have succesfully added the contact and the pubauthor entries then we want to
       // link them together

+ 23 - 8
tripal_pub/tripal_pub.install

@@ -54,8 +54,8 @@ function tripal_pub_install() {
 
   // add loading of the the tripal pub ontology to the job queue
   $obo_path =  drupal_realpath(drupal_get_path('module', 'tripal_pub') . '/files/tpub.obo');
-  $obo_id = tripal_cv_add_obo_ref('Tripal Publication', $obo_path);
-  tripal_cv_submit_obo_job($obo_id);
+  $obo_id = tripal_insert_obo('Tripal Publication', $obo_path);
+  tripal_submit_obo_job(array('ob_id' => $obo_id));
 
   tripal_pub_add_cvs();
   tripal_pub_add_cvterms();
@@ -86,8 +86,23 @@ function tripal_pub_uninstall() {
  */
 function tripal_pub_enable() {
   // make sure we have our supported databases
-  tripal_db_add_db('PMID', 'PubMed', 'http://www.ncbi.nlm.nih.gov/pubmed', 'http://www.ncbi.nlm.nih.gov/pubmed/', TRUE);
-  tripal_db_add_db('AGL', 'USDA National Agricultural Library', 'http://agricola.nal.usda.gov/', '', TRUE);
+  tripal_insert_db(
+    array(
+      'name' => 'PMID',
+      'description' => 'PubMed',
+      'url' => 'http://www.ncbi.nlm.nih.gov/pubmed',
+      'urlprefix' => 'http://www.ncbi.nlm.nih.gov/pubmed/'
+    ),
+    array('update_existing' => TRUE)
+  );
+  tripal_insert_db(
+    array(
+      'name' => 'AGL',
+      'description' => 'USDA National Agricultural Library',
+      'url' => 'http://agricola.nal.usda.gov/'
+    ),
+    array('update_existing' => TRUE)
+  );
 
   variable_set('tripal_pub_supported_dbs', array('PMID', 'AGL'));
 }
@@ -231,25 +246,25 @@ function tripal_pub_add_cvs() {
 
 
   // Add the cv for pub properties
-  tripal_cv_add_cv(
+  tripal_insert_cv(
     'tripal_pub',
     'A heirarchical set of terms for describing a publication. It is intended to be used as the default vocabularies in Tripal for publication types and contact properties.'
   );
 
   // Add the cv for pub types
-  tripal_cv_add_cv(
+  tripal_insert_cv(
     'pub_type',
     'Contains types of publications. This can be used if the tripal_pub vocabulary (which is default for publications in Tripal) is not desired.'
   );
 
   // Add the cv for pub properties
-  tripal_cv_add_cv(
+  tripal_insert_cv(
     'pub_property',
     'Contains properties for publications. This can be used if the tripal_pub vocabulary (which is default for publications in Tripal) is not desired.'
   );
 
   // Add cv for relationship types
-  tripal_cv_add_cv(
+  tripal_insert_cv(
     'pub_relationship',
     'Contains types of relationships between publications.'
   );

+ 1 - 1
tripal_stock/includes/tripal_stock.chado_node.inc

@@ -277,7 +277,7 @@ function chado_stock_form($node, $form_state) {
     '#description' => t('Optionally enter a description about the database accession.')
   );
 
-  $db_options = tripal_db_get_db_options();
+  $db_options = tripal_get_db_select_options();
   $db_options[0] = 'Select a Database';
   $form['database_reference']['database'] = array(
     '#type' => 'select',

+ 3 - 3
tripal_stock/tripal_stock.install

@@ -186,15 +186,15 @@ function tripal_stock_add_organism_count_mview() {
 function tripal_stock_add_cvs() {
 
   // Add cv for relationship types
-  tripal_cv_add_cv(
+  tripal_insert_cv(
     'stock_relationship',
     'Contains types of relationships between stocks.'
   );
-  tripal_cv_add_cv(
+  tripal_insert_cv(
     'stock_property',
     'Contains properties for stocks.'
   );
-  tripal_cv_add_cv(
+  tripal_insert_cv(
     'stock_type',
     'Contains a list of types for stocks.'
   );