From c04b62d61d703219efbff3afcf0d0d70ba04ca63 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Tue, 23 Jun 2020 17:13:38 +0100 Subject: [PATCH] Issue #3143713 by andypost, Kumar Kundan, codersukanta, alexpott, martin107: drupal_get_schema_versions() should return integer versions --- core/includes/schema.inc | 2 +- core/modules/system/system.post_update.php | 14 +++++++ .../drupal-8.update-schema-version-int.php | 21 ++++++++++ .../Update/SchemaVersionUpdateTest.php | 39 +++++++++++++++++++ .../Core/Extension/UpdateSchemaTest.php | 33 ++++++++++++++++ 5 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 core/modules/system/tests/fixtures/update/drupal-8.update-schema-version-int.php create mode 100644 core/modules/system/tests/src/Functional/Update/SchemaVersionUpdateTest.php create mode 100644 core/tests/Drupal/KernelTests/Core/Extension/UpdateSchemaTest.php diff --git a/core/includes/schema.inc b/core/includes/schema.inc index e168e89556e..9dc190e3cdf 100644 --- a/core/includes/schema.inc +++ b/core/includes/schema.inc @@ -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. diff --git a/core/modules/system/system.post_update.php b/core/modules/system/system.post_update.php index 4cbd93f5a94..cf9a0cb807e 100644 --- a/core/modules/system/system.post_update.php +++ b/core/modules/system/system.post_update.php @@ -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); + } + } +} diff --git a/core/modules/system/tests/fixtures/update/drupal-8.update-schema-version-int.php b/core/modules/system/tests/fixtures/update/drupal-8.update-schema-version-int.php new file mode 100644 index 00000000000..8f5283b2b0b --- /dev/null +++ b/core/modules/system/tests/fixtures/update/drupal-8.update-schema-version-int.php @@ -0,0 +1,21 @@ +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(); diff --git a/core/modules/system/tests/src/Functional/Update/SchemaVersionUpdateTest.php b/core/modules/system/tests/src/Functional/Update/SchemaVersionUpdateTest.php new file mode 100644 index 00000000000..a0390f6a17d --- /dev/null +++ b/core/modules/system/tests/src/Functional/Update/SchemaVersionUpdateTest.php @@ -0,0 +1,39 @@ +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')); + } + +} diff --git a/core/tests/Drupal/KernelTests/Core/Extension/UpdateSchemaTest.php b/core/tests/Drupal/KernelTests/Core/Extension/UpdateSchemaTest.php new file mode 100644 index 00000000000..607935a92d7 --- /dev/null +++ b/core/tests/Drupal/KernelTests/Core/Extension/UpdateSchemaTest.php @@ -0,0 +1,33 @@ +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); + } + } + +}