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 91b19da..3f7093a 100644 --- a/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php +++ b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php @@ -944,28 +944,23 @@ public function valid() { * {@inheritdoc} */ public function getHighestId() { - $destination_ids = array_filter( + array_filter( $this->migration->getDestinationPlugin()->getIds(), function (array $id) { - return $id['type'] === 'integer'; + if ($id['type'] !== 'integer') { + throw new \LogicException('Cannot determine the highest migrated ID without an integer ID column'); + } } ); - if (empty($destination_ids)) { - throw new \LogicException('Cannot determine the highest migrated ID without an integer ID column'); - } - $field_name = key($destination_ids); - - $sql_field = $this->destinationIdFields()[$field_name]; - $migration_id = $this->migration->id(); // List of mapping tables to look in for the highest ID. $map_tables = [ - $migration_id => $this->mapTableName(), + $this->migration->id() => $this->mapTableName(), ]; // If there's a bundle, it means we have a derived migration and we need to // find all the mapping tables from the related derived migrations. - if ($base_id = substr($migration_id, 0, strpos($migration_id, static::DERIVATIVE_SEPARATOR))) { + if ($base_id = substr($this->migration->id(), 0, strpos($this->migration->id(), static::DERIVATIVE_SEPARATOR))) { $migrations = $this->migration_plugin_manager->getDefinitions(); foreach ($migrations as $migration_id => $migration) { if ($migration['id'] === $base_id) { @@ -985,9 +980,11 @@ function (array $id) { } $query = $this->getDatabase()->select($map_table, 'map') - ->fields('map', [$sql_field]) - ->orderBy($sql_field, 'DESC') + ->fields('map', $this->destinationIdFields()) ->range(0, 1); + foreach (array_values($this->destinationIdFields()) as $order_field) { + $query->orderBy($order_field, 'DESC'); + } $ids[] = $query->execute()->fetchField(); }