Commit 2e663387 authored by alexpott's avatar alexpott

Issue #2507509 by catch, dawehner: Service changes should not result in fatal...

Issue #2507509 by catch, dawehner: Service changes should not result in fatal errors between patch or minor releases
parent 0bc8ee2f
......@@ -712,7 +712,7 @@ public function updateModules(array $module_list, array $module_filenames = arra
* The class name.
*/
protected function getClassName() {
$parts = array('service_container', $this->environment);
$parts = array('service_container', $this->environment, hash('crc32b', \Drupal::VERSION . Settings::get('deployment_identifier')));
return implode('_', $parts);
}
......
<?php
/**
* @file
* Contains \Drupal\system\Tests\DrupalKernel\ContainerRebuildWebTest.
*/
namespace Drupal\system\Tests\DrupalKernel;
use Drupal\simpletest\WebTestBase;
/**
* Ensures that the container rebuild works as expected.
*
* @group DrupalKernel
*/
class ContainerRebuildWebTest extends WebTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['service_provider_test'];
/**
* Sets a different deployment identifier.
*/
public function testSetContainerRebuildWithDifferentDeploymentIdentifier() {
$this->drupalGet('<front>');
$this->assertHeader('container_rebuild_indicator', FALSE);
$this->writeSettings(['settings' => ['deployment_identifier' => (object) ['value' => 'new-identifier', 'required' => TRUE]]]);
$this->drupalGet('<front>');
$this->assertHeader('container_rebuild_indicator', 'new-identifier');
}
}
......@@ -4,4 +4,5 @@ services:
tags:
- { name: event_subscriber }
- { name: needs_destruction }
parent: container.trait
arguments: ['@state']
......@@ -9,6 +9,7 @@
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceModifierInterface;
use Drupal\Core\Site\Settings;
class ServiceProviderTestServiceProvider implements ServiceModifierInterface {
......@@ -21,5 +22,9 @@ public function alter(ContainerBuilder $container) {
$definition = $container->getDefinition('file.usage');
$definition->setClass('Drupal\service_provider_test\TestFileUsage');
}
if ($indicator = Settings::get('deployment_identifier')) {
$container->setParameter('container_rebuild_indicator', $indicator);
}
}
}
......@@ -9,11 +9,16 @@
use Drupal\Core\State\StateInterface;
use Drupal\Core\DestructableInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class TestClass implements EventSubscriberInterface, DestructableInterface {
class TestClass implements EventSubscriberInterface, DestructableInterface, ContainerAwareInterface {
use ContainerAwareTrait;
/**
* The state keyvalue collection.
......@@ -39,6 +44,15 @@ public function onKernelRequestTest(GetResponseEvent $event) {
drupal_set_message(t('The service_provider_test event subscriber fired!'));
}
/**
* Flags the response in case a rebuild indicator is used.
*/
public function onKernelResponseTest(FilterResponseEvent $event) {
if ($this->container->hasParameter('container_rebuild_indicator')) {
$event->getResponse()->headers->set('container_rebuild_indicator', $this->container->getParameter('container_rebuild_indicator'));
}
}
/**
* Registers methods as kernel listeners.
*
......@@ -47,6 +61,7 @@ public function onKernelRequestTest(GetResponseEvent $event) {
*/
static function getSubscribedEvents() {
$events[KernelEvents::REQUEST][] = array('onKernelRequestTest');
$events[KernelEvents::RESPONSE][] = array('onKernelResponseTest');
return $events;
}
......
......@@ -286,6 +286,16 @@
*/
$settings['hash_salt'] = '';
/**
* Deployment identifier.
*
* Drupal's dependency injection container will be automatically invalidated and
* rebuilt when the Drupal core version changes. When updating contributed or
* custom code that changes the container, changing this identifier will also
* allow the container to be invalidated as soon as code is deployed.
*/
# $settings['deployment_identifier'] = \Drupal::VERSION;
/**
* Access control for update.php script.
*
......
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