Unverified Commit c04b62d6 authored by alexpott's avatar alexpott
Browse files

Issue #3143713 by andypost, Kumar Kundan, codersukanta, alexpott, martin107:...

Issue #3143713 by andypost, Kumar Kundan, codersukanta, alexpott, martin107: drupal_get_schema_versions() should return integer versions
parent e884efa3
......@@ -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.
......
......@@ -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);
}
}
}
<?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();
<?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'));
}
}
<?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);
}
}
}
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