From b680897ec825e43cdf1294eea574cf51fd8d9df2 Mon Sep 17 00:00:00 2001
From: heddn <lucashedding@1463982.no-reply.drupal.org>
Date: Sat, 21 Mar 2015 14:51:50 -0600
Subject: [PATCH] Issue #2390317 by techninja: Rows are ignored if external
 node migration is used

---
 components.inc               |  4 ----
 emails.inc                   |  4 ----
 lastdownload.inc             |  4 ----
 settings.inc                 | 10 ++++------
 submissions.inc              | 11 +++++------
 submitteddata.inc            |  9 +++------
 validationrule.inc           |  6 ++----
 validationrulecomponents.inc |  6 ++----
 8 files changed, 16 insertions(+), 38 deletions(-)

diff --git a/components.inc b/components.inc
index 41cbdbf..8655d8c 100644
--- a/components.inc
+++ b/components.inc
@@ -63,10 +63,6 @@ class WebformComponents extends Migration {
     if (parent::prepareRow($row) === FALSE) {
       return FALSE;
     }
-    $result = db_select("node", "n")->fields("n", array("nid"))->condition("nid", $row->nid)->execute()->fetchField();
-    if(!$result) {
-      return FALSE;
-    }
 
     // Users may have put tokens in the default values.
     // Prompt user if mapping uknown.
diff --git a/emails.inc b/emails.inc
index 42eb347..d83681c 100644
--- a/emails.inc
+++ b/emails.inc
@@ -57,10 +57,6 @@ class WebformEmails extends Migration {
     if (parent::prepareRow($row) === FALSE) {
       return FALSE;
     }
-    $result = db_select("node", "n")->fields("n", array("nid"))->condition("nid", $row->nid)->execute()->fetchField();
-    if(!$result) {
-      return FALSE;
-    }
   }
 
   public function prepare($entity, $row) {
diff --git a/lastdownload.inc b/lastdownload.inc
index f7cdf11..b720ad4 100644
--- a/lastdownload.inc
+++ b/lastdownload.inc
@@ -69,10 +69,6 @@ class WebformLastDownload extends Migration {
     if (parent::prepareRow($row) === FALSE) {
       return FALSE;
     }
-    $result = db_select("node", "n")->fields("n", array("nid"))->condition("nid", $row->nid)->execute()->fetchField();
-    if(!$result) {
-      return FALSE;
-    }
   }
 
   public function prepare($entity, $row) {
diff --git a/settings.inc b/settings.inc
index 7639a67..176da16 100644
--- a/settings.inc
+++ b/settings.inc
@@ -30,8 +30,7 @@ class WebformSettings extends Migration {
 
     $this->addSimpleMappings($simple_fields);
 
-    $this->addFieldMapping('nid', 'nid')
-      ->sourceMigration($arguments['node_migrations']);
+    $this->addFieldMapping('nid', 'nid');
 
     $this->addFieldMapping('confirmation_format', 'confirmation_format')
            ->callbacks(array($this, 'mapFormat'));
@@ -74,15 +73,14 @@ class WebformSettings extends Migration {
     if (parent::prepareRow($row) === FALSE) {
       return FALSE;
     }
-    $result = db_select("node", "n")->fields("n", array("nid"))->condition("nid", $row->nid)->execute()->fetchField();
-    if(!$result) {
-      return FALSE;
-    }
+
+    $row->nid = $this->handleSourceMigration($this->arguments['node_migrations'], $row->nid);
 
     // Node creation filled the table with a bunch of junk defaults.
     db_delete('webform')
       ->condition('nid', $row->nid)
       ->execute();
+
   }
 
   public function prepare($entity, $row) {
diff --git a/submissions.inc b/submissions.inc
index c916a58..ea556e8 100644
--- a/submissions.inc
+++ b/submissions.inc
@@ -29,8 +29,9 @@ class WebformSubmissions extends Migration {
 
     $this->addSimpleMappings($simple_fields);
 
-    $this->addFieldMapping('nid', 'nid')
-      ->sourceMigration($arguments['node_migrations']);
+    $this->addFieldMapping('nid', 'nid');
+
+    $this->addFieldMapping('serial', 'sid');
 
     // Get users if configured
     // Default uid to 1 if we're not mapping it.
@@ -58,10 +59,8 @@ class WebformSubmissions extends Migration {
     if (parent::prepareRow($row) === FALSE) {
       return FALSE;
     }
-    $result = db_select("node", "n")->fields("n", array("nid"))->condition("nid", $row->nid)->execute()->fetchField();
-    if(!$result) {
-      return FALSE;
-    }
+
+    $row->nid = $this->handleSourceMigration($this->arguments['node_migrations'], $row->nid);
   }
 
   public function prepare($entity, $row) {
diff --git a/submitteddata.inc b/submitteddata.inc
index 5e5205c..7e1c56d 100644
--- a/submitteddata.inc
+++ b/submitteddata.inc
@@ -47,8 +47,7 @@ class WebformSubmittedData extends Migration {
 
     $this->addSimpleMappings($simple_fields);
 
-    $this->addFieldMapping('nid', 'nid')
-      ->sourceMigration($arguments['node_migrations']);
+    $this->addFieldMapping('nid', 'nid');
 
     $this->addFieldMapping('sid', 'sid')
           ->sourceMigration('WebformSubmissions');
@@ -71,10 +70,8 @@ class WebformSubmittedData extends Migration {
     if (parent::prepareRow($row) === FALSE) {
       return FALSE;
     }
-    $result = db_select("node", "n")->fields("n", array("nid"))->condition("nid", $row->nid)->execute()->fetchField();
-    if(!$result) {
-      return FALSE;
-    }
+
+    $row->nid = $this->handleSourceMigration($this->arguments['node_migrations'], $row->nid);
 
     // find the type of the component we are transferring
     // cannot expand the base query because cid is part of the uniqueness
diff --git a/validationrule.inc b/validationrule.inc
index 3055dda..6b16f1b 100644
--- a/validationrule.inc
+++ b/validationrule.inc
@@ -49,10 +49,8 @@ class WebformValidationRule extends Migration {
     if (parent::prepareRow($row) === FALSE) {
       return FALSE;
     }
-    $result = db_select("node", "n")->fields("n", array("nid"))->condition("nid", $row->nid)->execute()->fetchField();
-    if(!$result) {
-      return FALSE;
-    }
+
+    $row->nid = $this->handleSourceMigration($this->arguments['node_migrations'], $row->nid);
   }
 
   public function prepare($entity, $row) {
diff --git a/validationrulecomponents.inc b/validationrulecomponents.inc
index 3670acb..18bc3ed 100644
--- a/validationrulecomponents.inc
+++ b/validationrulecomponents.inc
@@ -56,10 +56,8 @@ class WebformValidationRuleComponents extends Migration {
     if (parent::prepareRow($row) === FALSE) {
       return FALSE;
     }
-    $result = db_select("webform_validation_rule", "vr")->fields("vr", array("ruleid"))->condition("ruleid", $row->ruleid)->execute()->fetchField();
-    if(!$result) {
-        return FALSE;
-    }
+
+    $row->nid = $this->handleSourceMigration($this->arguments['node_migrations'], $row->nid);
   }
 
   public function prepare($entity, $row) {
-- 
2.3.3

