diff --git a/core/lib/Drupal/Core/Update/UpdateKernel.php b/core/lib/Drupal/Core/Update/UpdateKernel.php new file mode 100644 index 0000000..6fa3dbc --- /dev/null +++ b/core/lib/Drupal/Core/Update/UpdateKernel.php @@ -0,0 +1,99 @@ +initializeSettings($request); + $this->boot(); + + $container = $this->getContainer(); + /** @var \Symfony\Component\HttpFoundation\RequestStack $request_stack */ + $request_stack = $container->get('request_stack'); + $request_stack->push($request); + + $this->preHandle($request); + $this->bootSession($request, $type); + return $this->handleRaw($request); + } + catch (\Exception $e) { + return $this->handleException($e, $request, $type); + } + } + + protected function handleRaw(Request $request) { + + $container = $this->getContainer(); + /** @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 (!$db_update_access->access($account) && !Settings::get('update_free_access', FALSE)) { + 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.'); + } + + $controller_resolver = $container->get('controller_resolver'); + + /** @var callable $db_update_controller */ + $db_update_controller = $controller_resolver->getControllerFromDefinition('\Drupal\system\Controller\DbUpdateController::handle'); + + $this->setupTheme($container); + + $path = $request->getPathInfo(); + $args = explode('/', ltrim($path, '/')); + return $db_update_controller($args[0] ?: 'info', $request); + } + + /** + * @param \Symfony\Component\HttpFoundation\Request $request + * @param $type + */ + protected function bootSession(Request $request, $type) { + if ($type === self::MASTER_REQUEST && PHP_SAPI !== 'cli') { + $container = $this->getContainer(); + /** @var \Symfony\Component\HttpFoundation\Session\SessionInterface $session */ + $session = $container->get('session'); + $session->start(); + $request->setSession($session); + } + } + + /** + * @param ContainerInterface $container + */ + protected function setupTheme($container) { +// Set the active theme to be seven. + /** @var \Drupal\Core\Theme\ThemeManagerInterface $theme_manager */ + $theme_manager = $container->get('theme.manager'); + /** @var \Drupal\Core\Theme\ThemeInitializationInterface $theme_init */ + $theme_init = $container->get('theme.initialization'); + $active_theme = $theme_init->getActiveThemeByName(Settings::get('maintenance_theme', 'seven')); + $theme_manager->setActiveTheme($active_theme); + } + +} diff --git a/core/modules/system/src/Controller/DbUpdateController.php b/core/modules/system/src/Controller/DbUpdateController.php index c2e195e..e89da79 100644 --- a/core/modules/system/src/Controller/DbUpdateController.php +++ b/core/modules/system/src/Controller/DbUpdateController.php @@ -166,7 +166,7 @@ public function handle($op, Request $request) { switch ($op) { case 'selection': $regions['sidebar_first'] = $this->updateTasksList('selection'); - $output = $this->selection(); + $output = $this->selection($request); break; case 'run': @@ -176,12 +176,12 @@ public function handle($op, Request $request) { case 'info': $regions['sidebar_first'] = $this->updateTasksList('info'); - $output = $this->info(); + $output = $this->info($request); break; case 'results': $regions['sidebar_first'] = $this->updateTasksList('results'); - $output = $this->results(); + $output = $this->results($request); break; // Regular batch ops : defer to batch processing API. @@ -207,7 +207,7 @@ public function handle($op, Request $request) { * @return array * A render array. */ - protected function info() { + protected function info(Request $request) { // Change query-strings on css/js files to enforce reload for all users. _drupal_flush_css_js(); // Flush the cache of all data for the update status module. @@ -233,12 +233,11 @@ protected function info() { '#markup' => '

' . $this->t('When you have performed the steps above, you may proceed.') . '

', ); - $url = new Url('system.db_update', array('op' => 'selection')); $build['link'] = array( '#type' => 'link', '#title' => $this->t('Continue'), '#attributes' => array('class' => array('button', 'button--primary')), - '#url' => $url, + '#url' => Url::fromUri($request->getUriForPath('/selection')), ); return $build; } @@ -246,10 +245,13 @@ protected function info() { /** * Renders a list of available database updates. * - * @return array - * A render array. + * @param \Symfony\Component\HttpFoundation\Request $request + * The request. + * + * @return array A render array. + * A render array. */ - protected function selection() { + protected function selection(Request $request) { // Make sure there is no stale theme registry. $this->cache->deleteAll(); @@ -342,7 +344,7 @@ protected function selection() { unset($build); $build['links'] = array( '#theme' => 'links', - '#links' => $this->helpfulLinks(), + '#links' => $this->helpfulLinks($request), ); // No updates to run, so caches won't get flushed later. Clear them now. @@ -380,10 +382,13 @@ protected function selection() { /** * Displays results of the update script with any accompanying errors. * + * @param \Symfony\Component\HttpFoundation\Request $request + * The request. + * * @return array * A render array. */ - protected function results() { + protected function results(Request $request) { // Report end result. $dblog_exists = $this->moduleHandler->moduleExists('dblog'); if ($dblog_exists && $this->account->hasPermission('access site reports')) { @@ -420,7 +425,7 @@ protected function results() { ); $build['links'] = array( '#theme' => 'links', - '#links' => $this->helpfulLinks(), + '#links' => $this->helpfulLinks($request), ); // Output a list of info messages. @@ -603,7 +608,7 @@ protected function triggerBatch(Request $request) { ); batch_set($batch); - return batch_process('update.php/results', Url::fromRoute('system.db_update', array('op' => 'start'))); + return batch_process('update.php/results', $request->getUriForPath('/start')); } /** @@ -640,18 +645,22 @@ public static function batchFinished($success, $results, $operations) { /** * Provides links to the homepage and administration pages. * - * @return array - * An array of links. + * @param \Symfony\Component\HttpFoundation\Request $request + * The request. + * + * @return array An array of links. + * An array of links. */ - protected function helpfulLinks() { + protected function helpfulLinks(Request $request) { + $base_url = str_replace('/update.php', '', $request->getBaseUrl()); $links['front'] = array( 'title' => $this->t('Front page'), - 'url' => Url::fromRoute(''), + 'url' => Url::fromRoute('')->setOption('base_url', $base_url), ); if ($this->account->hasPermission('access administration pages')) { $links['admin-pages'] = array( 'title' => $this->t('Administration pages'), - 'url' => Url::fromRoute('system.admin'), + 'url' => Url::fromRoute('system.admin')->setOption('base_url', $base_url), ); } return $links; diff --git a/core/modules/system/src/Theme/DbUpdateNegotiator.php b/core/modules/system/src/Theme/DbUpdateNegotiator.php deleted file mode 100644 index 260923c..0000000 --- a/core/modules/system/src/Theme/DbUpdateNegotiator.php +++ /dev/null @@ -1,57 +0,0 @@ -configFactory = $config_factory; - } - - /** - * {@inheritdoc} - */ - public function applies(RouteMatchInterface $route_match) { - return $route_match->getRouteName() == 'system.db_update'; - } - - /** - * {@inheritdoc} - */ - public function determineActiveTheme(RouteMatchInterface $route_match) { - $custom_theme = Settings::get('maintenance_theme', 'seven'); - if (!$custom_theme) { - $config = $this->configFactory->get('system.theme'); - $custom_theme = $config->get('default'); - } - - return $custom_theme; - } - -} diff --git a/core/modules/system/system.routing.yml b/core/modules/system/system.routing.yml index a656ab3..e64b1f7 100644 --- a/core/modules/system/system.routing.yml +++ b/core/modules/system/system.routing.yml @@ -450,14 +450,9 @@ system.batch_page.json: system.db_update: path: '/update.php/{op}' - defaults: - _title: 'Drupal database update' - _controller: '\Drupal\system\Controller\DbUpdateController::handle' - op: 'info' - options: - _maintenance_access: TRUE requirements: - _access_system_update: 'TRUE' + requirements: + _access: 'TRUE' system.admin_content: path: '/admin/content' diff --git a/core/modules/system/system.services.yml b/core/modules/system/system.services.yml index 29ea018..44e2346 100644 --- a/core/modules/system/system.services.yml +++ b/core/modules/system/system.services.yml @@ -28,11 +28,6 @@ services: arguments: ['@batch.storage', '@request_stack'] tags: - { name: theme_negotiator, priority: 1000 } - theme.negotiator.system.db_update: - class: Drupal\system\Theme\DbUpdateNegotiator - arguments: ['@config.factory'] - tags: - - { name: theme_negotiator, priority: 100 } system.config_subscriber: class: Drupal\system\SystemConfigSubscriber tags: diff --git a/update.php b/update.php new file mode 100644 index 0000000..04125a3 --- /dev/null +++ b/update.php @@ -0,0 +1,14 @@ +handle($request); +$response->send(); + +$kernel->terminate($request, $response);