diff --git a/core/lib/Drupal/Core/Update/UpdateKernel.php b/core/lib/Drupal/Core/Update/UpdateKernel.php index 9212cc6..20a7275 100644 --- a/core/lib/Drupal/Core/Update/UpdateKernel.php +++ b/core/lib/Drupal/Core/Update/UpdateKernel.php @@ -72,17 +72,7 @@ public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = protected function handleRaw(Request $request) { $container = $this->getContainer(); - // Ensures that the page is accessible. - /** @var \Drupal\Core\Authentication\AuthenticationManager $authentication_manager */ - $authentication_manager = $container->get('authentication'); - $account = $authentication_manager->authenticate($request) ?: new AnonymousUserSession(); - - /** @var \Drupal\system\Access\DbUpdateAccessCheck $db_update_access */ - $db_update_access = $container->get('access_check.db_update'); - - if (!Settings::get('update_free_access', FALSE) && !$db_update_access->access($account)) { - throw new AccessDeniedHttpException('In order to run update.php you need to either be logged in as admin or have set $update_free_access in your settings.php.'); - } + $this->handleAccess($request, $container); /** @var \Drupal\Core\Controller\ControllerResolverInterface $controller_resolver */ $controller_resolver = $container->get('controller_resolver'); @@ -145,4 +135,30 @@ protected function setupRequestMatch(Request $request) { $request->attributes->set('_raw_variables', new ParameterBag(['op' => $op])); } + /** + * Checks access and throws an access, in case it is not. + * + * @param \Symfony\Component\HttpFoundation\Request $request + * The incoming request. + * + * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException + * Thrown when update.php should not be accessible. + */ + protected function handleAccess(Request $request) { + /** @var \Drupal\Core\Authentication\AuthenticationManager $authentication_manager */ + $authentication_manager = $this->getContainer()->get('authentication'); + $account = $authentication_manager->authenticate($request) ?: new AnonymousUserSession(); + + /** @var \Drupal\Core\Session\AccountProxyInterface $current_user */ + $current_user = $this->getContainer()->get('current_user'); + $current_user->setAccount($account); + + /** @var \Drupal\system\Access\DbUpdateAccessCheck $db_update_access */ + $db_update_access = $this->getContainer()->get('access_check.db_update'); + + if (!Settings::get('update_free_access', FALSE) && !$db_update_access->access($account)->isAllowed()) { + throw new AccessDeniedHttpException('In order to run update.php you need to either be logged in as admin or have set $update_free_access in your settings.php.'); + } + } + } diff --git a/core/modules/system/src/Controller/DbUpdateController.php b/core/modules/system/src/Controller/DbUpdateController.php index 6e04697..2a26ae0 100644 --- a/core/modules/system/src/Controller/DbUpdateController.php +++ b/core/modules/system/src/Controller/DbUpdateController.php @@ -503,7 +503,7 @@ protected function results(Request $request) { */ public function requirements($severity, array $requirements) { $options = $severity == REQUIREMENT_WARNING ? array('continue' => 1) : array(); - $try_again_url = Url::fromRoute('system.db_update', $options)->toString(TRUE)->getGeneratedUrl(); + $try_again_url = Url::fromUri(\Drupal::request()->getUriForPath(''))->setOptions(['query' => $options])->toString(TRUE)->getGeneratedUrl(); $build['status_report'] = array( '#theme' => 'status_report', diff --git a/core/modules/system/src/Tests/Update/UpdateScriptTest.php b/core/modules/system/src/Tests/Update/UpdateScriptTest.php index 9ffdb8e..7aed861 100644 --- a/core/modules/system/src/Tests/Update/UpdateScriptTest.php +++ b/core/modules/system/src/Tests/Update/UpdateScriptTest.php @@ -79,7 +79,7 @@ function testUpdateAccess() { /** * Tests that requirements warnings and errors are correctly displayed. */ - function ptestRequirements() { + function testRequirements() { $update_script_test_config = $this->config('update_script_test.settings'); $this->drupalLogin($this->updateUser); @@ -132,7 +132,7 @@ function ptestRequirements() { /** * Tests the effect of using the update script on the theme system. */ - function ptestThemeSystem() { + function testThemeSystem() { // Since visiting update.php triggers a rebuild of the theme system from an // unusual maintenance mode environment, we check that this rebuild did not // put any incorrect information about the themes into the database. @@ -146,7 +146,7 @@ function ptestThemeSystem() { /** * Tests update.php when there are no updates to apply. */ - function ptestNoUpdateFunctionality() { + function testNoUpdateFunctionality() { // Click through update.php with 'administer software updates' permission. $this->drupalLogin($this->updateUser); $this->drupalGet($this->updateUrl, array('external' => TRUE)); @@ -172,7 +172,7 @@ function ptestNoUpdateFunctionality() { /** * Tests update.php after performing a successful update. */ - function ptestSuccessfulUpdateFunctionality() { + function testSuccessfulUpdateFunctionality() { $initial_maintenance_mode = $this->container->get('state')->get('system.maintenance_mode'); $this->assertFalse($initial_maintenance_mode, 'Site is not in maintenance mode.'); $this->updateScriptTest($initial_maintenance_mode); @@ -206,7 +206,7 @@ function ptestSuccessfulUpdateFunctionality() { /** * Tests update.php while in maintenance mode. */ - function ptestMaintenanceModeUpdateFunctionality() { + function testMaintenanceModeUpdateFunctionality() { $this->container->get('state') ->set('system.maintenance_mode', TRUE); $initial_maintenance_mode = $this->container->get('state')