Browse Source

Fixed bug in pub import

Stephen Ficklin 10 years ago
parent
commit
5898e9d340
2 changed files with 16 additions and 15 deletions
  1. 2 2
      tripal_core/api/tripal_core.chado_query.api.inc
  2. 14 13
      tripal_pub/api/tripal_pub.api.inc

+ 2 - 2
tripal_core/api/tripal_core.chado_query.api.inc

@@ -1263,8 +1263,8 @@ function chado_select_record($table, $columns, $values, $options = NULL) {
           // Ensure that there were results returned.
           elseif (count($results)==0) {
             tripal_report_error('tripal_core', TRIPAL_ERROR,
-              'chado_select_record: the foreign key definition for %field
-              returned no results where the definition supplied was %value',
+              'chado_select_record: the foreign key definition for \'%field\' '.
+              'returned no results where the definition supplied was %value',
               array('%field' => $field, '%value' => print_r($value, TRUE))
             );
             return array();

+ 14 - 13
tripal_pub/api/tripal_pub.api.inc

@@ -75,7 +75,7 @@ function tripal_get_publication($identifiers, $options = array()) {
     unset($identifiers['property']);
     $pub = chado_get_record_with_property(
       array('table' => 'pub', 'base_records' => $identifiers),
-      array('type_name' => $property), 
+      array('type_name' => $property),
       $options
     );
   }
@@ -84,21 +84,22 @@ function tripal_get_publication($identifiers, $options = array()) {
       $dbname = $matches[1];
       $accession = $matches[2];
 
+      // First make sure the dbxref is present.
       $values = array(
-        'dbxref_id' => array (
-          'accession' => $accession,
-          'db_id' => array(
-            'name' => $dbname
-          ),
+        'accession' => $accession,
+        'db_id' => array(
+          'name' => $dbname
         ),
       );
-      $pub_dbxref = chado_select_record('pub_dbxref', array('pub_id'), $values);
-      if (count($pub_dbxref) > 0) {
-        $pub = chado_generate_var('pub', array('pub_id' => $pub_dbxref[0]->pub_id), $options);
+      $dbxref = chado_select_record('dbxref', array('dbxref_id'), $values);
+      if (count($dbxref) == 0) {
+        return FALSE;
       }
-      else {
+      $pub_dbxref = chado_select_record('pub_dbxref', array('pub_id'), array('dbxref_id' => $dbxref[0]->dbxref_id));
+      if (count($pub_dbxref) == 0) {
         return FALSE;
       }
+      $pub = chado_generate_var('pub', array('pub_id' => $pub_dbxref[0]->pub_id), $options);
     }
     else {
       tripal_report_error('tripal_pub_api', TRIPAL_ERROR,
@@ -215,13 +216,13 @@ function tripal_publication_exists($pub_details) {
     $pub_type = tripal_get_cvterm($identifiers);
   }
   else {
-    tripal_report_error('tripal_pub', TRIPAL_ERROR, 
+    tripal_report_error('tripal_pub', TRIPAL_ERROR,
       "tripal_publication_exists(): The Publication Type is a " .
       "required property but is missing", array());
     return array();
   }
   if (!$pub_type) {
-    tripal_report_error('tripal_pub', TRIPAL_ERROR, 
+    tripal_report_error('tripal_pub', TRIPAL_ERROR,
      "tripal_publication_exists(): Cannot find publication type: '%type'",
       array('%type' => $pub_details['Publication Type'][0]));
     return array();
@@ -238,7 +239,7 @@ function tripal_publication_exists($pub_details) {
   if (array_key_exists('Conference Name', $pub_details)) {
     $series_name = substr($pub_details['Conference Name'], 0, 255);
   }
-  
+
   // make sure the publication is unique using the prefereed import duplication check
   $import_dups_check = variable_get('tripal_pub_import_duplicate_check', 'title_year_media');
   $pubs = array();