Prechádzať zdrojové kódy

Various bug fixes realated to printing errors after rolling back transactions. Fixed issue with OBO parser not having a default CV and a few others

Stephen Ficklin 10 rokov pred
rodič
commit
138b11d0ce

+ 1 - 1
tripal_core/api/tripal_core.chado_nodes.api.inc

@@ -627,9 +627,9 @@ function chado_node_sync_records($base_table, $max_sync = FALSE, $organism_id =
     print "\n\nComplete!\n";
   }
   catch (Exception $e) {
+    $transaction->rollback();
     print "\n"; // make sure we start errors on new line
     watchdog_exception('trp-fsync', $e);
-    $transaction->rollback();
     print "FAILED: Rolling back database changes...\n";
   }
 

+ 2 - 2
tripal_core/api/tripal_core.chado_nodes.title_and_path.inc

@@ -239,8 +239,8 @@ function chado_add_admin_form_set_title(&$form, &$form_state, $details) {
   $form['set_titles']['submit'] = array(
     '#type' => 'submit',
     '#value' => 'Set Titles',
-		'#validate' => array('chado_add_admin_form_set_title_form_validate'),
- 		'#submit' => array('chado_add_admin_form_set_title_form_submit')
+    '#validate' => array('chado_add_admin_form_set_title_form_validate'),
+    '#submit' => array('chado_add_admin_form_set_title_form_submit')
   );
 
 }

+ 1 - 0
tripal_core/api/tripal_core.chado_query.api.inc

@@ -1298,6 +1298,7 @@ function chado_select_record($table, $columns, $values, $options = NULL) {
 function chado_query($sql, $args = array()) {
   $is_local = $GLOBALS["chado_is_local"];
 
+
   // Args should be an array
   if (!is_array($args)) {
     tripal_report_error('tripal_core', TRIPAL_ERROR,

+ 1 - 1
tripal_core/api/tripal_core.mviews.api.inc

@@ -412,13 +412,13 @@ function tripal_populate_mview($mview_id) {
       }
     }
     catch (Exception $e) {
+      $transaction->rollback();
       // print and save the error message
       $record = new stdClass();
       $record->mview_id = $mview_id;
       $record->status = "ERROR populating $mview->mv_table. See Drupal's recent log entries for details.\n";
       drupal_write_record('tripal_mviews', $record, 'mview_id');
       watchdog_exception('tripal_mviews', $e);
-      $transaction->rollback();
       return FALSE;
     }
     print "Done.\n";

+ 9 - 9
tripal_core/api/tripal_core.tripal.api.inc

@@ -44,14 +44,6 @@ define('TRIPAL_DEBUG',7);
  * @param $type
  *   The catagory to which this message belongs. Can be any string, but the general
  *   practice is to use the name of the module.
- * @param $message
- *   The message to store in the log. Keep $message translatable by not concatenating
- *   dynamic values into it! Variables in the message should be added by using placeholder
- *   strings alongside the variables argument to declare the value of the placeholders.
- *   See t() for documentation on how $message and $variables interact.
- * @param $variables
- *   Array of variables to replace in the message on display or NULL if message is
- *   already translated or not possible to translate.
  * @param $severity
  *   The severity of the message; one of the following values:
  *     - TRIPAL_CRITICAL: Critical conditions.
@@ -60,6 +52,14 @@ define('TRIPAL_DEBUG',7);
  *     - TRIPAL_NOTICE: (default) Normal but significant conditions.
  *     - TRIPAL_INFO: Informational messages.
  *     - TRIPAL_DEBUG: Debug-level messages.
+ * @param $message
+ *   The message to store in the log. Keep $message translatable by not concatenating
+ *   dynamic values into it! Variables in the message should be added by using placeholder
+ *   strings alongside the variables argument to declare the value of the placeholders.
+ *   See t() for documentation on how $message and $variables interact.
+ * @param $variables
+ *   Array of variables to replace in the message on display or NULL if message is
+ *   already translated or not possible to translate.
  * @param $options
  *   An array of options. Some available options include:
  *     - print: prints the error message to the terminal screen. Useful when display is the command-line
@@ -108,7 +108,7 @@ function tripal_report_error($type, $severity, $message, $variables = array(), $
     watchdog($type, $message, $variables, $severity);
   }
   catch (Exception $e) {
-    print "CRITICAL (TRIPAL_CORE): Unable to register error message with watchdog";
+    print "CRITICAL (TRIPAL_CORE): Unable to register error message with watchdog: " . $e->getMessage(). "\n.";
     $options['print'] = TRUE;
   }
 

+ 1 - 0
tripal_core/tripal_core.install

@@ -461,6 +461,7 @@ function tripal_core_update_7201() {
   }
 }
 
+
 /**
  * Adds in tripal token formats table to handle page title and path rewrites
  */

+ 56 - 28
tripal_cv/includes/tripal_cv.obo_loader.inc

@@ -186,16 +186,16 @@ function tripal_cv_load_obo_v1_2_id($obo_id, $jobid = NULL) {
 function tripal_cv_load_obo_v1_2_file($obo_name, $file, $jobid = NULL, $is_new = TRUE) {
   $newcvs = array();
 
-  // TODO: need better error detection
-
-  tripal_cv_load_obo_v1_2($file, $jobid, $newcvs);
   if ($is_new) {
     tripal_cv_add_obo_ref($obo_name, $file);
   }
-  print "\nDone\n";
 
-  // update the cvtermpath table
-  tripal_cv_load_update_cvtermpath($newcvs, $jobid);
+  $success = tripal_cv_load_obo_v1_2($file, $jobid, $newcvs);
+  if ($success) {
+    // update the cvtermpath table
+    tripal_cv_load_update_cvtermpath($newcvs, $jobid);
+    print "\nDone\n";
+  }
 }
 
 /**
@@ -236,21 +236,21 @@ function tripal_cv_load_obo_v1_2_url($obo_name, $url, $jobid = NULL, $is_new = T
   }
   fclose($url_fh);
   fclose($obo_fh);
-
-  // second, parse the OBO
-  tripal_cv_load_obo_v1_2($temp, $jobid, $newcvs);
-
-  // now remove the temp file
-  unlink($temp);
-
+  
   if ($is_new) {
     tripal_cv_add_obo_ref($obo_name, $url);
   }
 
-  // update the cvtermpath table
-  tripal_cv_load_update_cvtermpath($newcvs, $jobid);
-
-  print "Done\n";
+  // 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";
+  }
+  // now remove the temp file
+  unlink($temp);
 }
 
 /**
@@ -322,12 +322,36 @@ function tripal_cv_load_obo_v1_2($file, $jobid = NULL, &$newcvs) {
     // parse the obo file
     $default_db = tripal_cv_obo_parse($file, $header, $jobid);
 
-    // add the CV for this ontology to the database
-    $defaultcv = tripal_cv_add_cv($header['default-namespace'][0], '');
-    if (!$defaultcv) {
-      tripal_cv_obo_quiterror('Cannot add namespace ' . $header['default-namespace'][0]);
+    // add the CV for this ontology to the database.  The v1.2 definition
+    // specifies a 'default-namespace' to be used if a 'namespace' is not
+    // 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], '');
+      if (!$defaultcv) {
+        tripal_cv_obo_quiterror('Cannot add namespace ' . $header['default-namespace'][0]);
+      }
+      $newcvs[$header['default-namespace'][0]] = $defaultcv->cv_id;
+    }
+    // if the 'default-namespace' is missing
+    else {
+      
+      // 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]), '');
+        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', '');
+        $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.", 
+        array('%vocab' => $defaultcv->name), WATCHDOG_WARNING);
     }
-    $newcvs[$header['default-namespace'][0]] = $defaultcv->cv_id;
 
     // add any typedefs to the vocabulary first
     print "\nStep 2: Loading type defs...\n";
@@ -340,14 +364,14 @@ function tripal_cv_load_obo_v1_2($file, $jobid = NULL, &$newcvs) {
     }
   }
   catch (Exception $e) {
+    $transaction->rollback();
     print "\n"; // make sure we start errors on new line
+    print "FAILED. Rolling back database changes...\n";
     watchdog_exception('T_obo_loader', $e);
-    $transaction->rollback();
-    print "FAILED: Rolling back database changes...\n";
-    return 0;
+    return FALSE;
   }
 
-  return;
+  return TRUE;
 }
 
 /**
@@ -509,8 +533,7 @@ function tripal_cv_obo_process_terms($defaultcv, $jobid = NULL, &$newcvs, $defau
  * @param $term
  *   An array representing the cvterm. 
  * @param $defaultcv
- *   A database object containing a record from the cv table for the 
- *   default controlled vocabulary
+ *   The name of the default controlled vocabulary
  * @is_relationship
  *   Set to 1 if this term is a relationship term
  * @default_db
@@ -520,6 +543,11 @@ function tripal_cv_obo_process_terms($defaultcv, $jobid = NULL, &$newcvs, $defau
  */
 function tripal_cv_obo_process_term($term, $defaultcv, $is_relationship = 0, &$newcvs, $default_db) {
 
+  // make sure we have a namespace for this term
+  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();

+ 1 - 1
tripal_example/theme/templates/tripal_example_teaser.tpl.php

@@ -11,4 +11,4 @@ $example  = $variables['node']->example; ?>
       print "... " . l("[more]", "node/$node->nid");
     } ?>
   </div>
-</div>
+</div> <?php 

+ 1 - 1
tripal_feature/includes/tripal_feature.fasta_loader.inc

@@ -607,9 +607,9 @@ function tripal_feature_load_fasta($dfile, $organism_id, $type,
       $source, $residues, $method, $re_name, $match_type, $parentcvterm, $relcvterm);
   }
   catch (Exception $e) {
+    $transaction->rollback();
     print "\n"; // make sure we start errors on new line
     watchdog_exception('T_fasta_loader', $e);
-    $transaction->rollback();
     print "FAILED: Rolling back database changes...\n";
   }
   

+ 7 - 7
tripal_pub/api/tripal_pub.api.inc

@@ -616,9 +616,9 @@ function tripal_reimport_publications($do_contact = FALSE, $dbxref = NULL, $db =
     }
   }
   catch (Exception $e) {
+    $transaction->rollback();
     print "\n"; // make sure we start errors on new line
     watchdog_exception('T_pub_import', $e);
-    $transaction->rollback();
     print "FAILED: Rolling back database changes...\n";
     return;
   }
@@ -685,9 +685,9 @@ function tripal_execute_pub_importer($import_id, $job_id = NULL) {
     tripal_set_job_progress($job_id, '100');
   }
   catch (Exception $e) {
+    $transaction->rollback();
     print "\n"; // make sure we start errors on new line
     watchdog_exception('T_pub_import', $e);
-    $transaction->rollback();
     print "FAILED: Rolling back database changes...\n";
     return;
   }
@@ -783,10 +783,10 @@ function tripal_execute_active_pub_importers($report_email = FALSE, $do_update =
     }
   }
   catch (Exception $e) {
+    $transaction->rollback();
     print "\n"; // make sure we start errors on new line
     watchdog_exception('T_pub_import', $e);
-      $transaction->rollback();
-      print "FAILED: Rolling back database changes...\n";
+    print "FAILED: Rolling back database changes...\n";
     return;
   }
   print "Done.\n";
@@ -856,11 +856,11 @@ function tripal_import_pub_by_dbxref($pub_dbxref, $do_contact = FALSE, $do_updat
     }
   }
   catch (Exception $e) {
+    $transaction->rollback();
     print "\n"; // make sure we start errors on new line
     watchdog_exception('T_pub_import', $e);
-        $transaction->rollback();
-        print "FAILED: Rolling back database changes...\n";
-      return;
+    print "FAILED: Rolling back database changes...\n";
+    return;
   }
 
   print "Done.\n";