diff --git a/core/modules/ban/migration_templates/d7_blocked_ips.yml b/core/modules/ban/migration_templates/d7_blocked_ips.yml index 9197cf2..0122dc6 100644 --- a/core/modules/ban/migration_templates/d7_blocked_ips.yml +++ b/core/modules/ban/migration_templates/d7_blocked_ips.yml @@ -2,7 +2,6 @@ id: d7_blocked_ips label: Blocked IPs migration_tags: - Drupal 7 -audit_ids: true source: plugin: d7_blocked_ips process: diff --git a/core/modules/book/migration_templates/d6_book.yml b/core/modules/book/migration_templates/d6_book.yml index f075c39..94d7a8f 100644 --- a/core/modules/book/migration_templates/d6_book.yml +++ b/core/modules/book/migration_templates/d6_book.yml @@ -2,7 +2,6 @@ id: d6_book label: Books migration_tags: - Drupal 6 -audit_ids: true source: plugin: d6_book process: diff --git a/core/modules/file/migration_templates/d6_upload.yml b/core/modules/file/migration_templates/d6_upload.yml index 0942e10..a497099 100644 --- a/core/modules/file/migration_templates/d6_upload.yml +++ b/core/modules/file/migration_templates/d6_upload.yml @@ -2,7 +2,6 @@ id: d6_upload label: File uploads migration_tags: - Drupal 6 -audit_ids: true source: plugin: d6_upload process: diff --git a/core/modules/migrate/src/MigrateIdAuditor.php b/core/modules/migrate/src/MigrateIdAuditor.php index 03a8fe9..2f3b33c 100644 --- a/core/modules/migrate/src/MigrateIdAuditor.php +++ b/core/modules/migrate/src/MigrateIdAuditor.php @@ -2,7 +2,9 @@ namespace Drupal\migrate; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\migrate\Plugin\MigrateDestinationAuditInterface; +use Drupal\migrate\Plugin\MigrateIdMapAuditInterface; /** * Audits a set of migrations for potential ID conflicts. @@ -12,6 +14,11 @@ class MigrateIdAuditor { /** * Audits a set of migrations for potential ID conflicts. * + * ID conflicts exist if new content has been created without the migration + * system knowing about it. To find out if there is ID conflicts, this method + * should compare the highest destination ID to the highest migrated ID. If + * the former is greater than the later, there is ID conflicts. + * * @param \Drupal\migrate\Plugin\MigrationInterface[] $migrations * The set of migrations to audit. * @@ -22,11 +29,28 @@ class MigrateIdAuditor { public function auditIds(array $migrations) { $conflicts = []; foreach ($migrations as $migration) { - $destination = $migration->getDestinationPlugin(); - if ($destination instanceof MigrateDestinationAuditInterface) { - if ($destination->hasIdConflicts($migration->getIdMap())) { - $entity_type = $destination->getEntityType(); - $conflicts[$entity_type->id()] = $entity_type->getLabel(); + $definition = $migration->getPluginDefinition(); + if (!empty($definition['audit_ids'])) { + $destination = $migration->getDestinationPlugin(); + $id_map = $migration->getIdMap(); + if ($destination instanceof MigrateDestinationAuditInterface && $id_map instanceof MigrateIdMapAuditInterface) { + $field_name = $destination->getAuditedIdFieldName(); + if ($destination->getHighestDestinationId($field_name) > $id_map->getHighestMigratedId($field_name)) { + $base_id = $migration->getBaseId(); + $label = $migration->label(); + if (is_string($label)){ + $conflicts[$base_id] = $label; + } + elseif ($label instanceof TranslatableMarkup) { + $arguments = $label->getArguments(); + if (isset($arguments['@label'])) { + $conflicts[$base_id] = $arguments['@label']; + } + else { + $conflicts[$base_id] = $label->render(); + } + } + } } } } diff --git a/core/modules/migrate/src/Plugin/MigrateDestinationAuditInterface.php b/core/modules/migrate/src/Plugin/MigrateDestinationAuditInterface.php index df92efb..67bbfd0 100644 --- a/core/modules/migrate/src/Plugin/MigrateDestinationAuditInterface.php +++ b/core/modules/migrate/src/Plugin/MigrateDestinationAuditInterface.php @@ -9,27 +9,26 @@ interface MigrateDestinationAuditInterface { /** - * Checks whether ID conflicts exist. + * Gets the name of the field containing the IDs that should be audited. * - * ID conflicts exist if new content has been created without the migration - * system knowing about it. To find out if there is ID conflicts, this method - * should compare the highest destination ID to the highest migrated ID. If - * the former is greater than the later, there is ID conflicts. - * - * @param MigrateIdMapInterface $id_map - * The ID map for this migration. - * - * @return bool - * Whether ID conflicts exist. + * @return string + * The field name. */ - public function hasIdConflicts(MigrateIdMapInterface $id_map); + public function getAuditedIdFieldName(); /** - * Gets the entity type this destination creates. + * Gets the highest ID that exists for this destination. + * + * This is not the highest ID that has been migrated, but the highest ID that + * exists in the destination, eg: highest node ID on the site. + * + * @param string $field_name + * The name of the field containing the IDs that should be audited. * - * @return \Drupal\Core\Entity\EntityTypeInterface - * The entity type definition. + * @return int + * The highest ID found. If no IDs are found, or if the concept of a highest + * ID is not meaningful, zero should be returned. */ - public function getEntityType(); + public function getHighestDestinationId($field_name); } diff --git a/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php index c3c8ff0..93340b0 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php @@ -10,7 +10,6 @@ use Drupal\Core\TypedData\TranslatableInterface; use Drupal\Core\TypedData\TypedDataInterface; use Drupal\migrate\Plugin\MigrateDestinationAuditInterface; -use Drupal\migrate\Plugin\MigrateIdMapAuditInterface; use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\MigrateException; use Drupal\migrate\Plugin\MigrateIdMapInterface; @@ -299,52 +298,21 @@ protected function getDefinitionFromEntity($key) { } /** - * Gets the name of the field containing the IDs that should be audited. - * - * @return string - * The field name. + * {@inheritdoc} */ - protected function getIdAuditField() { + public function getAuditedIdFieldName() { return $this->getKey('id'); } /** - * Gets the highest ID that exists for this destination. - * - * This is not the highest ID that has been migrated, but the highest ID that - * exists in the destination, eg: highest node ID on the site. - * - * @return int - * The highest ID found. If no IDs are found, or if the concept of a highest - * ID is not meaningful, zero should be returned. + * {@inheritdoc} */ - protected function getHighestDestinationId() { + public function getHighestDestinationId($field_name) { $query = $this->storage->getQuery() - ->sort($this->getIdAuditField()) + ->sort($field_name) ->range(0, 1); $found = $query->execute(); return (int) reset($found); } - /** - * {@inheritdoc} - */ - public function hasIdConflicts(MigrateIdMapInterface $id_map) { - if (!empty($this->migration->getPluginDefinition()['audit_ids'])) { - if ($id_map instanceof MigrateIdMapAuditInterface) { - if ($this->getHighestDestinationId() > $id_map->getHighestMigratedId($this->getIdAuditField())) { - return TRUE; - } - } - } - return FALSE; - } - - /** - * {@inheritdoc} - */ - public function getEntityType() { - return $this->storage->getEntityType(); - } - } diff --git a/core/modules/migrate/src/Plugin/migrate/destination/EntityRevision.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityRevision.php index e452795..b0db476 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/EntityRevision.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityRevision.php @@ -78,11 +78,4 @@ public function getIds() { throw new MigrateException('This entity type does not support revisions.'); } - /** - * {@inheritdoc} - */ - public function getIdAuditField() { - return $this->getKey('revision'); - } - } diff --git a/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php index 1c12a0a..f59f48e 100644 --- a/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php +++ b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php @@ -942,8 +942,8 @@ public function valid() { /** * {@inheritdoc} */ - public function getHighestMigratedId($field) { - $sql_field = $this->destinationIdFields()[$field]; + public function getHighestMigratedId($field_name) { + $sql_field = $this->destinationIdFields()[$field_name]; $migration_id = $this->migration->id(); // List of mapping tables to look in for the highest ID. diff --git a/core/modules/migrate/tests/modules/migrate_high_water_test/migration_templates/migrate.migration.high_water_test.yml b/core/modules/migrate/tests/modules/migrate_high_water_test/migration_templates/migrate.migration.high_water_test.yml index 73f32a8..6a86577 100644 --- a/core/modules/migrate/tests/modules/migrate_high_water_test/migration_templates/migrate.migration.high_water_test.yml +++ b/core/modules/migrate/tests/modules/migrate_high_water_test/migration_templates/migrate.migration.high_water_test.yml @@ -1,6 +1,5 @@ id: high_water_test label: High water test. -audit_ids: true source: plugin: high_water_test high_water_property: diff --git a/core/modules/migrate_drupal/tests/modules/migrate_overwrite_test/migration_templates/users.yml b/core/modules/migrate_drupal/tests/modules/migrate_overwrite_test/migration_templates/users.yml index 0bddcf4..e23d90d 100644 --- a/core/modules/migrate_drupal/tests/modules/migrate_overwrite_test/migration_templates/users.yml +++ b/core/modules/migrate_drupal/tests/modules/migrate_overwrite_test/migration_templates/users.yml @@ -3,7 +3,6 @@ label: User migration migration_tags: - Drupal 6 - Drupal 7 -audit_ids: true source: plugin: d6_user process: 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 00ffb8d..9220ec1 100644 --- a/core/modules/migrate_drupal/tests/src/Kernel/d6/MigrateDrupal6AuditIdsTest.php +++ b/core/modules/migrate_drupal/tests/src/Kernel/d6/MigrateDrupal6AuditIdsTest.php @@ -82,11 +82,8 @@ public function testMultipleMigrationWithoutIdConflicts() { public function testAllMigrationsWithNoIdConflicts() { $plugin_manager = $this->container->get('plugin.manager.migration'); - // Get all migration definitions. - $migrations = []; - foreach ($plugin_manager->getDefinitions() as $migration_id => $migration) { - $migrations[$migration_id] = $this->getMigration($migration_id); - } + // Get all Drupal 6 migrations. + $migrations = $plugin_manager->createInstancesByTag('Drupal 6'); // Audit the IDs of all migrations. There should be no conflicts since no // content has been created. @@ -100,11 +97,8 @@ public function testAllMigrationsWithNoIdConflicts() { public function testAllMigrationsWithIdConflicts() { $plugin_manager = $this->container->get('plugin.manager.migration'); - // Get all migration definitions. - $migrations = []; - foreach ($plugin_manager->getDefinitions() as $migration_id => $migration) { - $migrations[$migration_id] = $this->getMigration($migration_id); - } + // Get all Drupal 6 migrations. + $migrations = $plugin_manager->createInstancesByTag('Drupal 6'); // Create content. $this->createContent(); @@ -115,15 +109,15 @@ public function testAllMigrationsWithIdConflicts() { ksort($conflicts); $expected = [ - 'aggregator_feed', - 'aggregator_item', - 'block_content', - 'comment', - 'file', - 'menu_link_content', - 'node', - 'taxonomy_term', - 'user', + 'd6_aggregator_feed', + 'd6_aggregator_item', + 'd6_comment', + 'd6_custom_block', + 'd6_file', + 'd6_menu_links', + 'd6_node', + 'd6_taxonomy_term', + 'd6_user', ]; $this->assertSame($expected, array_keys($conflicts)); 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 720dccc..9456df7 100644 --- a/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7AuditIdsTest.php +++ b/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7AuditIdsTest.php @@ -82,11 +82,8 @@ public function testMultipleMigrationWithoutIdConflicts() { public function testAllMigrationsWithNoIdConflicts() { $plugin_manager = $this->container->get('plugin.manager.migration'); - // Get all migration definitions. - $migrations = []; - foreach ($plugin_manager->getDefinitions() as $migration_id => $migration) { - $migrations[$migration_id] = $this->getMigration($migration_id); - } + // Get all Drupal 7 migrations. + $migrations = $plugin_manager->createInstancesByTag('Drupal 7'); // Audit the IDs of all migrations. There should be no conflicts since no // content has been created. @@ -100,11 +97,8 @@ public function testAllMigrationsWithNoIdConflicts() { public function testAllMigrationsWithIdConflicts() { $plugin_manager = $this->container->get('plugin.manager.migration'); - // Get all migration definitions. - $migrations = []; - foreach ($plugin_manager->getDefinitions() as $migration_id => $migration) { - $migrations[$migration_id] = $this->getMigration($migration_id); - } + // Get all Drupal 7 migrations. + $migrations = $plugin_manager->createInstancesByTag('Drupal 7'); // Create content. $this->createContent(); @@ -115,15 +109,16 @@ public function testAllMigrationsWithIdConflicts() { ksort($conflicts); $expected = [ - 'aggregator_feed', - 'aggregator_item', - 'block_content', - 'comment', - 'file', - 'menu_link_content', - 'node', - 'taxonomy_term', - 'user', + 'd7_aggregator_feed', + 'd7_aggregator_item', + 'd7_comment', + 'd7_custom_block', + 'd7_file', + 'd7_file_private', + 'd7_menu_links', + 'd7_node', + 'd7_taxonomy_term', + 'd7_user', ]; $this->assertSame($expected, array_keys($conflicts)); diff --git a/core/modules/node/migration_templates/d6_node_revision.yml b/core/modules/node/migration_templates/d6_node_revision.yml index ec44d58..f4ff301 100644 --- a/core/modules/node/migration_templates/d6_node_revision.yml +++ b/core/modules/node/migration_templates/d6_node_revision.yml @@ -3,7 +3,6 @@ label: Node revisions migration_tags: - Drupal 6 deriver: Drupal\node\Plugin\migrate\D6NodeDeriver -audit_ids: true source: plugin: d6_node_revision process: diff --git a/core/modules/node/migration_templates/d6_node_translation.yml b/core/modules/node/migration_templates/d6_node_translation.yml index 0f6579e..3eb06e8 100644 --- a/core/modules/node/migration_templates/d6_node_translation.yml +++ b/core/modules/node/migration_templates/d6_node_translation.yml @@ -3,7 +3,6 @@ label: Node translations migration_tags: - Drupal 6 deriver: Drupal\node\Plugin\migrate\D6NodeDeriver -audit_ids: true source: plugin: d6_node translations: true diff --git a/core/modules/node/migration_templates/d7_node_revision.yml b/core/modules/node/migration_templates/d7_node_revision.yml index 420fe58..c6081ef 100644 --- a/core/modules/node/migration_templates/d7_node_revision.yml +++ b/core/modules/node/migration_templates/d7_node_revision.yml @@ -3,7 +3,6 @@ label: Node revisions migration_tags: - Drupal 7 deriver: Drupal\node\Plugin\migrate\D7NodeDeriver -audit_ids: true source: plugin: d7_node_revision process: diff --git a/core/modules/node/migration_templates/d7_node_translation.yml b/core/modules/node/migration_templates/d7_node_translation.yml index 5a073d7..11dfbb7 100644 --- a/core/modules/node/migration_templates/d7_node_translation.yml +++ b/core/modules/node/migration_templates/d7_node_translation.yml @@ -4,7 +4,6 @@ migration_tags: - Drupal 7 - translation deriver: Drupal\node\Plugin\migrate\D7NodeDeriver -audit_ids: true source: plugin: d7_node translations: true diff --git a/core/modules/path/migration_templates/d6_url_alias.yml b/core/modules/path/migration_templates/d6_url_alias.yml index f9c604c..fcf2036 100644 --- a/core/modules/path/migration_templates/d6_url_alias.yml +++ b/core/modules/path/migration_templates/d6_url_alias.yml @@ -2,7 +2,6 @@ id: d6_url_alias label: URL aliases migration_tags: - Drupal 6 -audit_ids: true source: plugin: d6_url_alias constants: diff --git a/core/modules/path/migration_templates/d7_url_alias.yml b/core/modules/path/migration_templates/d7_url_alias.yml index 12a985c..dffaf46 100644 --- a/core/modules/path/migration_templates/d7_url_alias.yml +++ b/core/modules/path/migration_templates/d7_url_alias.yml @@ -2,7 +2,6 @@ id: d7_url_alias label: URL aliases migration_tags: - Drupal 7 -audit_ids: true source: plugin: d7_url_alias constants: diff --git a/core/modules/shortcut/migration_templates/d7_shortcut.yml b/core/modules/shortcut/migration_templates/d7_shortcut.yml index a597780..dac9354 100644 --- a/core/modules/shortcut/migration_templates/d7_shortcut.yml +++ b/core/modules/shortcut/migration_templates/d7_shortcut.yml @@ -2,7 +2,6 @@ id: d7_shortcut label: Shortcut links migration_tags: - Drupal 7 -audit_ids: false source: plugin: d7_shortcut constants: diff --git a/core/modules/shortcut/migration_templates/d7_shortcut_set_users.yml b/core/modules/shortcut/migration_templates/d7_shortcut_set_users.yml index 9726732..d0eb219 100644 --- a/core/modules/shortcut/migration_templates/d7_shortcut_set_users.yml +++ b/core/modules/shortcut/migration_templates/d7_shortcut_set_users.yml @@ -2,7 +2,6 @@ id: d7_shortcut_set_users label: Shortcut set user mapping migration_tags: - Drupal 7 -audit_ids: true source: plugin: d7_shortcut_set_users process: diff --git a/core/modules/taxonomy/migration_templates/d6_taxonomy_term_translation.yml b/core/modules/taxonomy/migration_templates/d6_taxonomy_term_translation.yml index 473ab23..11af8cd 100644 --- a/core/modules/taxonomy/migration_templates/d6_taxonomy_term_translation.yml +++ b/core/modules/taxonomy/migration_templates/d6_taxonomy_term_translation.yml @@ -2,7 +2,6 @@ id: d6_taxonomy_term_translation label: Taxonomy terms migration_tags: - Drupal 6 -audit_ids: true source: plugin: d6_taxonomy_term translations: true diff --git a/core/modules/taxonomy/migration_templates/d6_taxonomy_vocabulary_translation.yml b/core/modules/taxonomy/migration_templates/d6_taxonomy_vocabulary_translation.yml index 2d143d0..dbb1793 100644 --- a/core/modules/taxonomy/migration_templates/d6_taxonomy_vocabulary_translation.yml +++ b/core/modules/taxonomy/migration_templates/d6_taxonomy_vocabulary_translation.yml @@ -2,7 +2,6 @@ id: d6_taxonomy_vocabulary_translation label: Taxonomy vocabularies migration_tags: - Drupal 6 -audit_ids: true source: plugin: d6_taxonomy_vocabulary_translation process: diff --git a/core/modules/taxonomy/migration_templates/d6_term_node.yml b/core/modules/taxonomy/migration_templates/d6_term_node.yml index bda7d58..846334d 100644 --- a/core/modules/taxonomy/migration_templates/d6_term_node.yml +++ b/core/modules/taxonomy/migration_templates/d6_term_node.yml @@ -3,7 +3,6 @@ label: Term/node relationships migration_tags: - Drupal 6 deriver: Drupal\taxonomy\Plugin\migrate\D6TermNodeDeriver -audit_ids: true source: plugin: d6_term_node process: diff --git a/core/modules/taxonomy/migration_templates/d6_term_node_revision.yml b/core/modules/taxonomy/migration_templates/d6_term_node_revision.yml index 24da88f..91c8362 100644 --- a/core/modules/taxonomy/migration_templates/d6_term_node_revision.yml +++ b/core/modules/taxonomy/migration_templates/d6_term_node_revision.yml @@ -3,7 +3,6 @@ label: Term/node relationship revisions migration_tags: - Drupal 6 deriver: Drupal\taxonomy\Plugin\migrate\D6TermNodeDeriver -audit_ids: true source: plugin: d6_term_node_revision process: diff --git a/core/modules/tracker/migration_templates/d7_tracker_node.yml b/core/modules/tracker/migration_templates/d7_tracker_node.yml index 2bf3b07..02645d7 100644 --- a/core/modules/tracker/migration_templates/d7_tracker_node.yml +++ b/core/modules/tracker/migration_templates/d7_tracker_node.yml @@ -2,7 +2,6 @@ id: d7_tracker_node label: Tracker node migration_tags: - Drupal 7 -audit_ids: true source: plugin: d7_tracker_node process: diff --git a/core/modules/tracker/migration_templates/d7_tracker_user.yml b/core/modules/tracker/migration_templates/d7_tracker_user.yml index 776e1c7..ae3c51d 100644 --- a/core/modules/tracker/migration_templates/d7_tracker_user.yml +++ b/core/modules/tracker/migration_templates/d7_tracker_user.yml @@ -2,7 +2,6 @@ id: d7_tracker_user label: Tracker user migration_tags: - Drupal 7 -audit_ids: true source: plugin: d7_tracker_user process: diff --git a/core/modules/user/migration_templates/d6_profile_values.yml b/core/modules/user/migration_templates/d6_profile_values.yml index 8b0d4b0..5530ca5 100644 --- a/core/modules/user/migration_templates/d6_profile_values.yml +++ b/core/modules/user/migration_templates/d6_profile_values.yml @@ -3,7 +3,6 @@ label: Profile values class: Drupal\user\Plugin\migrate\ProfileValues migration_tags: - Drupal 6 -audit_ids: true source: plugin: d6_profile_field_values process: diff --git a/core/modules/user/migration_templates/d6_user_contact_settings.yml b/core/modules/user/migration_templates/d6_user_contact_settings.yml index 3fc3c3f..0d9a228 100644 --- a/core/modules/user/migration_templates/d6_user_contact_settings.yml +++ b/core/modules/user/migration_templates/d6_user_contact_settings.yml @@ -2,7 +2,6 @@ id: d6_user_contact_settings label: User contact settings migration_tags: - Drupal 6 -audit_ids: true source: plugin: d6_user constants: diff --git a/core/modules/user/migration_templates/d6_user_picture_file.yml b/core/modules/user/migration_templates/d6_user_picture_file.yml index 93a6e5e..3518d7a 100644 --- a/core/modules/user/migration_templates/d6_user_picture_file.yml +++ b/core/modules/user/migration_templates/d6_user_picture_file.yml @@ -2,7 +2,6 @@ id: d6_user_picture_file label: User pictures migration_tags: - Drupal 6 -audit_ids: true source: plugin: d6_user_picture_file constants: diff --git a/core/modules/user/src/Plugin/migrate/destination/EntityUser.php b/core/modules/user/src/Plugin/migrate/destination/EntityUser.php index 33d9e54..d802653 100644 --- a/core/modules/user/src/Plugin/migrate/destination/EntityUser.php +++ b/core/modules/user/src/Plugin/migrate/destination/EntityUser.php @@ -130,8 +130,8 @@ protected function processStubRow(Row $row) { /** * {@inheritdoc} */ - public function getHighestDestinationId() { - $found = parent::getHighestDestinationId(); + public function getHighestDestinationId($field_name) { + $found = parent::getHighestDestinationId($field_name); // Every Drupal site must have a user with UID of 1 and it's normal for // migrations to overwrite this user.