diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchemaConverter.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchemaConverter.php index ea0f57c..a589f56 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchemaConverter.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchemaConverter.php @@ -245,6 +245,7 @@ protected function copyData(array &$sandbox) { $original_base_table = $original_entity_type->getBaseTable(); $revision_id_key = $temporary_entity_type->getKey('revision'); + $revision_translation_affected_key = $temporary_entity_type->getKey('revision_translation_affected'); // If 'progress' is not set, then this will be the first run of the batch. if (!isset($sandbox['progress'])) { @@ -287,6 +288,11 @@ protected function copyData(array &$sandbox) { // Set the revision ID to be same as the entity ID. $entity->set($revision_id_key, $entity_id); + // Set the 'revision_translation_affected' flag to TRUE to match the + // previous API return value: if the field was not defined the value + // returned was always TRUE. + $entity->set($revision_translation_affected_key, TRUE); + // Treat the entity as new in order to make the storage do an INSERT // rather than an UPDATE. $entity->enforceIsNew(TRUE); @@ -386,8 +392,8 @@ protected function updateFieldStorageDefinitionsToRevisionable(ContentEntityType if ($update_cached_definitions) { $this->entityDefinitionUpdateManager->installFieldStorageDefinition($revision_translation_affected_field->getName(), $entity_type->id(), $entity_type->getProvider(), $revision_translation_affected_field); - $updated_storage_definitions[$entity_type->getKey('revision_translation_affected')] = $revision_translation_affected_field; } + $updated_storage_definitions[$entity_type->getKey('revision_translation_affected')] = $revision_translation_affected_field; } return $updated_storage_definitions; diff --git a/core/modules/system/src/Tests/Entity/Update/SqlContentEntityStorageSchemaConverterTest.php b/core/modules/system/src/Tests/Entity/Update/SqlContentEntityStorageSchemaConverterTest.php index 014f995..b6a8695 100644 --- a/core/modules/system/src/Tests/Entity/Update/SqlContentEntityStorageSchemaConverterTest.php +++ b/core/modules/system/src/Tests/Entity/Update/SqlContentEntityStorageSchemaConverterTest.php @@ -107,6 +107,10 @@ public function testMakeRevisionable() { $this->assertEqual($i, $revision->id()); $this->assertEqual($i, $revision->getRevisionId()); + // Check that the correct initial value was provided for the + // 'revision_translation_affected' field. + $this->assertTrue($revision->revision_translation_affected->value); + $this->assertEqual($i . ' - test single property', $revision->test_single_property->value); $this->assertEqual($i . ' - test multiple properties - value1', $revision->test_multiple_properties->value1); diff --git a/core/modules/system/src/Tests/Update/EntityUpdateAddRevisionTranslationAffected.php b/core/modules/system/src/Tests/Update/EntityUpdateAddRevisionTranslationAffected.php new file mode 100644 index 0000000..ad405de --- /dev/null +++ b/core/modules/system/src/Tests/Update/EntityUpdateAddRevisionTranslationAffected.php @@ -0,0 +1,88 @@ +entityManager = \Drupal::entityManager(); + $this->lastInstalledSchemaRepository = \Drupal::service('entity.last_installed_schema.repository'); + $this->state = \Drupal::state(); + } + + /** + * {@inheritdoc} + */ + protected function setDatabaseDumpFiles() { + $this->databaseDumpFiles = [ + __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.0.0-rc1-filled.standard.entity_test_update_mul_rev.php.gz', + ]; + } + + /** + * Tests the addition of the 'revision_translation_affected' base field. + * + * @covers system_update_8402 + */ + public function testAddingTheRevisionTranslationAffectedField() { + // Make the entity type revisionable and translatable prior to running the + // updates. + $this->updateEntityTypeToRevisionableAndTranslatable(); + + // Check that the test entity type does not have the + // 'revision_translation_affected' field before running the updates. + $field_storage_definitions = $this->lastInstalledSchemaRepository->getLastInstalledFieldStorageDefinitions('entity_test_update'); + $this->assertFalse(isset($field_storage_definitions['revision_translation_affected'])); + + $this->runUpdates(); + + // Check that the 'revision_translation_affected' field has been added by + // system_update_8402(). + $field_storage_definitions = $this->lastInstalledSchemaRepository->getLastInstalledFieldStorageDefinitions('entity_test_update'); + $this->assertTrue(isset($field_storage_definitions['revision_translation_affected'])); + + // Check that the correct initial value was set when the field was + // installed. + $entity = \Drupal::entityTypeManager()->getStorage('entity_test_update')->load(1); + $this->assertTrue($entity->revision_translation_affected->value); + } + +} diff --git a/core/modules/system/src/Tests/Update/EntityUpdateToRevisionableAndPublishableTest.php b/core/modules/system/src/Tests/Update/EntityUpdateToRevisionableAndPublishableTest.php index 37fcfb0..3edf6f7 100644 --- a/core/modules/system/src/Tests/Update/EntityUpdateToRevisionableAndPublishableTest.php +++ b/core/modules/system/src/Tests/Update/EntityUpdateToRevisionableAndPublishableTest.php @@ -79,7 +79,6 @@ protected function setDatabaseDumpFiles() { * Tests the conversion of an entity type to revisionable and publishable. * * @covers entity_test_update_update_8400 - * @covers system_update_8402 */ public function testConvertToRevisionableAndPublishable() { // Check that entity type is not revisionable nor publishable prior to @@ -103,11 +102,6 @@ public function testConvertToRevisionableAndPublishable() { $storage = \Drupal::entityTypeManager()->getStorage('entity_test_update'); $this->assertEqual(count($storage->loadMultiple()), 102, 'All test entities were found.'); - // Check that the 'revision_translation_affected' field has been added by - // system_update_8402(). - $field_storage_definitions = $this->lastInstalledSchemaRepository->getLastInstalledFieldStorageDefinitions('entity_test_update'); - $this->assertTrue(isset($field_storage_definitions['revision_translation_affected'])); - // The conversion to revisionable is already tested by // \Drupal\system\Tests\Entity\Update\SqlContentEntityStorageSchemaConverterTest::testMakeRevisionable() // so we only need to check that some special cases are handled. diff --git a/core/modules/system/tests/modules/entity_test_update/entity_test_update.module b/core/modules/system/tests/modules/entity_test_update/entity_test_update.module index 5b32eb8..225c549 100644 --- a/core/modules/system/tests/modules/entity_test_update/entity_test_update.module +++ b/core/modules/system/tests/modules/entity_test_update/entity_test_update.module @@ -79,6 +79,11 @@ function entity_test_update_entity_presave(EntityInterface $entity) { * (e.g. content_translation_status); * - 52 more test entities (with the IDs 51 - 102) crated, translated and saved. * + * The 'drupal-8.0.0-rc1-filled.standard.entity_test_update_mul_rev.php.gz' db + * dump was created like the multilingual one described above, with one change: + * The annotation of the entity_test_update entity type was also manually edited + * in order to make it revisionable. + * * @param int $start * (optional) The entity ID to start from. Defaults to 1. * @param int $end