From ee4ef8a47a68bd1abea87e212d54221261bfcf92 Mon Sep 17 00:00:00 2001
From: andrew morton <drewish@zivtech.com>
Date: Tue, 25 Oct 2011 11:11:22 -0400
Subject: [PATCH] Issue #1321078 by drewish: Display incomplete dependencies in the error message.

---
 CHANGELOG.txt                   |    3 ++-
 includes/base.inc               |   14 ++++++++++++++
 migrate.drush.inc               |   25 ++++++++++++++++++-------
 migrate_ui/migrate_ui.pages.inc |    7 +++++--
 4 files changed, 39 insertions(+), 10 deletions(-)
 mode change 100755 => 100644 migrate.drush.inc

diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 62114f6..ada7a6e 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -3,6 +3,7 @@ Next release
 ============
 
 Features and enhancements
+- #1321078 - Display incomplete dependencies in the error message.
 - #1321062 - Simple base class for field handlers.
 - #1314448 - Added tnid to node destination handler.
 - #1231492 - Added source handler for retrieving content from file directories.
@@ -259,4 +260,4 @@ Bug fixes
 Migrate 2.0 Beta 1
 ==================
 Version 2 of the Migrate module is an entirely new implementation - it is
-pointless to list changes since Migrate 1.
\ No newline at end of file
+pointless to list changes since Migrate 1.
diff --git a/includes/base.inc b/includes/base.inc
index b5de62c..684aa27 100644
--- a/includes/base.inc
+++ b/includes/base.inc
@@ -728,6 +728,20 @@ abstract class MigrationBase {
   }
 
   /**
+   * Returns an array of the migration's dependencies that are incomplete.
+   */
+  public function incompleteDependencies() {
+    $incomplete = array();
+    foreach ($this->getDependencies() as $dependency) {
+      $migration = MigrationBase::getInstance($dependency);
+      if (!$migration->isComplete()) {
+        $incomplete[] = $dependency;
+      }
+    }
+    return $incomplete;
+  }
+
+  /**
    * Begin a process, ensuring only one process can be active
    * at once on a given migration.
    *
diff --git a/migrate.drush.inc b/migrate.drush.inc
old mode 100755
new mode 100644
index c8cf5e5..6bd463d
--- a/migrate.drush.inc
+++ b/migrate.drush.inc
@@ -927,9 +927,12 @@ function drush_migrate_import($args = NULL) {
         // Our first pass and in the parent process. Run a migration right here.
         $return = $migration->processImport($options);
         if ($return == MigrationBase::RESULT_SKIPPED) {
-          drush_log(dt('Skipping migration !name due to unfulfilled dependencies -
-              use the --force option to run it anyway',
-            array('!name' => $machine_name)), 'warning');
+          drush_log(dt("Skipping migration !name due to unfulfilled dependencies:\n  !depends\nUse the --force option to run it anyway.",
+            array(
+              '!name' => $machine_name,
+              '!depends' => implode("\n  ", $migration->incompleteDependencies()),
+            )),
+            'warning');
         }
         elseif ($return == MigrationBase::RESULT_STOPPED) {
           break;
@@ -944,8 +947,12 @@ function drush_migrate_import($args = NULL) {
           // 'object' holds the return code we care about.
           $return = $return['object'];
           if ($return == MigrationBase::RESULT_SKIPPED) {
-            drush_log(dt('Skipping migration !name due to unfulfilled dependencies',
-              array('!name' => $machine_name)), 'warning');
+            drush_log(dt("Skipping migration !name due to unfulfilled dependencies:\n  !depends\nUse the --force option to run it anyway.",
+              array(
+                '!name' => $machine_name,
+                '!depends' => implode("\n  ", $migration->incompleteDependencies()),
+              )),
+              'warning');
           }
           elseif ($return == MigrationBase::RESULT_STOPPED) {
             $stop = TRUE;
@@ -958,8 +965,12 @@ function drush_migrate_import($args = NULL) {
         // I'm in a subshell. Import then set return value so parent process can respawn or move on.
         $return = $migration->processImport($options);
         if ($return == MigrationBase::RESULT_SKIPPED) {
-          drush_log(dt('Skipping migration !name due to unfulfilled dependencies',
-            array('!name' => $machine_name)), 'warning');
+          drush_log(dt("Skipping migration !name due to unfulfilled dependencies:\n  !depends\n",
+            array(
+              '!name' => $machine_name,
+              '!depends' => implode("\n  ", $migration->incompleteDependencies()),
+            )),
+            'warning');
         }
         drush_backend_set_result($return);
       }
diff --git a/migrate_ui/migrate_ui.pages.inc b/migrate_ui/migrate_ui.pages.inc
index 4476ca1..7c3dfda 100644
--- a/migrate_ui/migrate_ui.pages.inc
+++ b/migrate_ui/migrate_ui.pages.inc
@@ -330,8 +330,11 @@ function migrate_ui_batch($operation, $machine_name, $limit, $update, &$context)
       }
       break;
     case MigrationBase::RESULT_SKIPPED:
-      $_migrate_messages[] = t('Skipped !name due to unfulfilled dependencies',
-        array('!name' => $machine_name));
+      $_migrate_messages[] = t("Skipped !name due to unfulfilled dependencies: !depends",
+        array(
+          '!name' => $machine_name,
+          '!depends' => implode(", ", $migration->incompleteDependencies()),
+        ));
       $context['finished'] = 1;
       break;
     case MigrationBase::RESULT_STOPPED:
-- 
1.7.0.4

