diff --git a/core/includes/form.inc b/core/includes/form.inc index 4382723..d9f6a58 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -777,23 +777,12 @@ function &batch_get() { * * @return * The queue object. + * + * @deprecated as of Drupal 8.2.x, will be removed in Drupal 9.0.0. Use + * \Drupal\Core\Batch\BatchQueueController::getQueueForBatch() instead. */ function _batch_queue($batch_set) { - static $queues; - - if (!isset($queues)) { - $queues = array(); - } - - if (isset($batch_set['queue'])) { - $name = $batch_set['queue']['name']; - $class = $batch_set['queue']['class']; - - if (!isset($queues[$class][$name])) { - $queues[$class][$name] = new $class($name, \Drupal::database()); - } - return $queues[$class][$name]; - } + return BatchQueueController::getQueueForBatch($batch_set); } /** diff --git a/core/lib/Drupal/Core/Batch/BatchQueueController.php b/core/lib/Drupal/Core/Batch/BatchQueueController.php index b83204f..ac447bf 100644 --- a/core/lib/Drupal/Core/Batch/BatchQueueController.php +++ b/core/lib/Drupal/Core/Batch/BatchQueueController.php @@ -12,7 +12,8 @@ */ class BatchQueueController { - private static $batches = array(); + private static $batches = []; + private static $queues = []; /** * Places the batch in the queue to be processed. @@ -198,6 +199,41 @@ public static function &getBatches() { } /** + * Returns a queue object for a batch set. + * + * @param array $batch + * The batch set. + * + * @return \Drupal\Core\Queue\QueueInterface|null + * The queue object or null if the queue cannot be created. + */ + public static function getQueueForBatch($batch) { + if (isset($batch['queue'])) { + return self::getQueue($batch['queue']['name'], $batch['queue']['class']); + } + return NULL; + } + + /** + * Returns a queue object with the given name and class. + * + * @param string $name + * The name of the queue. + * @param string $class + * The class of the queue. + * Usually \Drupal\Core\Queue\Batch or \Drupal\Core\Queue\BatchMemory. + * + * @return \Drupal\Core\Queue\QueueInterface + * The queue object. + */ + protected static function getQueue($name, $class) { + if (!isset(self::$queues[$class][$name])) { + self::$queues[$class][$name] = new $class($name, \Drupal::database()); + } + return self::$queues[$class][$name]; + } + + /** * Populates a job queue with the operations of a batch set. * * Depending on whether the batch is progressive or not, the @@ -220,7 +256,7 @@ protected static function populateQueue($set_id = 0) { ), ); - $queue = _batch_queue($batch_set); + $queue = self::getQueueForBatch($batch_set); $queue->createQueue(); foreach ($batch_set['operations'] as $operation) { $queue->createItem($operation);