Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Running a Drupal migration from form submit
// You should probably just read Migrate Source UI code :) but ...
$migration_id = $form_state->getValue('migrations');
// Aha! We'll target the final migration, and let Migration
// dependencies do the legwork of starting the other two.
$migration_id = str_replace('node', 'media', $migration_id);
/** @var \Drupal\migrate\Plugin\Migration $migration */
$migration = $this->pluginManagerMigration->createInstance($migration_id);
// Reset status.
$status = $migration->getStatus();
if ($status != MigrationInterface::STATUS_IDLE) {
$migration->setStatus(MigrationInterface::STATUS_IDLE);
drupal_set_message($this->t('Migration @id reset to Idle', ['@id' => $migration_id]), 'warning');
}
$options = [
'file_path' => $form_state->getValue('file_path'),
];
// Force updates or not.
if ($form_state->getValue('update_existing_records')) {
$options['update'] = TRUE;
}
$executable = new MigrateBatchExecutable($migration, new StubMigrationMessage(), $options);
$executable->batchImport();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.