From fb65f06c6111b87f41e5e146869a9d5a39f5aeaa Mon Sep 17 00:00:00 2001 From: webchick <drupal@webchick.net> Date: Fri, 20 Dec 2019 17:31:21 -0800 Subject: [PATCH] Issue #3096969 by quietone, gabesullice, Wim Leers, mikelutz: migrate_drupal's Variable source plugin always returns a row for processing, even if none of the variables for a migration are set on the source site --- .../src/Plugin/migrate/source/Variable.php | 3 +- .../Plugin/migrate/source/VariableTest.php | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/Variable.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/Variable.php index c901b85c11e8..1ac4a1b9e589 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/source/Variable.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/Variable.php @@ -60,7 +60,8 @@ protected function values() { * {@inheritdoc} */ public function count($refresh = FALSE) { - return intval($this->query()->countQuery()->execute()->fetchField() > 0); + // Variable always returns a single row with at minimum an 'id' property. + return 1; } /** diff --git a/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/VariableTest.php b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/VariableTest.php index b68c4b467b35..1a52b1df30de 100644 --- a/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/VariableTest.php +++ b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/VariableTest.php @@ -48,6 +48,42 @@ public function providerSource() { 'bar', ]; + // Tests getting one of two variables. + $tests[1]['source_data']['variable'] = [ + ['name' => 'foo', 'value' => 'i:1;'], + ['name' => 'bar', 'value' => 'b:0;'], + ]; + + $tests[1]['expected_data'] = [ + [ + 'id' => 'foo', + 'foo' => 1, + ], + ]; + + $tests[1]['expected_count'] = NULL; + + $tests[1]['configuration']['variables'] = [ + 'foo', + 'bar0', + ]; + + // Tests requesting mis-spelled variable names. + $tests[2]['source_data']['variable'] = [ + ['name' => 'foo', 'value' => 'i:1;'], + ['name' => 'bar', 'value' => 'b:0;'], + ]; + $tests[2]['expected_data'] = [ + [ + 'id' => 'foo0', + ], + ]; + $tests[2]['expected_count'] = NULL; + $tests[2]['configuration']['variables'] = [ + 'foo0', + 'bar0', + ]; + return $tests; } -- GitLab