Issue #2507509 by catch, dawehner: Service changes should not result in fatal errors between patch or minor releases
							parent
							
								
									0bc8ee2f8f
								
							
						
					
					
						commit
						2e6633871a
					
				| 
						 | 
				
			
			@ -712,7 +712,7 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
 | 
			
		|||
   *   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);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,38 @@
 | 
			
		|||
<?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 @@ namespace Drupal\service_provider_test;
 | 
			
		|||
 | 
			
		||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
 | 
			
		||||
use Drupal\Core\DependencyInjection\ServiceModifierInterface;
 | 
			
		||||
use Drupal\Core\Site\Settings;
 | 
			
		||||
 | 
			
		||||
class ServiceProviderTestServiceProvider implements ServiceModifierInterface {
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -21,5 +22,9 @@ class ServiceProviderTestServiceProvider implements ServiceModifierInterface {
 | 
			
		|||
      $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 @@ namespace Drupal\service_provider_test;
 | 
			
		|||
 | 
			
		||||
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 @@ class TestClass implements EventSubscriberInterface, DestructableInterface {
 | 
			
		|||
    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 @@ class TestClass implements EventSubscriberInterface, DestructableInterface {
 | 
			
		|||
   */
 | 
			
		||||
  static function getSubscribedEvents() {
 | 
			
		||||
    $events[KernelEvents::REQUEST][] = array('onKernelRequestTest');
 | 
			
		||||
    $events[KernelEvents::RESPONSE][] = array('onKernelResponseTest');
 | 
			
		||||
    return $events;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -286,6 +286,16 @@ $config_directories = array();
 | 
			
		|||
 */
 | 
			
		||||
$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.
 | 
			
		||||
 *
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue