Issue #3143713 by andypost, Kumar Kundan, codersukanta, alexpott, martin107: drupal_get_schema_versions() should return integer versions

merge-requests/2/head
Alex Pott 2020-06-23 17:13:38 +01:00
parent e884efa3fa
commit c04b62d61d
No known key found for this signature in database
GPG Key ID: 31905460D4A69276
5 changed files with 108 additions and 1 deletions

View File

@ -47,7 +47,7 @@ function drupal_get_schema_versions($module) {
// If this function is a module update function, add it to the list of
// module updates.
if (preg_match($regexp, $function, $matches)) {
$updates[$matches['module']][] = $matches['version'];
$updates[$matches['module']][] = (int) $matches['version'];
}
}
// Ensure that updates are applied in numerical order.

View File

@ -147,3 +147,17 @@ function system_post_update_uninstall_stable() {
// depending on it.
}
}
/**
* Update schema version to integers.
*
* @see https://www.drupal.org/project/drupal/issues/3143713
*/
function system_post_update_schema_version_int() {
$registry = \Drupal::keyValue('system.schema');
foreach ($registry->getAll() as $name => $schema) {
if (is_string($schema)) {
$registry->set($name, (int) $schema);
}
}
}

View File

@ -0,0 +1,21 @@
<?php
/**
* @file
* Database to mimic the installation of the update_test_schema module.
*/
use Drupal\Core\Database\Database;
$connection = Database::getConnection();
// Set the schema version.
$connection->merge('key_value')
->condition('collection', 'system.schema')
->condition('name', 'update_test_schema')
->fields([
'collection' => 'system.schema',
'name' => 'update_test_schema',
'value' => 's:4:"8901";',
])
->execute();

View File

@ -0,0 +1,39 @@
<?php
namespace Drupal\Tests\system\Functional\Update;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
/**
* Tests that updates clean-up non-integer schema version.
*
* @group Update
* @see system_post_update_schema_version_int()
*/
class SchemaVersionUpdateTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['update_test_schema'];
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../fixtures/update/drupal-8.8.0.bare.standard.php.gz',
__DIR__ . '/../../../fixtures/update/drupal-8.update-schema-version-int.php',
];
}
/**
* Tests that upgrade converted string value to integer.
*/
public function testSchemaVersionsIsInt() {
$this->assertSame('8901', \Drupal::keyValue('system.schema')->get('update_test_schema'));
$this->runUpdates();
$this->assertSame(8901, \Drupal::keyValue('system.schema')->get('update_test_schema'));
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace Drupal\KernelTests\Core\Extension;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests for schema and update includes.
*
* @group Core
*/
class UpdateSchemaTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['update_test_schema'];
/**
* Tests the function parses schema updates as integer numbers.
*
* @see drupal_get_schema_versions()
*/
public function testDrupalGetSchemaVersionsInt() {
\Drupal::state()->set('update_test_schema_version', 8001);
$this->installSchema('update_test_schema', ['update_test_schema_table']);
$schema = drupal_get_schema_versions('update_test_schema');
foreach ($schema as $version) {
$this->assertIsInt($version);
}
}
}