diff --git a/core/lib/Drupal/Core/Batch/Batch.php b/core/lib/Drupal/Core/Batch/Batch.php index a114afb..11b9e87 100644 --- a/core/lib/Drupal/Core/Batch/Batch.php +++ b/core/lib/Drupal/Core/Batch/Batch.php @@ -19,26 +19,102 @@ */ class Batch { + /** + * The set of operations to be processed. + * + * Each operation is a tuple of the function / method to use and an array + * containing any parameters to be passed. + * + * @var array + */ protected $operations = []; + + /** + * The title for the batch. + * + * @var string + */ protected $title; + + /** + * The initializing message for the batch. + * + * @var string + */ protected $init_message; + + /** + * The message to be shown while the batch is in progress. + * + * @var string + */ protected $progress_message; + + /** + * The message to be shown if a problem occurs. + * + * @var string + */ protected $error_message; + + /** + * The name of a function / method to be called when the batch finishes. + * + * @var string + */ protected $finished; + + /** + * The file containing the operation and finished callbacks. + * + * If the callbacks are in the .module file or are static methods of a class, + * then this does not need to be set. + * + * @var + */ protected $file; + + /** + * An array of CSS file to be included when processing the batch. + * + * @var array + */ protected $css = []; + + /** + * An array of options to be used with the redirect URL. + * + * @var array + */ protected $url_options = []; - protected $progressive; + + /** + * Specifies if the batch is progressive. + * + * If true, multiple calls are used. Otherwise an attempt is made to process + * the batch in on page call. + * + * @var bool + */ + protected $progressive = TRUE; + + /** + * The details of the queue to use. + * + * A tuple containing the name of the queue and the class of the queue to use. + * + * @var array + */ protected $queue; /** * Constructs a new Batch instance. * * @param string $title - * The title. + * (optional) The title. */ public function __construct($title = NULL) { - $this->setTitle(is_null($title) ? 'Processing' : $title); + $this->setTitle($title ?: 'Processing'); $this->setInitMessage('Initializing.'); $this->setProgressMessage('Completed @current of @total.'); $this->setErrorMessage('An error has occurred.'); @@ -48,7 +124,7 @@ public function __construct($title = NULL) { * Static constructor for a batch process. * * @param string $title - * The title. + * (optional) The title. * * @return static * A new object. @@ -108,7 +184,7 @@ public function setFinishCallback($callback) { * Sets the displayed message while processing is initialized. * * @param string $message - * The text to display. Defaults to t('Initializing.'). + * The text to display. Defaults to 'Initializing.'. * * @return $this */ @@ -123,7 +199,7 @@ public function setInitMessage($message) { * @param string $message * The text to display. Available placeholders are '@current', * '@remaining', '@total', '@percentage', '@estimate' and '@elapsed'. - * Defaults to t('Completed @current of @total.'). + * Defaults to 'Completed @current of @total.'. * * @return $this */ @@ -136,7 +212,7 @@ public function setProgressMessage($message) { * Sets the message to display if an error occurs while processing. * * @param string $message - * The text to display. Defaults to t('An error has occurred.'). + * The text to display. Defaults to 'An error has occurred.'. * * @return $this */ @@ -162,13 +238,13 @@ public function setFile($filename) { } /** - * Sets the location of css files. + * Sets the location of CSS files. * * Adds the CSS files for use on the progress page. Any previously added CSS * files are removed. Use \Drupal\Core\Batch\Batch::addCss() to add a file. * - * @param array $filenames - * The css files to be used. + * @param string[] $filenames + * The CSS files to be used. * * @return $this */ @@ -196,12 +272,12 @@ public function setUrlOptions(array $options = []) { * Sets the batch to run progressively. * * @param bool $is_progressive - * TRUE indicates that the batch will run in more than one run. FALSE - * (default) indicates that the batch will finish in a single run. + * TRUE (default) indicates that the batch will run in more than one run. + * FALSE indicates that the batch will finish in a single run. * * @return $this */ - public function setProgressive($is_progressive) { + public function setProgressive($is_progressive = TRUE) { $this->progressive = $is_progressive; return $this; } diff --git a/core/lib/Drupal/Core/Batch/BatchQueueController.php b/core/lib/Drupal/Core/Batch/BatchQueueController.php index b8c6317..cad29c8 100644 --- a/core/lib/Drupal/Core/Batch/BatchQueueController.php +++ b/core/lib/Drupal/Core/Batch/BatchQueueController.php @@ -15,8 +15,23 @@ */ class BatchQueueController { - private static $batches = []; - private static $queues = []; + /** + * The batch sets to be processed. + * + * Used as a memory cache. + * + * @var array + */ + protected static $batches = []; + + /** + * The queue objects to be processed. + * + * Used as a memory cache. + * + * @var array + */ + protected static $queues = []; /** * Places the batch in the queue to be processed. @@ -25,7 +40,6 @@ class BatchQueueController { * The batch to place in the queue. */ public static function enqueue(Batch $batch) { - // Initialize the batch if needed. if (empty(self::$batches)) { self::$batches = array( @@ -82,7 +96,6 @@ public static function enqueue(Batch $batch) { self::$batches['sets'] = array_merge($slice1, array($batch_set), $slice2); self::populateQueue($index); } - } /** @@ -114,7 +127,6 @@ public static function enqueue(Batch $batch) { */ public static function process($redirect = NULL, Url $url = NULL, $redirect_callback = NULL) { if (isset(self::$batches)) { - // Add process information. $process_info = [ 'current_set' => 0,