diff -u b/core/modules/config_translation/src/Plugin/migrate/source/d6/I18nProfileField.php b/core/modules/config_translation/src/Plugin/migrate/source/d6/I18nProfileField.php --- b/core/modules/config_translation/src/Plugin/migrate/source/d6/I18nProfileField.php +++ b/core/modules/config_translation/src/Plugin/migrate/source/d6/I18nProfileField.php @@ -2,9 +2,7 @@ namespace Drupal\config_translation\Plugin\migrate\source\d6; -@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); +@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. @@ -23,2 +21 @@ -class I18nProfileField extends ProfileFieldTranslation { -} +class I18nProfileField extends ProfileFieldTranslation {} diff -u b/core/modules/config_translation/src/Plugin/migrate/source/d6/ProfileFieldTranslation.php b/core/modules/config_translation/src/Plugin/migrate/source/d6/I18nProfileField.php --- b/core/modules/config_translation/src/Plugin/migrate/source/d6/ProfileFieldTranslation.php +++ b/core/modules/config_translation/src/Plugin/migrate/source/d6/I18nProfileField.php @@ -5,49 +5,17 @@ -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. * * @MigrateSource( - * id = "d6_profile_field_translation", + * id = "d6_i18n_profile_field", * source_provider = "i18n" * ) + * + * @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 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; - } - -} +class I18nProfileField extends ProfileFieldTranslation {} diff -u b/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateSystemMaintenanceTranslationTest.php b/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateSystemMaintenanceTranslationTest.php --- b/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateSystemMaintenanceTranslationTest.php +++ b/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateSystemMaintenanceTranslationTest.php @@ -8,6 +8,7 @@ * Upgrade i18n maintenance variables to system.*.yml. * * @group migrate_drupal_6 + * @group legacy */ class MigrateSystemMaintenanceTranslationTest extends MigrateDrupal6TestBase { diff -u b/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateSystemSiteTranslationTest.php b/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateSystemSiteTranslationTest.php --- b/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateSystemSiteTranslationTest.php +++ b/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateSystemSiteTranslationTest.php @@ -8,6 +8,7 @@ * Upgrade i18n_strings site variables to system.*.yml. * * @group migrate_drupal_6 + * @group legacy */ class MigrateSystemSiteTranslationTest extends MigrateDrupal6TestBase { diff -u b/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateUserConfigsTranslationTest.php b/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateUserConfigsTranslationTest.php --- b/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateUserConfigsTranslationTest.php +++ b/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateUserConfigsTranslationTest.php @@ -9,6 +9,7 @@ * Upgrade i18n variables to user.*.yml. * * @group migrate_drupal_6 + * @group legacy */ class MigrateUserConfigsTranslationTest extends MigrateDrupal6TestBase { diff -u b/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateUserProfileFieldInstanceTranslationTest.php b/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateUserProfileFieldInstanceTranslationTest.php --- b/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateUserProfileFieldInstanceTranslationTest.php +++ b/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateUserProfileFieldInstanceTranslationTest.php @@ -8,6 +8,7 @@ * Tests the user profile field instance migration. * * @group migrate_drupal_6 + * @group legacy */ class MigrateUserProfileFieldInstanceTranslationTest extends MigrateDrupal6TestBase { reverted: --- b/core/modules/config_translation/tests/src/Kernel/Plugin/migrate/source/d6/ProfileFieldTranslationTest.php +++ /dev/null @@ -1,79 +0,0 @@ - [ - [ - '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; - } - -} diff -u b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/i18nVariable.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/VariableTranslation.php --- b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/i18nVariable.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/VariableTranslation.php @@ -4,19 +4,97 @@ -@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); +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 = "i18n_variable" + * id = "variable_translation" * ) - * - * @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 VariableTranslation { +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; + } + } reverted: --- b/core/modules/migrate_drupal/tests/src/Unit/source/d6/VariableTranslationTest.php +++ /dev/null @@ -1,61 +0,0 @@ - '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";'], - ], - ]; - -} only in patch2: unchanged: --- a/core/modules/config_translation/tests/src/Kernel/Plugin/migrate/source/d6/I18nProfileFieldTest.php +++ b/core/modules/config_translation/tests/src/Kernel/Plugin/migrate/source/d6/I18nProfileFieldTest.php @@ -9,6 +9,7 @@ * * @covers \Drupal\config_translation\Plugin\migrate\source\d6\I18nProfileField * @group migrate_drupal + * @group legacy */ class I18nProfileFieldTest extends MigrateSqlSourceTestBase { only in patch2: unchanged: --- a/core/modules/config_translation/tests/src/Kernel/Plugin/migrate/source/d6/I18nProfileFieldTest.php +++ b/core/modules/config_translation/tests/src/Kernel/Plugin/migrate/source/d6/ProfileFieldTranslationTest.php @@ -7,10 +7,10 @@ /** * Tests the i18nProfileField source plugin. * - * @covers \Drupal\config_translation\Plugin\migrate\source\d6\I18nProfileField + * @covers \Drupal\config_translation\Plugin\migrate\source\d6\ProfileFieldTranslation * @group migrate_drupal */ -class I18nProfileFieldTest extends MigrateSqlSourceTestBase { +class ProfileFieldTranslationTest extends MigrateSqlSourceTestBase { /** * {@inheritdoc} only in patch2: unchanged: --- a/core/modules/migrate_drupal/tests/src/Unit/source/d6/i18nVariableTest.php +++ b/core/modules/migrate_drupal/tests/src/Unit/source/d6/VariableTranslationTest.php @@ -9,11 +9,11 @@ * * @group migrate_drupal */ -class i18nVariableTest extends MigrateSqlSourceTestCase { +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\i18nVariable'; + const PLUGIN_CLASS = 'Drupal\migrate_drupal\Plugin\migrate\source\d6\VariableTranslation'; /** * Define bare minimum migration configuration. @@ -22,7 +22,7 @@ class i18nVariableTest extends MigrateSqlSourceTestCase { 'id' => 'test', 'highWaterProperty' => ['field' => 'test'], 'source' => [ - 'plugin' => 'i18n_variable', + 'plugin' => 'variable_translation', 'variables' => [ 'site_slogan', 'site_name', only in patch2: unchanged: --- a/core/modules/migrate_drupal/tests/src/Unit/source/d6/i18nVariableTest.php +++ b/core/modules/migrate_drupal/tests/src/Unit/source/d6/i18nVariableTest.php @@ -8,6 +8,7 @@ * Tests the variable source plugin. * * @group migrate_drupal + * @group legacy */ class i18nVariableTest extends MigrateSqlSourceTestCase {