Skip to content
Snippets Groups Projects
Unverified Commit 8faf10c9 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2738879 by mr.baileys, trobey, dawehner, alexpott, ravi.shankar, catch,...

Issue #2738879 by mr.baileys, trobey, dawehner, alexpott, ravi.shankar, catch, Fernly: system.schema can end up with missing schema information for some modules, resulting in hook_update_N() not getting called
parent 258f88ad
No related branches found
No related tags found
6 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1012Issue #3226887: Hreflang on non-canonical content pages,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10,!596Issue #3046532: deleting an entity reference field, used in a contextual view, makes the whole site unrecoverable,!496Issue #2463967: Use .user.ini file for PHP settings,!144Issue #2666286: Clean up menu_ui to conform to Drupal coding standards
...@@ -81,9 +81,10 @@ function drupal_get_installed_schema_version($module, $reset = FALSE, $array = F ...@@ -81,9 +81,10 @@ function drupal_get_installed_schema_version($module, $reset = FALSE, $array = F
} }
if (!$versions) { if (!$versions) {
if (!$versions = \Drupal::keyValue('system.schema')->getAll()) { $versions = \Drupal::keyValue('system.schema')->getAll();
$versions = []; $enabled_modules = \Drupal::moduleHandler()->getModuleList();
} $enabled_modules = array_fill_keys(array_keys($enabled_modules), \Drupal::CORE_MINIMUM_SCHEMA_VERSION);
$versions = array_merge($enabled_modules, $versions);
} }
if ($array) { if ($array) {
......
...@@ -607,7 +607,7 @@ function update_retrieve_dependencies() { ...@@ -607,7 +607,7 @@ function update_retrieve_dependencies() {
$return = []; $return = [];
// Get a list of installed modules, arranged so that we invoke their hooks in // Get a list of installed modules, arranged so that we invoke their hooks in
// the same order that \Drupal::moduleHandler()->invokeAll() does. // the same order that \Drupal::moduleHandler()->invokeAll() does.
foreach (\Drupal::keyValue('system.schema')->getAll() as $module => $schema) { foreach (drupal_get_installed_schema_version(NULL, FALSE, TRUE) as $module => $schema) {
if ($schema == SCHEMA_UNINSTALLED) { if ($schema == SCHEMA_UNINSTALLED) {
// Nothing to upgrade. // Nothing to upgrade.
continue; continue;
......
name: 'Update test'
type: module
description: 'Support module for update testing.'
package: Testing
version: VERSION
<?php
/**
* @file
* Install, update and uninstall functions for the update_test_no_preexisting module.
*/
/**
* Dummy update_test_no_preexisting update 8001.
*/
function update_test_no_preexisting_update_8001() {
\Drupal::state()->set('update_test_no_preexisting_update_8001', TRUE);
}
<?php
namespace Drupal\Tests\system\Functional\UpdateSystem;
use Drupal\Core\Database\Database;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\UpdatePathTestTrait;
/**
* Tries to update a module which has no pre-existing schema.
*
* @group Update
* @group legacy
*/
class NoPreExistingSchemaUpdateTest extends BrowserTestBase {
use UpdatePathTestTrait;
protected function setUp() {
parent::setUp();
$connection = Database::getConnection();
// Enable the update_test_no_preexisting module by altering the
// core.extension configuration directly, so that the schema version
// information is missing.
$extensions = $connection->select('config')
->fields('config', ['data'])
->condition('name', 'core.extension')
->execute()
->fetchField();
$extensions = unserialize($extensions);
$connection->update('config')
->fields([
'data' => serialize(array_merge_recursive($extensions, ['module' => ['update_test_no_preexisting' => 0]])),
])
->condition('name', 'core.extension')
->execute();
}
/**
* Test the system module updates with no dependencies installed.
*/
public function testNoPreExistingSchema() {
$schema = \Drupal::keyValue('system.schema')->getAll();
$this->assertArrayNotHasKey('update_test_no_preexisting', $schema);
$this->assertFalse(\Drupal::state()->get('update_test_no_preexisting_update_8001', FALSE));
$this->runUpdates();
$schema = \Drupal::keyValue('system.schema')->getAll();
$this->assertArrayHasKey('update_test_no_preexisting', $schema);
$this->assertEquals('8001', $schema['update_test_no_preexisting']);
$this->assertTrue(\Drupal::state()->get('update_test_no_preexisting_update_8001', FALSE));
}
}
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