diff --git a/core/modules/migrate/src/Plugin/migrate/destination/EntityRevision.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityRevision.php index 8195831..cd17ef1 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/EntityRevision.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityRevision.php @@ -46,6 +46,10 @@ protected function getEntity(Row $row, array $old_destination_id_values) { $row->getDestinationProperty($this->getKey('revision')); if (!empty($revision_id) && ($entity = $this->storage->loadRevision($revision_id))) { $entity->setNewRevision(FALSE); + + // Check if we're the default. + $default = $this->storage->load($entity->id()); + $entity->isDefaultRevision($default->getRevisionId() === $revision_id); } else { $entity_id = $row->getDestinationProperty($this->getKey('id')); @@ -59,9 +63,10 @@ protected function getEntity(Row $row, array $old_destination_id_values) { $entity->enforceIsNew(FALSE); $entity->setNewRevision(TRUE); + $entity->isDefaultRevision(FALSE); } + $this->updateEntity($entity, $row); - $entity->isDefaultRevision(FALSE); return $entity; } diff --git a/core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php b/core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php index ec3d0f2..462279e 100644 --- a/core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php +++ b/core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php @@ -49,6 +49,22 @@ protected function setUp() { $this->storage = $this->prophesize('\Drupal\Core\Entity\EntityStorageInterface'); $this->entityManager = $this->prophesize('\Drupal\Core\Entity\EntityManagerInterface'); $this->fieldTypeManager = $this->prophesize('\Drupal\Core\Field\FieldTypePluginManagerInterface'); + + // Add a mock for getting keys. + $entity_type = $this->prophesize('\Drupal\Core\Entity\EntityTypeInterface'); + $entity_type->getKey('id')->willReturn('nid'); + $entity_type->getKey('revision')->willReturn('vid'); + $this->storage->getEntityType()->willReturn($entity_type->reveal()); + + // Add the default revision of the entity. + // Claim to be revision 12 of node 5. + $default = $this->prophesize('\Drupal\Core\Entity\EntityInterface') + ->willImplement('\Drupal\Core\Entity\RevisionableInterface'); + $default->getRevisionId() + ->willReturn(12); + $default->id()->willReturn(5); + $this->storage->load(5) + ->willReturn($default->reveal()); } /** @@ -61,6 +77,14 @@ public function testGetEntityDestinationValues() { // Return a dummy because we don't care what gets called. $entity = $this->prophesize('\Drupal\Core\Entity\EntityInterface') ->willImplement('\Drupal\Core\Entity\RevisionableInterface'); + + // Make sure we check whether or not we're the default. + $entity->id()->willReturn(5); + $this->storage->load(5)->shouldBeCalled(); + $entity->isDefaultRevision(TRUE)->shouldBeCalled(); + + $entity->setNewRevision(FALSE)->shouldBeCalled(); + // Assert that the first ID from the destination values is used to load the // entity. $this->storage->loadRevision(12) @@ -80,19 +104,19 @@ public function testGetEntityUpdateRevision() { $entity = $this->prophesize('\Drupal\Core\Entity\EntityInterface') ->willImplement('\Drupal\Core\Entity\RevisionableInterface'); - $entity_type = $this->prophesize('\Drupal\Core\Entity\EntityTypeInterface'); - $entity_type->getKey('id')->willReturn('nid'); - $entity_type->getKey('revision')->willReturn('vid'); - $this->storage->getEntityType()->willReturn($entity_type->reveal()); - // Assert we load the correct revision. $this->storage->loadRevision(2) ->shouldBeCalled() ->willReturn($entity->reveal()); - // Make sure its set as an update and not the default revision. - $entity->setNewRevision(FALSE)->shouldBeCalled(); + + // Make sure we check whether or not we're the default. + $entity->id()->willReturn(5); + $this->storage->load(5)->shouldBeCalled(); $entity->isDefaultRevision(FALSE)->shouldBeCalled(); + // Make sure its set as an update. + $entity->setNewRevision(FALSE)->shouldBeCalled(); + $row = new Row(['nid' => 1, 'vid' => 2], ['nid' => 1, 'vid' => 2]); $row->setDestinationProperty('vid', 2); $this->assertEquals($entity->reveal(), $destination->getEntity($row, [])); @@ -108,11 +132,6 @@ public function testGetEntityNewRevision() { $entity = $this->prophesize('\Drupal\Core\Entity\EntityInterface') ->willImplement('\Drupal\Core\Entity\RevisionableInterface'); - $entity_type = $this->prophesize('\Drupal\Core\Entity\EntityTypeInterface'); - $entity_type->getKey('id')->willReturn('nid'); - $entity_type->getKey('revision')->willReturn('vid'); - $this->storage->getEntityType()->willReturn($entity_type->reveal()); - // Enforce is new should be disabled. $entity->enforceIsNew(FALSE)->shouldBeCalled(); // And toggle this as new revision but not the default revision. @@ -137,11 +156,6 @@ public function testGetEntityNewRevision() { public function testGetEntityLoadFailure() { $destination = $this->getEntityRevisionDestination([]); - $entity_type = $this->prophesize('\Drupal\Core\Entity\EntityTypeInterface'); - $entity_type->getKey('id')->willReturn('nid'); - $entity_type->getKey('revision')->willReturn('vid'); - $this->storage->getEntityType()->willReturn($entity_type->reveal()); - // Return a failed load and make sure we don't fail and we return FALSE. $this->storage->load(1) ->shouldBeCalled() diff --git a/core/modules/node/src/Tests/Migrate/d6/MigrateNodeRevisionTest.php b/core/modules/node/src/Tests/Migrate/d6/MigrateNodeRevisionTest.php index bb817b6..1bd17e6 100644 --- a/core/modules/node/src/Tests/Migrate/d6/MigrateNodeRevisionTest.php +++ b/core/modules/node/src/Tests/Migrate/d6/MigrateNodeRevisionTest.php @@ -87,6 +87,10 @@ public function testNodeRevision() { $languages = array_keys($node->getTranslationLanguages()); sort($languages); $this->assertIdentical(['en', 'fr'], $languages); + + // Check that the translations are actually present. + $this->assertIdentical('The Real McCoy', $node->title->value); + $this->assertIdentical('Le Vrai McCoy', $node->getTranslation('fr')->title->value); } /** diff --git a/core/modules/node/src/Tests/Migrate/d6/MigrateNodeTest.php b/core/modules/node/src/Tests/Migrate/d6/MigrateNodeTest.php index 104ad43..087c848 100644 --- a/core/modules/node/src/Tests/Migrate/d6/MigrateNodeTest.php +++ b/core/modules/node/src/Tests/Migrate/d6/MigrateNodeTest.php @@ -86,6 +86,7 @@ public function testNode() { $node = Node::load(9); $this->assertTrue($node instanceof NodeInterface); $this->assertIdentical('en', $node->langcode->value); + $this->assertIdentical('The Real McCoy', $node->title->value); // Node 10 is a translation of node 9, and should not be imported separately. $this->assertNull(Node::load(10));