瀏覽代碼

Pub importers on the command-line are working for both PubMed and AGL

Stephen Ficklin 11 年之前
父節點
當前提交
53dbe7f977
共有 3 個文件被更改,包括 41 次插入47 次删除
  1. 40 46
      tripal_pub/api/tripal_pub.api.inc
  2. 0 1
      tripal_pub/includes/importers/PMID.inc
  3. 1 0
      tripal_pub/includes/pub_citation.inc

+ 40 - 46
tripal_pub/api/tripal_pub.api.inc

@@ -192,52 +192,46 @@ function tripal_pub_update_publications($do_contact = FALSE, $dbxref = NULL, $db
  */
  */
 function tripal_pub_import_publications($report_email = FALSE, $do_update = FALSE) {
 function tripal_pub_import_publications($report_email = FALSE, $do_update = FALSE) {
   $num_to_retrieve = 100;
   $num_to_retrieve = 100;
-  $pager_id = 0;
   $page = 0;
   $page = 0;
-  $num_pubs = 0;
-
-  // get a persistent connection
-  $connection = tripal_db_persistent_chado();
-  if (!$connection) {
-    print "A persistant connection was not obtained. Loading will be slow\n";
-  }
-
-  // if we cannot get a connection then let the user know the loading will be slow
-  tripal_db_start_transaction();
-  if ($connection) {
-    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";
+  
+  // start the transaction
+  $transaction = db_transaction();
+  
+  try {
+    // get all of the loaders
+    $args = array();
+    $sql = "SELECT * FROM {tripal_pub_import} WHERE disabled = 0 ";
+    $results = db_query($sql, $args);
+    $do_contact = FALSE;
+    $reports = array();
+    foreach ($results as $import) {
+      $page = 0;
+      print "Importing: " . $import->name . "\n";
+      // keep track if any of the importers want to create contacts from authors
+      if ($import->do_contact == 1) {
+        $do_contact = TRUE;
+      }
+      $criteria = unserialize($import->criteria);
+      $remote_db = $criteria['remote_db'];
+      do {
+        // retrieve the pubs for this page. We'll retreive 100 at a time
+        $results = tripal_pub_get_remote_search_results($remote_db, $criteria, $num_to_retrieve, $page);
+        $pubs = $results['pubs'];
+        $reports[$import->name] = tripal_pub_add_publications($pubs, $import->do_contact, $do_update);
+        $page++;
+      }
+      // continue looping until we have a $pubs array that does not have
+      // our requested numer of records.  This means we've hit the end
+      while (count($pubs) == $num_to_retrieve);
+    }
   }
   }
-
-  // get all of the loaders
-  $args = array();
-  $sql = "SELECT * FROM {tripal_pub_import} WHERE disabled = 0 ";
-  $results = db_query($sql, $args);
-  $do_contact = FALSE;
-  $reports = array();
-  while ($import = $results->fetchObject()) {
-    print "Importing: " . $import->name . "\n";
-    // keep track if any of the importers want to create contacts from authors
-    if ($import->do_contact == 1) {
-      $do_contact = TRUE;
-    }
-    $criteria = unserialize($import->criteria);
-    $remote_db = $criteria['remote_db'];
-    do {
-      // retrieve the pubs for this page. We'll retreive 10 at a time
-      $pubs = tripal_pub_get_remote_search_results($remote_db, $criteria, $num_to_retrieve, $pager_id, $page);
-      $reports[$import->name] = tripal_pub_add_publications($pubs, $import->do_contact, $do_update);
-      $page++;
-    }
-    // continue looping until we have a $pubs array that does not have
-    // our requested numer of records.  This means we've hit the end
-    while (count($pubs) == $num_to_retrieve);
+  catch (Exception $e) {
+    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;
   }
   }
-
-  // transaction is complete
-  tripal_db_commit_transaction();
-
   print "Transaction Complete\n";
   print "Transaction Complete\n";
 
 
   // sync the newly added publications with Drupal. If the user
   // sync the newly added publications with Drupal. If the user
@@ -315,11 +309,11 @@ function tripal_pub_import_by_dbxref($pub_dbxref, $do_contact = FALSE, $do_updat
           'scope' => 'id',
           'scope' => 'id',
           'operation' => '',
           'operation' => '',
           'is_phrase' => 0,
           'is_phrase' => 0,
-    ),
-    ),
+        ),
+      ),
     );
     );
     $remote_db = $criteria['remote_db'];
     $remote_db = $criteria['remote_db'];
-    $pubs = tripal_pub_get_remote_search_results($remote_db, $criteria, $num_to_retrieve, $pager_id, $page);
+    $pubs = tripal_pub_get_remote_search_results($remote_db, $criteria, $num_to_retrieve, $page);
     $pub_id = tripal_pub_add_publications($pubs, $do_contact, $do_update);
     $pub_id = tripal_pub_add_publications($pubs, $do_contact, $do_update);
 
 
   }
   }

+ 0 - 1
tripal_pub/includes/importers/PMID.inc

@@ -37,7 +37,6 @@ function tripal_pub_remote_validate_form_PMID($form, $form_state) {
  *
  *
  */
  */
 function tripal_pub_remote_search_PMID($search_array, $num_to_retrieve, $page) {
 function tripal_pub_remote_search_PMID($search_array, $num_to_retrieve, $page) {
-
   // convert the terms list provicded by the caller into a string with words
   // convert the terms list provicded by the caller into a string with words
   // separated by a '+' symbol.
   // separated by a '+' symbol.
   $num_criteria = $search_array['num_criteria'];
   $num_criteria = $search_array['num_criteria'];

+ 1 - 0
tripal_pub/includes/pub_citation.inc

@@ -52,6 +52,7 @@ function tripal_pub_create_citations ($options) {
       cv_id = (SELECT cv_id FROM {cv} WHERE name = 'tripal_pub')
       cv_id = (SELECT cv_id FROM {cv} WHERE name = 'tripal_pub')
   ";
   ";
   $citation_type_id = chado_query($sql)->fetchField();
   $citation_type_id = chado_query($sql)->fetchField();
+  
   // Create and replace citation for all pubs
   // Create and replace citation for all pubs
   if ($options == 'all') {
   if ($options == 'all') {
     $sql = "SELECT pub_id FROM {pub} P WHERE pub_id <> 1";
     $sql = "SELECT pub_id FROM {pub} P WHERE pub_id <> 1";