Commit e1a041c4 authored by catch's avatar catch
Browse files

Issue #3087644 by jibran, Berdir, alexpott, longwave, Wim Leers, amateescu,...

Issue #3087644 by jibran, Berdir, alexpott, longwave, Wim Leers, amateescu, catch, xjm, larowlan, dpi, quietone: Remove Drupal 8 updates up to and including 88**
parent a7c51121
......@@ -644,8 +644,6 @@ function hook_install_tasks_alter(&$tasks, $install_state) {
* @see hook_update_last_removed()
* @see update_get_update_list()
* @see \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface
* @see node_update_8001
* @see system_update_8004
* @see https://www.drupal.org/node/2535316
*/
function hook_update_N(&$sandbox) {
......@@ -759,25 +757,10 @@ function hook_post_update_NAME(&$sandbox) {
$result = t('Node %nid saved', ['%nid' => $node->id()]);
// Example of disabling blocks with missing condition contexts. Note: The
// block itself is in a state which is valid at that point.
// @see block_update_8001()
// @see block_post_update_disable_blocks_with_missing_contexts()
$block_update_8001 = \Drupal::keyValue('update_backup')->get('block_update_8001', []);
$block_ids = array_keys($block_update_8001);
$block_storage = \Drupal::entityTypeManager()->getStorage('block');
$blocks = $block_storage->loadMultiple($block_ids);
/** @var $blocks \Drupal\block\BlockInterface[] */
foreach ($blocks as $block) {
// This block has had conditions removed due to an inability to resolve
// contexts in block_update_8001() so disable it.
// Disable currently enabled blocks.
if ($block_update_8001[$block->id()]['status']) {
$block->setStatus(FALSE);
$block->save();
}
// Example of updating some config.
if (\Drupal::moduleHandler()->moduleExists('taxonomy')) {
// Update the dependencies of all Vocabulary configuration entities.
\Drupal::classResolver(\Drupal\Core\Config\Entity\ConfigEntityUpdater::class)->update($sandbox, 'taxonomy_vocabulary');
}
return $result;
......
......@@ -23,30 +23,8 @@ function aggregator_requirements($phase) {
}
/**
* The simple presence of this update function clears cached field definitions.
* Implements hook_update_last_removed().
*/
function aggregator_update_8001() {
// Feed ID base field is now required.
}
/**
* Make the 'Source feed' field for aggregator items required.
*/
function aggregator_update_8200() {
// aggregator_update_8001() did not update the last installed field storage
// definition for the aggregator item's 'Source feed' field.
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$field_definition = $definition_update_manager->getFieldStorageDefinition('fid', 'aggregator_item');
$field_definition->setRequired(TRUE);
$definition_update_manager->updateFieldStorageDefinition($field_definition);
}
/**
* Add a default value for the 'Refresh' field for aggregator feed entities.
*/
function aggregator_update_8501() {
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$field_definition = $definition_update_manager->getFieldStorageDefinition('refresh', 'aggregator_feed');
$field_definition->setDefaultValue(3600);
$definition_update_manager->updateFieldStorageDefinition($field_definition);
function aggregator_update_last_removed() {
return 8501;
}
<?php
namespace Drupal\Tests\aggregator\Functional\Update;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
/**
* Tests that node settings are properly updated during database updates.
*
* @group aggregator
* @group legacy
*/
class AggregatorUpdateTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.filled.standard.php.gz',
];
}
/**
* Tests that the 'Source feed' field is required.
*
* @see aggregator_update_8200()
*/
public function testSourceFeedRequired() {
// Check that the 'fid' field is not required prior to the update.
$field_definition = \Drupal::entityDefinitionUpdateManager()->getFieldStorageDefinition('fid', 'aggregator_item');
$this->assertFalse($field_definition->isRequired());
// Run updates.
$this->runUpdates();
// Check that the 'fid' field is now required.
$field_definition = \Drupal::entityDefinitionUpdateManager()->getFieldStorageDefinition('fid', 'aggregator_item');
$this->assertTrue($field_definition->isRequired());
}
/**
* Tests that the 'Update interval' field has a default value.
*/
public function testUpdateIntervalDefaultValue() {
// Check that the 'refresh' field does not have a default value prior to the
// update.
$field_definition = \Drupal::entityDefinitionUpdateManager()->getFieldStorageDefinition('refresh', 'aggregator_feed');
$this->assertSame([], $field_definition->getDefaultValueLiteral());
// Run updates.
$this->runUpdates();
// Check that the 'refresh' has a default value now.
$field_definition = \Drupal::entityDefinitionUpdateManager()->getFieldStorageDefinition('refresh', 'aggregator_feed');
$this->assertSame([['value' => 3600]], $field_definition->getDefaultValueLiteral());
}
}
......@@ -18,102 +18,8 @@ function block_install() {
}
/**
* Update block visibility context mapping.
* Implements hook_update_last_removed().
*/
function block_update_8001() {
// This update function updates blocks for the change from
// https://www.drupal.org/node/2354889.
// Core visibility context plugins are updated automatically; blocks with
// unknown plugins are disabled and their previous visibility settings are
// saved in key value storage; see change record
// https://www.drupal.org/node/2527840 for more explanation.
// These are all the contexts that Drupal core provides.
$context_service_id_map = [
'node.node' => '@node.node_route_context:node',
'user.current_user' => '@user.current_user_context:current_user',
];
foreach (array_keys(\Drupal::languageManager()->getDefinedLanguageTypesInfo()) as $language_type_id) {
$context_service_id_map['language.' . $language_type_id] = '@language.current_language_context:' . $language_type_id;
}
// Contributed modules should leverage hook_update_dependencies() in order to
// be executed after block_update_8001(). The blocks are then disabled if the
// contexts are still missing via
// block_post_update_disable_blocks_with_missing_contexts().
$config_factory = \Drupal::configFactory();
$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 ($visibility as $condition_plugin_id => &$condition) {
foreach ($condition['context_mapping'] as $key => $context) {
if (!isset($context_service_id_map[$context])) {
// Remove the visibility condition for unknown context mapping
// entries, so the update process itself runs through and users can
// fix their block placements manually OR alternatively contributed
// modules can run their own update functions to update mappings
// that they provide.
$backup_values[$context][] = $condition_plugin_id;
unset($visibility[$condition_plugin_id]);
continue;
}
// Replace the context ID based on the defined mapping.
$condition['context_mapping'][$key] = $context_service_id_map[$context];
}
}
$block->set('visibility', $visibility);
if ($backup_values) {
// We not only store the missing context mappings but also the previous
// block status, in order to allow contributed and custom modules to do
// their own updates.
$update_backup[$block->get('id')] = [
'missing_context_ids' => $backup_values,
'status' => $block->get('status'),
];
}
}
// Mark the resulting configuration as trusted data. This avoids issues with
// future schema changes.
$block->save(TRUE);
}
if ($update_backup) {
\Drupal::keyValue('update_backup')->set('block_update_8001', $update_backup);
}
return t('Block context IDs updated.');
}
/**
* Placeholder for the previous 8002 update.
*/
function block_update_8002() {
\Drupal::state()->set('block_update_8002_placeholder', TRUE);
}
/**
* Remove 'cache' setting.
*/
function block_update_8003() {
$config_factory = \Drupal::configFactory();
foreach ($config_factory->listAll('block.block.') as $block_config_name) {
$block = $config_factory->getEditable($block_config_name);
// Remove the 'cache' setting.
$settings = $block->get('settings');
unset($settings['cache']);
$block->set('settings', $settings);
// Mark the resulting configuration as trusted data. This avoids issues with
// future schema changes.
$block->save(TRUE);
}
return t('Block settings updated.');
function block_update_last_removed() {
return 8003;
}
uuid: 1a6c0f14-78dc-4ede-bade-b8ce83881453
langcode: en
status: true
dependencies:
module:
- block_test
- system
theme:
- bartik
id: missing_schema
theme: bartik
region: sidebar_first
weight: 0
provider: null
plugin: system_branding_block
settings:
id: system_branding_block
label: 'Test missing schema on conditions'
provider: system
label_display: visible
use_site_logo: true
use_site_name: true
use_site_slogan: true
visibility:
missing_schema:
id: missing_schema
negate: 0
context_mapping: { }
<?php
/**
* @file
* Partial database to mimic the installation of the block_test module.
*/
use Drupal\Core\Database\Database;
use Symfony\Component\Yaml\Yaml;
$connection = Database::getConnection();
// Set the schema version.
$connection->insert('key_value')
->fields([
'collection' => 'system.schema',
'name' => 'block_test',
'value' => 'i:8000;',
])
->execute();
// Update core.extension.
$extensions = $connection->select('config')
->fields('config', ['data'])
->condition('collection', '')
->condition('name', 'core.extension')
->execute()
->fetchField();
$extensions = unserialize($extensions);
$extensions['module']['block_test'] = 8000;
$connection->update('config')
->fields([
'data' => serialize($extensions),
])
->condition('collection', '')
->condition('name', 'core.extension')
->execute();
// Install the block configuration.
$config = file_get_contents(__DIR__ . '/block.block.missing_schema.yml');
$config = Yaml::parse($config);
$connection->insert('config')
->fields(['data', 'name', 'collection'])
->values([
'name' => 'block.block.missing_schema',
'data' => serialize($config),
'collection' => '',
])
->execute();
<?php
namespace Drupal\Tests\block\Functional\Update;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
/**
* Tests the upgrade path for block with conditions missing context.
*
* @see https://www.drupal.org/node/2811519
*
* @group Update
* @group legacy
*/
class BlockConditionMissingSchemaUpdateTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['block_test', 'language'];
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
__DIR__ . '/../../../fixtures/update/drupal-8.block-test-enabled-missing-schema.php',
];
}
/**
* Tests that block context mapping is updated properly.
*/
public function testUpdateHookN() {
$this->runUpdates();
$this->drupalGet('<front>');
// If the block is fixed by block_post_update_fix_negate_in_conditions()
// then it will be visible.
$this->assertText('Test missing schema on conditions');
}
}
<?php
namespace Drupal\Tests\block\Functional\Update;
/**
* Runs BlockContextMappingUpdateTest with a dump filled with content.
*
* @group Update
* @group legacy
*/
class BlockContextMappingUpdateFilledTest extends BlockContextMappingUpdateTest {
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
parent::setDatabaseDumpFiles();
$this->databaseDumpFiles[0] = __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.filled.standard.php.gz';
}
}
<?php
namespace Drupal\Tests\block\Functional\Update;
use Drupal\block\Entity\Block;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
use Drupal\node\Entity\Node;
/**
* Tests the upgrade path for block context mapping renames.
*
* @see https://www.drupal.org/node/2354889
*
* @group Update
* @group legacy
*/
class BlockContextMappingUpdateTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['block_test', 'language'];
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.block-context-manager-2354889.php',
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.language-enabled.php',
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.block-test-enabled.php',
];
}
/**
* Tests that block context mapping is updated properly.
*/
public function testUpdateHookN() {
$this->runUpdates();
$this->assertRaw('Encountered an unknown context mapping key coming probably from a contributed or custom module: One or more mappings could not be updated. Please manually review your visibility settings for the following blocks, which are disabled now:<ul><li>User login (Visibility: Baloney spam)</li></ul>');
// Disable maintenance mode.
\Drupal::state()->set('system.maintenance_mode', FALSE);
// We finished updating so we can log in the user now.
$this->drupalLogin($this->rootUser);
// The block that we are testing has the following visibility rules:
// - only visible on node pages
// - only visible to authenticated users.
$block_title = 'Test for 2354889';
// Create two nodes, a page and an article.
$page = Node::create([
'type' => 'page',
'title' => 'Page node',
]);
$page->save();
$article = Node::create([
'type' => 'article',
'title' => 'Article node',
]);
$article->save();
// Check that the block appears only on Page nodes for authenticated users.
$this->drupalGet('node/' . $page->id());
$this->assertRaw($block_title, 'Test block is visible on a Page node as an authenticated user.');
$this->drupalGet('node/' . $article->id());
$this->assertNoRaw($block_title, 'Test block is not visible on a Article node as an authenticated user.');
$this->drupalLogout();
// Check that the block does not appear on any page for anonymous users.
$this->drupalGet('node/' . $page->id());
$this->assertNoRaw($block_title, 'Test block is not visible on a Page node as an anonymous user.');
$this->drupalGet('node/' . $article->id());
$this->assertNoRaw($block_title, 'Test block is not visible on a Article node as an anonymous user.');
// Ensure that all the context mappings got updated properly.
$block = Block::load('testfor2354889');
$visibility = $block->get('visibility');
$this->assertEqual('@node.node_route_context:node', $visibility['node_type']['context_mapping']['node']);
$this->assertEqual('@user.current_user_context:current_user', $visibility['user_role']['context_mapping']['user']);
$this->assertEqual('@language.current_language_context:language_interface', $visibility['language']['context_mapping']['language']);
// Check that a block with invalid context is being disabled and that it can
// still be edited afterward.
$disabled_block = Block::load('thirdtestfor2354889');
$this->assertFalse($disabled_block->status(), 'Block with invalid context is disabled');
$this->assertEqual(['thirdtestfor2354889' => ['missing_context_ids' => ['baloney_spam' => ['node_type']], 'status' => TRUE]], \Drupal::keyValue('update_backup')->get('block_update_8001'));
$disabled_block_visibility = $disabled_block->get('visibility');
$this->assertTrue(!isset($disabled_block_visibility['node_type']), 'The problematic visibility condition has been removed.');
$admin_user = $this->drupalCreateUser(['administer blocks']);
$this->drupalLogin($admin_user);
$this->drupalGet('admin/structure/block/manage/thirdtestfor2354889');
$this->assertResponse('200');
}
}
<?php
namespace Drupal\Tests\block\Functional\Update;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
/**
* Tests the upgrade path for removal of disabled region.
*
* @see https://www.drupal.org/node/2513534
*
* @group Update
* @group legacy
*/
class BlockRemoveDisabledRegionUpdateTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['block_test', 'language'];
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.update-test-block-disabled-2513534.php',
];
}
/**
* Tests that block context mapping is updated properly.
*/
public function testUpdateHookN() {
$this->runUpdates();
// Disable maintenance mode.
\Drupal::state()->set('system.maintenance_mode', FALSE);
// We finished updating so we can login the user now.
$this->drupalLogin($this->rootUser);
// Verify that a disabled block is in the default region.
$this->drupalGet('admin/structure/block');
$element = $this->xpath("//tr[contains(@data-drupal-selector, :block) and contains(@class, :status)]//select/option[@selected and @value=:region]",
[':block' => 'edit-blocks-pagetitle-1', ':status' => 'block-disabled', ':region' => 'header']);
$this->assertTrue(!empty($element));
// Verify that an enabled block is now disabled and in the default region.
$this->drupalGet('admin/structure/block');
$element = $this->xpath("//tr[contains(@data-drupal-selector, :block) and contains(@class, :status)]//select/option[@selected and @value=:region]",
[':block' => 'edit-blocks-pagetitle-2', ':status' => 'block-disabled', ':region' => 'header']);
$this->assertTrue(!empty($element));
}
}
......@@ -5,136 +5,9 @@
* Install, update and uninstall functions for the block_content module.
*/
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Add 'revision_translation_affected' field to 'block_content' entities.
*/
function block_content_update_8001() {
// Install the definition that this field had in
// \Drupal\block_content\Entity\BlockContent::baseFieldDefinitions()
// at the time that this update function was written. If/when code is
// deployed that changes that definition, the corresponding module must
// implement an update function that invokes
// \Drupal::entityDefinitionUpdateManager()->updateFieldStorageDefinition()
// with the new definition.
$storage_definition = BaseFieldDefinition::create('boolean')
->setLabel(t('Revision translation affected'))
->setDescription(t('Indicates if the last edit of a translation belongs to current revision.'))
->setReadOnly(TRUE)
->setRevisionable(TRUE)
->setTranslatable(TRUE);
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition('revision_translation_affected', 'block_content', 'block_content', $storage_definition);
}
/**
* Generalizes the d6_block_content_type and d6_block_content_body_field
* migrations.
*/
function block_content_update_8002() {
// Removed in issue #2569605. The Migrate and Migrate Drupal modules are
// marked experimental and do not need to support the update path until they