From c3e6adec61c4afcbcca2f3cae2ff3d888fd232eb Mon Sep 17 00:00:00 2001 From: Lee Rowlands Date: Fri, 4 Sep 2020 13:24:36 +1000 Subject: [PATCH] Issue #3101045 by quietone, mikelutz, Stefan Kangas, NiklasBr: LanguageContentSettingsTaxonomyVocabulary source plugin should only add language column if it exists (cherry picked from commit 3f7861f848056804f5e149b064094ab616e7fbb0) --- ...guageContentSettingsTaxonomyVocabulary.php | 14 +++++++--- ...eContentTaxonomyVocabularySettingsTest.php | 26 +++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/core/modules/language/src/Plugin/migrate/source/d6/LanguageContentSettingsTaxonomyVocabulary.php b/core/modules/language/src/Plugin/migrate/source/d6/LanguageContentSettingsTaxonomyVocabulary.php index 4cde5687f6..7787865b61 100644 --- a/core/modules/language/src/Plugin/migrate/source/d6/LanguageContentSettingsTaxonomyVocabulary.php +++ b/core/modules/language/src/Plugin/migrate/source/d6/LanguageContentSettingsTaxonomyVocabulary.php @@ -19,8 +19,14 @@ class LanguageContentSettingsTaxonomyVocabulary extends DrupalSqlBase { * {@inheritdoc} */ public function query() { - return $this->select('vocabulary', 'v') - ->fields('v', ['vid', 'language']); + $query = $this->select('vocabulary', 'v') + ->fields('v', ['vid']); + if ($this->getDatabase() + ->schema() + ->fieldExists('vocabulary', 'language')) { + $query->addField('v', 'language'); + } + return $query; } /** @@ -44,9 +50,9 @@ public function prepareRow(Row $row) { // 2 - Predefined language for a vocabulary and its terms. // 3 - Per-language terms, translatable (referencing terms with different // languages) but not localizable. - $i18ntaxonomy_vocabulary = $this->variableGet('i18ntaxonomy_vocabulary', NULL); + $i18ntaxonomy_vocabulary = $this->variableGet('i18ntaxonomy_vocabulary', []); $vid = $row->getSourceProperty('vid'); - $state = FALSE; + $state = 0; if (array_key_exists($vid, $i18ntaxonomy_vocabulary)) { $state = $i18ntaxonomy_vocabulary[$vid]; } diff --git a/core/modules/language/tests/src/Kernel/Plugin/migrate/source/d6/LanguageContentTaxonomyVocabularySettingsTest.php b/core/modules/language/tests/src/Kernel/Plugin/migrate/source/d6/LanguageContentTaxonomyVocabularySettingsTest.php index c709859f76..e4abb3d9fe 100644 --- a/core/modules/language/tests/src/Kernel/Plugin/migrate/source/d6/LanguageContentTaxonomyVocabularySettingsTest.php +++ b/core/modules/language/tests/src/Kernel/Plugin/migrate/source/d6/LanguageContentTaxonomyVocabularySettingsTest.php @@ -75,7 +75,33 @@ public function providerSource() { ], ]; + // Test without a language column in the database. + $tests[1] = $tests[0]; + foreach ($tests[1]['source_data']['vocabulary'] as $key => $row) { + unset($tests[1]['source_data']['vocabulary'][$key]['language']); + } + $tests[1]['source_data']['variable'] = [ + [ + 'name' => 'i18ntaxonomy_vocabulary', + 'value' => 'a:4:{i:1;s:1:"0";i:2;s:1:"0";i:3;s:1:"3";i:5;s:1:"1";}', + ], + ]; + $tests[1]['expected_data'] = [ + [ + 'vid' => 1, + 'state' => 0, + ], + [ + 'vid' => 2, + 'state' => 0, + ], + ]; + + // Test without a i18ntaxonomy_vocabulary variable. + $tests[2] = $tests[1]; + unset($tests[2]['source_data']['variable']); return $tests; + } } -- GitLab