Loading migrations/d7_scheduler_settings.yml +5 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ source: variables: - scheduler_allow_date_only - scheduler_default_time - scheduler_date_format source_module: scheduler process: allow_date_only: Loading @@ -18,6 +19,10 @@ process: plugin: default_value default_value: '00:00:00' source: scheduler_default_time hide_seconds: plugin: scheduler_hide_seconds default_value: false source: scheduler_date_format destination: plugin: config config_name: scheduler.settings src/Plugin/migrate/process/SchedulerHideSeconds.php 0 → 100644 +33 −0 Original line number Diff line number Diff line <?php namespace Drupal\scheduler\Plugin\migrate\process; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\Row; /** * Provides a process plugin for the hide_seconds global setting. * * The hide_seconds setting does not exist in Drupal 7 because the entire date * and time input format could be specified. However we can use the date format * as source input here and set hide_seconds to true if the seconds were not * included in the full date format. * * @MigrateProcessPlugin( * id = "scheduler_hide_seconds" * ) */ class SchedulerHideSeconds extends ProcessPluginBase { /** * {@inheritdoc} */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { // The value of hide_seconds is set to true if the source date format does // not contain seconds (lower case 's'). $hide_seconds = !strstr($value, 's'); return $hide_seconds; } } tests/fixtures/drupal7.php +4 −0 Original line number Diff line number Diff line Loading @@ -47,4 +47,8 @@ $connection->insert('variable') 'name' => 'scheduler_default_time', 'value' => 's:8:"00:00:38";', ]) ->values([ 'name' => 'scheduler_date_format', 'value' => 's:9:"Y-m-d H:i";', ]) ->execute(); tests/src/Kernel/MigrateSchedulerTest.php +2 −0 Original line number Diff line number Diff line Loading @@ -41,12 +41,14 @@ class MigrateSchedulerTest extends MigrateDrupal7TestBase { $config_before = $this->config('scheduler.settings'); $this->assertFalse($config_before->get('allow_date_only')); $this->assertSame('00:00:00', $config_before->get('default_time')); $this->assertFalse($config_before->get('hide_seconds')); $this->executeMigration('d7_scheduler_settings'); $config_after = $this->config('scheduler.settings'); $this->assertTrue($config_after->get('allow_date_only')); $this->assertSame('00:00:38', $config_after->get('default_time')); $this->assertTrue($config_after->get('hide_seconds')); } Loading Loading
migrations/d7_scheduler_settings.yml +5 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ source: variables: - scheduler_allow_date_only - scheduler_default_time - scheduler_date_format source_module: scheduler process: allow_date_only: Loading @@ -18,6 +19,10 @@ process: plugin: default_value default_value: '00:00:00' source: scheduler_default_time hide_seconds: plugin: scheduler_hide_seconds default_value: false source: scheduler_date_format destination: plugin: config config_name: scheduler.settings
src/Plugin/migrate/process/SchedulerHideSeconds.php 0 → 100644 +33 −0 Original line number Diff line number Diff line <?php namespace Drupal\scheduler\Plugin\migrate\process; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\Row; /** * Provides a process plugin for the hide_seconds global setting. * * The hide_seconds setting does not exist in Drupal 7 because the entire date * and time input format could be specified. However we can use the date format * as source input here and set hide_seconds to true if the seconds were not * included in the full date format. * * @MigrateProcessPlugin( * id = "scheduler_hide_seconds" * ) */ class SchedulerHideSeconds extends ProcessPluginBase { /** * {@inheritdoc} */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { // The value of hide_seconds is set to true if the source date format does // not contain seconds (lower case 's'). $hide_seconds = !strstr($value, 's'); return $hide_seconds; } }
tests/fixtures/drupal7.php +4 −0 Original line number Diff line number Diff line Loading @@ -47,4 +47,8 @@ $connection->insert('variable') 'name' => 'scheduler_default_time', 'value' => 's:8:"00:00:38";', ]) ->values([ 'name' => 'scheduler_date_format', 'value' => 's:9:"Y-m-d H:i";', ]) ->execute();
tests/src/Kernel/MigrateSchedulerTest.php +2 −0 Original line number Diff line number Diff line Loading @@ -41,12 +41,14 @@ class MigrateSchedulerTest extends MigrateDrupal7TestBase { $config_before = $this->config('scheduler.settings'); $this->assertFalse($config_before->get('allow_date_only')); $this->assertSame('00:00:00', $config_before->get('default_time')); $this->assertFalse($config_before->get('hide_seconds')); $this->executeMigration('d7_scheduler_settings'); $config_after = $this->config('scheduler.settings'); $this->assertTrue($config_after->get('allow_date_only')); $this->assertSame('00:00:38', $config_after->get('default_time')); $this->assertTrue($config_after->get('hide_seconds')); } Loading