diff --git a/core/lib/Drupal/Core/Update/UpdateBackend.php b/core/lib/Drupal/Core/Update/UpdateBackend.php new file mode 100644 index 000000000000..3101093b5894 --- /dev/null +++ b/core/lib/Drupal/Core/Update/UpdateBackend.php @@ -0,0 +1,54 @@ +backend = $backend; + } + + /** + * {@inheritdoc} + */ + public function delete($cid) { + $this->backend->delete($cid); + } + + /** + * {@inheritdoc} + */ + public function deleteMultiple(array $cids) { + $this->backend->deleteMultiple($cids); + } + + /** + * {@inheritdoc} + */ + public function deleteAll() { + $this->backend->deleteAll(); + } + +} diff --git a/core/lib/Drupal/Core/Update/UpdateCacheBackendFactory.php b/core/lib/Drupal/Core/Update/UpdateCacheBackendFactory.php new file mode 100644 index 000000000000..1a459f3a0bd1 --- /dev/null +++ b/core/lib/Drupal/Core/Update/UpdateCacheBackendFactory.php @@ -0,0 +1,51 @@ +cacheFactory = $cache_factory; + } + + /** + * {@inheritdoc} + */ + public function get($bin) { + if (!isset($this->bins[$bin])) { + $this->bins[$bin] = new UpdateBackend($this->cacheFactory->get($bin), $bin); + } + return $this->bins[$bin]; + } + +} diff --git a/core/lib/Drupal/Core/Update/UpdateServiceProvider.php b/core/lib/Drupal/Core/Update/UpdateServiceProvider.php index 22c9131eb381..7ac68e6b18e4 100644 --- a/core/lib/Drupal/Core/Update/UpdateServiceProvider.php +++ b/core/lib/Drupal/Core/Update/UpdateServiceProvider.php @@ -19,8 +19,16 @@ class UpdateServiceProvider implements ServiceProviderInterface, ServiceModifier */ public function register(ContainerBuilder $container) { $definition = new Definition('Drupal\Core\Cache\NullBackend', ['null']); + $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'); $container->setDefinition('cache.null', $definition); + // Decorate the cache factory in order to use + // \Drupal\Core\Update\UpdateBackend while running updates. + $container + ->register('update.cache_factory', UpdateCacheBackendFactory::class) + ->setDecoratedService('cache_factory') + ->addArgument(new Reference('update.cache_factory.inner')); + $container->addCompilerPass(new UpdateCompilerPass(), PassConfig::TYPE_REMOVE, 128); } @@ -28,25 +36,6 @@ class UpdateServiceProvider implements ServiceProviderInterface, ServiceModifier * {@inheritdoc} */ public function alter(ContainerBuilder $container) { - // Ensures for some services that they don't cache. - $null_cache_service = new Reference('cache.null'); - - $definition = $container->getDefinition('asset.resolver'); - $definition->replaceArgument(5, $null_cache_service); - - $definition = $container->getDefinition('library.discovery.collector'); - $definition->replaceArgument(0, $null_cache_service); - - $definition = $container->getDefinition('theme.registry'); - $definition->replaceArgument(1, $null_cache_service); - $definition->replaceArgument(7, $null_cache_service); - - $definition = $container->getDefinition('theme.initialization'); - $definition->replaceArgument(2, $null_cache_service); - - $definition = $container->getDefinition('plugin.manager.element_info'); - $definition->replaceArgument(1, $null_cache_service); - // Prevent the alias-based path processor, which requires a path_alias db // table, from being registered to the path processor manager. We do this by // removing the tags that the compiler pass looks for. This means the url diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 018d5d003ed7..218bc7244282 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -1859,20 +1859,20 @@ function system_update_8011() { * Enable automated cron module and move the config into it. */ function system_update_8013() { - $config_factory = \Drupal::configFactory(); - $system_cron_config = $config_factory->getEditable('system.cron'); - if ($autorun = $system_cron_config->get('threshold.autorun')) { + $autorun = \Drupal::configFactory()->getEditable('system.cron')->get('threshold.autorun'); + if ($autorun) { // Install 'automated_cron' module. \Drupal::service('module_installer')->install(['automated_cron'], FALSE); // Copy 'autorun' value into the new module's 'interval' setting. - $config_factory->getEditable('automated_cron.settings') + \Drupal::configFactory()->getEditable('automated_cron.settings') ->set('interval', $autorun) ->save(TRUE); } // Remove the 'autorun' key in system module config. - $system_cron_config + \Drupal::configFactory() + ->getEditable('system.cron') ->clear('threshold.autorun') ->save(TRUE); } diff --git a/core/modules/system/tests/src/Functional/Update/UpdateCacheTest.php b/core/modules/system/tests/src/Functional/Update/UpdateCacheTest.php new file mode 100644 index 000000000000..1d9765da4ddf --- /dev/null +++ b/core/modules/system/tests/src/Functional/Update/UpdateCacheTest.php @@ -0,0 +1,44 @@ +set('will_not_exist_after_update', TRUE); + // The site might be broken at the time so logging in using the UI might + // not work, so we use the API itself. + $this->writeSettings([ + 'settings' => [ + 'update_free_access' => (object) [ + 'value' => TRUE, + 'required' => TRUE, + ], + ], + ]); + + // Clicking continue should clear the caches. + $this->drupalGet(Url::fromRoute('system.db_update', [], ['path_processing' => FALSE])); + $this->updateRequirementsProblem(); + $this->clickLink(t('Continue')); + + $this->assertFalse(\Drupal::cache()->get('will_not_exist_after_update', FALSE)); + } + +}