Skip to content

Instantly share code, notes, and snippets.

@webflo
Created June 18, 2014 11:15
Show Gist options
  • Save webflo/c810bfc405eb8209881c to your computer and use it in GitHub Desktop.
Save webflo/c810bfc405eb8209881c to your computer and use it in GitHub Desktop.
<?php
/**
* @file
* CMI related drush commands.
*/
use Drupal\migrate\Entity\Migration;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateMessage;
/**
* Implementation of hook_drush_command().
*/
function migrate_drush_command() {
$items = array();
$items['d8-migrate-run'] = array(
'description' => 'Execute a migration',
'arguments' => array(
'migration' => 'The migrate id',
),
);
return $items;
}
function _drush_d8_migrate_execute($name, $force_update = TRUE) {
// Delete config cache for all migrate config entities.
db_delete('cache_config')->condition('cid', 'migrate.%', 'LIKE')->execute();
// Force update on all existing entities.
if (db_table_exists('migrate_map_' . $name) && $force_update) {
db_update('migrate_map_' . $name)->fields(array('source_row_status' => 1))->execute();
}
$migration = entity_load('migration', $name, TRUE);
$executable = new MigrateExecutable($migration, new MigrateMessage());
$executable->import();
}
function drush_migrate_d8_migrate_run($migration) {
$active = Drupal::service('config.storage');
$staging = Drupal::service('config.storage.staging');
$filename = 'migrate.migration.' . $migration;
$config = $staging->read($filename);
$active->write($filename, $config);
_drush_d8_migrate_execute($migration);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment