You are here

public function MigrateUpgradeDrushRunner::configure in Migrate Upgrade 8.3

Same name and namespace in other branches
  1. 8 src/MigrateUpgradeDrushRunner.php \Drupal\migrate_upgrade\MigrateUpgradeDrushRunner::configure()
  2. 8.2 src/MigrateUpgradeDrushRunner.php \Drupal\migrate_upgrade\MigrateUpgradeDrushRunner::configure()

From the provided source information, configure the appropriate migrations.

Configures from the currently active configuration.

Throws

\Exception

File

src/MigrateUpgradeDrushRunner.php, line 143

Class

MigrateUpgradeDrushRunner
Class MigrateUpgradeDrushRunner.

Namespace

Drupal\migrate_upgrade

Code

public function configure() {
  $legacy_db_key = $this->options['legacy-db-key'];
  if (!empty($legacy_db_key)) {
    $connection = Database::getConnection('default', $legacy_db_key);
    $this->version = $this
      ->getLegacyDrupalVersion($connection);
    $database_state['key'] = $legacy_db_key;
    $database_state_key = 'migrate_drupal_' . $this->version;
    \Drupal::state()
      ->set($database_state_key, $database_state);
    \Drupal::state()
      ->set('migrate.fallback_state_key', $database_state_key);
  }
  else {
    $db_url = $this->options['legacy-db-url'];
    $db_prefix = $this->options['legacy-db-prefix'];

    // Maintain some simple BC with Drush 8. Only call Drush 9+ if it exists.
    // Otherwise fallback to the legacy Drush 8 method.
    if (method_exists(SqlBase::class, 'dbSpecFromDBUrl')) {
      $db_spec = SqlBase::dbSpecFromDbUrl($db_url);
    }
    else {
      $db_spec = drush_convert_db_from_db_url($db_url);
    }
    $db_spec['prefix'] = $db_prefix;
    $connection = $this
      ->getConnection($db_spec);
    $this->version = $this
      ->getLegacyDrupalVersion($connection);
    $this
      ->createDatabaseStateSettings($db_spec, $this->version);
  }
  $this->databaseStateKey = 'migrate_drupal_' . $this->version;
  $migrations = $this
    ->getMigrations($this->databaseStateKey, $this->version);
  $this->migrationList = [];
  foreach ($migrations as $migration) {
    if (strpos($migration
      ->id(), $this->options['migration-prefix']) === 0) {
      continue;
    }
    $this
      ->applyFilePath($migration);
    $this
      ->prefixFileMigration($migration);
    $this->migrationList[$migration
      ->id()] = $migration;
  }
}