diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index df72fdd..a9ca59a 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -2381,10 +2381,6 @@ function install_configure_form_submit($form, &$form_state) { if ($form_state['values']['update_status_module'][1]) { module_enable(array('file', 'update'), FALSE); - // The kernel has been rebuilt, so add request info again. - Drupal::getContainer() - ->set('request', Request::createFromGlobals()); - // Add the site maintenance account's email address to the list of // addresses to be notified when updates are available, if selected. if ($form_state['values']['update_status_module'][2]) { diff --git a/core/includes/module.inc b/core/includes/module.inc index a4a47b5..99eac78 100644 --- a/core/includes/module.inc +++ b/core/includes/module.inc @@ -8,7 +8,6 @@ use Drupal\Component\Graph\Graph; use Drupal\Component\Utility\NestedArray; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpFoundation\Request; /** * Builds a list of bootstrap modules and enabled modules and themes. @@ -355,8 +354,6 @@ function module_enable($module_list, $enable_dependencies = TRUE) { // @todo install_begin_request() creates a container without a kernel. if ($kernel = drupal_container()->get('kernel', ContainerInterface::NULL_ON_INVALID_REFERENCE)) { $kernel->updateModules($module_filenames, $module_filenames); - // Kernel has been rebuilt so add the request info back. - Drupal::getContainer()->set('request', Request::createFromGlobals()); } // Refresh the schema to include it. @@ -515,8 +512,6 @@ function module_disable($module_list, $disable_dependents = TRUE) { // Update the kernel to exclude the disabled modules. $enabled = $module_handler->getModuleList(); drupal_container()->get('kernel')->updateModules($enabled, $enabled); - // Kernel has been rebuilt so add the request info back. - Drupal::getContainer()->set('request', Request::createFromGlobals()); // Update the theme registry to remove the newly-disabled module. drupal_theme_rebuild(); diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index ee14fb3..80a0c29 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -264,6 +264,11 @@ protected function getClassName() { */ protected function initializeContainer() { $persist = $this->getServicesToPersist(); + // If we are rebuilding the kernel and we are in a request scope, store + // request info so we can add them back after the rebuild. + if (isset($this->container) && $this->container->hasScope('request')) { + $request = $this->container->get('request'); + } $this->container = NULL; $class = $this->getClassName(); $cache_file = $class . '.php'; @@ -325,6 +330,10 @@ protected function initializeContainer() { $this->container->set('kernel', $this); // Set the class loader which was registered as a synthetic service. $this->container->set('class_loader', $this->classLoader); + // If we have a request set it back to the new container. + if (isset($request)) { + $this->container->set('request', $request); + } \Drupal::setContainer($this->container); } diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php index f0d8c08..dd39af3 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php @@ -908,8 +908,11 @@ protected function prepareEnvironment() { unset($GLOBALS['theme_key']); unset($GLOBALS['theme']); - // Add request info. - $this->container->set('request', Request::createFromGlobals()); + // Add a dummy request in the container. + $request = Request::create('http://example.com/'); + // We need an IP when storing sessions. + $request->server->set('REMOTE_ADDR', '3.3.3.3'); + $this->container->set('request', $request); // Log fatal errors. ini_set('log_errors', 1); @@ -972,8 +975,12 @@ protected function rebuildContainer() { // DrupalKernel replaces the container in drupal_container() with a // different object, so we need to replace the instance on this test class. $this->container = drupal_container(); - // Add request info to the container. - $this->container->set('request', Request::createFromGlobals()); + + // Add a dummy request in the container. + $request = Request::create('http://example.com/'); + // We need an IP when storing sessions. + $request->server->set('REMOTE_ADDR', '3.3.3.3'); + $this->container->set('request', $request); } /** diff --git a/core/update.php b/core/update.php index 6f350b6..99975d0 100644 --- a/core/update.php +++ b/core/update.php @@ -333,8 +333,6 @@ function update_access_allowed() { $module_handler->setModuleList($module_filenames); $module_handler->reload(); drupal_container()->get('kernel')->updateModules($module_filenames, $module_filenames); - // Kernel has been rebuilt, retrieve the new one and set request info back. - Drupal::getContainer()->set('request', Request::createFromGlobals()); return user_access('administer software updates'); } catch (\Exception $e) {