Commit d44acb46 authored by catch's avatar catch

Issue #2861383 by quietone, Jo Fitzgerald, heddn: Rename i18n migrations to _translation

parent e2e1f61c
id: d6_i18n_system_maintenance
id: d6_system_maintenance_translation
label: Maintenance page configuration
migration_tags:
- Drupal 6
source:
plugin: i18n_variable
plugin: variable_translation
variables:
- site_offline_message
source_module: i18n
......
id: d6_i18n_system_site
id: d6_system_site_translation
label: Site configuration
migration_tags:
- Drupal 6
source:
plugin: i18n_variable
plugin: variable_translation
constants:
slash: '/'
variables:
......
id: d6_i18n_user_mail
id: d6_user_mail_translation
label: User mail configuration
migration_tags:
- Drupal 6
source:
plugin: i18n_variable
plugin: variable_translation
variables:
- user_mail_status_activated_subject
- user_mail_status_activated_body
......
id: d6_i18n_user_profile_field_instance
id: d6_user_profile_field_instance_translation
label: User profile field instance configuration
migration_tags:
- Drupal 6
source:
plugin: d6_i18n_profile_field
plugin: d6_profile_field_translation
constants:
entity_type: user
bundle: user
......
id: d6_i18n_user_settings
id: d6_user_settings_translation
label: User configuration
migration_tags:
- Drupal 6
source:
plugin: i18n_variable
plugin: variable_translation
variables:
- user_mail_status_blocked_notify
- user_mail_status_activated_notify
......
......@@ -2,7 +2,7 @@
namespace Drupal\config_translation\Plugin\migrate\source\d6;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
@trigger_error('The ' . __NAMESPACE__ . '\I18nProfileField is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use ' . __NAMESPACE__ . '\ProfileFieldTranslation', E_USER_DEPRECATED);
/**
* i18n strings profile field source from database.
......@@ -11,43 +11,11 @@
* id = "d6_i18n_profile_field",
* source_module = "i18nprofile"
* )
*
* @deprecated in Drupal 8.4.x and will be removed in Drupal 9.0.x. Use
* \Drupal\config_translation\Plugin\migrate\source\d6\ProfileFieldTranslation
* instead.
*
* @see https://www.drupal.org/node/2898649
*/
class I18nProfileField extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('profile_fields', 'pf')
->fields('pf', ['fid', 'name'])
->fields('i18n', ['property'])
->fields('lt', ['lid', 'translation', 'language']);
$query->leftJoin('i18n_strings', 'i18n', 'i18n.objectid = pf.name');
$query->leftJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
return $query;
}
/**
* {@inheritdoc}
*/
public function fields() {
return [
'fid' => $this->t('Profile field ID.'),
'lid' => $this->t('Locales target language ID.'),
'language' => $this->t('Language for this field.'),
'translation' => $this->t('Translation of either the title or explanation.'),
];
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['fid']['type'] = 'integer';
$ids['language']['type'] = 'string';
$ids['lid']['type'] = 'integer';
$ids['lid']['alias'] = 'lt';
return $ids;
}
}
class I18nProfileField extends ProfileFieldTranslation {}
<?php
namespace Drupal\config_translation\Plugin\migrate\source\d6;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Gets i18n strings profile field source from database.
*
* @MigrateSource(
* id = "d6_profile_field_translation",
* source_module = "i18nprofile"
* )
*/
class ProfileFieldTranslation extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('profile_fields', 'pf')
->fields('pf', ['fid', 'name'])
->fields('i18n', ['property'])
->fields('lt', ['lid', 'translation', 'language']);
$query->leftJoin('i18n_strings', 'i18n', 'i18n.objectid = pf.name');
$query->leftJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
return $query;
}
/**
* {@inheritdoc}
*/
public function fields() {
return [
'fid' => $this->t('Profile field ID.'),
'lid' => $this->t('Locales target language ID.'),
'language' => $this->t('Language for this field.'),
'translation' => $this->t('Translation of either the title or explanation.'),
];
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['fid']['type'] = 'integer';
$ids['language']['type'] = 'string';
$ids['lid']['type'] = 'integer';
$ids['lid']['alias'] = 'lt';
return $ids;
}
}
......@@ -8,8 +8,9 @@
* Upgrade i18n maintenance variables to system.*.yml.
*
* @group migrate_drupal_6
* @group legacy
*/
class MigrateI18nSystemMaintenanceTest extends MigrateDrupal6TestBase {
class MigrateSystemMaintenanceTranslationTest extends MigrateDrupal6TestBase {
public static $modules = ['language', 'config_translation'];
......@@ -18,7 +19,7 @@ class MigrateI18nSystemMaintenanceTest extends MigrateDrupal6TestBase {
*/
protected function setUp() {
parent::setUp();
$this->executeMigration('d6_i18n_system_maintenance');
$this->executeMigration('d6_system_maintenance_translation');
}
/**
......
......@@ -8,8 +8,9 @@
* Upgrade i18n_strings site variables to system.*.yml.
*
* @group migrate_drupal_6
* @group legacy
*/
class MigrateI18nSystemSiteTest extends MigrateDrupal6TestBase {
class MigrateSystemSiteTranslationTest extends MigrateDrupal6TestBase {
public static $modules = ['language', 'config_translation'];
......@@ -18,7 +19,7 @@ class MigrateI18nSystemSiteTest extends MigrateDrupal6TestBase {
*/
protected function setUp() {
parent::setUp();
$this->executeMigration('d6_i18n_system_site');
$this->executeMigration('d6_system_site_translation');
}
/**
......
......@@ -9,8 +9,9 @@
* Upgrade i18n variables to user.*.yml.
*
* @group migrate_drupal_6
* @group legacy
*/
class MigrateI18nUserConfigsTest extends MigrateDrupal6TestBase {
class MigrateUserConfigsTranslationTest extends MigrateDrupal6TestBase {
use SchemaCheckTestTrait;
......@@ -23,7 +24,7 @@ protected function setUp() {
parent::setUp();
$this->installSchema('locale',
['locales_source', 'locales_target', 'locales_location']);
$this->executeMigrations(['d6_i18n_user_mail', 'd6_i18n_user_settings']);
$this->executeMigrations(['d6_user_mail_translation', 'd6_user_settings_translation']);
}
/**
......
......@@ -8,8 +8,9 @@
* Tests the user profile field instance migration.
*
* @group migrate_drupal_6
* @group legacy
*/
class MigrateI18nUserProfileFieldInstanceTest extends MigrateDrupal6TestBase {
class MigrateUserProfileFieldInstanceTranslationTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
......@@ -23,7 +24,7 @@ public function testUserProfileFields() {
$this->executeMigrations([
'user_profile_field',
'user_profile_field_instance',
'd6_i18n_user_profile_field_instance',
'd6_user_profile_field_instance_translation',
]);
$language_manager = $this->container->get('language_manager');
......
......@@ -9,6 +9,7 @@
*
* @covers \Drupal\config_translation\Plugin\migrate\source\d6\I18nProfileField
* @group migrate_drupal
* @group legacy
*/
class I18nProfileFieldTest extends MigrateSqlSourceTestBase {
......
<?php
namespace Drupal\Tests\config_translation\Kernel\Plugin\migrate\source\d6;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests the i18nProfileField source plugin.
*
* @covers \Drupal\config_translation\Plugin\migrate\source\d6\ProfileFieldTranslation
* @group migrate_drupal
*/
class ProfileFieldTranslationTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['config_translation', 'migrate_drupal', 'user'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$test = [];
$test[0]['source_data'] = [
'profile_fields' => [
[
'fid' => 42,
'title' => 'I love migrations',
'name' => 'profile_love_migrations',
],
],
'i18n_strings' => [
[
'lid' => 10,
'objectid' => 'profile_love_migrations',
'type' => 'field',
'property' => 'title',
],
[
'lid' => 11,
'objectid' => 'profile_love_migrations',
'type' => 'field',
'property' => 'explanation'
]
],
'locales_target' => [
[
'lid' => 10,
'translation' => "J'aime les migrations.",
'language' => 'fr',
],
[
'lid' => 11,
'translation' => 'Si vous cochez cette case, vous aimez les migrations.',
'language' => 'fr',
],
],
];
$test[0]['expected_results'] = [
[
'property' => 'title',
'translation' => "J'aime les migrations.",
'language' => 'fr',
'fid' => '42',
'name' => 'profile_love_migrations',
],
[
'property' => 'explanation',
'translation' => 'Si vous cochez cette case, vous aimez les migrations.',
'language' => 'fr',
'fid' => '42',
'name' => 'profile_love_migrations',
],
];
return $test;
}
}
<?php
namespace Drupal\migrate_drupal\Plugin\migrate\source\d6;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\State\StateInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Drupal i18n_variable source from database.
*
* @MigrateSource(
* id = "variable_translation"
* )
*/
class VariableTranslation extends DrupalSqlBase {
/**
* The variable names to fetch.
*
* @var array
*/
protected $variables;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityManagerInterface $entity_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_manager);
$this->variables = $this->configuration['variables'];
}
/**
* {@inheritdoc}
*/
protected function initializeIterator() {
return new \ArrayIterator($this->values());
}
/**
* Return the values of the variables specified in the plugin configuration.
*
* @return array
* An associative array where the keys are the variables specified in the
* plugin configuration and the values are the values found in the source.
* A key/value pair is added for the language code. Only those values are
* returned that are actually in the database.
*/
protected function values() {
$values = [];
$result = $this->prepareQuery()->execute()->FetchAllAssoc('language');
foreach ($result as $i18n_variable) {
$values[]['language'] = $i18n_variable->language;
}
$result = $this->prepareQuery()->execute()->FetchAll();
foreach ($result as $i18n_variable) {
foreach ($values as $key => $value) {
if ($values[$key]['language'] === $i18n_variable->language) {
$values[$key][$i18n_variable->name] = unserialize($i18n_variable->value);
break;
}
}
}
return $values;
}
/**
* {@inheritdoc}
*/
public function count() {
return $this->initializeIterator()->count();
}
/**
* {@inheritdoc}
*/
public function fields() {
return array_combine($this->variables, $this->variables);
}
/**
* {@inheritdoc}
*/
public function query() {
return $this->getDatabase()
->select('i18n_variable', 'v')
->fields('v')
->condition('name', (array) $this->configuration['variables'], 'IN');
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['language']['type'] = 'string';
return $ids;
}
}
......@@ -2,10 +2,7 @@
namespace Drupal\migrate_drupal\Plugin\migrate\source\d6;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\State\StateInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
@trigger_error('The ' . __NAMESPACE__ . '\i18nVariable is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use ' . __NAMESPACE__ . '\VariableTranslation', E_USER_DEPRECATED);
/**
* Drupal i18n_variable source from database.
......@@ -13,88 +10,10 @@
* @MigrateSource(
* id = "i18n_variable"
* )
*
* @deprecated in Drupal 8.4.x and will be removed in Drupal 9.0.x. Use
* \Drupal\migrate_drupal\Plugin\migrate\source\d6\VariableTranslation instead.
*
* @see https://www.drupal.org/node/2898649
*/
class i18nVariable extends DrupalSqlBase {
/**
* The variable names to fetch.
*
* @var array
*/
protected $variables;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityManagerInterface $entity_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_manager);
$this->variables = $this->configuration['variables'];
}
/**
* {@inheritdoc}
*/
protected function initializeIterator() {
return new \ArrayIterator($this->values());
}
/**
* Return the values of the variables specified in the plugin configuration.
*
* @return array
* An associative array where the keys are the variables specified in the
* plugin configuration and the values are the values found in the source.
* A key/value pair is added for the language code. Only those values are
* returned that are actually in the database.
*/
protected function values() {
$values = [];
$result = $this->prepareQuery()->execute()->FetchAllAssoc('language');
foreach ($result as $i18n_variable) {
$values[]['language'] = $i18n_variable->language;
}
$result = $this->prepareQuery()->execute()->FetchAll();
foreach ($result as $i18n_variable) {
foreach ($values as $key => $value) {
if ($values[$key]['language'] === $i18n_variable->language) {
$values[$key][$i18n_variable->name] = unserialize($i18n_variable->value);
break;
}
}
}
return $values;
}
/**
* {@inheritdoc}
*/
public function count() {
return $this->initializeIterator()->count();
}
/**
* {@inheritdoc}
*/
public function fields() {
return array_combine($this->variables, $this->variables);
}
/**
* {@inheritdoc}
*/
public function query() {
return $this->getDatabase()
->select('i18n_variable', 'v')
->fields('v')
->condition('name', (array) $this->configuration['variables'], 'IN');
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['language']['type'] = 'string';
return $ids;
}
}
class i18nVariable extends VariableTranslation {}
<?php
namespace Drupal\Tests\migrate_drupal\Unit\source\d6;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* Tests the variable source plugin.
*
* @group migrate_drupal
*/
class VariableTranslationTest extends MigrateSqlSourceTestCase {
// The plugin system is not working during unit testing so the source plugin
// class needs to be manually specified.
const PLUGIN_CLASS = 'Drupal\migrate_drupal\Plugin\migrate\source\d6\VariableTranslation';
/**
* Define bare minimum migration configuration.
*/
protected $migrationConfiguration = [
'id' => 'test',
'highWaterProperty' => ['field' => 'test'],
'source' => [
'plugin' => 'variable_translation',
'variables' => [
'site_slogan',
'site_name',
],
],
];
/**
* Expected results from the source.
*/
protected $expectedResults = [
[
'language' => 'fr',
'site_slogan' => 'Migrate est génial',
'site_name' => 'nom de site',
],
[
'language' => 'mi',
'site_slogan' => 'Ko whakamataku heke',
'site_name' => 'ingoa_pae',
]
];
/**
* Database contents for tests.
*/
protected $databaseContents = [
'i18n_variable' => [
['name' => 'site_slogan', 'language' => 'fr', 'value' => 's:19:"Migrate est génial";'],
['name' => 'site_name', 'language' => 'fr', 'value' => 's:11:"nom de site";'],
['name' => 'site_slogan', 'language' => 'mi', 'value' => 's:19:"Ko whakamataku heke";'],
['name' => 'site_name', 'language' => 'mi', 'value' => 's:9:"ingoa_pae";'],
],
];
}
......@@ -8,6 +8,7 @@
* Tests the variable source plugin.
*
* @group migrate_drupal
* @group legacy
*/
class i18nVariableTest extends MigrateSqlSourceTestCase {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment