diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php index 600527b..be85cd7 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php @@ -191,7 +191,40 @@ public function requiresFieldStorageSchemaChanges(FieldStorageDefinitionInterfac return FALSE; } - return $this->getSchemaFromStorageDefinition($storage_definition) != $this->loadFieldSchemaData($original); + $storage_definition_schema = $this->getSchemaFromStorageDefinition($storage_definition); + $original_schema = $this->loadFieldSchemaData($original); + + // Filter out irrelevant schema. + return $this->removeIrrelevantSchemaKeys($storage_definition_schema) != $this->removeIrrelevantSchemaKeys($original_schema); + } + + /** + * Remove irrelevant schema keys. + * + * We need to remove irrelevant schema keys before comparing two schemas to + * see if they've changed as there are certain keys that can safely be added + * at any point to existing schema. E.g. initial or initial_from_field. + * + * @param array $schema + * The schema array. + * @param array $remove_keys + * (optional) An array of keys to remove regardless of the depth. + * + * @return array + * The schema with any irrelevant keys removed. + */ + protected function removeIrrelevantSchemaKeys(&$schema, $remove_keys = ['initial', 'initial_from_field']) { + foreach ($schema as $key => &$value) { + if (is_array($value)) { + $this->removeIrrelevantSchemaKeys($value, $remove_keys); + } + else { + if (in_array($key, $remove_keys, TRUE)) { + unset($schema[$key]); + } + } + } + return $schema; } /** diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 96765e1..d9df274 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -1653,7 +1653,6 @@ function system_update_8014() { */ function system_update_8018() { foreach (\Drupal::entityTypeManager()->getDefinitions() as $entity_type_id => $entity_type) { - /** @var \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface $manager */ $manager = \Drupal::entityDefinitionUpdateManager(); @@ -1666,14 +1665,6 @@ function system_update_8018() { // Update the existing uuid field which has a new schema. if ($entity_type->hasKey('uuid') && $definition = $manager->getFieldStorageDefinition('uuid', $entity_type_id)) { - - // @TODO, see if we can remove this because right now SqlEntityStorageSchema::requiresFieldStorageSchemaChanges() - // compares the schemas directly and prevents the update. - $schema = $definition->getSchema(); - $schema['columns']['value']['initial_from_field'] = 'UUID()'; - $property = new ReflectionProperty($definition, 'schema'); - $property->setAccessible(TRUE); - $property->setValue($definition, $schema); $manager->updateFieldStorageDefinition($definition); } }