Commit 490e8753 authored by webchick's avatar webchick
Browse files

Issue #1987816 by pdrake, disasm, ParisLiakos, pguillard, vijaycs85, dawehner:...

Issue #1987816 by pdrake, disasm, ParisLiakos, pguillard, vijaycs85, dawehner: Convert system_batch_page() to a new style controller.
parent 12226d9c
......@@ -20,6 +20,8 @@
* @link authorize Authorized operation helper functions @endlink
*/
use Symfony\Component\HttpFoundation\Request;
// Change the directory to the Drupal root.
chdir('..');
......@@ -71,6 +73,9 @@ function authorize_access_allowed() {
// variables, however, so we have access to the class autoloader.
drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES);
$request = Request::createFromGlobals();
Drupal::getContainer()->set('request', $request);
// This must go after drupal_bootstrap(), which unsets globals!
global $conf;
......@@ -136,8 +141,8 @@ function authorize_access_allowed() {
$output .= theme('item_list', array('items' => $links, 'title' => t('Next steps')));
}
// If a batch is running, let it run.
elseif (isset($_GET['batch'])) {
$output = _batch_page();
elseif ($request->query->has('batch')) {
$output = _batch_page($request);
}
else {
if (empty($_SESSION['authorize_operation']) || empty($_SESSION['authorize_filetransfer_info'])) {
......
......@@ -16,23 +16,27 @@
use Drupal\Core\Batch\Percentage;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* Renders the batch processing page based on the current state of the batch.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request object.
*
* @see _batch_shutdown()
*/
function _batch_page() {
function _batch_page(Request $request) {
$batch = &batch_get();
if (!isset($_REQUEST['id'])) {
if (!($request_id = $request->get('id'))) {
return FALSE;
}
// Retrieve the current state of the batch.
if (!$batch) {
$batch = Drupal::service('batch.storage')->load($_REQUEST['id']);
$batch = Drupal::service('batch.storage')->load($request_id);
if (!$batch) {
drupal_set_message(t('No active batch.'), 'error');
return new RedirectResponse(url('<front>', array('absolute' => TRUE)));
......@@ -51,7 +55,7 @@ function _batch_page() {
}
}
$op = isset($_REQUEST['op']) ? $_REQUEST['op'] : '';
$op = $request->get('op', '');
$output = NULL;
switch ($op) {
case 'start':
......
......@@ -652,7 +652,7 @@ function install_run_task($task, &$install_state) {
// any output from the batch process, until the task is complete.
elseif ($current_batch == $function) {
include_once __DIR__ . '/batch.inc';
$output = _batch_page();
$output = _batch_page(Drupal::request());
// Because Batch API now returns a JSON response for intermediary steps,
// but the installer doesn't handle Response objects yet, just send the
// output here and emulate the old model.
......
<?php
/**
* @file
* Contains \Drupal\system\Controller\BatchController.
*/
namespace Drupal\system\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
/**
* Controller routines for batch routes.
*/
class BatchController {
/**
* Returns a system batch page.
*
* @param \Symfony\Component\HttpFoundation\Request
* The current request object.
*
* @return mixed
* A \Symfony\Component\HttpFoundation\Response object or page element.
*/
public function batchPage(Request $request) {
require_once DRUPAL_ROOT . '/core/includes/batch.inc';
$output = _batch_page($request);
if ($output === FALSE) {
throw new AccessDeniedHttpException();
}
elseif ($output instanceof Response) {
return $output;
}
elseif (isset($output)) {
// Force a page without blocks or messages to
// display a list of collected messages later.
drupal_set_page_content($output);
$page = element_info('page');
$page['#show_messages'] = FALSE;
return $page;
}
}
}
......@@ -273,29 +273,6 @@ function system_sort_themes($a, $b) {
return strcasecmp($a->info['name'], $b->info['name']);
}
/**
* Default page callback for batches.
*/
function system_batch_page() {
require_once DRUPAL_ROOT . '/core/includes/batch.inc';
$output = _batch_page();
if ($output === FALSE) {
throw new AccessDeniedHttpException();
}
elseif ($output instanceof Response) {
return $output;
}
elseif (isset($output)) {
// Force a page without blocks or messages to
// display a list of collected messages later.
drupal_set_page_content($output);
$page = element_info('page');
$page['#show_messages'] = FALSE;
return $page;
}
}
/**
* Returns HTML for an administrative block for display.
*
......
......@@ -893,11 +893,9 @@ function system_menu() {
// Default page for batch operations.
$items['batch'] = array(
'page callback' => 'system_batch_page',
'access callback' => TRUE,
'route_name' => 'system_batch_page',
'theme callback' => '_system_batch_theme',
'type' => MENU_CALLBACK,
'file' => 'system.admin.inc',
);
// Localize date formats.
......
......@@ -326,3 +326,10 @@ system_admin_config:
_content: '\Drupal\system\Controller\SystemController::overview'
requirements:
_permission: 'access administration pages'
system_batch_page:
pattern: '/batch'
defaults:
_controller: '\Drupal\system\Controller\BatchController::batchPage'
requirements:
_access: 'TRUE'
......@@ -432,6 +432,7 @@ function update_check_requirements($skip_warnings = FALSE) {
}
}
// Some unavoidable errors happen because the database is not yet up-to-date.
// Our custom error handler is not yet installed, so we just suppress them.
ini_set('display_errors', FALSE);
......@@ -452,11 +453,8 @@ function update_check_requirements($skip_warnings = FALSE) {
drupal_session_initialize();
// A request object from the HTTPFoundation to tell us about the request.
// @todo These two lines were copied from index.php which has its own todo about
// a change required here. Revisit this when that change has been made.
$request = Request::createFromGlobals();
drupal_container()
->set('request', $request);
Drupal::getContainer()->set('request', $request);
// Ensure that URLs generated for the home and admin pages don't have 'update.php'
// in them.
......@@ -555,7 +553,7 @@ function update_check_requirements($skip_warnings = FALSE) {
// Regular batch ops : defer to batch processing API.
default:
update_task_list('run');
$output = _batch_page();
$output = _batch_page($request);
break;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment