From 882121c0401814ffbc0f78585305e1fe87ef19f4 Mon Sep 17 00:00:00 2001
From: Marco Villegas <marvil07@gmail.com>
Date: Thu, 12 Apr 2012 20:50:00 -0500
Subject: [PATCH] Issue #1350284: Let drush migrate-status show migrations by
 group.

---
 migrate.drush.inc |  112 +++++++++++++++++++++++++++++-----------------------
 1 files changed, 62 insertions(+), 50 deletions(-)

diff --git a/migrate.drush.inc b/migrate.drush.inc
index bd695fe..77d1215 100644
--- a/migrate.drush.inc
+++ b/migrate.drush.inc
@@ -282,61 +282,73 @@ function drush_migrate_status($name = NULL) {
       $migrations = migrate_migrations();
     }
 
-    $table[] = array(dt('Name'), dt('Total'), dt('Imported'), dt('Unimported'),
-      dt('Status'), dt('Last imported'));
-    foreach ($migrations as $migration) {
-      $has_counts = TRUE;
-      if (method_exists($migration, 'sourceCount')) {
-        $total = $migration->sourceCount($refresh);
-        if ($total < 0) {
+    $groups = MigrateGroup::groups();
+    $table = array();
+    foreach ($groups as $group) {
+      $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('');
+          $table[] = array(dt('Group: !name', array('!name' => $group->getName())), dt('Total'), dt('Imported'), dt('Unimported'), dt('Status'), dt('Last imported'));
+        }
+        $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 {
-        $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());
-    }
-    drush_print_table($table, TRUE);
     }
+    drush_print_table($table);
+  }
   catch (MigrateException $e) {
     drush_print($e->getMessage());
     exit;
-- 
1.7.9.1

