diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php index 63af197..ba48469 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php @@ -174,6 +174,8 @@ protected function hasSharedTableNameChanges(EntityTypeInterface $entity_type, E public function requiresFieldStorageSchemaChanges(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) { $table_mapping = $this->storage->getTableMapping(); + // @TODO, move the getSchema() check into a hasSchemaChanged() function so + // we can filter out initial and initial_from_field. if ( $storage_definition->hasCustomStorage() != $original->hasCustomStorage() || $storage_definition->getSchema() != $original->getSchema() || @@ -1946,7 +1948,17 @@ protected function isTableEmpty($table_name) { * Returns TRUE if there are schema changes in the column definitions. */ protected function hasColumnChanges(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) { - if ($storage_definition->getColumns() != $original->getColumns()) { + $new_columns = $storage_definition->getColumns(); + $original_columns = $original->getColumns(); + foreach ($new_columns as $delta => $column) { + foreach ($column as $key => $value) { + if (!in_array($key, $this->getColumnSchemaRelevantKeys(), TRUE)) { + unset($new_columns[$delta][$key]); + unset($original_columns[$delta][$key]); + } + } + } + if ($new_columns != $original_columns) { // Base field definitions have schema data stored in the original // definition. return TRUE; diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UuidItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UuidItem.php index 94aa8aa..b7daa16 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UuidItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UuidItem.php @@ -45,6 +45,7 @@ public function applyDefaultValue($notify = TRUE) { public static function schema(FieldStorageDefinitionInterface $field_definition) { $schema = parent::schema($field_definition); $schema['unique keys']['value'] = array('value'); + $schema['columns']['value']['initial_from_field'] = 'UUID()'; return $schema; } diff --git a/core/modules/block_content/block_content.install b/core/modules/block_content/block_content.install index 2d7d37c..4279cde 100644 --- a/core/modules/block_content/block_content.install +++ b/core/modules/block_content/block_content.install @@ -61,13 +61,3 @@ function block_content_update_8003() { \Drupal::entityDefinitionUpdateManager() ->installFieldStorageDefinition('revision_user', 'block_content', 'block_content', $revision_user); } - -/** - * Install new revision_uuid schema. - */ -function block_content_update_8004() { - /** @var \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface $manager */ - $manager = \Drupal::entityDefinitionUpdateManager(); - $manager->updateEntityType($manager->getEntityType('block_content')); - $manager->installFieldStorageDefinition('revision_uuid', 'block_content', 'block_content', \Drupal::service('entity_field.manager')->getFieldStorageDefinitions('block_content')['revision_uuid']); -} diff --git a/core/modules/node/node.install b/core/modules/node/node.install index 758a6d8..c754880 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -218,13 +218,3 @@ function node_update_8003() { $manager->updateFieldStorageDefinition($manager->getFieldStorageDefinition($field_name, 'node')); } } - -/** - * Install new revision_uuid schema. - */ -function node_update_8004() { - /** @var \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface $manager */ - $manager = \Drupal::entityDefinitionUpdateManager(); - $manager->updateEntityType($manager->getEntityType('node')); - $manager->installFieldStorageDefinition('revision_uuid', 'node', 'node', \Drupal::service('entity_field.manager')->getFieldStorageDefinitions('node')['revision_uuid']); -} diff --git a/core/modules/system/src/Tests/Update/UpdatePathTestBase.php b/core/modules/system/src/Tests/Update/UpdatePathTestBase.php index 82169ad..0401991 100644 --- a/core/modules/system/src/Tests/Update/UpdatePathTestBase.php +++ b/core/modules/system/src/Tests/Update/UpdatePathTestBase.php @@ -270,6 +270,7 @@ protected function runUpdates() { if ($needs_updates) { foreach (\Drupal::entityDefinitionUpdateManager()->getChangeSummary() as $entity_type_id => $summary) { foreach ($summary as $message) { + debug($entity_type_id); $this->fail($message); } } diff --git a/core/modules/system/system.install b/core/modules/system/system.install index b3a0ec1..e1da665 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -1647,3 +1647,35 @@ function system_update_8014() { /** * @} End of "addtogroup updates-8.0.0-rc". */ + +/** + * Install new revision_uuid schema. + */ +function system_update_8018() { + foreach (\Drupal::entityTypeManager()->getDefinitions() as $entity_type_id => $entity_type) { + + /** @var \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface $manager */ + $manager = \Drupal::entityDefinitionUpdateManager(); + $field_manager = \Drupal::service('entity_field.manager'); + $manager->updateEntityType($manager->getEntityType($entity_type_id)); + + // Install the new revision_uuid field. + if ($entity_type->hasKey('revision_uuid')) { + $field_storage_definitions = $field_manager->getFieldStorageDefinitions($entity_type_id); + $manager->installFieldStorageDefinition($entity_type->getKey('revision_uuid'), $entity_type_id, $entity_type->getProvider(), $field_storage_definitions[$entity_type->getKey('revision_uuid')]); + } + + // 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); + } + } +} diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php index 63ac58d..0e5fe1b 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php @@ -570,6 +570,9 @@ protected function doTestDataStructureInterfaces($entity_type) { // Field format. NULL, ); + if ($uuid = $entity->getRevisionUuid()) { + $target_strings[] = $uuid; + } asort($strings); asort($target_strings); $this->assertEqual(array_values($strings), array_values($target_strings), format_string('%entity_type: All contained strings found.', array('%entity_type' => $entity_type))); diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityUUIDTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityUUIDTest.php index 5b0a643..4a038e1 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityUUIDTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityUUIDTest.php @@ -93,6 +93,10 @@ protected function assertCRUD($entity_type) { $this->assertNotEqual($entity_duplicate->getRevisionId(), $entity->getRevisionId()); $this->assertNotEqual($entity_duplicate->{$property}->getValue(), $entity->{$property}->getValue()); break; + case 'revision_uuid': + $this->assertNotNull($entity->getRevisionUuid()); + $this->assertNotEqual($entity_duplicate->getRevisionUuid(), $entity->getRevisionUuid()); + break; default: $this->assertEqual($entity_duplicate->{$property}->getValue(), $entity->{$property}->getValue()); }