function _drush_migrate_tools_execute_migration in Migrate Tools 8.4
Same name and namespace in other branches
- 8 migrate_tools.drush.inc \_drush_migrate_tools_execute_migration()
- 8.2 migrate_tools.drush.inc \_drush_migrate_tools_execute_migration()
- 8.3 migrate_tools.drush.inc \_drush_migrate_tools_execute_migration()
Executes a single migration.
If the --execute-dependencies option was given, the migration's dependencies will also be executed first.
Parameters
\Drupal\migrate\Plugin\MigrationInterface $migration: The migration to execute.
string $migration_id: The migration ID (not used, just an artifact of array_walk()).
array $options: Additional options for the migration.
1 string reference to '_drush_migrate_tools_execute_migration'
- drush_migrate_tools_migrate_import in ./
migrate_tools.drush.inc - Import a migration.
File
- ./
migrate_tools.drush.inc, line 298 - Command-line tools to aid performing and developing migrations.
Code
function _drush_migrate_tools_execute_migration(MigrationInterface $migration, $migration_id, array $options = []) {
$log = new DrushLogMigrateMessage();
if (drush_get_option('execute-dependencies')) {
if ($required_IDS = $migration
->get('requirements')) {
$manager = \Drupal::service('plugin.manager.migration');
$required_migrations = $manager
->createInstances($required_IDS);
$dependency_options = array_merge($options, [
'is_dependency' => TRUE,
]);
array_walk($required_migrations, __FUNCTION__, $dependency_options);
}
}
if (!empty($options['force'])) {
$migration
->set('requirements', []);
}
if (!empty($options['update'])) {
if (empty($options['idlist'])) {
$migration
->getIdMap()
->prepareUpdate();
}
else {
$source_id_values_list = MigrateTools::buildIdList($options);
$keys = array_keys($migration
->getSourcePlugin()
->getIds());
foreach ($source_id_values_list as $source_id_values) {
$migration
->getIdMap()
->setUpdate(array_combine($keys, $source_id_values));
}
}
}
$executable = new MigrateExecutable($migration, $log, $options);
// Function drush_op() provides --simulate support.
drush_op([
$executable,
'import',
]);
if ($count = $executable
->getFailedCount()) {
// Nudge Drush to use a non-zero exit code.
drush_set_error('MIGRATE_ERROR', dt('!name Migration - !count failed.', [
'!name' => $migration_id,
'!count' => $count,
]));
}
}