Ver código fonte

Fixed other drush commands

Stephen Ficklin 6 anos atrás
pai
commit
07aaa9560e

+ 42 - 18
tripal_chado/api/modules/tripal_chado.pub.api.inc

@@ -345,6 +345,7 @@ function chado_autocomplete_pub($string = '') {
  */
 function chado_import_pub_by_dbxref($pub_dbxref, $do_contact = FALSE, 
     $publish = TRUE, $do_update = TRUE) {
+    
   $num_to_retrieve = 1;
   $pager_id = 0;
   $page = 0;
@@ -352,10 +353,21 @@ function chado_import_pub_by_dbxref($pub_dbxref, $do_contact = FALSE,
   $pub_id = NULL;
 
   module_load_include('inc', 'tripal_chado', 'includes/loaders/tripal_chado.pub_importers');
-
-  print "\nNOTE: Loading of publications is performed using a database transaction. \n" .
-      "If the load fails or is terminated prematurely then the entire set of \n" .
-      "insertions/updates is rolled back and will not be found in the database\n\n";
+  
+  // These are options for the tripal_report_error function. We do not
+  // want to log messages to the watchdog but we do for the job and to
+  // the terminal
+  $message_type = 'pub_import';
+  $message_opts = [
+    'watchdog' == FALSE,
+    'print' => TRUE,
+  ];
+  
+  $message = "Importing of publications is performed using a database transaction. " .
+    "If the load fails or is terminated prematurely then the entire set of " .
+    "deletions is rolled back and will not be found in the database";
+  tripal_report_error($message_type, TRIPAL_INFO, $message, [], $message_opts);
+  
 
   $transaction = db_transaction();
   try {
@@ -377,8 +389,8 @@ function chado_import_pub_by_dbxref($pub_dbxref, $do_contact = FALSE,
       );
       $remote_db = $criteria['remote_db'];
       $results = tripal_get_remote_pubs($remote_db, $criteria, $num_to_retrieve, $page);
-      $pubs          = $results['pubs'];
-      $search_str    = $results['search_str'];
+      $pubs = $results['pubs'];
+      $search_str = $results['search_str'];
       $total_records = $results['total_records'];
       tripal_pub_add_publications($pubs, $do_contact, $do_update);
     }
@@ -575,7 +587,7 @@ function chado_execute_pub_importer($import_id, $publish = TRUE, $do_update = FA
  *   only entities are created.
  */
 function _chado_execute_pub_importer_publish($publish, $job, $message_type, $message_opts) {
-  
+    
   // If the user wants to publish then do so.
   if ($publish === TRUE or $publish === 'both') {
     
@@ -640,9 +652,20 @@ function _chado_execute_pub_importer_publish($publish, $job, $message_type, $mes
 function chado_reimport_publications($do_contact = FALSE, $dbxref = NULL, 
     $db = NULL, $publish = TRUE) {
 
-  print "\nNOTE: Loading of publications is performed using a database transaction. \n" .
-      "If the load fails or is terminated prematurely then the entire set of \n" .
-      "insertions/updates is rolled back and will not be found in the database\n\n";
+  // These are options for the tripal_report_error function. We do not
+  // want to log messages to the watchdog but we do for the job and to
+  // the terminal
+  $message_type = 'pub_import';
+  $message_opts = [
+    'watchdog' == FALSE,
+    'print' => TRUE,
+  ];
+  
+  $message = "Importing of publications for this importer is performed using a database transaction. " .
+    "If the load fails or is terminated prematurely then the entire set of " .
+    "deletions is rolled back and will not be found in the database";
+  tripal_report_error($message_type, TRIPAL_INFO, $message, [], $message_opts);
+  
   $transaction = db_transaction();
   try {
 
@@ -650,10 +673,10 @@ function chado_reimport_publications($do_contact = FALSE, $dbxref = NULL,
     // databases.
     $sql = "
       SELECT DB.name as db_name, DBX.accession
-      FROM pub P
-        INNER JOIN pub_dbxref PDBX ON P.pub_id = PDBX.pub_id
-        INNER JOIN dbxref DBX      ON DBX.dbxref_id = PDBX.dbxref_id
-        INNER JOIN db DB           ON DB.db_id = DBX.db_id
+      FROM {pub} P
+        INNER JOIN {pub_dbxref} PDBX ON P.pub_id = PDBX.pub_id
+        INNER JOIN {dbxref} DBX      ON DBX.dbxref_id = PDBX.dbxref_id
+        INNER JOIN {db} DB           ON DB.db_id = DBX.db_id
     ";
     $args = array();
     if ($dbxref and preg_match('/^(.*?):(.*?)$/', $dbxref, $matches)) {
@@ -698,7 +721,8 @@ function chado_reimport_publications($do_contact = FALSE, $dbxref = NULL,
           ),
         ),
       );
-      $pubs = tripal_get_remote_pubs($remote_db, $search, 1, 0);
+      $qresults = tripal_get_remote_pubs($remote_db, $search, 1, 0);
+      $pubs = $qresults['pubs'];      
       tripal_pub_add_publications($pubs, $do_contact, TRUE);
 
       $i++;
@@ -709,10 +733,10 @@ function chado_reimport_publications($do_contact = FALSE, $dbxref = NULL,
   }
   catch (Exception $e) {
     $transaction->rollback();
-    print "\n"; // make sure we start errors on new line
     watchdog_exception('T_pub_import', $e);
-    print "FAILED: Rolling back database changes...\n";
-    return;
+    tripal_report_error($message_type, TRIPAL_ERROR,
+      "Rolling back database changes... !message",
+      ['!message' => $e->getMessage()], $message_opts);return;
   }
   print "Done.\n";
 }

+ 1 - 2
tripal_chado/includes/loaders/tripal_chado.pub_importers.inc

@@ -1068,8 +1068,7 @@ function tripal_pub_add_publication($pub_details, &$action, $do_contact = FALSE,
   }
   else {
     tripal_report_error($message_type, TRIPAL_ERROR,
-      "The Publication Type is a required property but is missing", 
-      [], $error_opts);
+      "The Publication Type is a required property but is missing", [], $error_opts);
     $action = 'error';
     return FALSE;
   }

+ 10 - 16
tripal_chado/tripal_chado.drush.inc

@@ -110,11 +110,11 @@ function tripal_chado_drush_command() {
     'options' => array(
       'dbxref' => dt('An accession number for a publication from a remote database (e.g. PMID:23582642)'),
       'db' => dt('The database name (e.g. PMID or AGL)'),
-    ),
-    'publish' => dt("Set to 'Y' to publish publications after import into Chado. (default: Y)."),
-    'sync' => dt("For Tripal v3 legacy mode only. Set to 'Y' to sync publications after import into Chado. This will create legacy \"nodes\" rather than the newer Tripal v3 entities."),
-    'username' => array(
-      'description' => dt('The Drupal user name for which the job should be run.  The permissions for this user will be used.'),
+      'publish' => dt("Set to 'Y' to publish publications after import into Chado. (default: Y)."),
+      'sync' => dt("For Tripal v3 legacy mode only. Set to 'Y' to sync publications after import into Chado. This will create legacy \"nodes\" rather than the newer Tripal v3 entities."),
+      'username' => array(
+        'description' => dt('The Drupal user name for which the job should be run.  The permissions for this user will be used.'),
+      ),
     ),
     'examples' => array(
       'Standard example' => 'drush trp-update-pubs --username=[username]',
@@ -161,12 +161,9 @@ function drush_tripal_chado_trp_import_pubs() {
   elseif ($publish  == 'Y'  and $sync  != 'Y' ) {
     $publish = TRUE;
   }
-  
-  // Set a default to 'Y' if not specified.
-  if (!$publish) {
-    $publish == TRUE;
-  }
-  
+  else {
+    $publish = TRUE;
+  } 
 
   module_load_include('inc', 'tripal_chado', 'includes/loaders/tripal_chado.pub_importers');
   if ($dbxref) {
@@ -190,7 +187,6 @@ function drush_tripal_chado_trp_update_pubs() {
   $sync = drush_get_option('sync');
   
   $uname = drush_get_option('username');
-  
   drush_tripal_set_user($uname);
   
   if ($publish == 'Y' and $sync == 'Y' ) {
@@ -202,10 +198,8 @@ function drush_tripal_chado_trp_update_pubs() {
   elseif ($publish  == 'Y'  and $sync  != 'Y' ) {
     $publish = TRUE;
   }
-  
-  // Set a default to 'Y' if not specified.
-  if (!$publish) {
-    $publish == TRUE;
+  else {
+    $publish = TRUE;
   }
 
   module_load_include('inc', 'tripal_chado', 'includes/loaders/tripal_chado.pub_importers');