From f6ac1c96f29a7c592cb17569716d5416018f8208 Mon Sep 17 00:00:00 2001
From: Sweetchuck <Sweetchuck@23728.no-reply.drupal.org>
Date: Tue, 15 Sep 2020 09:42:42 +0300
Subject: [PATCH] Issue #3144355 by Sweetchuck: Moving progress-bar

---
 src/QueueUIBatch.php | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/QueueUIBatch.php b/src/QueueUIBatch.php
index 97a12c6..a2e43d0 100644
--- a/src/QueueUIBatch.php
+++ b/src/QueueUIBatch.php
@@ -42,12 +42,19 @@ class QueueUIBatch {
     $queue_worker = $queue_manager->createInstance($queue_name);
     $queue = $queue_factory->get($queue_name);
 
+    $num_of_items = $queue->numberOfItems();
+    if (!array_key_exists('num_of_total_items', $context['sandbox'])
+      || $context['sandbox']['num_of_total_items'] < $num_of_items
+    ) {
+      $context['sandbox']['num_of_total_items'] = $num_of_items;
+    }
+
     $context['finished'] = 0;
     $context['results']['queue_name'] = $info['title'];
 
     $title = t('Processing queue %name: %count items remaining', [
       '%name' => $info['title'],
-      '%count' => $queue->numberOfItems(),
+      '%count' => $num_of_items,
     ]);
 
     try {
@@ -61,8 +68,11 @@ class QueueUIBatch {
         $queue_worker->processItem($item->data);
         $queue->deleteItem($item);
 
+        $num_of_items = $queue->numberOfItems();
+
         // Update context
         $context['results']['processed'][] = $item->item_id;
+        $context['finished'] = ($context['sandbox']['num_of_total_items'] - $num_of_items) / $context['sandbox']['num_of_total_items'];
       }
       else {
         // If we cannot claim an item we must be done processing this queue.
@@ -137,4 +147,4 @@ class QueueUIBatch {
       );
     }
   }
-}
\ No newline at end of file
+}
-- 
GitLab