You are here

function drush_migrate_deregister in Migrate 6.2

Same name and namespace in other branches
  1. 7.2 migrate.drush.inc \drush_migrate_deregister()

Deregister a given migration, or all orphaned migrations. Note that the migration might no longer "exist" (the class implementation might be gone), so we can't count on being able to instantiate it, or use migrate_migrations().

File

./migrate.drush.inc, line 1224
Drush support for the migrate module

Code

function drush_migrate_deregister($args = NULL) {
  try {
    $orphans = drush_get_option('orphans');
    if ($orphans) {
      $migrations = array();
      $result = db_select('migrate_status', 'ms')
        ->fields('ms', array(
        'class_name',
        'machine_name',
      ))
        ->execute();
      foreach ($result as $row) {
        if (!class_exists($row->class_name)) {
          $migrations[] = $row->machine_name;
        }
      }
    }
    else {
      $migrations = explode(',', $args);
    }
    foreach ($migrations as $machine_name) {
      drush_migrate_deregister_migration($machine_name);
      drush_log(dt("Deregistered '!description' migration", array(
        '!description' => $machine_name,
      )), 'success');
    }
  } catch (MigrateException $e) {
    drush_print($e
      ->getMessage());
    exit;
  }
}