You are here

function drush_migrate_status in Migrate 7.2

Same name and namespace in other branches
  1. 6.2 migrate.drush.inc \drush_migrate_status()
  2. 6 migrate.drush.inc \drush_migrate_status()

A simplified version of the dashboard page.

File

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

Code

function drush_migrate_status($name = NULL) {
  try {
    $refresh = drush_get_option('refresh');
    $group_option = drupal_strtolower(drush_get_option('group'));
    $names_only = drush_get_option('names-only');

    // Validate input and load Migration(s).
    if ($name) {
      if ($migration = MigrationBase::getInstance($name)) {
        $migrations = array(
          $migration,
        );
      }
      else {
        return drush_set_error(dt('Unrecognized migration: !cn', array(
          '!cn' => $name,
        )));
      }
    }
    else {
      $migrations = migrate_migrations();
    }
    $groups = MigrateGroup::groups();
    $table = array();
    foreach ($groups as $group) {
      if ($group_option && drupal_strtolower($group
        ->getName()) != $group_option) {
        continue;
      }
      $group_members_count = 0;
      foreach ($migrations as $migration) {
        if ($migration
          ->getGroup() != $group) {

          // This migration is not from this group.
          continue;
        }
        ++$group_members_count;
        if ($group_members_count == 1) {

          // An empty line and the headers.
          $table[] = array(
            '',
          );
          if ($names_only) {
            $table[] = array(
              dt('Group: !name', array(
                '!name' => $group
                  ->getName(),
              )),
            );
          }
          else {
            $table[] = array(
              dt('Group: !name', array(
                '!name' => $group
                  ->getName(),
              )),
              dt('Total'),
              dt('Imported'),
              dt('Unprocessed'),
              dt('Status'),
              dt('Last imported'),
            );
          }
        }
        if (!$names_only) {
          $has_counts = TRUE;
          if (method_exists($migration, 'sourceCount')) {
            $total = $migration
              ->sourceCount($refresh);
            if ($total < 0) {
              $has_counts = FALSE;
              $total = dt('N/A');
            }
          }
          else {
            $has_counts = FALSE;
            $total = dt('N/A');
          }
          if (method_exists($migration, 'importedCount')) {
            $imported = $migration
              ->importedCount();
            $processed = $migration
              ->processedCount();
          }
          else {
            $has_counts = FALSE;
            $imported = dt('N/A');
          }
          if ($has_counts) {
            $unimported = $total - $processed;
          }
          else {
            $unimported = dt('N/A');
          }
          $status = $migration
            ->getStatus();
          switch ($status) {
            case MigrationBase::STATUS_IDLE:
              $status = dt('Idle');
              break;
            case MigrationBase::STATUS_IMPORTING:
              $status = dt('Importing');
              break;
            case MigrationBase::STATUS_ROLLING_BACK:
              $status = dt('Rolling back');
              break;
            case MigrationBase::STATUS_STOPPING:
              $status = dt('Stopping');
              break;
            case MigrationBase::STATUS_DISABLED:
              $status = dt('Disabled');
              break;
            default:
              $status = dt('Unknown');
              break;
          }
          $table[] = array(
            $migration
              ->getMachineName(),
            $total,
            $imported,
            $unimported,
            $status,
            $migration
              ->getLastImported(),
          );
        }
        else {
          $table[] = array(
            $migration
              ->getMachineName(),
          );
        }
      }
    }
    drush_print_table($table);
  } catch (MigrateException $e) {
    drush_print($e
      ->getMessage());
    exit;
  }
}