diff --git a/core/modules/migrate/src/Plugin/MigrateMaxIdInterface.php b/core/modules/migrate/src/Plugin/MigrateMaxIdInterface.php index 30b089b..16d3ab0 100644 --- a/core/modules/migrate/src/Plugin/MigrateMaxIdInterface.php +++ b/core/modules/migrate/src/Plugin/MigrateMaxIdInterface.php @@ -10,11 +10,14 @@ * * @param string $field * The destination field for which to get the highest ID. + * @param array $bundles + * The destination bundles to handle multiple migrations to the same + * destination, eg: d7_node:article & d7_node:page. * * @return int * The highest ID value found. If no IDs at all are found, or if the * concept of a highest ID is not meaningful, zero should be returned. */ - public function getMaxId($field); + public function getMaxId($field, $bundles); } diff --git a/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php index e154b0f..c22404d 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php @@ -338,7 +338,7 @@ public function unsafeIdsExist(MigrateIdMapInterface $idMap) { // We don't know how to audit IDs without a cooperating ID map. return FALSE; } - $highestMigrated = $idMap->getMaxId($this->getHighestIdField()); + $highestMigrated = $idMap->getMaxId($this->getHighestIdField(), $this->bundles); if ($this->highestDestinationId() > $highestMigrated) { // There's a new ID that we might conflict with! return TRUE; 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 2b6e30c..21cc941 100644 --- a/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php +++ b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php @@ -927,19 +927,31 @@ public function valid() { /** * {@inheritdoc} */ - public function getMaxId($field) { + public function getMaxId($field, $bundles) { if (!$this->getDatabase()->schema()->tableExists($this->mapTableName())) { return 0; } $sqlField = $this->destinationIdFields()[$field]; - $query = $this->getDatabase()->select($this->mapTableName(), 'map') - ->fields('map', [$sqlField]) - ->orderBy($sqlField, 'DESC') - ->range(0, 1); - $found = $query->execute()->fetchField(); - return (int) $found; + // Explode the migration ID to see if this migration is part of multiple + // migrations to the same destination. + list($migration_id, $migration_bundle) = explode(':', $this->migration->id()); + + $ids = []; + foreach ($bundles as $bundle) { + // If this migration is part of multiple migrations to the same + // destination, get the highest ID from all those migration tables. + $map_table = $migration_bundle ? 'migrate_map_' . $migration_id . '__' . $bundle : $this->mapTableName(); + + $query = $this->getDatabase()->select($map_table, 'map') + ->fields('map', [$sqlField]) + ->orderBy($sqlField, 'DESC') + ->range(0, 1); + $ids[] = (int) $query->execute()->fetchField(); + } + + return max($ids); } }