UpdateServiceProvider.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace Drupal\Core\Update;
  3. use Drupal\Core\DependencyInjection\ContainerBuilder;
  4. use Drupal\Core\DependencyInjection\ServiceModifierInterface;
  5. use Drupal\Core\DependencyInjection\ServiceProviderInterface;
  6. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  7. use Symfony\Component\DependencyInjection\Definition;
  8. use Symfony\Component\DependencyInjection\Reference;
  9. /**
  10. * Customizes the container for running updates.
  11. */
  12. class UpdateServiceProvider implements ServiceProviderInterface, ServiceModifierInterface {
  13. /**
  14. * {@inheritdoc}
  15. */
  16. public function register(ContainerBuilder $container) {
  17. $definition = new Definition('Drupal\Core\Cache\NullBackend', ['null']);
  18. $definition->setDeprecated(TRUE, 'The "%service_id%\" service is deprecated. While updating Drupal all caches use \Drupal\Core\Update\UpdateBackend. See https://www.drupal.org/node/3066407');
  19. $container->setDefinition('cache.null', $definition);
  20. // Decorate the cache factory in order to use
  21. // \Drupal\Core\Update\UpdateBackend while running updates.
  22. $container
  23. ->register('update.cache_factory', UpdateCacheBackendFactory::class)
  24. ->setDecoratedService('cache_factory')
  25. ->addArgument(new Reference('update.cache_factory.inner'));
  26. $container->addCompilerPass(new UpdateCompilerPass(), PassConfig::TYPE_REMOVE, 128);
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function alter(ContainerBuilder $container) {
  32. // The alias-based processor requires the path_alias entity schema to be
  33. // installed, so we prevent it from being registered to the path processor
  34. // manager. We do this by removing the tags that the compiler pass looks
  35. // for. This means that the URL generator can safely be used during the
  36. // database update process.
  37. if ($container->hasDefinition('path_alias.path_processor')) {
  38. $container->getDefinition('path_alias.path_processor')
  39. ->clearTag('path_processor_inbound')
  40. ->clearTag('path_processor_outbound');
  41. }
  42. }
  43. }