summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2017-03-14 09:55:39 +0000
committerAlex Pott2017-03-14 09:55:39 +0000
commit8fa8911c363f96934649f2c534876032e8ea67b2 (patch)
tree73dffeeaea8c3e7028bf6114cd2e30f147490ffe
parentd65d76f9581ca4726109518c755580ccc419fd4c (diff)
Issue #2824267 by quietone, shashikant_chauhan, faline, mikeryan, OnkelTem, ohthehugemanatee: Highwater condition isn't added (on remote databases)
-rw-r--r--core/modules/migrate/src/Plugin/migrate/source/SqlBase.php1
-rw-r--r--core/modules/migrate/tests/src/Kernel/HighWaterNotJoinableTest.php68
-rw-r--r--core/modules/migrate/tests/src/Kernel/HighWaterTest.php58
-rw-r--r--core/modules/migrate/tests/src/Kernel/MigrateSourceTestBase.php16
-rw-r--r--core/modules/migrate/tests/src/Kernel/MigrateSqlSourceTestBase.php6
-rw-r--r--core/modules/migrate/tests/src/Unit/MigrateSqlSourceTestCase.php9
6 files changed, 150 insertions, 8 deletions
diff --git a/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php b/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php
index 380814c..a8c66b2 100644
--- a/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php
+++ b/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php
@@ -274,6 +274,7 @@ abstract class SqlBase extends SourcePluginBase implements ContainerFactoryPlugi
$high_water_field = $this->getHighWaterField();
$conditions->condition($high_water_field, $high_water, '>');
$this->query->orderBy($high_water_field);
+ $condition_added = TRUE;
}
if ($condition_added) {
$this->query->condition($conditions);
diff --git a/core/modules/migrate/tests/src/Kernel/HighWaterNotJoinableTest.php b/core/modules/migrate/tests/src/Kernel/HighWaterNotJoinableTest.php
new file mode 100644
index 0000000..d0bc155
--- /dev/null
+++ b/core/modules/migrate/tests/src/Kernel/HighWaterNotJoinableTest.php
@@ -0,0 +1,68 @@
+<?php
+
+namespace Drupal\Tests\migrate\Kernel;
+
+/**
+ * Tests the high water handling.
+ *
+ * @covers \Drupal\migrate_sql_test\Plugin\migrate\source\HighWaterTest
+ * @group migrate
+ */
+class HighWaterNotJoinableTest extends MigrateSqlSourceTestBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = ['migrate', 'migrate_drupal', 'migrate_sql_test'];
+
+ /**
+ * {@inheritdoc}
+ */
+ public function providerSource() {
+
+ $tests = [];
+
+ // The source data.
+ $tests[0]['source_data']['high_water_node'] = [
+ [
+ 'id' => 1,
+ 'title' => 'Item 1',
+ 'changed' => 1,
+ ],
+ [
+ 'id' => 2,
+ 'title' => 'Item 2',
+ 'changed' => 2,
+ ],
+ [
+ 'id' => 3,
+ 'title' => 'Item 3',
+ 'changed' => 3,
+ ],
+ ];
+
+ // The expected results.
+ $tests[0]['expected_data'] = [
+ [
+ 'id' => 2,
+ 'title' => 'Item 2',
+ 'changed' => 2,
+ ],
+ [
+ 'id' => 3,
+ 'title' => 'Item 3',
+ 'changed' => 3,
+ ],
+ ];
+
+ $tests[0]['expected_count'] = NULL;
+ $tests[0]['configuration'] = [
+ 'high_water_property' => [
+ 'name' => 'changed',
+ ],
+ ];
+ $tests[0]['high_water'] = $tests[0]['source_data']['high_water_node'][0]['changed'];
+ return $tests;
+ }
+
+}
diff --git a/core/modules/migrate/tests/src/Kernel/HighWaterTest.php b/core/modules/migrate/tests/src/Kernel/HighWaterTest.php
index 0b6d368..952acd8 100644
--- a/core/modules/migrate/tests/src/Kernel/HighWaterTest.php
+++ b/core/modules/migrate/tests/src/Kernel/HighWaterTest.php
@@ -137,6 +137,64 @@ class HighWaterTest extends MigrateTestBase {
}
/**
+ * Tests high water property of SqlBase when rows marked for update.
+ */
+ public function testHighWaterUpdate() {
+ // Assert all of the nodes have been imported.
+ $this->assertNodeExists('Item 1');
+ $this->assertNodeExists('Item 2');
+ $this->assertNodeExists('Item 3');
+
+ // Update Item 1 setting its high_water_property to value that is below
+ // current high water mark.
+ $this->sourceDatabase->update('high_water_node')
+ ->fields([
+ 'title' => 'Item 1 updated',
+ 'changed' => 2,
+ ])
+ ->condition('title', 'Item 1')
+ ->execute();
+
+ // Update Item 2 setting its high_water_property to value equal to
+ // current high water mark.
+ $this->sourceDatabase->update('high_water_node')
+ ->fields([
+ 'title' => 'Item 2 updated',
+ 'changed' => 3,
+ ])
+ ->condition('title', 'Item 2')
+ ->execute();
+
+ // Update Item 3 setting its high_water_property to value that is above
+ // current high water mark.
+ $this->sourceDatabase->update('high_water_node')
+ ->fields([
+ 'title' => 'Item 3 updated',
+ 'changed' => 4,
+ ])
+ ->condition('title', 'Item 3')
+ ->execute();
+
+ // Set all rows as needing an update.
+ $id_map = $this->getMigration('high_water_test')->getIdMap();
+ $id_map->prepareUpdate();
+
+ $this->executeMigration('high_water_test');
+
+ // Item with lower highwater should be updated.
+ $this->assertNodeExists('Item 1 updated');
+ $this->assertNodeDoesNotExist('Item 1');
+
+ // Item with equal highwater should be updated.
+ $this->assertNodeExists('Item 2 updated');
+ $this->assertNodeDoesNotExist('Item 2');
+
+ // Item with greater highwater should be updated.
+ $this->assertNodeExists('Item 3 updated');
+ $this->assertNodeDoesNotExist('Item 3');
+ }
+
+ /**
* Assert that node with given title exists.
*
* @param string $title
diff --git a/core/modules/migrate/tests/src/Kernel/MigrateSourceTestBase.php b/core/modules/migrate/tests/src/Kernel/MigrateSourceTestBase.php
index e3b2f8c..8a99cad 100644
--- a/core/modules/migrate/tests/src/Kernel/MigrateSourceTestBase.php
+++ b/core/modules/migrate/tests/src/Kernel/MigrateSourceTestBase.php
@@ -135,23 +135,33 @@ abstract class MigrateSourceTestBase extends KernelTestBase {
* value (like FALSE or 'nope'), the source plugin will not be counted.
* @param array $configuration
* (optional) Configuration for the source plugin.
+ * @param mixed $high_water
+ * (optional) The value of the high water field.
*
* @dataProvider providerSource
*/
- public function testSource(array $source_data, array $expected_data, $expected_count = NULL, array $configuration = []) {
+ public function testSource(array $source_data, array $expected_data, $expected_count = NULL, array $configuration = [], $high_water = NULL) {
$plugin = $this->getPlugin($configuration);
// All source plugins must define IDs.
$this->assertNotEmpty($plugin->getIds());
+ // If there is a high water mark, set it in the high water storage.
+ if (isset($high_water)) {
+ $this->container
+ ->get('keyvalue')
+ ->get('migrate:high_water')
+ ->set($this->migration->reveal()->id(), $high_water);
+ }
+
if (is_null($expected_count)) {
$expected_count = count($expected_data);
}
// If an expected count was given, assert it only if the plugin is
// countable.
if (is_numeric($expected_count)) {
- $this->assertInstanceOf('\Countable', $plugin);
- $this->assertCount($expected_count, $plugin);
+ $this->assertInstanceOf('\Iterator', $plugin);
+ $this->assertSame($expected_count, iterator_count($plugin));
}
$i = 0;
diff --git a/core/modules/migrate/tests/src/Kernel/MigrateSqlSourceTestBase.php b/core/modules/migrate/tests/src/Kernel/MigrateSqlSourceTestBase.php
index f04183f..90187c9 100644
--- a/core/modules/migrate/tests/src/Kernel/MigrateSqlSourceTestBase.php
+++ b/core/modules/migrate/tests/src/Kernel/MigrateSqlSourceTestBase.php
@@ -63,12 +63,14 @@ abstract class MigrateSqlSourceTestBase extends MigrateSourceTestBase {
* (optional) How many rows the source plugin is expected to return.
* @param array $configuration
* (optional) Configuration for the source plugin.
+ * @param mixed $high_water
+ * (optional) The value of the high water field.
*
* @dataProvider providerSource
*
* @requires extension pdo_sqlite
*/
- public function testSource(array $source_data, array $expected_data, $expected_count = NULL, array $configuration = []) {
+ public function testSource(array $source_data, array $expected_data, $expected_count = NULL, array $configuration = [], $high_water = NULL) {
$plugin = $this->getPlugin($configuration);
// Since we don't yet inject the database connection, we need to use a
@@ -78,7 +80,7 @@ abstract class MigrateSqlSourceTestBase extends MigrateSourceTestBase {
$property->setAccessible(TRUE);
$property->setValue($plugin, $this->getDatabase($source_data));
- parent::testSource($source_data, $expected_data, $expected_count, $configuration);
+ parent::testSource($source_data, $expected_data, $expected_count, $configuration, $high_water);
}
}
diff --git a/core/modules/migrate/tests/src/Unit/MigrateSqlSourceTestCase.php b/core/modules/migrate/tests/src/Unit/MigrateSqlSourceTestCase.php
index be600c8..5f0d550 100644
--- a/core/modules/migrate/tests/src/Unit/MigrateSqlSourceTestCase.php
+++ b/core/modules/migrate/tests/src/Unit/MigrateSqlSourceTestCase.php
@@ -106,9 +106,12 @@ abstract class MigrateSqlSourceTestCase extends MigrateTestCase {
\Drupal::setContainer($container);
$migration = $this->getMigration();
- $migration->expects($this->any())
- ->method('getHighWater')
- ->will($this->returnValue(static::ORIGINAL_HIGH_WATER));
+
+ // Set the high water value.
+ \Drupal::keyValue('migrate:high_water')
+ ->expects($this->any())
+ ->method('get')
+ ->willReturn(static::ORIGINAL_HIGH_WATER);
// Setup the plugin.
$plugin_class = static::PLUGIN_CLASS;