function drush_migrate_rollback in Migrate 6.2
Same name and namespace in other branches
- 7.2 migrate.drush.inc \drush_migrate_rollback()
Roll back one specified migration
File
- ./
migrate.drush.inc, line 766 - Drush support for the migrate module
Code
function drush_migrate_rollback($args = NULL) {
try {
$migrations = drush_migrate_get_migrations($args);
// Rollback in reverse order
$migrations = array_reverse($migrations, TRUE);
$options = array();
if ($idlist = drush_get_option('idlist', FALSE)) {
$options['idlist'] = $idlist;
}
if (drush_get_option('force', FALSE) == 1) {
$options['force'] = TRUE;
}
$limit = drush_get_option('limit');
if ($limit) {
$parts = explode(' ', $limit);
$options['limit']['value'] = $parts[0];
$options['limit']['unit'] = $parts[1];
if (!$options['limit']['unit']) {
$options['limit']['unit'] = 'items';
}
elseif ($options['limit']['unit'] != 'seconds' && $options['limit']['unit'] != 'second' && $options['limit']['unit'] != 'items' && $options['limit']['unit'] != 'item') {
drush_set_error(NULL, dt("Invalid limit unit '!unit'", array(
'!unit' => $options['limit']['unit'],
)));
return;
}
}
$feedback = drush_get_option('feedback');
if ($feedback) {
$parts = explode(' ', $feedback);
$options['feedback']['value'] = $parts[0];
$options['feedback']['unit'] = $parts[1];
if ($options['feedback']['unit'] != 'seconds' && $options['feedback']['unit'] != 'second' && $options['feedback']['unit'] != 'items' && $options['feedback']['unit'] != 'item') {
drush_set_error(NULL, dt("Invalid feedback frequency unit '!unit'", array(
'!unit' => $options['feedback']['unit'],
)));
return;
}
}
$instrument = drush_get_option('instrument');
global $_migrate_track_memory, $_migrate_track_timer;
switch ($instrument) {
case 'timer':
$_migrate_track_timer = TRUE;
break;
case 'memory':
$_migrate_track_memory = TRUE;
break;
case 'all':
$_migrate_track_timer = TRUE;
$_migrate_track_memory = TRUE;
break;
}
foreach ($migrations as $migration) {
drush_log(dt("Rolling back '!description' migration", array(
'!description' => $migration
->getMachineName(),
)));
$return = $migration
->processRollback($options);
// If it couldn't finish (presumably because it was appraoching memory_limit),
// continue in a subprocess
if ($return == MigrationBase::RESULT_INCOMPLETE) {
drush_migrate_invoke_process();
}
elseif ($return == MigrationBase::RESULT_STOPPED) {
break;
}
elseif ($return == MigrationBase::RESULT_SKIPPED) {
drush_log(dt("Skipping migration !name due to unfulfilled dependencies, use the --force option to run it anyway.", array(
'!name' => $migration
->getMachineName(),
)), 'warning');
}
}
} catch (MigrateException $e) {
drush_print($e
->getMessage());
exit;
}
if ($_migrate_track_memory) {
drush_migrate_print_memory();
}
if ($_migrate_track_timer && !drush_get_context('DRUSH_DEBUG')) {
drush_print_timers();
}
}