Verified Commit 136f0550 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

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

Issue #3087644 by jibran, Berdir, alexpott, longwave, Wim Leers, amateescu, catch, larowlan, dpi, quietone: Remove Drupal 8 updates up to and including 88**
parent d712cec8
Loading
Loading
Loading
Loading
+4 −21
Original line number Diff line number Diff line
@@ -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;
+3 −25
Original line number Diff line number Diff line
@@ -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;
}
+0 −59
Original line number Diff line number Diff line
<?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());
  }

}
+3 −97
Original line number Diff line number Diff line
@@ -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;
}
+0 −28
Original line number Diff line number Diff line
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: {  }
Loading