.../migrate/src/Audit/NodeMasterIdAuditor.php | 56 +++++++++++++++------- .../src/Plugin/Derivative/MigrateEntityMaster.php | 6 ++- core/modules/migrate_drupal/migrate_drupal.module | 8 ++-- .../migrate/EntityReferenceTranslationDeriver.php | 4 +- 4 files changed, 48 insertions(+), 26 deletions(-) diff --git a/core/modules/migrate/src/Audit/NodeMasterIdAuditor.php b/core/modules/migrate/src/Audit/NodeMasterIdAuditor.php index 52dd5f25e9..8d199921e8 100644 --- a/core/modules/migrate/src/Audit/NodeMasterIdAuditor.php +++ b/core/modules/migrate/src/Audit/NodeMasterIdAuditor.php @@ -2,6 +2,8 @@ namespace Drupal\migrate\Audit; +use Drupal\migrate\Plugin\MigrationInterface; + /** * Audits the node master migrations. */ @@ -14,32 +16,20 @@ class NodeMasterIdAuditor { * The migrations to audit. * * @return \Drupal\migrate\Audit\AuditResult[] - * Array of migration results. + * The audit results, keyed by migration ID. */ public function audit($migrations) { $results = []; // If dN_node_master migration is being used, get the audit results for node // revisions manually. We need to do this manually because the node master - // map has the ids for both nodes and revisions and Sql::getHighestId() - // only returns the highest migrated ID of the destination entity type, - // which for node_master is node. + // map has the IDs for both nodes and revisions and Sql::getHighestId() only + // returns the highest migrated ID of the destination entity type, which for + // node_master is node. $migration_plugin_manager = \Drupal::service('plugin.manager.migration'); foreach ($migrations as $migration) { $migration_id = $migration->getPluginId(); if (preg_match('/node_master/', $migration_id) === 1) { - $map_table = $migration->getIdMap()->mapTableName(); - - $database = \Drupal::database(); - if (!$database->schema()->tableExists($map_table)) { - continue; - } - // Get highest migrated node revision id. - $query = $database->select($map_table, 'map') - ->fields('map', ['destid2']) - ->range(0, 1) - ->orderBy('destid2', 'DESC'); - $ids[] = $query->execute()->fetchField(); - $max = (int) (max($ids)); + $max = static::getHighestMigratedNodeRevisionId($migration); // Make a migration based on node_master but with an entity_revision // destination. @@ -48,7 +38,7 @@ public function audit($migrations) { $revision_migration['destination']['plugin'] = 'entity_revision:node'; $revision_migration = $migration_plugin_manager->createStubMigration($revision_migration); - // Get the highest node revision id. + // Get the highest node revision ID. $destination = $revision_migration->getDestinationPlugin(); $highest = $destination->getHighestId(); @@ -65,4 +55,34 @@ public function audit($migrations) { return $results; } + /** + * Gets highest migrated node revision ID. + * + * @param \Drupal\migrate\Plugin\MigrationInterface $migration + * A node_master migration. + * + * @return int + * The highest migrated node revision ID. + * + * @throws \InvalidArgumentException + * Thrown when the ID map table does not exist. + */ + protected static function getHighestMigratedNodeRevisionId(MigrationInterface $migration) : int { + $map_table = $migration->getIdMap()->mapTableName(); + + $database = \Drupal::database(); + if (!$database->schema()->tableExists($map_table)) { + throw new \InvalidArgumentException(); + } + + $query = $database->select($map_table, 'map') + ->fields('map', ['destid2']) + ->range(0, 1) + ->orderBy('destid2', 'DESC'); + $ids[] = $query->execute()->fetchField(); + $max = (int) (max($ids)); + + return $max; + } + } diff --git a/core/modules/migrate/src/Plugin/Derivative/MigrateEntityMaster.php b/core/modules/migrate/src/Plugin/Derivative/MigrateEntityMaster.php index d54db942f7..af0dc4ae1b 100644 --- a/core/modules/migrate/src/Plugin/Derivative/MigrateEntityMaster.php +++ b/core/modules/migrate/src/Plugin/Derivative/MigrateEntityMaster.php @@ -2,8 +2,10 @@ namespace Drupal\migrate\Plugin\Derivative; +use Drupal\migrate\Plugin\migrate\destination\EntityContentMaster; + /** - * MigrateEntityMaster Deriver. + * MigrateEntityMaster deriver. */ class MigrateEntityMaster extends MigrateEntity { @@ -14,7 +16,7 @@ public function getDerivativeDefinitions($base_plugin_definition) { foreach ($this->entityDefinitions as $entity_type => $entity_info) { $this->derivatives[$entity_type] = [ 'id' => "entity_master:$entity_type", - 'class' => 'Drupal\migrate\Plugin\migrate\destination\EntityContentMaster', + 'class' => EntityContentMaster::class, 'requirements_met' => 1, 'provider' => $entity_info->getProvider(), ]; diff --git a/core/modules/migrate_drupal/migrate_drupal.module b/core/modules/migrate_drupal/migrate_drupal.module index ef52b571e5..800093ab64 100644 --- a/core/modules/migrate_drupal/migrate_drupal.module +++ b/core/modules/migrate_drupal/migrate_drupal.module @@ -109,11 +109,11 @@ function migrate_drupal_migration_plugins_alter(&$definitions) { // Alter references to the classic node migration to the master node // migration in all relevant core migrations. The references altered are // those in migration_dependencies and in the process pipeline. In the - // process pipeline we are concerned with references to classic mode + // process pipeline we are concerned with references to classic node // migrations in a migration_lookup process. // // The process pipeline is altered so that the migration_lookup returns - // the correct ids. For example, the classic d6_node_revision migration + // the correct IDs. For example, the classic d6_node_revision migration // has a single ID, the revision ID, but the d6_node_master has three IDs, // the node ID, the revision ID and the language. To ensure the pipeline // works for both migrations we need to insert a process to return only @@ -122,7 +122,7 @@ function migrate_drupal_migration_plugins_alter(&$definitions) { // Example: d6_term_node_revision // // Before - // vid: + // vid: // - // plugin: migration_lookup // migration: d6_node_revision @@ -130,7 +130,7 @@ function migrate_drupal_migration_plugins_alter(&$definitions) { // - // plugin: skip_on_empty // method: row - //After + // After // vid: // - // plugin: migration_lookup diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/EntityReferenceTranslationDeriver.php b/core/modules/migrate_drupal/src/Plugin/migrate/EntityReferenceTranslationDeriver.php index e0ea95b7d5..3354815f84 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/EntityReferenceTranslationDeriver.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/EntityReferenceTranslationDeriver.php @@ -186,8 +186,8 @@ public function getDerivativeDefinitions($base_plugin_definition) { } } } - // Ensure these migrations are also altered. This is done here because This - // deriver is only used for the follow up migrations which are created after + // Ensure these migrations are also altered. This is done here because this + // deriver is only used for the follow-up migrations which are created after // the migrations_plugin_alter is run. if ($this->derivatives) { migrate_drupal_migration_plugins_alter($this->derivatives);