diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/i18nVariable.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/i18nVariable.php new file mode 100644 index 0000000..660b507 --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/i18nVariable.php @@ -0,0 +1,101 @@ +variables = $this->configuration['variables']; + } + + /** + * {@inheritdoc} + */ + protected function initializeIterator() { + return new \ArrayIterator(array($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 an assiociative array of + * langauge and the values found in the source. + */ + protected function values() { + // Create an ID field so we can record migration in the map table. + // Arbitrarily, use the first variable name. + $values['id'] = reset($this->variables); + $results = $this->prepareQuery()->execute(); + $x = []; + foreach ($results->fetchAll() as $result) { + $x[$result->name][$result->language] = unserialize($result->value); + } + return $values + $x; + } + + /** + * {@inheritdoc} + */ + public function count() { + return intval($this->query()->countQuery()->execute()->fetchField() > 0); + } + + /** + * {@inheritdoc} + */ + public function fields() { + return array_combine($this->variables, $this->variables); + } + + /** + * {@inheritdoc} + */ + public function query() { + return $this->getDatabase() + ->select('variable', 'v') + ->fields('v') + ->condition('name', $this->variables, 'IN'); + } + + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['id']['type'] = 'string'; + return $ids; + } + +} diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal6.php b/core/modules/migrate_drupal/tests/fixtures/drupal6.php index 0f60343..6d7b3e6 100644 --- a/core/modules/migrate_drupal/tests/fixtures/drupal6.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal6.php @@ -7971,6 +7971,62 @@ 'mysql_character_set' => 'utf8', )); +$connection->schema()->createTable('i18n_variable', array( + 'fields' => array( + 'name' => array( + 'type' => 'varchar', + 'not null' => TRUE, + 'length' => '128', + 'default' => '', + ), + 'language' => array( + 'type' => 'varchar', + 'not null' => TRUE, + 'length' => '12', + 'default' => '', + ), + 'value' => array( + 'type' => 'varchar', + 'not null' => TRUE, + 'length' => '128', + 'default' => '', + ), + ), + 'primary key' => array( + 'name', + 'language', + ), + 'mysql_character_set' => 'utf8', +)); + +$connection->insert('i18n_variable') +->fields(array( + 'name', + 'language', + 'value', +)) +->values(array( + 'name' => 'site_name', + 'language' => 'fr', + 'value' => 's:11:"nom de site";', +)) +->values(array( + 'name' => 'site_slogan', + 'language' => 'fr', + 'value' => 's:19:"Migrate est génial";', +)) +->values(array( + 'name' => 'site_name', + 'language' => 'mi', + 'value' => 's:9:"ingoa_pae";', +)) +->values(array( + 'name' => 'site_slogan', + 'language' => 'mi', + 'value' => 's:19:"Ko whakamataku heke";', +)) +->execute(); + $connection->schema()->createTable('imagecache_action', array( 'fields' => array( 'actionid' => array( diff --git a/core/modules/migrate_drupal/tests/src/Unit/source/d6/i18nVariableTest.php b/core/modules/migrate_drupal/tests/src/Unit/source/d6/i18nVariableTest.php new file mode 100644 index 0000000..145660d --- /dev/null +++ b/core/modules/migrate_drupal/tests/src/Unit/source/d6/i18nVariableTest.php @@ -0,0 +1,67 @@ + 'test', + 'highWaterProperty' => array('field' => 'test'), + 'source' => [ + 'plugin' => 'i18n_variable', + 'variables' => [ + 'site_slogan', + 'site_name', + ], + ], + ]; + + /** + * Expected results from the source. + */ + protected $expectedResults = [ + [ + 'id' => 'site_slogan', + 'site_slogan' => [ + 'fr' => 'Migrate est génial', + 'mi' => 'Ko whakamataku heke', + ], + 'site_name' => [ + 'fr' => 'nom de site', + 'mi' => 'ingoa_pae', + ], + ] + ]; + + /** + * Database contents for tests. + */ + protected $databaseContents = [ + 'variable' => [ + array('name' => 'site_slogan', 'language' => 'mi', 'value' => 's:19:"Ko whakamataku heke";'), + array('name' => 'site_name', 'language' => 'mi', 'value' => 's:9:"ingoa_pae";'), + array('name' => 'site_slogan', 'language' => 'fr', 'value' => 's:19:"Migrate est génial";'), + array('name' => 'site_name', 'language' => 'fr', 'value' => 's:11:"nom de site";'), + ], + ]; + +}