diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php index ec3ebaf..63af197 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php @@ -1153,7 +1153,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); } } } diff --git a/core/modules/block_content/block_content.install b/core/modules/block_content/block_content.install index 4279cde..2d7d37c 100644 --- a/core/modules/block_content/block_content.install +++ b/core/modules/block_content/block_content.install @@ -61,3 +61,13 @@ 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/block_content/src/Entity/BlockContent.php b/core/modules/block_content/src/Entity/BlockContent.php index 23dc1ca..1da567d 100644 --- a/core/modules/block_content/src/Entity/BlockContent.php +++ b/core/modules/block_content/src/Entity/BlockContent.php @@ -161,7 +161,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setDescription(t('The block type.')); $fields['revision_uuid'] = BaseFieldDefinition::create('uuid') - ->setLabel(t('UUID')) + ->setLabel(t('Revision UUID')) ->setDescription(t('The revision UUID.')) ->setReadOnly(TRUE); diff --git a/core/modules/node/node.install b/core/modules/node/node.install index c754880..758a6d8 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -218,3 +218,13 @@ 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/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/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/Tests/Core/Entity/EntityTypeTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php index 8ee7478..a6cbbed 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' => '')), ); } diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php index 02970d7..c794c57 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php @@ -92,6 +92,13 @@ class SqlContentEntityStorageTest extends UnitTestCase { protected $connection; /** + * The UUID service. + * + * @var \Drupal\Component\Uuid\UuidInterface + */ + protected $uuidService; + + /** * {@inheritdoc} */ protected function setUp() { @@ -113,6 +120,7 @@ protected function setUp() { $this->connection = $this->getMockBuilder('Drupal\Core\Database\Connection') ->disableOriginalConstructor() ->getMock(); + $this->uuidService = $this->getMock('Drupal\Component\Uuid\UuidInterface'); } /** @@ -342,7 +350,7 @@ public function testOnEntityTypeCreate() { ->will($this->returnValue($schema_handler)); $storage = $this->getMockBuilder('Drupal\Core\Entity\Sql\SqlContentEntityStorage') - ->setConstructorArgs(array($this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager)) + ->setConstructorArgs(array($this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager, $this->uuidService)) ->setMethods(array('getStorageSchema')) ->getMock(); @@ -520,6 +528,7 @@ public function testGetTableMappingRevisionable(array $entity_keys) { 'revision' => 'test_revision', 'bundle' => $entity_keys['bundle'], 'uuid' => $entity_keys['uuid'], + 'revision_uuid' => 'test_revision_uuid', ); $this->entityType->expects($this->exactly(2)) @@ -532,6 +541,7 @@ public function testGetTableMappingRevisionable(array $entity_keys) { array('uuid', $entity_keys['uuid']), array('bundle', $entity_keys['bundle']), array('revision', $entity_keys['revision']), + array('revision_uuid', $entity_keys['revision_uuid']), ))); $this->setUpEntityStorage(); @@ -543,7 +553,7 @@ public function testGetTableMappingRevisionable(array $entity_keys) { $expected = array_values(array_filter($entity_keys)); $this->assertEquals($expected, $mapping->getFieldNames('entity_test')); - $expected = array($entity_keys['id'], $entity_keys['revision']); + $expected = array($entity_keys['id'], $entity_keys['revision'], $entity_keys['revision_uuid']); $this->assertEquals($expected, $mapping->getFieldNames('entity_test_revision')); $this->assertEquals(array(), $mapping->getExtraColumns('entity_test')); @@ -568,6 +578,7 @@ public function testGetTableMappingRevisionableWithFields(array $entity_keys) { 'revision' => 'test_revision', 'bundle' => $entity_keys['bundle'], 'uuid' => $entity_keys['uuid'], + 'revision_uuid' => 'test_revision_uuid', ); // PHPUnit does not allow for multiple data providers. @@ -602,6 +613,7 @@ public function testGetTableMappingRevisionableWithFields(array $entity_keys) { array('uuid', $entity_keys['uuid']), array('bundle', $entity_keys['bundle']), array('revision', $entity_keys['revision']), + array('revision_uuid', $entity_keys['revision_uuid']), ))); $this->setUpEntityStorage(); @@ -613,7 +625,7 @@ public function testGetTableMappingRevisionableWithFields(array $entity_keys) { $this->assertEquals($field_names, $mapping->getFieldNames('entity_test')); $expected = array_merge( - array($entity_keys['id'], $entity_keys['revision']), + array($entity_keys['id'], $entity_keys['revision'], $entity_keys['revision_uuid']), $revisionable_field_names, $revision_metadata_field_names ); @@ -756,6 +768,7 @@ public function testGetTableMappingRevisionableTranslatable(array $entity_keys) $entity_keys = array( 'id' => $entity_keys['id'], 'revision' => 'test_revision', + 'revision_uuid' => 'test_revision_uuid', 'bundle' => $entity_keys['bundle'], 'uuid' => $entity_keys['uuid'], 'langcode' => 'langcode', @@ -777,6 +790,7 @@ public function testGetTableMappingRevisionableTranslatable(array $entity_keys) array('uuid', $entity_keys['uuid']), array('bundle', $entity_keys['bundle']), array('revision', $entity_keys['revision']), + array('revision_uuid', $entity_keys['revision_uuid']), array('langcode', $entity_keys['langcode']), ))); @@ -798,6 +812,7 @@ public function testGetTableMappingRevisionableTranslatable(array $entity_keys) $entity_keys['revision'], $entity_keys['bundle'], $entity_keys['uuid'], + $entity_keys['revision_uuid'], $entity_keys['langcode'], ))); $actual = $mapping->getFieldNames('entity_test'); @@ -807,6 +822,7 @@ public function testGetTableMappingRevisionableTranslatable(array $entity_keys) $expected = array_values(array_filter(array( $entity_keys['id'], $entity_keys['revision'], + $entity_keys['revision_uuid'], $entity_keys['langcode'], ))); $actual = $mapping->getFieldNames('entity_test_revision'); @@ -856,6 +872,7 @@ public function testGetTableMappingRevisionableTranslatableWithFields(array $ent $entity_keys = array( 'id' => $entity_keys['id'], 'revision' => 'test_revision', + 'revision_uuid' => 'test_revision_uuid', 'bundle' => $entity_keys['bundle'], 'uuid' => $entity_keys['uuid'], 'langcode' => 'langcode', @@ -898,6 +915,7 @@ public function testGetTableMappingRevisionableTranslatableWithFields(array $ent array('uuid', $entity_keys['uuid']), array('bundle', $entity_keys['bundle']), array('revision', $entity_keys['revision']), + array('revision_uuid', $entity_keys['revision_uuid']), array('langcode', $entity_keys['langcode']), ))); @@ -927,6 +945,7 @@ public function testGetTableMappingRevisionableTranslatableWithFields(array $ent $entity_keys['revision'], $entity_keys['bundle'], $entity_keys['uuid'], + $entity_keys['revision_uuid'], $entity_keys['langcode'], ))); $actual = $mapping->getFieldNames('entity_test'); @@ -936,6 +955,7 @@ public function testGetTableMappingRevisionableTranslatableWithFields(array $ent $expected = array_merge(array_filter(array( $entity_keys['id'], $entity_keys['revision'], + $entity_keys['revision_uuid'], $entity_keys['langcode'], )), $revision_metadata_field_names); $actual = $mapping->getFieldNames('entity_test_revision'); @@ -1085,7 +1105,7 @@ protected function setUpEntityStorage() { ->method('getBaseFieldDefinitions') ->will($this->returnValue($this->fieldDefinitions)); - $this->entityStorage = new SqlContentEntityStorage($this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager); + $this->entityStorage = new SqlContentEntityStorage($this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager, $this->uuidService); } /** @@ -1162,7 +1182,7 @@ public function testLoadMultipleNoPersistentCache() { ->method('set'); $entity_storage = $this->getMockBuilder('Drupal\Core\Entity\Sql\SqlContentEntityStorage') - ->setConstructorArgs(array($this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager)) + ->setConstructorArgs(array($this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager, $this->uuidService)) ->setMethods(array('getFromStorage', 'invokeStorageLoadHook')) ->getMock(); $entity_storage->method('invokeStorageLoadHook') @@ -1214,7 +1234,7 @@ public function testLoadMultiplePersistentCacheMiss() { ->with($key, $entity, CacheBackendInterface::CACHE_PERMANENT, array($this->entityTypeId . '_values', 'entity_field_info')); $entity_storage = $this->getMockBuilder('Drupal\Core\Entity\Sql\SqlContentEntityStorage') - ->setConstructorArgs(array($this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager)) + ->setConstructorArgs(array($this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager, $this->uuidService)) ->setMethods(array('getFromStorage', 'invokeStorageLoadHook')) ->getMock(); $entity_storage->method('invokeStorageLoadHook') @@ -1271,7 +1291,7 @@ public function testHasData() { ->method('getBaseFieldDefinitions') ->will($this->returnValue($this->fieldDefinitions)); - $this->entityStorage = new SqlContentEntityStorage($this->entityType, $database, $this->entityManager, $this->cache, $this->languageManager); + $this->entityStorage = new SqlContentEntityStorage($this->entityType, $database, $this->entityManager, $this->cache, $this->languageManager, $this->uuidService); $result = $this->entityStorage->hasData();