Verified Commit 88187a5e authored by Dave Long's avatar Dave Long
Browse files

task: #3580877 Remove updates added prior to 11.3.0 from 12.x

By: catch
By: quietone
By: smustgrave
By: dcam
parent 42f62b89
Loading
Loading
Loading
Loading
Loading
+0 −12
Original line number Diff line number Diff line
@@ -10945,12 +10945,6 @@
	'count' => 1,
	'path' => __DIR__ . '/modules/block/tests/src/Functional/BlockUiTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\block\\\\Functional\\\\BlockWeightUpdateTest\\:\\:testRunUpdates\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/block/tests/src/Functional/BlockWeightUpdateTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\block\\\\Functional\\\\Views\\\\DisplayBlockTest\\:\\:assertBlockAppears\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
@@ -22465,12 +22459,6 @@
	'count' => 1,
	'path' => __DIR__ . '/modules/search/tests/modules/search_extra_type/src/Plugin/Search/SearchExtraTypeSearch.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\search\\\\Functional\\\\Update\\\\SearchBlockPageIdUpdatePathTest\\:\\:testRunUpdates\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/search/tests/src/Functional/Update/SearchBlockPageIdUpdatePathTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\search\\\\Kernel\\\\SearchMatchTest\\:\\:getText\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
+2 −37
Original line number Diff line number Diff line
@@ -5,9 +5,6 @@
 * Post update functions for Block.
 */

use Drupal\block\BlockInterface;
use Drupal\Core\Config\Entity\ConfigEntityUpdater;

/**
 * Implements hook_removed_post_updates().
 */
@@ -17,39 +14,7 @@ function block_removed_post_updates(): array {
    'block_post_update_disabled_region_update' => '9.0.0',
    'block_post_update_fix_negate_in_conditions' => '9.0.0',
    'block_post_update_replace_node_type_condition' => '10.0.0',
    'block_post_update_make_weight_integer' => '12.0.0',
    'block_post_update_set_menu_block_depth_to_null_if_zero' => '12.0.0',
  ];
}

/**
 * Ensures that all block weights are integers.
 */
function block_post_update_make_weight_integer(array &$sandbox = []): void {
  \Drupal::classResolver(ConfigEntityUpdater::class)
    ->update($sandbox, 'block', function (BlockInterface $block): bool {
      $weight = $block->getWeight();
      if (!is_int($weight)) {
        $block->setWeight($weight);
        return TRUE;
      }
      return FALSE;
    });
}

/**
 * Updates the `depth` setting to NULL if it is 0 in any menu blocks.
 */
function block_post_update_set_menu_block_depth_to_null_if_zero(array &$sandbox = []): void {
  \Drupal::classResolver(ConfigEntityUpdater::class)
    ->update($sandbox, 'block', function (BlockInterface $block): bool {
      if ($block->getPlugin()->getBaseId() === 'system_menu_block') {
        $settings = $block->get('settings');
        // Use `empty()` to account for either integer 0, or '0'.
        if (empty($settings['depth'])) {
          $settings['depth'] = NULL;
        }
        $block->set('settings', $settings);
        return TRUE;
      }
      return FALSE;
    });
}
+0 −47
Original line number Diff line number Diff line
@@ -35,51 +35,4 @@ public function setDeprecationsEnabled(bool $enabled): void {
    $this->deprecationsEnabled = $enabled;
  }

  /**
   * Performs the required update.
   *
   * @param \Drupal\block\BlockInterface $block
   *   The block to update.
   *
   * @return bool
   *   Whether the block was updated.
   */
  public function updateBlock(BlockInterface $block): bool {
    $changed = FALSE;
    if ($this->needsInfoStatusSettingsRemoved($block)) {
      $settings = $block->get('settings');
      unset($settings['info'], $settings['status']);
      $block->set('settings', $settings);
      $changed = TRUE;
    }
    return $changed;
  }

  /**
   * Checks if the block contains deprecated info and status settings.
   *
   * @param \Drupal\block\BlockInterface $block
   *   The block to update.
   *
   * @return bool
   *   TRUE if the block has deprecated settings.
   */
  public function needsInfoStatusSettingsRemoved(BlockInterface $block): bool {
    if (!str_starts_with($block->getPluginId(), 'block_content')) {
      return FALSE;
    }
    $settings = $block->get('settings');
    if (!isset($settings['info']) && !isset($settings['status'])) {
      return FALSE;
    }

    $deprecations_triggered = &$this->triggeredDeprecations['3426302'][$block->id()];
    if ($this->deprecationsEnabled && !$deprecations_triggered) {
      $deprecations_triggered = TRUE;
      @trigger_error('Block content blocks with the "status" and "info" settings is deprecated in drupal:11.3.0 and will be removed in drupal:12.0.0. They were unused, so there is no replacement. Profile, module and theme provided configuration should be updated. See https://www.drupal.org/node/3499836', E_USER_DEPRECATED);
    }

    return TRUE;
  }

}
+0 −26
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Adds a menu block with a `depth` setting of 0.
 */

use Drupal\Core\Database\Database;

$connection = Database::getConnection();

$data = $connection->select('config')
  ->condition('name', 'block.block.olivero_account_menu')
  ->fields('config', ['data'])
  ->execute()
  ->fetchField();
$data = unserialize($data);
// Change the depth setting to 0, which the update hook should change to NULL.
// @see system_post_update_set_menu_block_depth_to_null_if_zero().
$data['settings']['depth'] = 0;
$connection->update('config')
  ->condition('name', 'block.block.olivero_account_menu')
  ->fields([
    'data' => serialize($data),
  ])
  ->execute();
+0 −59
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\Tests\block\Functional;

use Drupal\block\Entity\Block;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
use PHPUnit\Framework\Attributes\CoversFunction;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;

/**
 * Tests Block Weight Update.
 */
#[Group('block')]
#[CoversFunction('block_post_update_make_weight_integer')]
#[RunTestsInSeparateProcesses]
class BlockWeightUpdateTest extends UpdatePathTestBase {

  /**
   * {@inheritdoc}
   */
  protected function setDatabaseDumpFiles(): void {
    $this->databaseDumpFiles = [
      __DIR__ . '/../../../../system/tests/fixtures/update/drupal-10.3.0.filled.standard.php.gz',
      __DIR__ . '/../../../../system/tests/fixtures/update/uninstall-history.php',
      __DIR__ . '/../../../../system/tests/fixtures/update/uninstall-ban.php',
      __DIR__ . '/../../../../system/tests/fixtures/update/uninstall-contact.php',
    ];
  }

  /**
   * Tests update path for blocks' `weight` property.
   */
  public function testRunUpdates() {
    // Find a block and change it to have a null weight.
    /** @var \Drupal\Core\Database\Connection $database */
    $database = $this->container->get('database');
    $block = $database->select('config', 'c')
      ->fields('c', ['data'])
      ->condition('name', 'block.block.claro_content')
      ->execute()
      ->fetchField();
    $block = unserialize($block);
    $block['weight'] = NULL;
    $database->update('config')
      ->fields([
        'data' => serialize($block),
      ])
      ->condition('name', 'block.block.claro_content')
      ->execute();

    $this->assertNull(Block::load('claro_content')->get('weight'));
    $this->runUpdates();
    $this->assertSame(0, Block::load('claro_content')->get('weight'));
  }

}
Loading