From f5d7fdbaf4dd471506092ce049d00f3b81d45ab5 Mon Sep 17 00:00:00 2001
From: James Sansbury <james.sansbury@lullabot.com>
Date: Tue, 22 May 2012 16:34:21 -0400
Subject: [PATCH] Issue #1595166: Support multiple source keys in MigrateList.

---
 plugins/sources/list.inc |   22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/plugins/sources/list.inc b/plugins/sources/list.inc
index d675e79..37c03d0 100644
--- a/plugins/sources/list.inc
+++ b/plugins/sources/list.inc
@@ -165,21 +165,29 @@ class MigrateSourceList extends MigrateSource {
   public function getNextRow() {
     $row = NULL;
     while ($this->idIterator->valid()) {
-      $id = $this->idIterator->current();
+      $ids = $this->idIterator->current();
       $this->idIterator->next();
 
       // Skip empty IDs
-      if (empty($id)) {
+      if (empty($ids)) {
         continue;
       }
 
       // Got a good ID, get the data and get out.
-      $row = $this->itemClass->getItem($id);
+      $row = $this->itemClass->getItem($ids);
+
       if ($row) {
-        // Save the ID using the map source key - it will be used for mapping
-        $sourceKey = $this->activeMap->getSourceKey();
-        $key_name = key($sourceKey);
-        $row->$key_name = $id;
+        // No matter what $ids is, be it a string, integer, object, or array, we
+        // cast it to an array so that it can be properly mapped to the source
+        // keys as specified by the map. This is done after getItem is called so
+        // that the ItemClass doesn't have to care about this requirement.
+        $ids = (array) $ids;
+        foreach (array_keys($this->activeMap->getSourceKey()) as $key_name) {
+          // Grab the first id and advance the array cursor. Then save the ID
+          // using the map source key - it will be used for mapping.
+          list(, $id) = each($ids);
+          $row->$key_name = $id;
+        }
       }
       break;
     }
-- 
1.7.10

