Commit 8faf10c9 authored by alexpott's avatar alexpott

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
......@@ -81,9 +81,10 @@ function drupal_get_installed_schema_version($module, $reset = FALSE, $array = F
}
if (!$versions) {
if (!$versions = \Drupal::keyValue('system.schema')->getAll()) {
$versions = [];
}
$versions = \Drupal::keyValue('system.schema')->getAll();
$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) {
......
......@@ -607,7 +607,7 @@ function update_retrieve_dependencies() {
$return = [];
// Get a list of installed modules, arranged so that we invoke their hooks in
// 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) {
// Nothing to upgrade.
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));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment