From 3c6f01be6e316eb6901c002528f66a761b3336e1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Florian=20Lore=CC=81tan?= <florian.loretan@wunderkraut.com>
Date: Fri, 16 Oct 2015 11:19:10 +0200
Subject: [PATCH] Issue #2594549: Update cron integration to match current API

---
 queue_ui.module | 27 +++++++++------------------
 1 file changed, 9 insertions(+), 18 deletions(-)

diff --git a/queue_ui.module b/queue_ui.module
index 5b89201..3395a49 100644
--- a/queue_ui.module
+++ b/queue_ui.module
@@ -159,25 +159,16 @@ function queue_ui_defined_queues() {
 }
 
 /**
- * Implements hook_cron().
+ * hook_queue_info_alter()
  */
-function queue_ui_cron() {
-  // Retrieve queues set for cron processing.
-  $defs = queue_ui_defined_queues();
-  if (!empty($defs)) {
-    foreach ($defs as $name => $definition) {
-      $queue = Drupal::queue($name);
-      // A cron callback must be defined and there must be items in the queue.
-      if (isset($definition['cron']) && is_object($queue) && $queue->numberOfItems()) {
-        $active = variable_get('queue_ui_cron_' . $name, FALSE);
-        if ($active) {
-          // Pass $queue to cron callback for processing.
-          $function = $definition['cron']['callback'];
-          // Definitions can define arguments.
-          $args = isset($definition['cron']['callback']) ? $definition['cron']['callback'] : NULL;
-          $function($queue, $args);
-        }
-      }
+function queue_ui_queue_info_alter(&$queues) {
+  foreach ($queues as $queue_name => $definition) {
+
+    // Check if a time limit override exists for this queue.
+    $time_limit = \Drupal::state()->get('queue_ui_cron_' . $queue_name);
+    if (!is_null($time_limit)) {
+      // Override the original definition.
+      $queues[$queue_name]['cron']['time'] = $time_limit;
     }
   }
 }
-- 
GitLab