diff --git a/core/modules/language/migration_templates/d6_default_language.yml b/core/modules/language/migration_templates/d6_default_language.yml deleted file mode 100644 index 8c37415..0000000 --- a/core/modules/language/migration_templates/d6_default_language.yml +++ /dev/null @@ -1,23 +0,0 @@ -id: d6_default_language -label: Default language -migration_tags: - - Drupal 6 -source: - plugin: default_language -process: - default_langcode: - - - plugin: callback - callable: get_object_vars - source: language_default - - - plugin: extract - index: - - language - -destination: - plugin: config - config_name: system.site -migration_dependencies: - required: - - language diff --git a/core/modules/language/migration_templates/default_language.yml b/core/modules/language/migration_templates/default_language.yml new file mode 100644 index 0000000..d7e52ad --- /dev/null +++ b/core/modules/language/migration_templates/default_language.yml @@ -0,0 +1,25 @@ +id: default_language +label: Default language +migration_tags: + - Drupal 6 + - Drupal 7 +source: + plugin: variable + variables: + - language_default +process: + default_langcode: + - + plugin: callback + callable: get_object_vars + source: language_default + - + plugin: extract + index: + - language +destination: + plugin: default_langcode + config_name: system.site +migration_dependencies: + required: + - language diff --git a/core/modules/language/src/Plugin/migrate/destination/DefaultLangcode.php b/core/modules/language/src/Plugin/migrate/destination/DefaultLangcode.php new file mode 100644 index 0000000..47c44c0 --- /dev/null +++ b/core/modules/language/src/Plugin/migrate/destination/DefaultLangcode.php @@ -0,0 +1,35 @@ +getDestination(); + + // Check if the language exists. + if (ConfigurableLanguage::load($destination['default_langcode']) === NULL) { + throw new MigrateException(sprintf("The language '%s' does not exist on this site.", $destination['default_langcode'])); + } + + $this->config->set('default_langcode', $destination['default_langcode']); + $this->config->save(); + return [$this->config->getName()]; + } + +} diff --git a/core/modules/language/src/Plugin/migrate/source/DefaultLanguage.php b/core/modules/language/src/Plugin/migrate/source/DefaultLanguage.php deleted file mode 100644 index 2d0d650..0000000 --- a/core/modules/language/src/Plugin/migrate/source/DefaultLanguage.php +++ /dev/null @@ -1,83 +0,0 @@ -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 deleted file mode 100644 index 9f7c7c9..0000000 --- a/core/modules/language/src/Tests/Migrate/d6/MigrateDefaultLanguageTest.php +++ /dev/null @@ -1,61 +0,0 @@ -doTestMigration('fr'); - } - - /** - * Tests the migration of the language_default variable to the - * system.site.default_langcode config key, with a non-existent language. - */ - public function testMigrationWithNonExistentLanguage() { - $this->doTestMigration('tv'); - } - - /** - * Helper method to test the migration. - */ - protected function doTestMigration($langcode) { - // The default language of the test fixture is English. Change it to - // something else before migrating, to be sure that the source site - // default language is migrated. - $value = 'O:8:"stdClass":11:{s:8:"language";s:2:"' . $langcode . '";s:4:"name";s:6:"French";s:6:"native";s:6:"French";s:9:"direction";s:1:"0";s:7:"enabled";i:1;s:7:"plurals";s:1:"0";s:7:"formula";s:0:"";s:6:"domain";s:0:"";s:6:"prefix";s:0:"";s:6:"weight";s:1:"0";s:10:"javascript";s:0:"";}'; - $this->sourceDatabase->update('variable') - ->fields(array( - 'value' => $value - )) - ->condition('name', 'language_default' ) - ->execute(); - $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')); - } - -} diff --git a/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateDefaultLanguageTest.php b/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateDefaultLanguageTest.php new file mode 100644 index 0000000..4f408e2 --- /dev/null +++ b/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateDefaultLanguageTest.php @@ -0,0 +1,56 @@ +doTestMigration('fr'); + } + + /** + * Tests the migration of the language_default variable to the + * system.site.default_langcode config key, with a non-existent language. + */ + public function testMigrationWithNonExistentLanguage() { + $this->doTestMigration('tv'); + } + + /** + * Helper method to test the migration. + */ + protected function doTestMigration($langcode) { + // The default language of the test fixture is English. Change it to + // something else before migrating, to be sure that the source site + // default language is migrated. + $value = 'O:8:"stdClass":11:{s:8:"language";s:2:"' . $langcode . '";s:4:"name";s:6:"French";s:6:"native";s:6:"French";s:9:"direction";s:1:"0";s:7:"enabled";i:1;s:7:"plurals";s:1:"0";s:7:"formula";s:0:"";s:6:"domain";s:0:"";s:6:"prefix";s:0:"";s:6:"weight";s:1:"0";s:10:"javascript";s:0:"";}'; + $this->sourceDatabase->update('variable') + ->fields(array( + 'value' => $value + )) + ->condition('name', 'language_default' ) + ->execute(); + $this->executeMigrations(['language', 'default_language']); + $default_language = ConfigurableLanguage::load($langcode); + $this->assertNotNull($default_language); + $this->assertIdentical($langcode, $this->config('system.site')->get('default_langcode')); + } + +} diff --git a/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateDefaultLanguageTest.php b/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateDefaultLanguageTest.php new file mode 100644 index 0000000..7867652 --- /dev/null +++ b/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateDefaultLanguageTest.php @@ -0,0 +1,56 @@ +doTestMigration('is'); + } + + /** + * Tests the migration of the language_default variable to the + * system.site.default_langcode config key, with a non-existent language. + */ + public function testMigrationWithNonExistentLanguage() { + $this->doTestMigration('tv'); + } + + /** + * Helper method to test the migration. + */ + protected function doTestMigration($langcode) { + // The default language of the test fixture is English. Change it to + // something else before migrating, to be sure that the source site + // default language is migrated. + $value = 'O:8:"stdClass":11:{s:8:"language";s:2:"' . $langcode . '";s:4:"name";s:9:"Icelandic";s:6:"native";s:9:"Icelandic";s:9:"direction";s:1:"0";s:7:"enabled";i:1;s:7:"plurals";s:1:"0";s:7:"formula";s:0:"";s:6:"domain";s:0:"";s:6:"prefix";s:0:"";s:6:"weight";s:1:"0";s:10:"javascript";s:0:"";}'; + $this->sourceDatabase->update('variable') + ->fields(array( + 'value' => $value + )) + ->condition('name', 'language_default' ) + ->execute(); + $this->executeMigrations(['language', 'default_language']); + $default_language = ConfigurableLanguage::load($langcode); + $this->assertNotNull($default_language); + $this->assertIdentical($langcode, $this->config('system.site')->get('default_langcode')); + } + +} diff --git a/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php index f5ffdbf..4c1f4d3 100644 --- a/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php +++ b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php @@ -170,7 +170,7 @@ class MigrateUpgradeForm extends ConfirmFormBase { 'source_module' => 'dblog', 'destination_module' => 'dblog', ], - 'd6_default_language' => [ + 'default_language' => [ 'source_module' => 'locale', 'destination_module' => 'language', ],