You are here

public function MigrateToolsCommands::import in Migrate Tools 8.5

Same name and namespace in other branches
  1. 8.4 src/Commands/MigrateToolsCommands.php \Drupal\migrate_tools\Commands\MigrateToolsCommands::import()

Perform one or more migration processes.

@command migrate:import

@option all Process all migrations. @option group A comma-separated list of migration groups to import @option tag Name of the migration tag to import @option limit Limit on the number of items to process in each migration @option feedback Frequency of progress messages, in items processed @option idlist Comma-separated list of IDs to import @option idlist-delimiter The delimiter for records @option update In addition to processing unprocessed items from the source, update previously-imported items with the current data @option force Force an operation to run, even if all dependencies are not satisfied @option continue-on-failure When a migration fails, continue processing remaining migrations. @option execute-dependencies Execute all dependent migrations first. @option skip-progress-bar Skip displaying a progress bar. @option sync Sync source and destination. Delete destination records that do not exist in the source.

@default $options []

@usage migrate:import --all Perform all migrations @usage migrate:import --group=beer Import all migrations in the beer group @usage migrate:import --tag=user Import all migrations with the user tag @usage migrate:import --group=beer --tag=user Import all migrations in the beer group and with the user tag @usage migrate:import beer_term,beer_node Import new terms and nodes @usage migrate:import beer_user --limit=2 Import no more than 2 users @usage migrate:import beer_user --idlist=5 Import the user record with source ID 5 @usage migrate:import beer_node_revision --idlist=1:2,2:3,3:5 Import the node revision record with source IDs [1,2], [2,3], and [3,5]

@validate-module-enabled migrate_tools

@aliases mim, migrate-import

Parameters

string $migration_names: ID of migration(s) to import. Delimit multiple using commas.

array $options: Additional options for the command.

Throws

\Exception If there are not enough parameters to the command.

File

src/Commands/MigrateToolsCommands.php, line 388

Class

MigrateToolsCommands
Migrate Tools drush commands.

Namespace

Drupal\migrate_tools\Commands

Code

public function import($migration_names = '', array $options = [
  'all' => FALSE,
  'group' => self::REQ,
  'tag' => self::REQ,
  'limit' => self::REQ,
  'feedback' => self::REQ,
  'idlist' => self::REQ,
  'idlist-delimiter' => MigrateTools::DEFAULT_ID_LIST_DELIMITER,
  'update' => FALSE,
  'force' => FALSE,
  'continue-on-failure' => FALSE,
  'execute-dependencies' => FALSE,
  'skip-progress-bar' => FALSE,
  'sync' => FALSE,
]) {
  $group_names = $options['group'];
  $tag_names = $options['tag'];
  $all = $options['all'];
  if (!$all && !$group_names && !$migration_names && !$tag_names) {
    throw new \Exception(dt('You must specify --all, --group, --tag or one or more migration names separated by commas'));
  }
  $migrations = $this
    ->migrationsList($migration_names, $options);
  if (empty($migrations)) {
    $this->logger
      ->error(dt('No migrations found.'));
  }

  // Take it one group at a time, importing the migrations within each group.
  foreach ($migrations as $group_id => $migration_list) {
    array_walk($migration_list, [
      $this,
      'executeMigration',
    ], $options);
  }
}