From db9a8337ae06dedf2fdf76c96722b7467e81aa62 Mon Sep 17 00:00:00 2001
From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org>
Date: Tue, 16 May 2017 13:38:21 +0100
Subject: [PATCH] Issue #2865497 by quietone, pritish.kumar, Jo Fitzgerald,
 moshe weitzman, phenaproxima: Fix high-water condition for new migrations

---
 .../src/Plugin/migrate/source/SqlBase.php     |  2 +-
 .../src/Kernel/HighWaterNotJoinableTest.php   | 49 ++++++++++++++++++-
 2 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php b/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php
index de1accd510cb..2e85c6314e49 100644
--- a/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php
+++ b/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php
@@ -270,7 +270,7 @@ protected function initializeIterator() {
       }
       // 2. If we are using high water marks, also include rows above the mark.
       //    But, include all rows if the high water mark is not set.
-      if ($this->getHighWaterProperty() && ($high_water = $this->getHighWater()) !== '') {
+      if ($this->getHighWaterProperty() && ($high_water = $this->getHighWater())) {
         $high_water_field = $this->getHighWaterField();
         $conditions->condition($high_water_field, $high_water, '>');
         $this->query->orderBy($high_water_field);
diff --git a/core/modules/migrate/tests/src/Kernel/HighWaterNotJoinableTest.php b/core/modules/migrate/tests/src/Kernel/HighWaterNotJoinableTest.php
index 72edcd00457a..419857902672 100644
--- a/core/modules/migrate/tests/src/Kernel/HighWaterNotJoinableTest.php
+++ b/core/modules/migrate/tests/src/Kernel/HighWaterNotJoinableTest.php
@@ -19,9 +19,9 @@ class HighWaterNotJoinableTest extends MigrateSqlSourceTestBase {
    * {@inheritdoc}
    */
   public function providerSource() {
-
     $tests = [];
 
+    // Test high water when the map is not joinable.
     // The source data.
     $tests[0]['source_data']['high_water_node'] = [
       [
@@ -64,6 +64,53 @@ public function providerSource() {
       ],
     ];
     $tests[0]['high_water'] = $tests[0]['source_data']['high_water_node'][0]['changed'];
+
+    // Test high water initialized to NULL.
+    $tests[1]['source_data'] = $tests[0]['source_data'];
+    $tests[1]['expected_data'] = [
+      [
+        'id' => 1,
+        'title' => 'Item 1',
+        'changed' => 1,
+      ],
+      [
+        'id' => 2,
+        'title' => 'Item 2',
+        'changed' => 2,
+      ],
+      [
+        'id' => 3,
+        'title' => 'Item 3',
+        'changed' => 3,
+      ],
+    ];
+    $tests[1]['expected_count'] = $tests[0]['expected_count'];
+    $tests[1]['configuration'] = $tests[0]['configuration'];
+    $tests[1]['high_water'] = NULL;
+
+    // Test high water initialized to an empty string.
+    $tests[2]['source_data'] = $tests[0]['source_data'];
+    $tests[2]['expected_data'] = [
+      [
+        'id' => 1,
+        'title' => 'Item 1',
+        'changed' => 1,
+      ],
+      [
+        'id' => 2,
+        'title' => 'Item 2',
+        'changed' => 2,
+      ],
+      [
+        'id' => 3,
+        'title' => 'Item 3',
+        'changed' => 3,
+      ],
+    ];
+    $tests[2]['expected_count'] = $tests[0]['expected_count'];
+    $tests[2]['configuration'] = $tests[0]['configuration'];
+    $tests[2]['high_water'] = '';
+
     return $tests;
   }
 
-- 
GitLab