diff --git a/core/includes/batch.inc b/core/includes/batch.inc index 99d8bc3..974fda0 100644 --- a/core/includes/batch.inc +++ b/core/includes/batch.inc @@ -74,7 +74,7 @@ function _batch_page(Request $request) { case 'do_nojs': // Display the full progress page on startup and on each additional // non-JavaScript iteration. - $current_set = _batch_current_set(); + $current_set = \Drupal::service('batch.processor')->currentSet(); $build['#title'] = $current_set['title']; $build['content'] = _batch_progress_page(); break; @@ -84,8 +84,9 @@ function _batch_page(Request $request) { return _batch_do(); case 'finished': - // _batch_finished() returns a RedirectResponse. - return _batch_finished(); + // \Drupal\Core\Batch\BatchProcessorInterface::finished() returns a + // RedirectResponse. + return \Drupal::service('batch.processor')->finished(); } return $build; @@ -95,11 +96,11 @@ function _batch_page(Request $request) { * Does one execution pass with JavaScript and returns progress to the browser. * * @see _batch_progress_page_js() - * @see _batch_process() + * @see \Drupal\Core\Batch\BatchProcessorInterface::process() */ function _batch_do() { // Perform actual processing. - list($percentage, $message, $label) = _batch_process(); + list($percentage, $message, $label) = \Drupal::service('batch.processor')->process(); return new JsonResponse(array('status' => TRUE, 'percentage' => $percentage, 'message' => $message, 'label' => $label)); } @@ -107,12 +108,12 @@ function _batch_do() { /** * Outputs a batch processing page. * - * @see _batch_process() + * @see \Drupal\Core\Batch\BatchProcessorInterface::process() */ function _batch_progress_page() { $batch = &batch_get(); - $current_set = _batch_current_set(); + $current_set = \Drupal::service('batch.processor')->currentSet(); $new_op = 'do_nojs'; @@ -143,7 +144,7 @@ function _batch_progress_page() { print $fallback; // Perform actual processing. - list($percentage, $message, $label) = _batch_process($batch); + list($percentage, $message, $label) = \Drupal::service('batch.processor')->process($batch); if ($percentage == 100) { $new_op = 'finished'; } @@ -201,83 +202,6 @@ function _batch_progress_page() { } /** - * Processes sets in a batch. - * - * If the batch was marked for progressive execution (default), this executes as - * many operations in batch sets until an execution time of 1 second has been - * exceeded. It will continue with the next operation of the same batch set in - * the next request. - * - * @return - * An array containing a completion value (in percent) and a status message. - * - * @deprecated Use \Drupal::service('batch.processor')->process() instead. - */ -function _batch_process() { - return \Drupal::service('batch.processor')->process(); -} - -/** - * Formats the percent completion for a batch set. - * - * @param $total - * The total number of operations. - * @param $current - * The number of the current operation. This may be a floating point number - * rather than an integer in the case of a multi-step operation that is not - * yet complete; in that case, the fractional part of $current represents the - * fraction of the operation that has been completed. - * - * @return - * The properly formatted percentage, as a string. We output percentages - * using the correct number of decimal places so that we never print "100%" - * until we are finished, but we also never print more decimal places than - * are meaningful. - * - * @see _batch_process() - * - * @deprecated Use \Drupal\Core\Batch\Percentage::format() instead. - */ -function _batch_api_percentage($total, $current) { - return Percentage::format($total, $current); -} - -/** - * Returns the batch set being currently processed. - * - * @deprecated Use \Drupal::service('batch.processor')->currentSet() instead. - */ -function &_batch_current_set() { - return \Drupal::service('batch.processor')->currentSet(); -} - -/** - * Retrieves the next set in a batch. - * - * If there is a subsequent set in this batch, assign it as the new set to - * process and execute its form submit handler (if defined), which may add - * further sets to this batch. - * - * @return - * TRUE if a subsequent set was found in the batch. - * - * @deprecated Use \Drupal::service('batch.processor')->nextSet() instead. - */ -function _batch_next_set() { - return \Drupal::service('batch.processor')->nextSet(); -} - -/** - * Ends the batch processing. - * - * Call the 'finished' callback of each batch set to allow custom handling of - * the results and resolve page redirection. - */ -function _batch_finished() { - \Drupal::service('batch.processor')->finished(); -} - -/** * Shutdown function: Stores the current batch data for the next request. * * @see _batch_page() diff --git a/core/includes/form.inc b/core/includes/form.inc index f06cb17..2551d88 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -1042,8 +1042,7 @@ function batch_process($redirect = NULL, $url = 'batch', $redirect_callback = NU else { // Non-progressive execution: bypass the whole progressbar workflow // and execute the batch in one pass. - require_once __DIR__ . '/batch.inc'; - _batch_process(); + \Drupal::service('batch.processor')->process(); } } } diff --git a/core/lib/Drupal/Core/Batch/BatchProcessor.php b/core/lib/Drupal/Core/Batch/BatchProcessor.php index 56cc7f0..1b65da5 100644 --- a/core/lib/Drupal/Core/Batch/BatchProcessor.php +++ b/core/lib/Drupal/Core/Batch/BatchProcessor.php @@ -16,8 +16,6 @@ use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RequestStack; -require_once DRUPAL_ROOT . '/core/includes/form.inc'; - /** * Provides a batch processor. */ @@ -137,7 +135,7 @@ public function process() { // When all operations in the current batch set are completed, browse // through the remaining sets, marking them 'successfully processed' // along the way, until we find a set that contains operations. - // _batch_next_set() executes form submit handlers stored in 'control' + // nextSet() executes form submit handlers stored in 'control' // sets (see form_execute_handlers()), which can in turn add new sets to // the batch. $set_changed = FALSE; diff --git a/core/lib/Drupal/Core/Batch/BatchProcessorInterface.php b/core/lib/Drupal/Core/Batch/BatchProcessorInterface.php index d5e3444..4ccb995 100644 --- a/core/lib/Drupal/Core/Batch/BatchProcessorInterface.php +++ b/core/lib/Drupal/Core/Batch/BatchProcessorInterface.php @@ -6,6 +6,7 @@ */ namespace Drupal\Core\Batch; +use Symfony\Component\HttpFoundation\RedirectResponse; /** * Processes batch requests. @@ -50,6 +51,9 @@ public function nextSet(); * * Call the 'finished' callback of each batch set to allow custom handling of * the results and resolve page redirection. + * + * @return \Symfony\Component\HttpFoundation\RedirectResponse + * A redirect response. */ public function finished(); diff --git a/core/lib/Drupal/Core/Batch/Percentage.php b/core/lib/Drupal/Core/Batch/Percentage.php index 6cb1bef..0eb30e2 100644 --- a/core/lib/Drupal/Core/Batch/Percentage.php +++ b/core/lib/Drupal/Core/Batch/Percentage.php @@ -29,7 +29,7 @@ class Percentage { * until we are finished, but we also never print more decimal places than * are meaningful. * - * @see _batch_process() + * @see \Drupal\Core\Batch\BatchProcessorInterface::process() */ public static function format($total, $current) { if (!$total || $total == $current) { diff --git a/core/lib/Drupal/Core/Form/FormBuilder.php b/core/lib/Drupal/Core/Form/FormBuilder.php index b1e2260..6e516fb 100644 --- a/core/lib/Drupal/Core/Form/FormBuilder.php +++ b/core/lib/Drupal/Core/Form/FormBuilder.php @@ -195,7 +195,8 @@ public function buildForm($form_id, FormStateInterface &$form_state) { if (isset($_SESSION['batch_form_state'])) { // We've been redirected here after a batch processing. The form has - // already been processed, but needs to be rebuilt. See _batch_finished(). + // already been processed, but needs to be rebuilt. See + // \Drupal\Core\Batch\BatchProcessorInterface::finished(). $form_state = $_SESSION['batch_form_state']; unset($_SESSION['batch_form_state']); return $this->rebuildForm($form_id, $form_state); diff --git a/core/lib/Drupal/Core/Form/FormSubmitter.php b/core/lib/Drupal/Core/Form/FormSubmitter.php index ab7e76e..f25f560 100644 --- a/core/lib/Drupal/Core/Form/FormSubmitter.php +++ b/core/lib/Drupal/Core/Form/FormSubmitter.php @@ -71,8 +71,9 @@ public function doSubmitForm(&$form, FormStateInterface &$form_state) { // Execution continues only for programmatic forms. // For 'regular' forms, we get redirected to the batch processing - // page. Form redirection will be handled in _batch_finished(), - // after the batch is processed. + // page. Form redirection will be handled in + // \Drupal\Core\Batch\BatchProcessorInterface::finished(), after the batch + // is processed. } // Set a flag to indicate the the form has been processed and executed. @@ -113,7 +114,7 @@ public function executeSubmitHandlers(&$form, FormStateInterface &$form_state) { if (($batch = &$this->batchGet()) && !isset($batch['id'])) { // Some previous submit handler has set a batch. To ensure correct // execution order, store the call in a special 'control' batch set. - // See _batch_next_set(). + // See \Drupal\Core\Batch\BatchProcessorInterface::nextSet(). $batch['sets'][] = array('form_submit' => $callback); $batch['has_form_submits'] = TRUE; }