diff -u b/core/modules/comment/tests/src/Unit/Migrate/d6/CommentSourceWithHighWaterTest.php b/core/modules/comment/tests/src/Unit/Migrate/d6/CommentSourceWithHighWaterTest.php --- b/core/modules/comment/tests/src/Unit/Migrate/d6/CommentSourceWithHighWaterTest.php +++ b/core/modules/comment/tests/src/Unit/Migrate/d6/CommentSourceWithHighWaterTest.php @@ -15,7 +15,7 @@ * {@inheritdoc} */ protected function setUp() { - $this->migrationConfiguration['high_water_property']['name'] = 'timestamp'; + $this->migrationConfiguration['source']['high_water_property']['name'] = 'timestamp'; array_shift($this->expectedResults); parent::setUp(); } diff -u b/core/modules/migrate/src/Plugin/Migration.php b/core/modules/migrate/src/Plugin/Migration.php --- b/core/modules/migrate/src/Plugin/Migration.php +++ b/core/modules/migrate/src/Plugin/Migration.php @@ -703,17 +703,20 @@ * {@inheritdoc} */ public function getHighWaterProperty() { - return $this->high_water_property; + return isset($this->getSourceConfiguration()['high_water_property']) ? $this->getSourceConfiguration()['high_water_property'] : NULL; } /** * {@inheritdoc} */ public function getHighWaterField() { - if (!empty($this->high_water_property['name'])) { - return !empty($this->high_water_property['alias']) ? - $this->high_water_property['alias'] . '.' . $this->high_water_property['name'] : - $this->high_water_property['name']; + if (isset ($this->getSourceConfiguration()['high_water_property'])) { + $high_water_property = $this->getSourceConfiguration()['high_water_property']; + if (!empty($high_water_property['name'])) { + return !empty($high_water_property['alias']) ? + $high_water_property['alias'] . '.' . $high_water_property['name'] : + $high_water_property['name']; + } } return NULL; } diff -u b/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php b/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php --- b/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php +++ b/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php @@ -210,20 +210,19 @@ } $this->query->addField($alias, 'source_row_status', 'migrate_map_source_row_status'); } - // 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 ($high_water_field = $this->migration->getHighWaterField()) { - $this->query->orderBy($high_water_field); - - $high_water = $this->migration->getHighWater(); - if (!empty($high_water)) { + if (isset($this->configuration['high_water_property'])) { + $high_water_property = $this->configuration['high_water_property']; + if (isset($high_water_property['name']) && ($high_water = $this->migration->getHighWater()) !== '') { + $high_water_field = $this->migration->getHighWaterField(); $conditions->condition($high_water_field, $high_water, '>'); + $this->query->orderBy($high_water_field); $condition_added = TRUE; } - if ($condition_added) { - $this->query->condition($conditions); - } + } + if ($condition_added) { + $this->query->condition($conditions); } return new \IteratorIterator($this->query->execute()); } diff -u b/core/modules/migrate/tests/modules/migrate_high_water_test/migration_templates/migrate.migration.high_water_test.yml b/core/modules/migrate/tests/modules/migrate_high_water_test/migration_templates/migrate.migration.high_water_test.yml --- b/core/modules/migrate/tests/modules/migrate_high_water_test/migration_templates/migrate.migration.high_water_test.yml +++ b/core/modules/migrate/tests/modules/migrate_high_water_test/migration_templates/migrate.migration.high_water_test.yml @@ -1,9 +1,9 @@ id: high_water_test label: High water test. -high_water_property: - name: changed source: plugin: high_water_test + high_water_property: + name: changed destination: plugin: entity:node migration_tags: diff -u b/core/modules/migrate/tests/modules/migrate_high_water_test/src/Plugin/migrate/source/HighWaterTest.php b/core/modules/migrate/tests/modules/migrate_high_water_test/src/Plugin/migrate/source/HighWaterTest.php --- b/core/modules/migrate/tests/modules/migrate_high_water_test/src/Plugin/migrate/source/HighWaterTest.php +++ b/core/modules/migrate/tests/modules/migrate_high_water_test/src/Plugin/migrate/source/HighWaterTest.php @@ -20,7 +20,6 @@ $query = $this ->select('high_water_node', 'm') ->fields('m', array_keys($this->fields())); - return $query; } diff -u b/core/modules/migrate/tests/src/Unit/MigrateSqlSourceTestCase.php b/core/modules/migrate/tests/src/Unit/MigrateSqlSourceTestCase.php --- b/core/modules/migrate/tests/src/Unit/MigrateSqlSourceTestCase.php +++ b/core/modules/migrate/tests/src/Unit/MigrateSqlSourceTestCase.php @@ -70,6 +70,13 @@ protected $plugin; /** + * The mock migration plugin. + * + * @var \Drupal\migrate\Plugin\Migration|\PHPUnit_Framework_MockObject_MockObject + */ + protected $migration; + + /** * {@inheritdoc} */ protected function setUp() { @@ -77,22 +84,11 @@ $state = $this->getMock('Drupal\Core\State\StateInterface'); $entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface'); - $migration = $this->getMigration(); - $migration->expects($this->any()) - ->method('getHighWater') - ->will($this->returnValue(static::ORIGINAL_HIGH_WATER)); - - // If the high-water value is set, expect that $migration->getHighWater() - // will be called at least once. - if (static::ORIGINAL_HIGH_WATER !== NULL) { - $migration->expects($this->atLeastOnce()) - ->method('getHighWater') - ->willReturn(static::ORIGINAL_HIGH_WATER); - } + $this->migration = $this->getMigration(); // Setup the plugin. $plugin_class = static::PLUGIN_CLASS; - $plugin = new $plugin_class($this->migrationConfiguration['source'], $this->migrationConfiguration['source']['plugin'], array(), $migration, $state, $entity_manager); + $plugin = new $plugin_class($this->migrationConfiguration['source'], $this->migrationConfiguration['source']['plugin'], array(), $this->migration, $state, $entity_manager); // Do some reflection to set the database and moduleHandler. $plugin_reflection = new \ReflectionClass($plugin); @@ -106,7 +102,7 @@ $module_handler_property->setValue($plugin, $module_handler); $plugin->setStringTranslation($this->getStringTranslationStub()); - $migration->expects($this->any()) + $this->migration->expects($this->any()) ->method('getSourcePlugin') ->will($this->returnValue($plugin)); $this->source = $plugin; @@ -117,6 +113,18 @@ * Tests that the source returns the same rows as expected. */ public function testRetrieval() { + + // If the high-water value is set, expect that $migration->getHighWater() + // and $migration->getHighWaterField. + if (static::ORIGINAL_HIGH_WATER !== NULL) { + $this->migration->expects($this->atLeastOnce()) + ->method('getHighWater') + ->willReturn(static::ORIGINAL_HIGH_WATER); + + $this->migration->expects($this->atLeastOnce()) + ->method('getHighWaterField') + ->will($this->returnValue('timestamp')); + } $this->assertInstanceOf(SelectInterface::class, $this->source->query()); $this->queryResultTest($this->source, $this->expectedResults); }