Skip to content
Snippets Groups Projects
Commit 8d156b1c authored by catch's avatar catch
Browse files

Issue #3463226 by quietone, dww, smustgrave, catch, xjm: Use the new...

Issue #3463226 by quietone, dww, smustgrave, catch, xjm: Use the new equivalent updates API to prevent updates from 10.4.0 to 11.0.0

(cherry picked from commit e4df25b6)
parent da479cec
No related branches found
No related tags found
15 merge requests!11380Issue #3490698 by catch, spokje: Bump MINIMUM_STABILITY back to 'stable' when...,!11239Issue #3507548: Allow workspace changes listing to show all items, without a pager,!11238Fix issue #3051797,!11213Issue #3506743 by tomislav.matokovic: Increasing the color contrast for the navigation block title against the background of the navigation sidebar to at least 4.5:1,!11147Draft: Try to avoid manually setting required cache contexts,!11108Issue #3490298 by nicxvan: Profiles can be missed in OOP hooks,!11093Drupal on MongoDB 11.1.x,!11017Issue #3502540: Add date filter for moderated content.,!11009Issue #3486972 migrate feed icon,!10999Cleaning up Taxonomy hooks and updating baseline.,!10977Issue #3501457: Fix path used in a A11y Test Admin,!10881Issue #3489329 by mfb, casey: symfony/http-foundation commit 32310ff breaks PathValidator,!10570Issue #3494197: Convert Twig engine hooks,!10567Issue #3494154: Index is not added if entity doesn't support revisions,!10548Revert "Issue #3478621 by catch, longwave, nicxvan: Add filecache to OOP hook attribute parsing"
Pipeline #364806 passed
Pipeline: drupal

#364807

    ......@@ -24,6 +24,7 @@
    use Drupal\Core\StringTranslation\ByteSizeMarkup;
    use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    use Drupal\Core\Update\EquivalentUpdate;
    use Drupal\Core\Url;
    use Drupal\Core\Utility\Error;
    use Psr\Http\Client\ClientExceptionInterface;
    ......@@ -1744,3 +1745,17 @@ function system_update_11001(): void {
    ];
    $schema->changeField('menu_tree', 'route_param_key', 'route_param_key', $spec);
    }
    /**
    * Equivalent update to 10400.
    */
    function system_update_11102(): TranslatableMarkup|null {
    // This is a no-op that exists to prevent an upgrade from 10.4+ to 11.0. That
    // path is actually a downgrade.
    $equivalent_update = \Drupal::service('update.update_hook_registry')
    ->getEquivalentUpdate();
    if ($equivalent_update instanceof EquivalentUpdate) {
    return $equivalent_update->toSkipMessage();
    }
    return NULL;
    }
    name: '10.4 downgrade prevention test'
    type: module
    description: 'Support module for testing that an update hook prevents a downgrade.'
    package: Testing
    version: VERSION
    <?php
    /**
    * @file
    * Update hooks and schema definition for the downgrade_prevention_test module.
    */
    declare(strict_types=1);
    /**
    * A hook_update_N that is equivalent update to 10400.
    */
    function downgrade_prevention_test_update_11102(): void {
    }
    <?php
    declare(strict_types=1);
    namespace Drupal\Tests\system\Functional\UpdateSystem;
    use Drupal\FunctionalTests\Update\UpdatePathTestBase;
    /**
    * Tests that a site on 10.4.0 is prevented from downgrading to 11.0.0.
    *
    * This tests the upgrade path when there is a pair of equivalent updates. The
    * earlier update is 10400 and the latter one is 11102.
    *
    * @group Update
    */
    class PreventDowngradeTest extends UpdatePathTestBase {
    /**
    * {@inheritdoc}
    */
    protected $defaultTheme = 'stark';
    /**
    * {@inheritdoc}
    */
    protected function setDatabaseDumpFiles(): void {
    $this->databaseDumpFiles[] = __DIR__ . '/../../../../tests/fixtures/update/drupal-10.3.0.filled.standard.php.gz';
    }
    /**
    * Tests prevention of incorrect update path.
    */
    public function testDowngradePrevention(): void {
    $database = \Drupal::database();
    // Record the update 10400 as an equivalent to update 11102.
    $database->insert('key_value')
    ->fields([
    'collection' => 'core.equivalent_updates',
    'name' => 'downgrade_prevention_test',
    'value' => 'a:1:{i:11102;a:2:{s:10:"ran_update";s:5:"10400";s:21:"future_version_string";s:6:"11.1.0";}}',
    ])
    ->execute();
    // Set the test module schema to 10400.
    $database->insert('key_value')
    ->fields([
    'value' => 'i:10400;',
    'collection' => 'system.schema',
    'name' => 'downgrade_prevention_test',
    ])
    ->execute();
    // Running the updates should fail with a requirements failure because the
    // later update, 11102, is missing from the code base.
    try {
    $this->runUpdates();
    }
    catch (\Exception) {
    // Continue.
    }
    $this->assertSession()->pageTextContains('Missing updates for: 10.4 downgrade prevention test');
    $this->assertSession()->pageTextContains('The version of the 10.4 downgrade prevention test module that you are attempting to update to is missing update 11102 (which was marked as an equivalent by 10400). Update to at least Drupal Core 11.1.0.');
    // Repeat the test with a code base that does have the 11102 update,
    // downgrade_prevention_test_update_11102(). First, install
    // downgrade_prevention_test.
    $extensions = $database->select('config')
    ->fields('config', ['data'])
    ->condition('collection', '')
    ->condition('name', 'core.extension')
    ->execute()
    ->fetchField();
    $extensions = unserialize($extensions);
    // Install the 'downgrade_prevention_test' module.
    $extensions['module']['downgrade_prevention_test'] = 0;
    $database->update('config')
    ->fields([
    'data' => serialize($extensions),
    ])
    ->condition('collection', '')
    ->condition('name', 'core.extension')
    ->execute();
    // Set the schema for 'downgrade_prevention_test' to the update function, 11102.
    $database->update('key_value')
    ->fields([
    'value' => 'i:11102;',
    ])
    ->condition('collection', 'system.schema')
    ->condition('name', 'downgrade_prevention_test')
    ->execute();
    // Running the updates should succeed because the 11102 update function,
    // downgrade_prevention_test_update_11102(), now exists.
    $this->runUpdates();
    $this->assertSession()->pageTextContains('Updates were attempted.');
    }
    }
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment