diff --git a/core/modules/language/migration_templates/d6_default_language.yml b/core/modules/language/migration_templates/d6_default_language.yml index 9813d01..8c37415 100644 --- a/core/modules/language/migration_templates/d6_default_language.yml +++ b/core/modules/language/migration_templates/d6_default_language.yml @@ -3,9 +3,7 @@ label: Default language migration_tags: - Drupal 6 source: - plugin: variable - variables: - - language_default + plugin: default_language process: default_langcode: - @@ -20,3 +18,6 @@ process: destination: plugin: config config_name: system.site +migration_dependencies: + required: + - language diff --git a/core/modules/language/src/Plugin/migrate/source/DefaultLanguage.php b/core/modules/language/src/Plugin/migrate/source/DefaultLanguage.php new file mode 100644 index 0000000..2d0d650 --- /dev/null +++ b/core/modules/language/src/Plugin/migrate/source/DefaultLanguage.php @@ -0,0 +1,83 @@ +values())); + } + + /** + * Return the value of the language_default variable. + * + * @return array + * An associative array where the key is the variable name + * and the value is the value found in the database. + */ + protected function values() { + // Create an ID field so we can record migration in the map table. + $values['id'] = 'language_default'; + $results = $this->prepareQuery()->execute()->fetchAllKeyed(); + $language_default = unserialize($results['language_default']); + + // Check if the language exists, fail otherwise. + if (ConfigurableLanguage::load($language_default->language) === NULL) { + throw new MigrateException("The language $language_default->language does not exists on this site."); + } + + return $values + ['language_default' => $language_default]; + } + + /** + * {@inheritdoc} + */ + public function query() { + return $this->getDatabase() + ->select('variable', 'v') + ->fields('v', array('name', 'value')) + ->condition('name', 'language_default'); + } + + /** + * {@inheritdoc} + */ + public function fields() { + return ['language_default' => 'language_default']; + } + + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['id']['type'] = 'string'; + return $ids; + } + +} diff --git a/core/modules/language/src/Tests/Migrate/d6/MigrateDefaultLanguageTest.php b/core/modules/language/src/Tests/Migrate/d6/MigrateDefaultLanguageTest.php index ff5965a..9f7c7c9 100644 --- a/core/modules/language/src/Tests/Migrate/d6/MigrateDefaultLanguageTest.php +++ b/core/modules/language/src/Tests/Migrate/d6/MigrateDefaultLanguageTest.php @@ -52,8 +52,7 @@ protected function doTestMigration($langcode) { )) ->condition('name', 'language_default' ) ->execute(); - $this->executeMigration('language'); - $this->executeMigration('d6_default_language'); + $this->executeMigrations(['language', 'd6_default_language']); $default_language = ConfigurableLanguage::load($langcode); $this->assertNotNull($default_language); $this->assertIdentical($langcode, $this->config('system.site')->get('default_langcode'));