Browse Source

fix core problem in importer too

bradfordcondon 6 years ago
parent
commit
1138abec58

+ 13 - 10
tests/tripal_chado/loaders/TaxonomyImporterTest.php

@@ -5,15 +5,17 @@ namespace Tests\tripal_chado;
 use StatonLab\TripalTestSuite\DBTransaction;
 use StatonLab\TripalTestSuite\TripalTestCase;
 
-
+/**
+ *
+ */
 class TaxonomyImporterTest extends TripalTestCase {
 
   use DBTransaction;
 
-
-  /*
+  /**
    * Adds an organism and checks that the importer runs and adds some properties to it.
    *
+   * @group waffle
    */
   public function testImportExistingTaxonomyLoader() {
     module_load_include('inc', 'tripal_chado', 'includes/TripalImporter/TaxonomyImporter');
@@ -26,12 +28,13 @@ class TaxonomyImporterTest extends TripalTestCase {
       'type_id' => NULL,
     ];
 
+    // Speed up test an ensure no organisms
+    // in db since it will check all.
     $prev_db = chado_set_active('chado');
     chado_query('TRUNCATE TABLE {organism} CASCADE');
     chado_set_active($prev_db);
-
     $organism = factory('chado.organism')->create($org);
-    //  $this->publish('organism');
+    // $this->publish('organism');.
     $file = [];
     $run_args = ['import_existing' => TRUE];
     $importer = new \TaxonomyImporter();
@@ -40,7 +43,6 @@ class TaxonomyImporterTest extends TripalTestCase {
     $importer->run();
     ob_end_clean();
 
-
     $query = db_select('chado.organism', 'o');
     $query->join('chado.organismprop', 'op', 'o.organism_id = op.organism_id');
     $query->fields('op', ['value'])
@@ -51,10 +53,10 @@ class TaxonomyImporterTest extends TripalTestCase {
   }
 
   /**
-   * the importer can also load an array of pubmed ids.  We use the pillbug
+   * The importer can also load an array of pubmed ids.  We use the pillbug
    * again.
    *
-   * https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=Info&id=96821
+   * Https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=Info&id=96821
    *
    * @throws \Exception
    */
@@ -63,7 +65,8 @@ class TaxonomyImporterTest extends TripalTestCase {
     module_load_include('inc', 'tripal_chado', 'includes/TripalImporter/TaxonomyImporter');
 
     $file = [];
-    $run_args = ['taxonomy_ids' => '96821']; //its the pillbug again!
+    // Its the pillbug again!
+    $run_args = ['taxonomy_ids' => '96821'];
     $importer = new \TaxonomyImporter();
 
     ob_start();
@@ -79,4 +82,4 @@ class TaxonomyImporterTest extends TripalTestCase {
 
   }
 
-}
+}

+ 17 - 0
tripal_chado/includes/TripalImporter/TaxonomyImporter.inc

@@ -463,6 +463,10 @@ class TaxonomyImporter extends TripalImporter {
    */
   private function updateExisting() {
 
+    $i = 0;
+
+    $total = count($this->all_orgs);
+
     foreach ($this->all_orgs as $organism) {
       // If the organism record is marked as new then let's skip it because
       // it was newly added and should have the updated information already.
@@ -483,6 +487,12 @@ class TaxonomyImporter extends TripalImporter {
       // Get the search response from NCBI.
       $rfh = fopen($search_url, "r");
       $xml_text = '';
+
+      if (!$rfh){
+
+        $this->logMessage("Could not look up " . $sci_name, [], TRIPAL_WARNING);
+        continue;
+      }
       while (!feof($rfh)) {
         $xml_text .= fread($rfh, 255);
       }
@@ -497,6 +507,13 @@ class TaxonomyImporter extends TripalImporter {
         }
       }
       $this->addItemsHandled(1);
+
+      // NCBI limits requests to 3/second.
+      if ($i % 3 == 0) {
+        sleep(1);
+      }
+      $i++;
+
     }
   }