You are here

public function MigrateUpgradeDrushRunner::export in Migrate Upgrade 8.2

Same name and namespace in other branches
  1. 8.3 src/MigrateUpgradeDrushRunner.php \Drupal\migrate_upgrade\MigrateUpgradeDrushRunner::export()

Export the configured migration plugins as configuration entities.

File

src/MigrateUpgradeDrushRunner.php, line 162

Class

MigrateUpgradeDrushRunner

Namespace

Drupal\migrate_upgrade

Code

public function export() {
  $db_info = \Drupal::state()
    ->get($this->databaseStateKey);

  // Create a group to hold the database configuration.
  $group = [
    'id' => $this->databaseStateKey,
    'label' => 'Import from Drupal ' . $this->version,
    'description' => 'Migrations originally generated from drush migrate-upgrade --configure-only',
    'source_type' => 'Drupal ' . $this->version,
    'shared_configuration' => [
      'source' => [
        'key' => 'drupal_' . $this->version,
      ],
    ],
  ];

  // Only add the database connection info to the configuration entity
  // if it was passed in as a parameter.
  if (!empty(drush_get_option('legacy-db-url'))) {
    $group['shared_configuration']['source']['database'] = $db_info['database'];
  }
  $group = MigrationGroup::create($group);
  $group
    ->save();
  foreach ($this->migrationList as $migration_id => $migration) {
    drush_print(dt('Exporting @migration as @new_migration', [
      '@migration' => $migration_id,
      '@new_migration' => $this
        ->modifyId($migration_id),
    ]));
    $entity_array['id'] = $migration_id;
    $entity_array['migration_group'] = $this->databaseStateKey;
    $entity_array['migration_tags'] = $migration
      ->get('migration_tags');
    $entity_array['label'] = $migration
      ->get('label');
    $entity_array['source'] = $migration
      ->getSourceConfiguration();
    $entity_array['destination'] = $migration
      ->getDestinationConfiguration();
    $entity_array['process'] = $migration
      ->get('process');
    $entity_array['migration_dependencies'] = $migration
      ->getMigrationDependencies();
    $migration_entity = Migration::create($this
      ->substituteIds($entity_array));
    $migration_entity
      ->save();
  }
}