ソースを参照

Merge pull request #704 from tripal/701-tv3-publishing_fix

701 tv3 publishing fix
Lacey-Anne Sanderson 6 年 前
コミット
60436a561b

+ 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

+ 29 - 33
tripal_chado/api/tripal_chado.api.inc

@@ -27,7 +27,7 @@
  *   A key/value associative array that supports the following keys:
  *   - bundle_name:  The name of the the TripalBundle (e.g. bio_data-12345).
  * @param $job
- *   The jobs management object for the job if this function is run as a job. 
+ *   The jobs management object for the job if this function is run as a job.
  *   This argument is added by Tripal during a job run and is not needed if
  *   this function is run directly.
  *
@@ -38,7 +38,7 @@
  * @ingroup tripal_chado_api
  */
 function chado_publish_records($values, $job = NULL) {
- 
+
   // Used for adding runtime to the progress report.
   $started_at = microtime(true);
 
@@ -48,7 +48,11 @@ function chado_publish_records($values, $job = NULL) {
     $job = new TripalJob();
     $job->load($job_id);
   }
-  
+  $report_progress = TRUE;
+  if (!is_object($job)) {
+    $report_progress = FALSE;
+  }
+
   // 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
@@ -206,40 +210,29 @@ function chado_publish_records($values, $job = NULL) {
   $sql = "SELECT count(*) as num_records " . $from . $where;
   $result = chado_query($sql, $args);
   $count = $result->fetchField();
-  
+
   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",
-        $i, $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 
-    // ensures nested trasactions work the same as passing a transaction 
-    // through to the deepest level and not starting a new transaction if we 
+    // 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
+    // ensures nested trasactions work the same as passing a transaction
+    // through to the deepest level and not starting a new transaction if we
     // are already in one.
     $transaction = db_transaction();
     try {
@@ -288,7 +281,9 @@ function chado_publish_records($values, $job = NULL) {
         }
 
         $i++;
-        $total_published++;
+        if ($report_progress) {
+          $job->setItemsHandled($i);
+        }
       }
     }
     catch (Exception $e) {
@@ -299,7 +294,8 @@ function chado_publish_records($values, $job = NULL) {
       return FALSE;
     }
 
-    // If we get through the loop and haven't completed 100 records, then we're done!
+    // If we get through the loop and haven't completed 100 records, then 
+    // we're done!
     if ($i < $chunk_size) {
       $more_records_to_publish = FALSE;
     }
@@ -309,9 +305,9 @@ function chado_publish_records($values, $job = NULL) {
   }
 
   tripal_report_error($message_type, TRIPAL_INFO,
-    "Succesfully published %count %type record(s).",
-    ['%count' => $total_published, '%type' => $bundle->label], $message_opts);
-  
+    "Successfully published !count !type record(s).",
+    ['!count' => $i, '!type' => $bundle->label], $message_opts);
+
   return TRUE;
 }