Created
July 10, 2019 21:46
-
-
Save xurizaemon/50eb4996aec5fbe59fcfdde7b1610f5d to your computer and use it in GitHub Desktop.
Running a Drupal migration from form submit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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