Issue #2395515 by alexpott, Berdir: Config static cache is not cleared properly on delete
parent
3f28dd7c42
commit
d05559a373
|
@ -109,27 +109,20 @@ class ConfigFactory implements ConfigFactoryInterface, EventSubscriberInterface
|
|||
return $config[$name];
|
||||
}
|
||||
else {
|
||||
// If the configuration object does not exist in the configuration
|
||||
// storage, create a new object and add it to the static cache.
|
||||
$cache_key = $this->getConfigCacheKey($name);
|
||||
// If the config object has been deleted it will already exist in the
|
||||
// cache but self::loadMultiple does not return such objects.
|
||||
// @todo Explore making ConfigFactory a listener to the config.delete
|
||||
// event to reset the static cache when this occurs.
|
||||
if (!isset($this->cache[$cache_key])) {
|
||||
// If the configuration object does not exist in the configuration
|
||||
// storage or static cache create a new object and add it to the static
|
||||
// cache.
|
||||
$this->cache[$cache_key] = new Config($name, $this->storage, $this->eventDispatcher, $this->typedConfigManager);
|
||||
$this->cache[$cache_key] = new Config($name, $this->storage, $this->eventDispatcher, $this->typedConfigManager);
|
||||
|
||||
if ($this->useOverrides) {
|
||||
// Get and apply any overrides.
|
||||
$overrides = $this->loadOverrides(array($name));
|
||||
if (isset($overrides[$name])) {
|
||||
$this->cache[$cache_key]->setModuleOverride($overrides[$name]);
|
||||
}
|
||||
// Apply any settings.php overrides.
|
||||
if (isset($GLOBALS['config'][$name])) {
|
||||
$this->cache[$cache_key]->setSettingsOverride($GLOBALS['config'][$name]);
|
||||
}
|
||||
if ($this->useOverrides) {
|
||||
// Get and apply any overrides.
|
||||
$overrides = $this->loadOverrides(array($name));
|
||||
if (isset($overrides[$name])) {
|
||||
$this->cache[$cache_key]->setModuleOverride($overrides[$name]);
|
||||
}
|
||||
// Apply any settings.php overrides.
|
||||
if (isset($GLOBALS['config'][$name])) {
|
||||
$this->cache[$cache_key]->setSettingsOverride($GLOBALS['config'][$name]);
|
||||
}
|
||||
}
|
||||
return $this->cache[$cache_key];
|
||||
|
@ -143,10 +136,8 @@ class ConfigFactory implements ConfigFactoryInterface, EventSubscriberInterface
|
|||
$list = array();
|
||||
|
||||
foreach ($names as $key => $name) {
|
||||
// @todo: Deleted configuration stays in $this->cache, only return
|
||||
// configuration objects that are not new.
|
||||
$cache_key = $this->getConfigCacheKey($name);
|
||||
if (isset($this->cache[$cache_key]) && !$this->cache[$cache_key]->isNew()) {
|
||||
if (isset($this->cache[$cache_key])) {
|
||||
$list[$name] = $this->cache[$cache_key];
|
||||
unset($names[$key]);
|
||||
}
|
||||
|
@ -318,11 +309,25 @@ class ConfigFactory implements ConfigFactoryInterface, EventSubscriberInterface
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes stale static cache entries when configuration is deleted.
|
||||
*
|
||||
* @param \Drupal\Core\Config\ConfigCrudEvent $event
|
||||
* The configuration event.
|
||||
*/
|
||||
public function onConfigDelete(ConfigCrudEvent $event) {
|
||||
// Ensure that the static cache does not contain deleted configuration.
|
||||
foreach ($this->getConfigCacheKeys($event->getConfig()->getName()) as $cache_key) {
|
||||
unset($this->cache[$cache_key]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static function getSubscribedEvents() {
|
||||
$events[ConfigEvents::SAVE][] = array('onConfigSave', 255);
|
||||
$events[ConfigEvents::DELETE][] = array('onConfigDelete', 255);
|
||||
return $events;
|
||||
}
|
||||
|
||||
|
|
|
@ -72,6 +72,11 @@ class ConfigCRUDTest extends KernelTestBase {
|
|||
$this->assertIdentical($new_config->get(), $config->get());
|
||||
$this->assertIdentical($config->isNew(), FALSE);
|
||||
|
||||
// Pollute the config factory static cache.
|
||||
$this->container->get('config.factory')->setOverrideState(FALSE);
|
||||
\Drupal::config($name);
|
||||
$this->container->get('config.factory')->setOverrideState(TRUE);
|
||||
|
||||
// Delete the configuration object.
|
||||
$config->delete();
|
||||
|
||||
|
@ -79,6 +84,12 @@ class ConfigCRUDTest extends KernelTestBase {
|
|||
$this->assertIdentical($config->get(), array());
|
||||
$this->assertIdentical($config->isNew(), TRUE);
|
||||
|
||||
// Verify that all copies of the configuration has been removed from the
|
||||
// static cache.
|
||||
$this->container->get('config.factory')->setOverrideState(FALSE);
|
||||
$this->assertIdentical(\Drupal::config($name)->isNew(), TRUE);
|
||||
$this->container->get('config.factory')->setOverrideState(TRUE);
|
||||
|
||||
// Verify the active configuration contains no value.
|
||||
$actual_data = $storage->read($name);
|
||||
$this->assertIdentical($actual_data, FALSE);
|
||||
|
|
|
@ -215,7 +215,7 @@ function editor_form_filter_admin_format_submit($form, FormStateInterface $form_
|
|||
// Delete the existing editor if disabling or switching between editors.
|
||||
$format_id = $form_state->getFormObject()->getEntity()->id();
|
||||
$original_editor = editor_load($format_id);
|
||||
if ($original_editor && $original_editor->getEditor() != $form_state->getValue('editor')) {
|
||||
if ($original_editor && $original_editor->getEditor() != $form_state->getValue(array('editor', 'editor'))) {
|
||||
$original_editor->delete();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue