Commit 783ba6b0 authored by Gábor Hojtsy's avatar Gábor Hojtsy

Issue #2970848 by quietone, maxocub: i18n Variable to config: site offline message [d7]

(cherry picked from commit 34800398)
parent 73bcd5bd
......@@ -5,7 +5,7 @@ migration_tags:
- Configuration
- Multilingual
source:
plugin: variable_translation
plugin: d6_variable_translation
variables:
- site_offline_message
source_module: i18n
......
......@@ -5,7 +5,7 @@ migration_tags:
- Configuration
- Multilingual
source:
plugin: variable_translation
plugin: d6_variable_translation
constants:
slash: '/'
variables:
......
......@@ -5,7 +5,7 @@ migration_tags:
- Configuration
- Multilingual
source:
plugin: variable_translation
plugin: d6_variable_translation
variables:
- user_mail_status_activated_subject
- user_mail_status_activated_body
......
......@@ -5,7 +5,7 @@ migration_tags:
- Configuration
- Multilingual
source:
plugin: variable_translation
plugin: d6_variable_translation
variables:
- user_mail_status_blocked_notify
- user_mail_status_activated_notify
......
id: d7_system_maintenance_translation
label: Maintenance page configuration
migration_tags:
- Drupal 7
- Configuration
- Multilingual
source:
plugin: d7_variable_translation
variables:
- maintenance_mode_message
process:
langcode: language
message: maintenance_mode_message
destination:
plugin: config
config_name: system.maintenance
translations: true
<?php
namespace Drupal\Tests\config_translation\Kernel\Migrate\d7;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
/**
* Tests migrations of i18n maintenance variable.
*
* @group migrate_drupal_7
*/
class MigrateSystemMaintenanceTranslationTest extends MigrateDrupal7TestBase {
public static $modules = [
'language',
'config_translation',
// Required for translation migrations.
'migrate_drupal_multilingual',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->executeMigration('d7_system_maintenance_translation');
}
/**
* Tests migrations of i18n maintenance variable.
*/
public function testSystemMaintenance() {
$config = \Drupal::service('language_manager')->getLanguageConfigOverride('is', 'system.maintenance');
$this->assertSame('is - This is a custom maintenance mode message.', $config->get('message'));
}
}
<?php
namespace Drupal\migrate_drupal\Plugin\migrate\source\d6;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\State\StateInterface;
use Drupal\migrate\Plugin\MigrationInterface;
/**
* Gets Drupal i18n_variable source from database.
*
* @deprecated in Drupal 8.7.x and will be removed in Drupal 9.0.x.
* Use \Drupal\migrate_drupal\Plugin\migrate\source\d6\VariableTranslation.
*
* @see https://www.drupal.org/node/3006487
*
* @MigrateSource(
* id = "variable_translation",
* source_module = "system",
* )
*/
class D6VariableTranslation extends VariableTranslation {
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityManagerInterface $entity_manager) {
@trigger_error('The ' . __NAMESPACE__ . '\D6VariableTranslation is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Instead, use ' . __NAMESPACE__ . '\VariableTranslation. See https://www.drupal.org/node/3006487.', E_USER_DEPRECATED);
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_manager);
}
}
......@@ -11,7 +11,7 @@
* Drupal i18n_variable source from database.
*
* @MigrateSource(
* id = "variable_translation",
* id = "d6_variable_translation",
* source_module = "system",
* )
*/
......
<?php
namespace Drupal\migrate_drupal\Plugin\migrate\source\d7;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\State\StateInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Gets Drupal variable_store source from database.
*
* @MigrateSource(
* id = "d7_variable_translation",
* source_module = "i18n_variable",
* )
*/
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('realm_key');
foreach ($result as $variable_store) {
$values[]['language'] = $variable_store['realm_key'];
}
$result = $this->prepareQuery()->execute()->FetchAll();
foreach ($result as $variable_store) {
foreach ($values as $key => $value) {
if ($values[$key]['language'] === $variable_store['realm_key']) {
if ($variable_store['serialized']) {
$values[$key][$variable_store['name']] = unserialize($variable_store['value']);
break;
}
else {
$values[$key][$variable_store['name']] = $variable_store['value'];
break;
}
}
}
}
return $values;
}
/**
* {@inheritdoc}
*/
public function count($refresh = FALSE) {
return $this->initializeIterator()->count();
}
/**
* {@inheritdoc}
*/
public function fields() {
return array_combine($this->variables, $this->variables);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['language']['type'] = 'string';
return $ids;
}
/**
* {@inheritdoc}
*/
public function query() {
return $this->select('variable_store', 'vs')
->fields('vs')
->condition('realm', 'language')
->condition('name', (array) $this->configuration['variables'], 'IN');
}
}
......@@ -10,6 +10,7 @@
* @covers \Drupal\migrate_drupal\Plugin\migrate\source\d6\i18nVariable
*
* @group migrate_drupal
* @group legacy
*/
class i18nVariableTest extends MigrateSqlSourceTestBase {
......
<?php
namespace Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\d7;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests the variable source plugin.
*
* @covers \Drupal\migrate_drupal\Plugin\migrate\source\d7\VariableTranslation
*
* @group migrate_drupal
*/
class VariableTranslationTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['variable_store'] = [
[
'realm' => 'language',
'realm_key' => 'fr',
'name' => 'site_slogan',
'value' => 'fr - site slogan',
'serialized' => '0',
],
[
'realm' => 'language',
'realm_key' => 'fr',
'name' => 'user_mail_status_blocked_subject',
'value' => 'fr - BEGONE!',
'serialized' => '0',
],
[
'realm' => 'language',
'realm_key' => 'is',
'name' => 'site_slogan',
'value' => 's:16:"is - site slogan";',
'serialized' => '1',
],
];
// The expected results.
$tests[0]['expected_data'] = [
[
'language' => 'fr',
'site_slogan' => 'fr - site slogan',
'user_mail_status_blocked_subject' => 'fr - BEGONE!',
],
[
'language' => 'is',
'site_slogan' => 'is - site slogan',
],
];
// The expected count.
$tests[0]['expected_count'] = NULL;
// The migration configuration.
$tests[0]['configuration']['variables'] = [
'site_slogan',
'user_mail_status_blocked_subject',
];
return $tests;
}
}
......@@ -8,6 +8,7 @@
* Tests the variable source plugin.
*
* @group migrate_drupal
* @group legacy
*/
class VariableTranslationTest extends MigrateSqlSourceTestCase {
......
......@@ -20,6 +20,7 @@ class MigrateUpgrade7NoMultilingualTest extends MigrateUpgradeExecuteTestBase {
'file',
'language',
'content_translation',
'config_translation',
'migrate_drupal_ui',
'telephone',
'aggregator',
......@@ -207,7 +208,7 @@ public function testMigrateUpgradeExecute() {
}
$edits = $this->translatePostValues($edit);
$this->drupalPostForm(NULL, $edits, t('Review upgrade'));
$session->pageTextContains("Install migrate_drupal_multilingual to run migration 'd7_node_translation:article'.");
$session->pageTextContains("Install migrate_drupal_multilingual to run migration 'd7_system_maintenance_translation'.");
}
}
......@@ -138,6 +138,29 @@ protected function getAvailablePaths() {
*/
protected function getMissingPaths() {
return [
'entity_translation_i18n_menu',
'entity_translation_upgrade',
'i18n',
'i18n_block',
'i18n_contact',
'i18n_field',
'i18n_forum',
'i18n_menu',
'i18n_node',
'i18n_path',
'i18n_redirect',
'i18n_select',
'i18n_string',
'i18n_sync',
'i18n_taxonomy',
'i18n_translation',
'i18n_user',
'i18n_variable',
'variable',
'variable_admin',
'variable_realm',
'variable_store',
'variable_views',
'views',
];
}
......
......@@ -23,6 +23,7 @@ class MigrateUpgrade7Test extends MigrateUpgradeExecuteTestBase {
public static $modules = [
'file',
'language',
'config_translation',
'content_translation',
'migrate_drupal_ui',
'telephone',
......@@ -87,7 +88,7 @@ protected function getEntityCounts() {
'menu' => 6,
'taxonomy_term' => 18,
'taxonomy_vocabulary' => 4,
'tour' => 4,
'tour' => 5,
'user' => 4,
'user_role' => 3,
'menu_link_content' => 12,
......@@ -136,6 +137,7 @@ protected function getAvailablePaths() {
'file',
'filter',
'forum',
'i18n_variable',
'image',
'language',
'link',
......@@ -177,6 +179,10 @@ protected function getAvailablePaths() {
*/
protected function getMissingPaths() {
return [
'i18n',
'variable',
'variable_realm',
'variable_store',
// These modules are in the missing path list because they are installed
// on the source site but they are not installed on the destination site.
'syslog',
......
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