Commit 6ef8ba79 authored by catch's avatar catch

Issue #2248297 by Berdir: Fixed Ensure routes are rebuilt when install modules.

parent ad5024c4
......@@ -173,7 +173,7 @@ services:
arguments: [default]
form_builder:
class: Drupal\Core\Form\FormBuilder
arguments: ['@form_validator', '@form_submitter', '@form_cache', '@module_handler', '@event_dispatcher', '@request_stack', '@class_resolver', '@theme.manager', '@?csrf_token', '@?http_kernel']
arguments: ['@form_validator', '@form_submitter', '@form_cache', '@module_handler', '@event_dispatcher', '@request_stack', '@class_resolver', '@theme.manager', '@?csrf_token', '@?kernel']
form_validator:
class: Drupal\Core\Form\FormValidator
arguments: ['@request_stack', '@string_translation', '@csrf_token', '@logger.channel.form']
......
......@@ -530,7 +530,6 @@ public function initialize() {
// We have extensions to process.
if ($this->totalExtensionsToProcess > 0) {
$sync_steps[] = 'processExtensions';
$sync_steps[] = 'flush';
}
$sync_steps[] = 'processConfigurations';
......@@ -540,20 +539,6 @@ public function initialize() {
return $sync_steps;
}
/**
* Flushes Drupal's caches.
*/
public function flush(array &$context) {
// Rebuild the container and flush Drupal's caches. If the container is not
// rebuilt first the entity types are not discovered correctly due to using
// an entity manager that has the incorrect container namespaces injected.
\Drupal::service('kernel')->rebuildContainer(TRUE);
drupal_flush_all_caches();
$this->reInjectMe();
$context['message'] = $this->t('Flushed all caches.');
$context['finished'] = 1;
}
/**
* Processes extensions as a batch operation.
*
......
......@@ -810,8 +810,9 @@ public function install(array $module_list, $enable_dependencies = TRUE) {
// Now install the module's schema if necessary.
drupal_install_schema($module);
// Clear plugin manager caches.
// Clear plugin manager caches and flag router to rebuild if requested.
\Drupal::getContainer()->get('plugin.cache_clearer')->clearCachedDefinitions();
\Drupal::service('router.builder')->setRebuildNeeded();
// Set the schema version to the number of the last update provided by
// the module, or the minimum core schema version.
......@@ -999,7 +1000,9 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
// its statically cached list.
drupal_static_reset('system_rebuild_module_data');
// Clear plugin manager caches and flag router to rebuild if requested.
\Drupal::getContainer()->get('plugin.cache_clearer')->clearCachedDefinitions();
\Drupal::service('router.builder')->setRebuildNeeded();
// Update the kernel to exclude the uninstalled modules.
\Drupal::service('kernel')->updateModules($module_filenames, $module_filenames);
......@@ -1022,8 +1025,6 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
// Let other modules react.
$this->invokeAll('modules_uninstalled', array($module_list));
drupal_flush_all_caches();
return TRUE;
}
......
......@@ -14,6 +14,7 @@
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Access\CsrfTokenGenerator;
use Drupal\Core\DependencyInjection\ClassResolverInterface;
use Drupal\Core\DrupalKernelInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Site\Settings;
......@@ -61,11 +62,15 @@ class FormBuilder implements FormBuilderInterface, FormValidatorInterface, FormS
protected $csrfToken;
/**
* The HTTP kernel to handle forms returning response objects.
* The kernel to handle forms returning response objects.
*
* @var \Symfony\Component\HttpKernel\HttpKernel
* Explicitly use the DrupalKernel as that is consistent with index.php for
* terminating the request and in case someone rebuilds the container,
* this kernel is synthetic and always points to the new container.
*
* @var \Drupal\Core\DrupalKernelInterface
*/
protected $httpKernel;
protected $kernel;
/**
* The class resolver.
......@@ -126,10 +131,10 @@ class FormBuilder implements FormBuilderInterface, FormValidatorInterface, FormS
* The theme manager.
* @param \Drupal\Core\Access\CsrfTokenGenerator $csrf_token
* The CSRF token generator.
* @param \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel
* The HTTP kernel.
* @param \Drupal\Core\DrupalKernelInterface $kernel
* The kernel.
*/
public function __construct(FormValidatorInterface $form_validator, FormSubmitterInterface $form_submitter, FormCacheInterface $form_cache, ModuleHandlerInterface $module_handler, EventDispatcherInterface $event_dispatcher, RequestStack $request_stack, ClassResolverInterface $class_resolver, ThemeManagerInterface $theme_manager, CsrfTokenGenerator $csrf_token = NULL, HttpKernelInterface $http_kernel = NULL) {
public function __construct(FormValidatorInterface $form_validator, FormSubmitterInterface $form_submitter, FormCacheInterface $form_cache, ModuleHandlerInterface $module_handler, EventDispatcherInterface $event_dispatcher, RequestStack $request_stack, ClassResolverInterface $class_resolver, ThemeManagerInterface $theme_manager, CsrfTokenGenerator $csrf_token = NULL, DrupalKernelInterface $kernel = NULL) {
$this->formValidator = $form_validator;
$this->formSubmitter = $form_submitter;
$this->formCache = $form_cache;
......@@ -138,7 +143,7 @@ public function __construct(FormValidatorInterface $form_validator, FormSubmitte
$this->requestStack = $request_stack;
$this->classResolver = $class_resolver;
$this->csrfToken = $csrf_token;
$this->httpKernel = $http_kernel;
$this->kernel = $kernel;
$this->themeManager = $theme_manager;
}
......@@ -1075,14 +1080,14 @@ protected function buttonWasClicked($element, FormStateInterface &$form_state) {
*/
protected function sendResponse(Response $response) {
$request = $this->requestStack->getCurrentRequest();
$event = new FilterResponseEvent($this->httpKernel, $request, HttpKernelInterface::MASTER_REQUEST, $response);
$event = new FilterResponseEvent($this->kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response);
$this->eventDispatcher->dispatch(KernelEvents::RESPONSE, $event);
// Prepare and send the response.
$event->getResponse()
->prepare($request)
->send();
$this->httpKernel->terminate($request, $response);
$this->kernel->terminate($request, $response);
}
/**
......
......@@ -396,7 +396,6 @@ public static function finishBatch($success, $results, $operations) {
$message = \Drupal::translation()->translate('An error occurred while processing %error_operation with arguments: @arguments', array('%error_operation' => $error_operation[0], '@arguments' => print_r($error_operation[1], TRUE)));
drupal_set_message($message, 'error');
}
drupal_flush_all_caches();
}
......
......@@ -147,7 +147,6 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
// Gets module list after install process, flushes caches and displays a
// message if there are changes.
if ($before != $this->moduleHandler->getModuleList()) {
drupal_flush_all_caches();
drupal_set_message($this->t('The configuration options have been saved.'));
}
......
......@@ -511,7 +511,6 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
// Gets module list after install process, flushes caches and displays a
// message if there are changes.
if ($before != $this->moduleHandler->getModuleList()) {
drupal_flush_all_caches();
drupal_set_message(t('The configuration options have been saved.'));
}
}
......
......@@ -8,6 +8,7 @@
namespace Drupal\system\Tests\Routing;
use Drupal\simpletest\WebTestBase;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
/**
* Functional class for the full integrated routing system.
......@@ -189,9 +190,18 @@ public function testControllerResolutionAjax() {
/**
* Tests that routes no longer exist for a module that has been uninstalled.
*/
public function testRouterUninstall() {
public function testRouterUninstallInstall() {
\Drupal::moduleHandler()->uninstall(array('router_test'));
$route_count = \Drupal::database()->query('SELECT COUNT(*) FROM {router} WHERE name = :route_name', array(':route_name' => 'router_test.1'))->fetchField();
$this->assertEqual(0, $route_count, 'All router_test routes have been removed on uninstall.');
try {
\Drupal::service('router.route_provider')->getRouteByName('router_test.1');
$this->fail('Route was delete on uninstall.');
}
catch (RouteNotFoundException $e) {
$this->pass('Route was delete on uninstall.');
}
// Install the module again.
\Drupal::moduleHandler()->install(array('router_test'));
$route = \Drupal::service('router.route_provider')->getRouteByName('router_test.1');
$this->assertNotNull($route, 'Route exists after module installation');
}
}
......@@ -244,8 +244,6 @@ function testSwitchDefaultTheme() {
$this->clickLink(t('Set as default'));
$this->assertEqual(\Drupal::config('system.theme')->get('default'), 'bartik');
drupal_flush_all_caches();
// Test the default theme on the secondary links (blocks admin page).
$this->drupalGet('admin/structure/block');
$this->assertText('Bartik(' . t('active tab') . ')', 'Default local task on blocks admin page is the default theme.');
......
......@@ -117,9 +117,9 @@ abstract class FormTestBase extends UnitTestCase {
protected $translationManager;
/**
* @var \Symfony\Component\HttpKernel\HttpKernel|\PHPUnit_Framework_MockObject_MockObject
* @var \Drupal\Core\DrupalKernelInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $httpKernel;
protected $kernel;
/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Psr\Log\LoggerInterface
......@@ -142,7 +142,7 @@ protected function setUp() {
$this->csrfToken = $this->getMockBuilder('Drupal\Core\Access\CsrfTokenGenerator')
->disableOriginalConstructor()
->getMock();
$this->httpKernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernel')
$this->kernel = $this->getMockBuilder('\Drupal\Core\DrupalKernel')
->disableOriginalConstructor()
->getMock();
$this->account = $this->getMock('Drupal\Core\Session\AccountInterface');
......@@ -161,7 +161,7 @@ protected function setUp() {
->setMethods(array('batchGet', 'drupalInstallationAttempted'))
->getMock();
$this->formBuilder = new TestFormBuilder($this->formValidator, $this->formSubmitter, $this->formCache, $this->moduleHandler, $this->eventDispatcher, $this->requestStack, $this->classResolver, $this->themeManager, $this->csrfToken, $this->httpKernel);
$this->formBuilder = new TestFormBuilder($this->formValidator, $this->formSubmitter, $this->formCache, $this->moduleHandler, $this->eventDispatcher, $this->requestStack, $this->classResolver, $this->themeManager, $this->csrfToken, $this->kernel);
$this->formBuilder->setCurrentUser($this->account);
}
......
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