diff --git a/core/modules/migrate_drupal/tests/src/Kernel/d6/MigrateDrupal6AuditIdsTest.php b/core/modules/migrate_drupal/tests/src/Kernel/d6/MigrateDrupal6AuditIdsTest.php index c6cd858508..256e469d13 100644 --- a/core/modules/migrate_drupal/tests/src/Kernel/d6/MigrateDrupal6AuditIdsTest.php +++ b/core/modules/migrate_drupal/tests/src/Kernel/d6/MigrateDrupal6AuditIdsTest.php @@ -6,7 +6,9 @@ use Drupal\migrate\Audit\AuditResult; use Drupal\migrate\Audit\IdAuditor; use Drupal\node\Entity\Node; +use Drupal\node\Entity\NodeType; use Drupal\Tests\migrate_drupal\Traits\CreateTestContentEntitiesTrait; +use Drupal\workflows\Entity\Workflow; /** * Tests the migration auditor for ID conflicts. @@ -33,8 +35,17 @@ protected function setUp() { $this->installSchema('book', ['book']); $this->installSchema('dblog', ['watchdog']); $this->installSchema('forum', ['forum_index']); + $this->installSchema('node', ['node_access']); $this->installSchema('search', ['search_dataset']); $this->installSchema('tracker', ['tracker_node', 'tracker_user']); + + // Enable content moderation for nodes of type page. + $this->installEntitySchema('content_moderation_state'); + $this->installConfig('content_moderation'); + NodeType::create(['type' => 'page'])->save(); + $workflow = Workflow::load('editorial'); + $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'page'); + $workflow->save(); } /** @@ -42,7 +53,9 @@ protected function setUp() { */ public function testMultipleMigrationWithoutIdConflicts() { // Create a node of type page. - Node::create(['type' => 'page', 'title' => 'foo'])->save(); + $node = Node::create(['type' => 'page', 'title' => 'foo']); + $node->moderation_state->value = 'published'; + $node->save(); // Insert data in the d6_node:page migration mappping table to simulate a // previously migrated node. @@ -127,4 +140,37 @@ function (AuditResult $result) { $this->assertEmpty(array_diff(array_filter($conflicts), $expected)); } + /** + * Tests draft revisions ID conflicts. + */ + public function testDraftRevisionIdConflicts() { + // Create a published node of type page. + $node = Node::create(['type' => 'page', 'title' => 'foo']); + $node->moderation_state->value = 'published'; + $node->save(); + + // Create a draft revision. + $node->moderation_state->value = 'draft'; + $node->setNewRevision(TRUE); + $node->save(); + + // Insert data in the d6_node_revision:page migration mappping table to + // simulate a previously migrated node revison. + $table_name = $this->getMigration('d6_node_revision:page')->getIdMap()->mapTableName(); + $this->container->get('database')->insert($table_name) + ->fields([ + 'source_ids_hash' => 1, + 'sourceid1' => 1, + 'destid1' => 1, + ]) + ->execute(); + + // Audit the IDs of the d6_node_revision migration. There should be + // conflicts since a draft revision has been created. + /** @var \Drupal\migrate\Audit\AuditResult $result */ + $result = (new IdAuditor())->audit($this->getMigration('d6_node_revision:page')); + $this->assertInstanceOf(AuditResult::class, $result); + $this->assertFalse($result->passed()); + } + } diff --git a/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7AuditIdsTest.php b/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7AuditIdsTest.php index 8a2431e957..377985a331 100644 --- a/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7AuditIdsTest.php +++ b/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7AuditIdsTest.php @@ -6,7 +6,9 @@ use Drupal\migrate\Audit\AuditResult; use Drupal\migrate\Audit\IdAuditor; use Drupal\node\Entity\Node; +use Drupal\node\Entity\NodeType; use Drupal\Tests\migrate_drupal\Traits\CreateTestContentEntitiesTrait; +use Drupal\workflows\Entity\Workflow; /** * Tests the migration auditor for ID conflicts. @@ -33,8 +35,17 @@ protected function setUp() { $this->installSchema('book', ['book']); $this->installSchema('dblog', ['watchdog']); $this->installSchema('forum', ['forum_index']); + $this->installSchema('node', ['node_access']); $this->installSchema('search', ['search_dataset']); $this->installSchema('tracker', ['tracker_node', 'tracker_user']); + + // Enable content moderation for nodes of type page. + $this->installEntitySchema('content_moderation_state'); + $this->installConfig('content_moderation'); + NodeType::create(['type' => 'page'])->save(); + $workflow = Workflow::load('editorial'); + $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'page'); + $workflow->save(); } /** @@ -42,7 +53,9 @@ protected function setUp() { */ public function testMultipleMigrationWithoutIdConflicts() { // Create a node of type page. - Node::create(['type' => 'page', 'title' => 'foo'])->save(); + $node = Node::create(['type' => 'page', 'title' => 'foo']); + $node->moderation_state->value = 'published'; + $node->save(); // Insert data in the d7_node:page migration mappping table to simulate a // previously migrated node. @@ -126,4 +139,37 @@ function (AuditResult $result) { $this->assertEmpty(array_diff(array_filter($conflicts), $expected)); } + /** + * Tests draft revisions ID conflicts. + */ + public function testDraftRevisionIdConflicts() { + // Create a published node of type page. + $node = Node::create(['type' => 'page', 'title' => 'foo']); + $node->moderation_state->value = 'published'; + $node->save(); + + // Create a draft revision. + $node->moderation_state->value = 'draft'; + $node->setNewRevision(TRUE); + $node->save(); + + // Insert data in the d7_node_revision:page migration mappping table to + // simulate a previously migrated node revison. + $table_name = $this->getMigration('d7_node_revision:page')->getIdMap()->mapTableName(); + $this->container->get('database')->insert($table_name) + ->fields([ + 'source_ids_hash' => 1, + 'sourceid1' => 1, + 'destid1' => 1, + ]) + ->execute(); + + // Audit the IDs of the d7_node_revision migration. There should be + // conflicts since a draft revision has been created. + /** @var \Drupal\migrate\Audit\AuditResult $result */ + $result = (new IdAuditor())->audit($this->getMigration('d7_node_revision:page')); + $this->assertInstanceOf(AuditResult::class, $result); + $this->assertFalse($result->passed()); + } + } diff --git a/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php index 1e38cc14ee..08a0498d21 100644 --- a/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php +++ b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php @@ -490,6 +490,9 @@ public function buildIdConflictForm(array &$form, FormStateInterface $form_state foreach ($results as $result) { $destination = $result->getMigration()->getDestinationPlugin(); if ($destination instanceof EntityContentBase && $destination->isTranslationDestination()) { + // Translations are not yet supperted by the audit system. For now, we + // only warn the user to be cautious when migrating translated content. + // I18n support should be added in https://www.drupal.org/node/2905759. $translated_content_conflicts[] = $result; } elseif (!$result->passed()) {