diff --git a/core/modules/block/block.install b/core/modules/block/block.install index bd12f0f..3a019a2 100644 --- a/core/modules/block/block.install +++ b/core/modules/block/block.install @@ -4,6 +4,7 @@ * @file * Install, update, and uninstall functions for the Block module. */ +use Drupal\Core\Cache\Cache; /** * @addtogroup updates-8.0.0-beta @@ -34,18 +35,21 @@ function block_update_8001() { // converting the format of the context_mapping, which makes code reacting // to Entity API hooks tricky, because they would need to be different for // before/after the update. + // We also doesn't use the Drupal config API (\Drupal::configFactory()) as + // this triggers events, which has similar problems. // For updating the status flag of the block in the next update function, // however, we can use Entity API. // Contributed modules should leverage hook_update_dependencies() in order to // be executed before block_update_8002(). - $config_factory = \Drupal::configFactory(); + /** @var \Drupal\Core\Config\StorageInterface $config_storage */ + $config_storage = \Drupal::service('config.storage'); $message = NULL; $backup_values = []; $update_backup = []; - foreach ($config_factory->listAll('block.block.') as $block_config_name) { - $block = $config_factory->getEditable($block_config_name); - if ($visibility = $block->get('visibility')) { + foreach ($config_storage->listAll('block.block.') as $block_config_name) { + $block = $config_storage->read($block_config_name); + if ($visibility = $block['visibility']) { foreach ($visibility as $condition_plugin_id => &$condition) { foreach ($condition['context_mapping'] as $key => $context) { if (!isset($context_service_id_map[$key])) { @@ -64,18 +68,21 @@ function block_update_8001() { $condition['context_mapping'][$key] = '@' . $context_service_id_map[$key] . ':' . $new_context_id[1]; } } - $block->set('visibility', $visibility); + $block['visibility'] = $visibility; if ($backup_values) { // We not only store the missing context mappings but also the // previous block status so contributed and custom modules could update. - $update_backup[$block->get('id')] = ['missing_context_ids' => $backup_values, 'status' => $block->get('status')]; + $update_backup[$block['id']] = ['missing_context_ids' => $backup_values, 'status' => $block['id']]; } } - $block->save(); + debug($block); + $config_storage->write($block_config_name, $block); } + Cache::invalidateTags(['cache.config']); + if ($update_backup) { \Drupal::keyValue('update_backup')->set('block_update_8001', $update_backup); } diff --git a/core/modules/system/tests/fixtures/update/drupal-8.block-context-manager-2354889.php b/core/modules/system/tests/fixtures/update/drupal-8.block-context-manager-2354889.php index 207fc30..736282b 100644 --- a/core/modules/system/tests/fixtures/update/drupal-8.block-context-manager-2354889.php +++ b/core/modules/system/tests/fixtures/update/drupal-8.block-context-manager-2354889.php @@ -30,3 +30,21 @@ )) ->execute(); } + +// Update the config entity query "index". +$existing_blocks = $connection->select('key_value') + ->fields('key_value', ['value']) + ->condition('collection', 'config.entity.key_store.block') + ->condition('name', 'theme:bartik') + ->execute() + ->fetchField(); +$existing_blocks = unserialize($existing_blocks); + +debug(array_merge($existing_blocks, ['block.block.testfor2354889', 'block.block.secondtestfor2354889', 'block.block.thirdtestfor2354889'])); +$connection->update('key_value') + ->fields([ + 'value' => serialize(array_merge($existing_blocks, ['block.block.testfor2354889', 'block.block.secondtestfor2354889', 'block.block.thirdtestfor2354889'])) + ]) + ->condition('collection', 'config.entity.key_store.block') + ->condition('name', 'theme:bartik') + ->execute();