diff --git a/core/modules/migrate_drupal/src/Tests/Table/d6/Users.php b/core/modules/migrate_drupal/src/Tests/Table/d6/Users.php index 099c3605f5e2f7a182bb40a15fd3b488464da229..8d61b052e0dace86837ff411e635d425693ce3f2 100644 --- a/core/modules/migrate_drupal/src/Tests/Table/d6/Users.php +++ b/core/modules/migrate_drupal/src/Tests/Table/d6/Users.php @@ -251,12 +251,12 @@ public function load() { 'access' => '1391259674', 'login' => '1391152255', 'status' => '1', - 'timezone' => '3600', + 'timezone' => '-28800', 'language' => 'en', 'picture' => '', 'init' => 'bloggs@example.com', 'data' => 'a:0:{}', - 'timezone_name' => NULL, + 'timezone_name' => 'America/Anchorage', 'pass_plain' => 'joe.bloggs_pass', 'expected_timezone' => NULL, 'timezone_id' => '0', @@ -275,12 +275,12 @@ public function load() { 'access' => '1391259574', 'login' => '1391162255', 'status' => '1', - 'timezone' => '3600', + 'timezone' => '0', 'language' => 'en', 'picture' => '', 'init' => 'sal.saraniti@example.com', 'data' => 'a:0:{}', - 'timezone_name' => NULL, + 'timezone_name' => 'UTC', 'pass_plain' => 'sal.saraniti', 'expected_timezone' => NULL, 'timezone_id' => '0', @@ -299,7 +299,7 @@ public function load() { 'access' => '1390259574', 'login' => '1390162255', 'status' => '1', - 'timezone' => '3600', + 'timezone' => NULL, 'language' => 'en', 'picture' => '', 'init' => 'terry.saraniti@example.com', @@ -312,4 +312,4 @@ public function load() { } } -#ce6d7264b7ef5ed1ffe854326893e1e0 +#4a42570fa3c819b0b84e9552d689e2e7 diff --git a/core/modules/migrate_drupal/src/Tests/Table/d6/Variable.php b/core/modules/migrate_drupal/src/Tests/Table/d6/Variable.php index 83555c74935775d746cf0c6358d07f7bc90613d2..79e6680aca7d24b237dcf101d17127cd51f38e17 100644 --- a/core/modules/migrate_drupal/src/Tests/Table/d6/Variable.php +++ b/core/modules/migrate_drupal/src/Tests/Table/d6/Variable.php @@ -172,6 +172,9 @@ public function load() { ))->values(array( 'name' => 'comment_subject_field_story', 'value' => 's:1:"0";', + ))->values(array( + 'name' => 'configurable_timezones', + 'value' => 's:1:"0";', ))->values(array( 'name' => 'contact_default_status', 'value' => 'i:1;', @@ -379,6 +382,12 @@ public function load() { ))->values(array( 'name' => 'date_api_version', 'value' => 's:3:"5.2";', + ))->values(array( + 'name' => 'date_default_timezone', + 'value' => 's:4:"3600";', + ))->values(array( + 'name' => 'date_first_day', + 'value' => 's:1:"4";', ))->values(array( 'name' => 'date_format_long', 'value' => 's:24:"\L\O\N\G l, F j, Y - H:i";', @@ -725,4 +734,4 @@ public function load() { } } -#32b72a0543c243804368c7bc10b05be5 +#dd0717c35d3b181c80e5ad74ea2ed2f7 diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php index 551b70d2c3c474b67a589a5820d799ce80aaf055..b7dfb9ae5309070b058309f188246705316f569f 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php @@ -117,6 +117,7 @@ class MigrateDrupal6Test extends MigrateFullDrupalTestBase { 'd6_statistics_settings', 'd6_syslog_settings', 'd6_system_cron', + 'd6_system_date', 'd6_system_file', 'd6_system_image', 'd6_system_image_gd', diff --git a/core/modules/system/migration_templates/d6_system_date.yml b/core/modules/system/migration_templates/d6_system_date.yml new file mode 100644 index 0000000000000000000000000000000000000000..d9ee7880c1202ec964231715431abf6224b5674f --- /dev/null +++ b/core/modules/system/migration_templates/d6_system_date.yml @@ -0,0 +1,19 @@ +id: d6_system_date +label: Drupal 6 system date configuration +migration_tags: + - Drupal 6 +source: + plugin: variable + variables: + - configurable_timezones + - date_first_day + - date_default_timezone +process: + 'timezone/user/configurable': configurable_timezones + first_day: date_first_day + 'timezone/default': + plugin: timezone + source: date_default_timezone +destination: + plugin: config + config_name: system.date diff --git a/core/modules/system/src/Plugin/migrate/process/d6/TimeZone.php b/core/modules/system/src/Plugin/migrate/process/d6/TimeZone.php new file mode 100644 index 0000000000000000000000000000000000000000..dbb4a1d70ed3d45843970ca28e0db225cb713c69 --- /dev/null +++ b/core/modules/system/src/Plugin/migrate/process/d6/TimeZone.php @@ -0,0 +1,38 @@ +<?php + +/** + * @file + * Contains \Drupal\systeml\Plugin\migrate\process\d6\TimeZone. + */ + +namespace Drupal\system\Plugin\migrate\process\d6; + +use Drupal\migrate\MigrateExecutableInterface; +use Drupal\migrate\ProcessPluginBase; +use Drupal\migrate\Row; + +/** + * Process the D6 Timezone offset into a D8 compatible timezone name. + * + * @MigrateProcessPlugin( + * id = "timezone" + * ) + */ +class TimeZone extends ProcessPluginBase { + /** + * {@inheritdoc} + */ + public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { + $offset = $value; + // Convert the integer value of the offset (which can be either + // negative or positive) to a timezone name. + // Note: Daylight saving time is not to be used. + $timezone_name = timezone_name_from_abbr('', intval($offset), 0); + if (!$timezone_name) { + $timezone_name = 'UTC'; + } + + return $timezone_name; + } + +} diff --git a/core/modules/system/src/Tests/Migrate/d6/MigrateSystemDateTest.php b/core/modules/system/src/Tests/Migrate/d6/MigrateSystemDateTest.php new file mode 100644 index 0000000000000000000000000000000000000000..28b6bcb628961881400e2bdab24cc69fcf8fa901 --- /dev/null +++ b/core/modules/system/src/Tests/Migrate/d6/MigrateSystemDateTest.php @@ -0,0 +1,37 @@ +<?php + +/** + * @file + * Contains \Drupal\system\Tests\Migrate\d6\MigrateSystemDateTest. + */ + +namespace Drupal\system\Tests\Migrate\d6; + +use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase; + +/** + * Upgrade date time variables to system.date config + * + * @group migrate_drupal_6 + */ +class MigrateSystemDateTest extends MigrateDrupal6TestBase { + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + $this->executeMigration('d6_system_date'); + } + + /** + * Tests migration of user variables to system_date.yml. + */ + public function testSystemDate() { + $config = $this->config('system.date'); + $this->assertIdentical(4, $config->get('first_day')); + $this->assertIdentical(FALSE, $config->get('timezone.user.configurable')); + $this->assertIdentical("Europe/Paris", $config->get('timezone.default')); + } + +} diff --git a/core/modules/user/src/Plugin/migrate/process/d6/UserUpdate7002.php b/core/modules/user/src/Plugin/migrate/process/d6/UserUpdate7002.php index 9104b439cdd00d44b1443b683002c8844ce020fa..7e7331f531ebe14544b0cbd4351691e5b7e9d234 100644 --- a/core/modules/user/src/Plugin/migrate/process/d6/UserUpdate7002.php +++ b/core/modules/user/src/Plugin/migrate/process/d6/UserUpdate7002.php @@ -10,6 +10,9 @@ use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\Row; +use Drupal\Core\Config\Config; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Converts user time zones from time zone offsets to time zone names. @@ -18,7 +21,7 @@ * id = "user_update_7002" * ) */ -class UserUpdate7002 extends ProcessPluginBase { +class UserUpdate7002 extends ProcessPluginBase implements ContainerFactoryPluginInterface { /** * System timezones. @@ -27,16 +30,35 @@ class UserUpdate7002 extends ProcessPluginBase { */ protected static $timezones; + /** + * Contains the system.theme configuration object. + * + * @var \Drupal\Core\Config\Config + */ + protected $dateConfig; + /** * {@inheritdoc} */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition) { + public function __construct(array $configuration, $plugin_id, array $plugin_definition, Config $date_config) { parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->dateConfig = $date_config; if (!isset(static::$timezones)) { static::$timezones = system_time_zones(); } } + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('config.factory')->get('system.date') + ); + } /** * {@inheritdoc} */ @@ -54,6 +76,9 @@ public function transform($value, MigrateExecutableInterface $migrate_executable } } + if ($timezone === NULL) { + $timezone = $this->dateConfig->get('timezone.default'); + } return $timezone; } diff --git a/core/modules/user/src/Tests/Migrate/d6/MigrateUserTest.php b/core/modules/user/src/Tests/Migrate/d6/MigrateUserTest.php index 15368ab6d83e1ef4cae03ffa88402cddd4570aaa..b38bdeecbbfa95eaf0c8272a647532966fb97265 100644 --- a/core/modules/user/src/Tests/Migrate/d6/MigrateUserTest.php +++ b/core/modules/user/src/Tests/Migrate/d6/MigrateUserTest.php @@ -151,8 +151,8 @@ public function testUser() { // user preferred language is not configured on the site. We just want to // test if the value was imported correctly. $this->assertIdentical($source->language, $user->preferred_langcode->value); - $time_zone = $source->expected_timezone ?: $this->config('system.date')->get('timezone.default'); - $this->assertIdentical($time_zone, $user->getTimeZone()); + $expected_timezone_name = $source->timezone_name ?: $this->config('system.date')->get('timezone.default'); + $this->assertIdentical($expected_timezone_name, $user->getTimeZone()); $this->assertIdentical($source->init, $user->getInitialEmail()); $this->assertIdentical($roles, $user->getRoles());