Pārlūkot izejas kodu

updated publishing code to properly use job object for reporting progress

Stephen Ficklin 6 gadi atpakaļ
vecāks
revīzija
4b03d8bff7

+ 7 - 0
docs/user_guide/install_tripal/manual_install/install_prereqs.rst

@@ -41,3 +41,10 @@ Optionally, you can install the ckeditor module.  This module provides a nice WY
 
   drush pm-download ckeditor
   drush pm-enable ckeditor
+  
+Finally, we need an more recent version of JQuery that what comes with Drupal.  We can get this by installing the JQuery update module.
+
+.. code-block:: bash
+
+  drush pm-download jquery_update
+  drush pm-enable jquery_update

+ 11 - 20
tripal_chado/api/tripal_chado.api.inc

@@ -214,31 +214,20 @@ function chado_publish_records($values, $job = NULL) {
   tripal_report_error($message_type, TRIPAL_INFO,
     "There are !count records to publish.",
     ['!count' => $count], $message_opts);
+  
+  if ($report_progress) {
+    $job->setTotalItems($count); 
+    $job->setItemsHandled(0);
+    $job->setInterval(1);
+  }
 
-  // Perform the query.
-  $sql = $select . $from . $where . ' LIMIT '.$chunk_size;
+  // Perform the query in chunks.
+  $sql = $select . $from . $where . ' LIMIT '. $chunk_size;
   $more_records_to_publish = TRUE;
-  $total_published = 0;
   while ($more_records_to_publish) {
 
     $records = chado_query($sql, $args);
 
-    // Update the job status every chunk start.
-    // Because this is outside of hte transaction, we can update the admin through the jobs UI.
-    $complete = 0;
-    if ($count > 0) {
-      $complete = ($total_published / $count) * 33.33333333;
-    }
-    if ($report_progress) { $job->setProgress(intval($complete * 3)); }
-    if ($total_published === 0) {
-      printf("%d of %d records. (%0.2f%%) Memory: %s bytes.\r",
-        0, $count, 0, number_format(memory_get_usage()), 0);
-    }
-    else {
-      printf("%d of %d records. (%0.2f%%) Memory: %s bytes; Current run time: %s minutes.\r",
-        $total_published, $count, $complete * 3, number_format(memory_get_usage()), number_format((microtime(true) - $started_at)/60, 2));
-    }
-
     // There is no need to cache transactions since Drupal handles nested
     // transactions "by performing no transactional operations (as far as the
     // database sees) within the inner nesting layers". Effectively, Drupal
@@ -292,7 +281,9 @@ function chado_publish_records($values, $job = NULL) {
         }
 
         $i++;
-        $total_published++;
+        if ($report_progress) {
+          $job->setItemsHandled($i);
+        }
       }
     }
     catch (Exception $e) {