You are here

protected function MigrationState::buildDiscoveredDestinationsBySource in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/migrate_drupal/src/MigrationState.php \Drupal\migrate_drupal\MigrationState::buildDiscoveredDestinationsBySource()
  2. 9 core/modules/migrate_drupal/src/MigrationState.php \Drupal\migrate_drupal\MigrationState::buildDiscoveredDestinationsBySource()

Builds migration source and destination module information.

Parameters

string $version: The legacy Drupal version.

array $migrations: The discovered migrations.

array $source_system_data: The data from the source site system table.

File

core/modules/migrate_drupal/src/MigrationState.php, line 331

Class

MigrationState
Determines the migrate state for all modules enabled on the source.

Namespace

Drupal\migrate_drupal

Code

protected function buildDiscoveredDestinationsBySource($version, array $migrations, array $source_system_data) {
  $discovered_upgrade_paths = [];
  $table_data = [];
  foreach ($migrations as $migration) {
    $migration_id = $migration
      ->getPluginId();
    $source_module = $migration
      ->getSourcePlugin()
      ->getSourceModule();
    if (!$source_module) {
      $this
        ->messenger()
        ->addError($this
        ->t('Source module not found for @migration_id.', [
        '@migration_id' => $migration_id,
      ]));
    }
    $destination_module = $migration
      ->getDestinationPlugin()
      ->getDestinationModule();
    if (!$destination_module) {
      $this
        ->messenger()
        ->addError($this
        ->t('Destination module not found for @migration_id.', [
        '@migration_id' => $migration_id,
      ]));
    }
    if ($source_module && $destination_module) {
      $discovered_upgrade_paths[$source_module][] = $destination_module;
      $table_data[$source_module][$destination_module][$migration_id] = $migration
        ->label();
    }
  }

  // Add entries for the field plugins to discovered_upgrade_paths.
  $definitions = $this->fieldPluginManager
    ->getDefinitions();
  foreach ($definitions as $definition) {

    // This is not strict so that we find field plugins with an annotation
    // where the Drupal core version is an integer and when it is a string.
    if (in_array($version, $definition['core'])) {
      $source_module = $definition['source_module'];
      $destination_module = $definition['destination_module'];
      $discovered_upgrade_paths[$source_module][] = $destination_module;
      $table_data[$source_module][$destination_module][$definition['id']] = $definition['id'];
    }
  }
  ksort($table_data);
  foreach ($table_data as $source_module => $destination_module_info) {
    ksort($table_data[$source_module]);
  }
  $this->discoveredBySource[$version] = array_map('array_unique', $discovered_upgrade_paths);
}