You are here

protected function MigrationCreationTrait::getMigrationTemplates in Migrate Upgrade 8

Sets up the relevant migrations for import from a database connection.

Parameters

array|\Drupal\Core\Database\Database $database: Database array representing the source Drupal database.

string $source_base_path: Address of the source Drupal site (e.g., http://example.com/).

Return value

int[] An array of Migration entity IDs.

Throws

\Exception

2 calls to MigrationCreationTrait::getMigrationTemplates()
MigrateUpgradeDrushRunner::configure in src/MigrateUpgradeDrushRunner.php
From the provided source information, instantiate the appropriate migrations in the active configuration.
MigrateUpgradeForm::validateCredentialForm in src/Form/MigrateUpgradeForm.php
Validation handler for the credentials form.

File

src/MigrationCreationTrait.php, line 79
Contains \Drupal\migrate_upgrade\MigrationCreationTrait.

Class

MigrationCreationTrait
Creates the appropriate migrations for a given source Drupal database.

Namespace

Drupal\migrate_upgrade

Code

protected function getMigrationTemplates(array $database, $source_base_path) {

  // Set up the connection.
  $connection = $this
    ->getConnection($database);
  if (!($drupal_version = $this
    ->getLegacyDrupalVersion($connection))) {
    throw new \Exception('Source database does not contain a recognizable Drupal version.');
  }
  $database_state['key'] = 'upgrade';
  $database_state['database'] = $database;
  $database_state_key = 'migrate_upgrade_' . $drupal_version;
  \Drupal::state()
    ->set($database_state_key, $database_state);
  $version_tag = 'Drupal ' . $drupal_version;
  $template_storage = \Drupal::service('migrate.template_storage');
  $migration_templates = $template_storage
    ->findTemplatesByTag($version_tag);
  foreach ($migration_templates as $id => $template) {
    $migration_templates[$id]['source']['database_state_key'] = $database_state_key;

    // Configure file migrations so they can find the files.
    if ($template['destination']['plugin'] == 'entity:file') {
      if ($source_base_path) {

        // Make sure we have a single trailing slash.
        $source_base_path = rtrim($source_base_path, '/') . '/';
        $migration_templates[$id]['destination']['source_base_path'] = $source_base_path;
      }
    }
  }
  return $migration_templates;
}