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 @@ -3,7 +3,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 +Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use ' . __NAMESPACE__ . '\ProfileFieldTranslation', E_USER_DEPRECATED); /** @@ -17,6 +17,8 @@ * @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 ProfileFieldTranslation { } reverted: --- b/core/modules/config_translation/src/Plugin/migrate/source/d6/ProfileFieldTranslation.php +++ /dev/null @@ -1,53 +0,0 @@ -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; - } - -} reverted: --- b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/VariableTranslation.php +++ /dev/null @@ -1,100 +0,0 @@ -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; - } - -} 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,17 +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. */ -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 +++ a/core/modules/migrate_drupal/tests/src/Unit/source/d6/i18nVariableTest.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 @@ 'id' => 'test', 'highWaterProperty' => ['field' => 'test'], 'source' => [ + 'plugin' => 'i18n_variable', - 'plugin' => 'variable_translation', 'variables' => [ 'site_slogan', 'site_name', only in patch2: unchanged: --- /dev/null +++ b/core/modules/config_translation/tests/src/Kernel/Plugin/migrate/source/d6/ProfileFieldTranslationTest.php @@ -0,0 +1,79 @@ + [ + [ + '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; + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/migrate_drupal/tests/src/Unit/source/d6/VariableTranslationTest.php @@ -0,0 +1,61 @@ + '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";'], + ], + ]; + +}