You are here

public static function MigrateManifest::setDbState in Migrate Manifest 8

Same name and namespace in other branches
  1. 8.2 src/MigrateManifest.php \Drupal\migrate_manifest\MigrateManifest::setDbState()
  2. 3.x src/MigrateManifest.php \Drupal\migrate_manifest\MigrateManifest::setDbState()

Setup the legacy database connection to migrate from.

1 call to MigrateManifest::setDbState()
MigrateManifestCommands::manifest in src/Commands/MigrateManifestCommands.php
Execute the migrations as specified in a manifest file.

File

src/MigrateManifest.php, line 200

Class

MigrateManifest

Namespace

Drupal\migrate_manifest

Code

public static function setDbState($db_key, $db_url, $db_prefix) {
  if ($db_key) {
    $database_state['key'] = $db_key;
    $database_state_key = 'migrate_fallback_key';
    \Drupal::state()
      ->set($database_state_key, $database_state);
    \Drupal::state()
      ->set('migrate.fallback_state_key', $database_state_key);
  }
  else {
    if ($db_url) {
      if (function_exists('drush_convert_db_from_db_url')) {
        $db_spec = drush_convert_db_from_db_url($db_url);
      }
      elseif (class_exists('\\Drush\\Sql\\SqlBase')) {
        $db_spec = \Drush\Sql\SqlBase::dbSpecFromDbUrl($db_url);
      }
      else {
        $db_spec = [];

        // support other conversion methods?
      }
      $db_spec['prefix'] = $db_prefix;
      Database::removeConnection('migrate');
      Database::addConnectionInfo('migrate', 'default', $db_spec);
    }
  }
}