diff --git a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php index e71b74d..13fce61 100644 --- a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php +++ b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php @@ -166,7 +166,6 @@ public static function open(array &$connection_options = array()) { return $pdo; } - /** * Destructor for the SQLite connection. * diff --git a/core/lib/Drupal/Core/Database/Schema.php b/core/lib/Drupal/Core/Database/Schema.php index 8b9eb7e..c4bba41 100644 --- a/core/lib/Drupal/Core/Database/Schema.php +++ b/core/lib/Drupal/Core/Database/Schema.php @@ -305,7 +305,7 @@ public function fieldExists($table, $column) { * created field will be set to the value of the key in all rows. * This is most useful for creating NOT NULL columns with no default * value in existing tables. - * Alternatively, the 'initial_form_field' key may be used, which will + * Alternatively, the 'initial_from_field' key may be used, which will * auto-populate the new field with values from the specified field. * @param $keys_new * (optional) Keys and indexes specification to be created on the diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index 1d69be2..444684c 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -17,7 +17,7 @@ * * @ingroup entity_api */ -abstract class ContentEntityBase extends Entity implements \IteratorAggregate, ContentEntityInterface, TranslationStatusInterface { +abstract class ContentEntityBase extends Entity implements \IteratorAggregate, ContentEntityInterface, TranslationStatusInterface, RevisionUuidInterface { /** * The plain data values of the contained fields. @@ -257,6 +257,11 @@ public function setNewRevision($value = TRUE) { // to ensure that a new revision will actually be created. $this->set($this->getEntityType()->getKey('revision'), NULL); + if ($this->getEntityType()->hasKey('revision_uuid')) { + // Also generate a new revision uuid. + $this->set($this->getEntityType()->getKey('revision_uuid'), \Drupal::service('uuid')->generate()); + } + // Make sure that the flag tracking which translations are affected by the // current revision is reset. foreach ($this->translations as $langcode => $data) { @@ -324,6 +329,13 @@ public function getRevisionId() { /** * {@inheritdoc} */ + public function getRevisionUuid() { + return $this->getEntityKey('revision_uuid'); + } + + /** + * {@inheritdoc} + */ public function isTranslatable() { // Check that the bundle is translatable, the entity has a language defined // and if we have more than one language on the site. @@ -1025,6 +1037,12 @@ public function createDuplicate() { // Check whether the entity type supports revisions and initialize it if so. if ($entity_type->isRevisionable()) { $duplicate->{$entity_type->getKey('revision')}->value = NULL; + + // Check if the entity type supports revision UUIDs and generate a new one + // if so. + if ($entity_type->hasKey('revision_uuid')) { + $duplicate->{$entity_type->getKey('revision_uuid')}->value = $this->uuidGenerator()->generate(); + } } return $duplicate; @@ -1167,6 +1185,12 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setReadOnly(TRUE) ->setSetting('unsigned', TRUE); } + if ($entity_type->hasKey('revision_uuid')) { + $fields[$entity_type->getKey('revision_uuid')] = BaseFieldDefinition::create('uuid') + ->setLabel(new TranslatableMarkup('Revision UUID')) + ->setRevisionable(TRUE) + ->setReadOnly(TRUE); + } if ($entity_type->hasKey('langcode')) { $fields[$entity_type->getKey('langcode')] = BaseFieldDefinition::create('language') ->setLabel(new TranslatableMarkup('Language')) @@ -1246,7 +1270,7 @@ public function hasTranslationChanges() { foreach ($this->getFieldDefinitions() as $field_name => $definition) { // @todo Avoid special-casing the following fields. See // https://www.drupal.org/node/2329253. - if ($field_name == 'revision_translation_affected' || $field_name == 'revision_id') { + if ($field_name == 'revision_translation_affected' || $field_name == 'revision_id' || ($this->getEntityType()->hasKey('revision_uuid') && $field_name == $this->getEntityType()->getKey('revision_uuid'))) { continue; } if (!$definition->isComputed() && (!$translated || $definition->isTranslatable())) { diff --git a/core/lib/Drupal/Core/Entity/EntityType.php b/core/lib/Drupal/Core/Entity/EntityType.php index 89b83cf..384dbb4 100644 --- a/core/lib/Drupal/Core/Entity/EntityType.php +++ b/core/lib/Drupal/Core/Entity/EntityType.php @@ -288,10 +288,12 @@ public function __construct($definition) { // Ensure defaults. $this->entity_keys += array( 'revision' => '', + 'revision_uuid' => '', 'bundle' => '', 'langcode' => '', 'default_langcode' => 'default_langcode', ); + $this->handlers += array( 'access' => 'Drupal\Core\Entity\EntityAccessControlHandler', ); diff --git a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php index c6336c9..e267ebd 100644 --- a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php @@ -88,6 +88,8 @@ public function getOriginalClass(); * revision ID of the entity. The Field API assumes that all revision IDs * are unique across all entities of a type. If this entry is omitted * the entities of this type are not revisionable. + * - revision_uuid: (optional) The name of the property that contains the + * revision UUID of the entity. * - bundle: (optional) The name of the property that contains the bundle * name for the entity. The bundle name defines which set of fields are * attached to the entity (e.g. what nodes call "content type"). This diff --git a/core/lib/Drupal/Core/Entity/RevisionUuidInterface.php b/core/lib/Drupal/Core/Entity/RevisionUuidInterface.php new file mode 100644 index 0000000..3dcbcb8 --- /dev/null +++ b/core/lib/Drupal/Core/Entity/RevisionUuidInterface.php @@ -0,0 +1,25 @@ +tableMapping = NULL; $this->revisionKey = NULL; + $this->revisionUuidKey = NULL; $this->revisionTable = NULL; $this->dataTable = NULL; $this->revisionDataTable = NULL; @@ -180,6 +188,7 @@ protected function initTableLayout() { $revisionable = $this->entityType->isRevisionable(); if ($revisionable) { $this->revisionKey = $this->entityType->getKey('revision') ?: 'revision_id'; + $this->revisionUuidKey = $this->entityType->getKey('revision_uuid'); $this->revisionTable = $this->entityType->getRevisionTable() ?: $this->entityTypeId . '_revision'; } $translatable = $this->entityType->isTranslatable(); @@ -317,7 +326,10 @@ public function getTableMapping(array $storage_definitions = NULL) { // together with the entity ID and the revision ID as identifiers. $table_mapping->setFieldNames($this->baseTable, array_diff($all_fields, $revision_metadata_fields)); $revision_key_fields = array($this->idKey, $this->revisionKey); - $table_mapping->setFieldNames($this->revisionTable, array_merge($revision_key_fields, $revisionable_fields)); + if (!empty($this->revisionUuidKey)) { + $revision_key_fields[] = $this->revisionUuidKey; + } + $table_mapping->setFieldNames($this->revisionTable, array_unique(array_merge($revision_key_fields, $revisionable_fields))); } elseif (!$revisionable && $translatable) { // Multilingual layouts store key field values in the base table. The @@ -343,15 +355,18 @@ public function getTableMapping(array $storage_definitions = NULL) { // Like in the multilingual, non-revisionable case the UUID is not // in the data table. Additionally, do not store revision metadata // fields in the data table. - $data_fields = array_values(array_diff($all_fields, array($this->uuidKey), $revision_metadata_fields)); + $data_fields = array_values(array_diff($all_fields, array($this->uuidKey, $this->revisionUuidKey), $revision_metadata_fields)); $table_mapping->setFieldNames($this->dataTable, $data_fields); $revision_base_fields = array_merge(array($this->idKey, $this->revisionKey, $this->langcodeKey), $revision_metadata_fields); + if (!empty($this->revisionUuidKey)) { + $revision_base_fields[] = $this->revisionUuidKey; + } $table_mapping->setFieldNames($this->revisionTable, $revision_base_fields); $revision_data_key_fields = array($this->idKey, $this->revisionKey, $this->langcodeKey); - $revision_data_fields = array_diff($revisionable_fields, $revision_metadata_fields, array($this->langcodeKey)); - $table_mapping->setFieldNames($this->revisionDataTable, array_merge($revision_data_key_fields, $revision_data_fields)); + $revision_data_fields = array_diff($revisionable_fields, $revision_metadata_fields, array($this->langcodeKey, $this->revisionUuidKey)); + $table_mapping->setFieldNames($this->revisionDataTable, array_unique(array_merge($revision_data_key_fields, $revision_data_fields))); } // Add dedicated tables. diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php index f43461f..504ee92 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php @@ -192,7 +192,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; } /** @@ -1153,7 +1186,9 @@ protected function createSharedTableSchema(FieldStorageDefinitionInterface $stor } if (!empty($schema[$table_name]['unique keys'])) { foreach ($schema[$table_name]['unique keys'] as $name => $specifier) { - $schema_handler->addUniqueKey($table_name, $name, $specifier); + // Check if the unique key exists because it might already have + // been created as part of the earlier entity type update event. + $this->addUniqueKey($table_name, $name, $specifier); } } } @@ -1944,7 +1979,19 @@ 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()) { + // Remove any fields that can be changed in the column array structure such + // as initial. + $new_columns = $storage_definition->getColumns(); + $original_columns = $original->getColumns(); + foreach ($new_columns as $delta => $column) { + foreach ($column as $key => $value) { + if (in_array($key, ['initial', 'initial_from_field'], 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 8bd33ce..f591ad7 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UuidItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UuidItem.php @@ -4,6 +4,7 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Field\FieldDefinitionInterface; +use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; /** * Defines the 'uuid' entity field type. @@ -46,6 +47,19 @@ public function applyDefaultValue($notify = TRUE) { public static function schema(FieldStorageDefinitionInterface $field_definition) { $schema = parent::schema($field_definition); $schema['unique keys']['value'] = array('value'); + + // @todo inject an initial value in a better way. + try { + $entity_type = \Drupal::entityTypeManager() + ->getDefinition($field_definition->getTargetEntityTypeId()); + if ($entity_type->hasKey('revision') && $entity_type->getKey('revision_uuid') == $field_definition->getName()) { + $schema['columns']['value']['initial_from_field'] = $entity_type->getKey('revision'); + } + } + catch (ServiceNotFoundException $exception) { + // Just a hack to get \Drupal\Tests\views\Unit\EntityViewsDataTest passing. + } + return $schema; } diff --git a/core/modules/block_content/block_content.install b/core/modules/block_content/block_content.install index 4279cde..363675a 100644 --- a/core/modules/block_content/block_content.install +++ b/core/modules/block_content/block_content.install @@ -6,6 +6,7 @@ */ use Drupal\Core\Field\BaseFieldDefinition; +use Drupal\Core\StringTranslation\TranslatableMarkup; /** * Add 'revision_translation_affected' field to 'block_content' entities. @@ -61,3 +62,19 @@ function block_content_update_8003() { \Drupal::entityDefinitionUpdateManager() ->installFieldStorageDefinition('revision_user', 'block_content', 'block_content', $revision_user); } + +/** + * Install revision_uuid base field. + */ +function block_content_update_8300() { + $revision_uuid = BaseFieldDefinition::create('uuid') + ->setLabel(new TranslatableMarkup('Revision UUID')) + ->setRevisionable(TRUE) + ->setReadOnly(TRUE); + \Drupal::entityDefinitionUpdateManager()->installFieldStorageDefinition('revision_uuid', 'block_content', 'block_content', $revision_uuid); + + $state = \Drupal::state(); + $revision_uuid_update = $state->get('revision_uuid_update'); + $revision_uuid_update[] = 'block_content'; + $state->set('revision_uuid_update', $revision_uuid_update); +} diff --git a/core/modules/block_content/src/Entity/BlockContent.php b/core/modules/block_content/src/Entity/BlockContent.php index 13af342..d1cdbbd 100644 --- a/core/modules/block_content/src/Entity/BlockContent.php +++ b/core/modules/block_content/src/Entity/BlockContent.php @@ -45,6 +45,7 @@ * entity_keys = { * "id" = "id", * "revision" = "revision_id", + * "revision_uuid" = "revision_uuid", * "bundle" = "type", * "label" = "info", * "langcode" = "langcode", diff --git a/core/modules/block_content/src/Tests/BlockContentUpdateTest.php b/core/modules/block_content/src/Tests/BlockContentUpdateTest.php new file mode 100644 index 0000000..9cf871b --- /dev/null +++ b/core/modules/block_content/src/Tests/BlockContentUpdateTest.php @@ -0,0 +1,40 @@ +databaseDumpFiles = [ + __DIR__ . '/../../../system/tests/fixtures/update/drupal-8-rc1.filled.standard.php.gz', + ]; + } + + /** + * Tests block_content_update_8300(). + * + * @see block_content_update_8300() + */ + public function testRevisionUuidUpdate() { + $this->runUpdates(); + sleep(5); + $this->cronRun(); + + $block_contents = \Drupal::entityTypeManager()->getStorage('block_content')->loadMultiple(); + foreach ($block_contents as $block_content) { + $this->assertTrue(Uuid::isValid($block_content->get('revision_uuid')->value)); + } + } + +} diff --git a/core/modules/comment/src/CommentStorage.php b/core/modules/comment/src/CommentStorage.php index cc4fdcf..07e8287 100644 --- a/core/modules/comment/src/CommentStorage.php +++ b/core/modules/comment/src/CommentStorage.php @@ -2,6 +2,7 @@ namespace Drupal\comment; +use Drupal\Component\Uuid\UuidInterface; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Database\Connection; use Drupal\Core\Entity\EntityManagerInterface; @@ -43,6 +44,8 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn * Cache backend instance to use. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. + * @param \Drupal\Component\Uuid\UuidInterface $uuid_service + * The UUID service. */ public function __construct(EntityTypeInterface $entity_info, Connection $database, EntityManagerInterface $entity_manager, AccountInterface $current_user, CacheBackendInterface $cache, LanguageManagerInterface $language_manager) { parent::__construct($entity_info, $database, $entity_manager, $cache, $language_manager); diff --git a/core/modules/node/node.install b/core/modules/node/node.install index 2751b2c..661831f 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -6,7 +6,9 @@ */ use Drupal\Core\Database\Database; +use Drupal\Core\Entity\EntityFieldValueUpdater; use Drupal\Core\Field\BaseFieldDefinition; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\user\RoleInterface; /** @@ -253,5 +255,22 @@ function node_update_8301() { } /** + * Install revision_uuid base field. + */ +function node_update_8302() { + $revision_uuid = BaseFieldDefinition::create('uuid') + ->setLabel(new TranslatableMarkup('Revision UUID')) + ->setRevisionable(TRUE) + ->setReadOnly(TRUE); + \Drupal::entityDefinitionUpdateManager()->installFieldStorageDefinition('revision_uuid', 'node', 'node', $revision_uuid); + + + $state = \Drupal::state(); + $revision_uuid_update = $state->get('revision_uuid_update'); + $revision_uuid_update[] = 'node'; + $state->set('revision_uuid_update', $revision_uuid_update); +} + +/** * @} End of "addtogroup updates-8.3.x". */ diff --git a/core/modules/node/src/Entity/Node.php b/core/modules/node/src/Entity/Node.php index f034957..ad50d9f 100644 --- a/core/modules/node/src/Entity/Node.php +++ b/core/modules/node/src/Entity/Node.php @@ -51,6 +51,7 @@ * entity_keys = { * "id" = "nid", * "revision" = "vid", + * "revision_uuid" = "revision_uuid", * "bundle" = "type", * "label" = "title", * "langcode" = "langcode", diff --git a/core/modules/node/src/Tests/Update/NodeUpdateTest.php b/core/modules/node/src/Tests/Update/NodeUpdateTest.php index b8b30be..e1d8964 100644 --- a/core/modules/node/src/Tests/Update/NodeUpdateTest.php +++ b/core/modules/node/src/Tests/Update/NodeUpdateTest.php @@ -2,6 +2,7 @@ namespace Drupal\node\Tests\Update; +use Drupal\Component\Uuid\Uuid; use Drupal\system\Tests\Update\UpdatePathTestBase; /** @@ -16,7 +17,7 @@ class NodeUpdateTest extends UpdatePathTestBase { */ protected function setDatabaseDumpFiles() { $this->databaseDumpFiles = [ - __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8-rc1.bare.standard.php.gz', + __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8-rc1.filled.standard.php.gz', ]; } @@ -38,4 +39,19 @@ public function testPublishedEntityKey() { $this->assertEqual('status', $entity_type->getKey('published')); } + /** + * Tests node_update_8302(). + * + * @see node_update_8302() + */ + public function testRevisionUuidUpdate() { + $this->runUpdates(); + $this->cronRun(); + + $nodes = \Drupal::entityTypeManager()->getStorage('node')->loadMultiple(); + foreach ($nodes as $node) { + $this->assertTrue(Uuid::isValid($node->get('revision_uuid')->value)); + } + } + } diff --git a/core/modules/node/src/Tests/Views/FilterUidRevisionTest.php b/core/modules/node/src/Tests/Views/FilterUidRevisionTest.php index 017d5eb..083db64 100644 --- a/core/modules/node/src/Tests/Views/FilterUidRevisionTest.php +++ b/core/modules/node/src/Tests/Views/FilterUidRevisionTest.php @@ -35,7 +35,7 @@ public function testFilter() { $expected_result[] = array('nid' => $node->id()); $revision = clone $node; // Force to add a new revision. - $revision->set('vid', NULL); + $revision->setNewRevision(TRUE); $revision->set('revision_uid', $author->id()); $revision->save(); diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Node/NodeResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/Node/NodeResourceTestBase.php index d7651c4..45b2f04 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/Node/NodeResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Node/NodeResourceTestBase.php @@ -97,6 +97,9 @@ protected function getExpectedNormalizedEntity() { 'vid' => [ ['value' => 1], ], + 'revision_uuid' => [ + ['value' => $this->entity->getRevisionUuid()], + ], 'langcode' => [ [ 'value' => 'en', diff --git a/core/modules/system/src/Tests/Entity/EntityDefinitionTestTrait.php b/core/modules/system/src/Tests/Entity/EntityDefinitionTestTrait.php index 0123597..0dc7053 100644 --- a/core/modules/system/src/Tests/Entity/EntityDefinitionTestTrait.php +++ b/core/modules/system/src/Tests/Entity/EntityDefinitionTestTrait.php @@ -36,6 +36,7 @@ protected function updateEntityTypeToRevisionable() { $keys = $entity_type->getKeys(); $keys['revision'] = 'revision_id'; + $keys['revision_uuid'] = 'revision_uuid'; $entity_type->set('entity_keys', $keys); $this->state->set('entity_test_update.entity_type', $entity_type); diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 6dc2663..dde05e3 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -732,6 +732,16 @@ function system_requirements($phase) { $requirements['entity_update']['value'] = t('Mismatched entity and/or field definitions'); $requirements['entity_update']['description'] = t('The following changes were detected in the entity type and field definitions. @updates', ['@updates' => $entity_update_issues]); } + + $node_revision_uuid_update = \Drupal::state()->get('node:revision_uuid_update'); + $block_content_revision_uuid_update = \Drupal::state()->get('block_content:revision_uuid_update'); + if (!empty($node_revision_uuid_update) || !empty($block_content_revision_uuid_update)) { + $requirements['entity_field_value_update'] = [ + 'severity' => REQUIREMENT_WARNING, + 'value' => t('Field value updates required'), + 'description' => t('There are fields with the incorrect value which need updating.') + ]; + } } // Verify the update.php access setting @@ -1782,10 +1792,6 @@ function system_update_8202() { } /** - * @} End of "addtogroup updates-8.2.3". - */ - -/** * Add detailed cron logging configuration. */ function system_update_8203() { @@ -1794,3 +1800,7 @@ function system_update_8203() { ->set('logging', 1) ->save(TRUE); } + +/** + * @} End of "addtogroup updates-8.2.3". + */ diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 3c858f9..11d22a1 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -1289,6 +1289,36 @@ function system_cron() { // Clean up PHP storage. PhpStorageFactory::get('container')->garbageCollection(); PhpStorageFactory::get('service_container')->garbageCollection(); + + // Update revision_uuid field values + $state = \Drupal::state(); + $revision_uuid_update = $state->get('revision_uuid_update'); + foreach ($revision_uuid_update as $entity_type_id) { + $entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id); + $query = \Drupal::database() + ->select($entity_type->getRevisionTable(), 'revision_table') + ->fields('revision_table', [$entity_type->getKey('revision')]) + ->where('%revision = %revision_uuid', [ + '%revision' => $entity_type->getKey('revision'), + '%revision_uuid' => $entity_type->getKey('revision_uuid') + ]) + ->range(0, 100); + $revisions = $query->execute()->fetchCol(); + if ($revisions) { + foreach ($revisions as $revision) { + \Drupal::database() + ->update($this->entityType->getRevisionTable()) + ->fields([$this->entityType->getKey('revision_uuid') => \Drupal::service('uuid')->generate()]) + ->condition($this->entityType->getKey('revision'), $revision) + ->execute(); + } + } + else { + unset($revision_uuid_update[$entity_type->id()]); + $state->set('node:revision_uuid_update', $revision_uuid_update); + } + } + } /** diff --git a/core/modules/system/tests/modules/entity_schema_test/entity_schema_test.module b/core/modules/system/tests/modules/entity_schema_test/entity_schema_test.module index 45892a8..ecd9da6 100644 --- a/core/modules/system/tests/modules/entity_schema_test/entity_schema_test.module +++ b/core/modules/system/tests/modules/entity_schema_test/entity_schema_test.module @@ -20,6 +20,7 @@ function entity_schema_test_entity_type_alter(array &$entity_types) { $entity_type->set('data_table', 'entity_test_field_data'); $keys = $entity_type->getKeys(); $keys['revision'] = 'revision_id'; + $keys['revision_uuid'] = 'revision_uuid'; $entity_type->set('entity_keys', $keys); } } diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php index 23cf034..8b6b7e4 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php @@ -102,6 +102,7 @@ public function testEntityTypeUpdateWithoutData() { $expected = array( 'entity_test_update' => array( t('The %entity_type entity type needs to be updated.', ['%entity_type' => $this->entityManager->getDefinition('entity_test_update')->getLabel()]), + t('The %field_name field needs to be installed.', ['%field_name' => $this->entityManager->getFieldStorageDefinitions('entity_test_update')['revision_uuid']->getLabel()]), ), ); $this->assertEqual($this->entityDefinitionUpdateManager->getChangeSummary(), $expected); //, 'EntityDefinitionUpdateManager reports the expected change summary.'); diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php index 56af888..e51b132 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php @@ -572,6 +572,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 ae26ec5..2541264 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityUUIDTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityUUIDTest.php @@ -97,6 +97,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()); } diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php index d633afc..7f2f67a 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php @@ -117,9 +117,9 @@ public function providerTestSet() { */ public function providerTestGetKeys() { return array( - array(array(), array('revision' => '', 'bundle' => '', 'langcode' => '')), - array(array('id' => 'id'), array('id' => 'id', 'revision' => '', 'bundle' => '', 'langcode' => '')), - array(array('bundle' => 'bundle'), array('bundle' => 'bundle', 'revision' => '', 'langcode' => '')), + array(array(), array('revision' => '', 'revision_uuid' => '', 'bundle' => '', 'langcode' => '')), + array(array('id' => 'id'), array('id' => 'id', 'revision' => '', 'revision_uuid' => '', 'bundle' => '', 'langcode' => '')), + array(array('bundle' => 'bundle'), array('bundle' => 'bundle', 'revision' => '', 'revision_uuid' => '', 'langcode' => '')), ); }