Unverified Commit 8181767f authored by larowlan's avatar larowlan

Issue #2869573 by Mile23, alexpott, mikelutz, voleger: Remove usages of...

Issue #2869573 by Mile23, alexpott, mikelutz, voleger: Remove usages of deprecated DrupalKernel::prepareLegacyRequest()
parent ef014784
......@@ -27,6 +27,8 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\Site\Settings;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\Routing\Route;
// Change the directory to the Drupal root.
chdir('..');
......@@ -65,7 +67,15 @@ function authorize_access_allowed(Request $request) {
try {
$request = Request::createFromGlobals();
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod');
$kernel->prepareLegacyRequest($request);
$kernel->boot();
// A route is required for route matching.
$request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('<none>'));
$request->attributes->set(RouteObjectInterface::ROUTE_NAME, '<none>');
$kernel->preHandle($request);
// Ensure our request includes the session if appropriate.
if (PHP_SAPI !== 'cli') {
$request->setSession($kernel->getContainer()->get('session'));
}
}
catch (HttpExceptionInterface $e) {
$response = new Response('', $e->getStatusCode());
......
......@@ -627,6 +627,7 @@ function drupal_install_system($install_state) {
// Add the normal installer service provider.
$GLOBALS['conf']['container_service_providers']['InstallerServiceProvider'] = 'Drupal\Core\Installer\NormalInstallerServiceProvider';
// Get the existing request.
$request = \Drupal::request();
// Reboot into a full production environment to continue the installation.
/** @var \Drupal\Core\Installer\InstallerKernel $kernel */
......@@ -634,7 +635,13 @@ function drupal_install_system($install_state) {
$kernel->shutdown();
// Have installer rebuild from the disk, rather then building from scratch.
$kernel->rebuildContainer(FALSE);
$kernel->prepareLegacyRequest($request);
// Reboot the kernel with new container.
$kernel->boot();
$kernel->preHandle($request);
// Ensure our request includes the session if appropriate.
if (PHP_SAPI !== 'cli') {
$request->setSession($kernel->getContainer()->get('session'));
}
// Before having installed the system module and being able to do a module
// rebuild, prime the \Drupal\Core\Extension\ModuleExtensionList static cache
......
......@@ -35,13 +35,16 @@ function drupal_rebuild($class_loader, Request $request) {
// Bootstrap up to where caches exist and clear them.
$kernel = new DrupalKernel('prod', $class_loader);
$kernel->setSitePath(DrupalKernel::findSitePath($request));
$kernel->boot();
$kernel->preHandle($request);
// Ensure our request includes the session if appropriate.
if (PHP_SAPI !== 'cli') {
$request->setSession($kernel->getContainer()->get('session'));
}
// Invalidate the container.
$kernel->invalidateContainer();
// Prepare a NULL request.
$kernel->prepareLegacyRequest($request);
foreach (Cache::getBins() as $bin) {
$bin->deleteAll();
}
......
......@@ -753,6 +753,7 @@ public function prepareLegacyRequest(Request $request) {
$request->attributes->set(RouteObjectInterface::ROUTE_NAME, '<none>');
$this->container->get('request_stack')->push($request);
$this->container->get('router.request_context')->fromRequest($request);
@trigger_error(__NAMESPACE__ . '\DrupalKernel::prepareLegacyRequest is deprecated drupal:8.0.0 and is removed from drupal:9.0.0. Use DrupalKernel::boot() and DrupalKernel::preHandle() instead. See https://www.drupal.org/node/3070678', E_USER_DEPRECATED);
return $this;
}
......
......@@ -132,8 +132,10 @@ public function invalidateContainer();
*
* @return $this
*
* @deprecated in Drupal 8.0.x and will be removed before 9.0.0. Only used by
* legacy front-controller scripts.
* @deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use
* DrupalKernel::boot() and DrupalKernel::preHandle() instead.
*
* @see https://www.drupal.org/node/3070678
*/
public function prepareLegacyRequest(Request $request);
......
......@@ -18,6 +18,8 @@
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Yaml\Yaml as SymfonyYaml;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\Routing\Route;
/**
* Defines a trait for shared functional test setup functionality.
......@@ -390,13 +392,15 @@ protected function initUserSession() {
*/
protected function initKernel(Request $request) {
$this->kernel = DrupalKernel::createFromRequest($request, $this->classLoader, 'prod', TRUE);
// Force the container to be built from scratch instead of loaded from the
// disk. This forces us to not accidentally load the parent site.
$this->kernel->invalidateContainer();
$this->kernel->prepareLegacyRequest($request);
return \Drupal::getContainer();
$this->kernel->boot();
// Add our request to the stack and route context.
$request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('<none>'));
$request->attributes->set(RouteObjectInterface::ROUTE_NAME, '<none>');
$this->kernel->preHandle($request);
return $this->kernel->getContainer();
}
/**
......@@ -446,7 +450,6 @@ protected function rebuildAll() {
// @todo Test-specific setUp() methods may set up further fixtures; find a
// way to execute this after setUp() is done, or to eliminate it entirely.
$this->resetAll();
$this->kernel->prepareLegacyRequest(\Drupal::request());
// Explicitly call register() again on the container registered in \Drupal.
// @todo This should already be called through
......@@ -580,7 +583,8 @@ protected function prepareEnvironment() {
$kernel = TestRunnerKernel::createFromRequest($request, $this->classLoader);
// TestRunnerKernel expects the working directory to be DRUPAL_ROOT.
chdir(DRUPAL_ROOT);
$kernel->prepareLegacyRequest($request);
$kernel->boot();
$kernel->preHandle($request);
$this->prepareDatabasePrefix();
$this->originalSite = $kernel->findSitePath($request);
......
......@@ -158,8 +158,13 @@ protected function setUp() {
// Not using File API; a potential error must trigger a PHP warning.
chmod($this->container->get('app.root') . '/' . $this->siteDirectory, 0777);
$this->kernel = DrupalKernel::createFromRequest($request, $class_loader, 'prod', FALSE);
$this->kernel->prepareLegacyRequest($request);
$this->kernel->boot();
$this->kernel->preHandle($request);
$this->container = $this->kernel->getContainer();
// Ensure our request includes the session if appropriate.
if (PHP_SAPI !== 'cli') {
$request->setSession($this->container->get('session'));
}
// Manually configure the test mail collector implementation to prevent
// tests from sending out emails and collect them in state instead.
......
......@@ -539,7 +539,8 @@ function simpletest_script_init() {
try {
$request = Request::createFromGlobals();
$kernel = TestRunnerKernel::createFromRequest($request, $autoloader);
$kernel->prepareLegacyRequest($request);
$kernel->boot();
$kernel->preHandle($request);
}
catch (Exception $e) {
echo (string) $e;
......
......@@ -181,7 +181,8 @@ protected function setUp() {
// Not using File API; a potential error must trigger a PHP warning.
chmod($this->container->get('app.root') . '/' . $this->siteDirectory, 0777);
$this->kernel = DrupalKernel::createFromRequest($request, $class_loader, 'prod', FALSE);
$this->kernel->prepareLegacyRequest($request);
$this->kernel->boot();
$this->kernel->preHandle($request);
$this->container = $this->kernel->getContainer();
// Manually configure the test mail collector implementation to prevent
......
......@@ -191,4 +191,24 @@ public function testPreventChangeOfSitePath() {
$kernel->setSitePath($path);
}
/**
* @group legacy
* @expectedDeprecation Drupal\Core\DrupalKernel::prepareLegacyRequest is deprecated drupal:8.0.0 and is removed from drupal:9.0.0. Use DrupalKernel::boot() and DrupalKernel::preHandle() instead. See https://www.drupal.org/node/3070678
*/
public function testPrepareLegacyRequest() {
$request = Request::createFromGlobals();
// Manually create kernel to avoid replacing settings.
$class_loader = require $this->root . '/autoload.php';
$kernel = DrupalKernel::createFromRequest($request, $class_loader, 'testing');
$this->setSetting('container_yamls', []);
$this->setSetting('hash_salt', $this->databasePrefix);
$this->assertNull($kernel->getContainer());
// Restore the usual PHPUnit error handler for deprecation testing.
restore_error_handler();
$kernel->prepareLegacyRequest($request);
$this->assertSame($request, $kernel->getContainer()->get('request_stack')->getMasterRequest());
}
}
......@@ -27,6 +27,8 @@
use Symfony\Component\HttpFoundation\Request;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\visitor\vfsStreamPrintVisitor;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\Routing\Route;
/**
* Base class for functional integration tests.
......@@ -341,9 +343,11 @@ private function bootKernel() {
// DrupalKernel::boot() is not sufficient as it does not invoke preHandle(),
// which is required to initialize legacy global variables.
$request = Request::create('/');
$kernel->prepareLegacyRequest($request);
$kernel->boot();
$request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('<none>'));
$request->attributes->set(RouteObjectInterface::ROUTE_NAME, '<none>');
$kernel->preHandle($request);
// register() is only called if a new container was built/compiled.
$this->container = $kernel->getContainer();
// Ensure database tasks have been run.
......@@ -358,8 +362,6 @@ private function bootKernel() {
$this->container->get('module_handler')->loadAll();
}
$this->container->get('request_stack')->push($request);
// Setup the destion to the be frontpage by default.
\Drupal::destination()->set('/');
......
......@@ -214,7 +214,8 @@ public function testRenderWithTheme() {
/**
* @covers ::bootKernel
*/
public function testFileDefaultScheme() {
public function testBootKernel() {
$this->assertNull($this->container->get('request_stack')->getParentRequest(), 'There should only be one request on the stack');
$this->assertEquals('public', \Drupal::config('system.file')->get('default_scheme'));
}
......
......@@ -52,9 +52,9 @@ protected function execute(InputInterface $input, OutputInterface $output) {
Settings::initialize($kernel->getAppRoot(), $kernel->getSitePath(), $this->classLoader);
$request = Request::createFromGlobals();
$kernel->prepareLegacyRequest($request);
$kernel->boot();
$kernel->preHandle($request);
$container = $kernel->getContainer();
$uid = $input->getArgument('uid');
......
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