diff --git a/core/modules/datetime/src/Plugin/migrate/field/d6/DateField.php b/core/modules/datetime/src/Plugin/migrate/field/d6/DateField.php new file mode 100644 index 0000000000000000000000000000000000000000..60b1c68c830678d48245887b2302e9e63dc26abb --- /dev/null +++ b/core/modules/datetime/src/Plugin/migrate/field/d6/DateField.php @@ -0,0 +1,79 @@ + 'datetime_default', + 'datetime' => 'datetime_default', + 'datestamp' => 'datetime_timestamp', + ]; + } + + /** + * {@inheritdoc} + */ + public function getFieldFormatterMap() { + // See d6_field_formatter_settings.yml and + // FieldPluginBase::processFieldFormatter(). + return []; + } + + /** + * {@inheritdoc} + */ + public function processFieldValues(MigrationInterface $migration, $field_name, $data) { + switch ($data['type']) { + case 'date': + $from_format = 'Y-m-d\TH:i:s'; + $to_format = 'Y-m-d\TH:i:s'; + break; + case 'datestamp': + $from_format = 'U'; + $to_format = 'U'; + break; + case 'datetime': + $from_format = 'Y-m-d H:i:s'; + $to_format = 'Y-m-d\TH:i:s'; + break; + default: + throw new MigrateException(sprintf('Field %s of type %s is an unknown date field type.', $field_name, var_export($data['type'], TRUE))); + } + $process = [ + 'value' => [ + 'plugin' => 'format_date', + 'from_format' => $from_format, + 'to_format' => $to_format, + 'source' => 'value', + ], + ]; + + $process = [ + 'plugin' => 'iterator', + 'source' => $field_name, + 'process' => $process, + ]; + $migration->mergeProcessOfProperty($field_name, $process); + } + +} diff --git a/core/modules/datetime/tests/src/Unit/Plugin/migrate/field/d6/DateFieldTest.php b/core/modules/datetime/tests/src/Unit/Plugin/migrate/field/d6/DateFieldTest.php new file mode 100644 index 0000000000000000000000000000000000000000..b8b545af805a250a83b342fbafa6217747c65754 --- /dev/null +++ b/core/modules/datetime/tests/src/Unit/Plugin/migrate/field/d6/DateFieldTest.php @@ -0,0 +1,35 @@ +migration = $this->prophesize('Drupal\migrate\Plugin\MigrationInterface')->reveal(); + $this->plugin = new DateField([], '', []); + + $this->setExpectedException(MigrateException::class, "Field field_date of type 'timestamp' is an unknown date field type."); + $this->plugin->processFieldValues($this->migration, 'field_date', ['type' => 'timestamp']); + } + +} diff --git a/core/modules/field/migration_templates/d6_field.yml b/core/modules/field/migration_templates/d6_field.yml index 1205b67efac8ca6088746997c1560940897cbef8..f6888424f2136aacf17996ede6a1051cc0207b16 100644 --- a/core/modules/field/migration_templates/d6_field.yml +++ b/core/modules/field/migration_templates/d6_field.yml @@ -40,12 +40,6 @@ process: filefield: imagefield_widget: image filefield_widget: file - date: - date_select: datetime - datestamp: - date_select: datetime - datetime: - date_select: datetime fr_phone: phone_textfield: telephone be_phone: diff --git a/core/modules/field/migration_templates/d6_field_instance_widget_settings.yml b/core/modules/field/migration_templates/d6_field_instance_widget_settings.yml index 46b7d75989b2fde0cddc93f927f6cb2192f3dac7..8b1fb47ca10680b696bae31169e50330112ad7c2 100644 --- a/core/modules/field/migration_templates/d6_field_instance_widget_settings.yml +++ b/core/modules/field/migration_templates/d6_field_instance_widget_settings.yml @@ -49,6 +49,7 @@ process: email_textfield: email_default date_select: datetime_default date_text: datetime_default + date_popup: datetime_default imagefield_widget: image_image phone_textfield: telephone_default optionwidgets_onoff: boolean_checkbox diff --git a/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceTest.php b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceTest.php index 089ec4906ab1cc40f0d80685bb3a8edc2c900f82..049a50fa1ca02b64a246fbec9fec2275a7be85e6 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceTest.php @@ -101,6 +101,44 @@ public function testFieldInstanceMigration() { $this->assertIdentical('default link title', $entity->field_test_link->title, 'Field field_test_link default title is correct.'); $this->assertIdentical('https://www.drupal.org', $entity->field_test_link->url, 'Field field_test_link default title is correct.'); $this->assertIdentical([], $entity->field_test_link->options['attributes']); + + // Test date field. + $field = FieldConfig::load('node.story.field_test_date'); + $this->assertInstanceOf(FieldConfig::class, $field); + $this->assertSame('Date Field', $field->label()); + $this->assertSame('An example date field.', $field->getDescription()); + $expected = ['datetime_type' => 'datetime']; + $this->assertSame($expected, $field->getSettings()); + $expected = [ + [ + 'default_date_type' => 'relative', + 'default_date' => 'blank', + ], + ]; + $this->assertSame($expected, $field->getDefaultValueLiteral()); + $this->assertTrue($field->isTranslatable()); + + // Test datetime field. + $field = FieldConfig::load('node.story.field_test_datetime'); + $this->assertInstanceOf(FieldConfig::class, $field); + $this->assertSame('Datetime Field', $field->label()); + $this->assertSame('An example datetime field.', $field->getDescription()); + $expected = ['datetime_type' => 'datetime']; + $this->assertSame($expected, $field->getSettings()); + $expected = []; + $this->assertSame($expected, $field->getDefaultValueLiteral()); + $this->assertTrue($field->isTranslatable()); + + // Test datestamp field. + $field = FieldConfig::load('node.story.field_test_datestamp'); + $this->assertInstanceOf(FieldConfig::class, $field); + $this->assertSame('Date Stamp Field', $field->label()); + $this->assertSame('An example date stamp field.', $field->getDescription()); + $expected = []; + $this->assertSame($expected, $field->getSettings()); + $expected = []; + $this->assertSame($expected, $field->getDefaultValueLiteral()); + $this->assertTrue($field->isTranslatable()); } /** diff --git a/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldTest.php b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldTest.php index 835956cb93f8f845f1d90c619b6a319a09c14140..fd0035d03ebf879a8bb18bd346f7ee519516d247 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldTest.php @@ -62,6 +62,14 @@ public function testFields() { $field_storage = FieldStorageConfig::load('node.field_test_datetime'); $this->assertIdentical("datetime", $field_storage->getType(), t('Field type is @fieldtype. It should be datetime.', ['@fieldtype' => $field_storage->getType()])); + // Date fields. + $field_storage = FieldStorageConfig::load('node.field_test_datetime'); + $this->assertSame("datetime", $field_storage->getType(), t('Field type is @fieldtype. It should be datetime.', ['@fieldtype' => $field_storage->getType()])); + $field_storage = FieldStorageConfig::load('node.field_test_datestamp'); + $this->assertSame("timestamp", $field_storage->getType(), t('Field type is @fieldtype. It should be timestamp.', ['@fieldtype' => $field_storage->getType()])); + $field_storage = FieldStorageConfig::load('node.field_test_date'); + $this->assertSame("datetime", $field_storage->getType(), t('Field type is @fieldtype. It should be datetime.', ['@fieldtype' => $field_storage->getType()])); + // Decimal field with radio buttons. $field_storage = FieldStorageConfig::load('node.field_test_decimal_radio_buttons'); $this->assertIdentical("list_float", $field_storage->getType(), t('Field type is @fieldtype. It should be list_float.', ['@fieldtype' => $field_storage->getType()])); diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal6.php b/core/modules/migrate_drupal/tests/fixtures/drupal6.php index a2fbc81dd5776d35f58eda926205ce41bed9ecc9..adb27c73e33074bbc049948d6c349641f1f2dea0 100644 --- a/core/modules/migrate_drupal/tests/fixtures/drupal6.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal6.php @@ -2602,24 +2602,24 @@ ->values(array( 'field_name' => 'field_test_datestamp', 'type' => 'datestamp', - 'global_settings' => 'a:7:{s:11:"granularity";a:5:{s:4:"year";s:4:"year";s:5:"month";s:5:"month";s:3:"day";s:3:"day";s:4:"hour";s:4:"hour";s:6:"minute";s:6:"minute";}s:11:"timezone_db";s:3:"UTC";s:11:"tz_handling";s:4:"site";s:6:"todate";s:0:"";s:6:"repeat";i:0;s:16:"repeat_collapsed";s:0:"";s:14:"default_format";s:6:"medium";}', + 'global_settings' => 'a:13:{s:11:"granularity";a:6:{s:4:"year";s:4:"year";s:5:"month";s:5:"month";s:3:"day";s:3:"day";s:4:"hour";s:4:"hour";s:6:"minute";s:6:"minute";s:6:"second";i:0;}s:11:"timezone_db";s:3:"UTC";s:11:"tz_handling";s:4:"site";s:6:"todate";s:0:"";s:6:"repeat";i:0;s:18:"output_format_date";s:5:"m/d/Y";s:20:"output_format_custom";s:0:"";s:23:"output_format_date_long";s:5:"m/d/Y";s:25:"output_format_custom_long";s:0:"";s:25:"output_format_date_medium";s:5:"m/d/Y";s:27:"output_format_custom_medium";s:0:"";s:24:"output_format_date_short";s:5:"m/d/Y";s:26:"output_format_custom_short";s:0:"";}', 'required' => '0', 'multiple' => '0', 'db_storage' => '1', 'module' => 'date', - 'db_columns' => 'a:1:{s:5:"value";a:4:{s:4:"type";s:3:"int";s:8:"not null";b:0;s:8:"sortable";b:1;s:5:"views";b:1;}}', + 'db_columns' => 'a:2:{s:5:"value";a:4:{s:4:"type";s:3:"int";s:6:"length";i:11;s:8:"not null";b:0;s:8:"sortable";b:1;}s:6:"value2";a:4:{s:4:"type";s:3:"int";s:6:"length";i:11;s:8:"not null";b:0;s:8:"sortable";b:1;}}', 'active' => '1', 'locked' => '0', )) ->values(array( 'field_name' => 'field_test_datetime', 'type' => 'datetime', - 'global_settings' => 'a:7:{s:11:"granularity";a:5:{s:4:"year";s:4:"year";s:5:"month";s:5:"month";s:3:"day";s:3:"day";s:4:"hour";s:4:"hour";s:6:"minute";s:6:"minute";}s:11:"timezone_db";s:3:"UTC";s:11:"tz_handling";s:4:"site";s:6:"todate";s:0:"";s:6:"repeat";i:0;s:16:"repeat_collapsed";s:0:"";s:14:"default_format";s:6:"medium";}', + 'global_settings' => 'a:13:{s:11:"granularity";a:6:{s:4:"year";s:4:"year";s:5:"month";s:5:"month";s:3:"day";s:3:"day";s:4:"hour";s:4:"hour";s:6:"minute";s:6:"minute";s:6:"second";i:0;}s:11:"timezone_db";s:3:"UTC";s:11:"tz_handling";s:4:"site";s:6:"todate";s:0:"";s:6:"repeat";i:0;s:18:"output_format_date";s:5:"m/d/Y";s:20:"output_format_custom";s:0:"";s:23:"output_format_date_long";s:5:"m/d/Y";s:25:"output_format_custom_long";s:0:"";s:25:"output_format_date_medium";s:5:"m/d/Y";s:27:"output_format_custom_medium";s:0:"";s:24:"output_format_date_short";s:5:"m/d/Y";s:26:"output_format_custom_short";s:0:"";}', 'required' => '0', 'multiple' => '0', 'db_storage' => '1', 'module' => 'date', - 'db_columns' => 'a:1:{s:5:"value";a:4:{s:4:"type";s:8:"datetime";s:8:"not null";b:0;s:8:"sortable";b:1;s:5:"views";b:1;}}', + 'db_columns' => 'a:2:{s:5:"value";a:3:{s:4:"type";s:8:"datetime";s:8:"not null";b:0;s:8:"sortable";b:1;}s:6:"value2";a:3:{s:4:"type";s:8:"datetime";s:8:"not null";b:0;s:8:"sortable";b:1;}}', 'active' => '1', 'locked' => '0', )) @@ -2950,7 +2950,7 @@ 'type_name' => 'story', 'weight' => '11', 'label' => 'Date Stamp Field', - 'widget_type' => 'date_select', + 'widget_type' => 'date_text', 'widget_settings' => 'a:10:{s:13:"default_value";s:5:"blank";s:18:"default_value_code";s:0:"";s:14:"default_value2";s:4:"same";s:19:"default_value_code2";s:0:"";s:12:"input_format";s:13:"m/d/Y - H:i:s";s:19:"input_format_custom";s:0:"";s:9:"increment";s:1:"1";s:10:"text_parts";a:0:{}s:10:"year_range";s:5:"-3:+3";s:14:"label_position";s:5:"above";}', 'display_settings' => 'a:7:{s:6:"weight";s:2:"11";s:6:"parent";s:0:"";i:5;a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}s:5:"label";a:1:{s:6:"format";s:5:"above";}s:6:"teaser";a:2:{s:6:"format";s:6:"medium";s:7:"exclude";i:0;}s:4:"full";a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}i:4;a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}}', 'description' => 'An example date stamp field.', @@ -2962,8 +2962,8 @@ 'type_name' => 'story', 'weight' => '12', 'label' => 'Datetime Field', - 'widget_type' => 'date_select', - 'widget_settings' => 'a:10:{s:13:"default_value";s:5:"blank";s:18:"default_value_code";s:0:"";s:14:"default_value2";s:4:"same";s:19:"default_value_code2";s:0:"";s:12:"input_format";s:13:"m/d/Y - H:i:s";s:19:"input_format_custom";s:0:"";s:9:"increment";s:1:"1";s:10:"text_parts";a:0:{}s:10:"year_range";s:5:"-3:+3";s:14:"label_position";s:5:"above";}', + 'widget_type' => 'date_popup', + 'widget_settings' => 'a:10:{s:13:"default_value";s:5:"blank";s:18:"default_value_code";s:0:"";s:14:"default_value2";s:4:"same";s:19:"default_value_code2";s:0:"";s:12:"input_format";s:11:"d/m/Y H:i:s";s:19:"input_format_custom";s:0:"";s:9:"increment";s:1:"1";s:10:"text_parts";a:0:{}s:10:"year_range";s:5:"-3:+3";s:14:"label_position";s:5:"above";}', 'display_settings' => 'a:7:{s:6:"weight";s:2:"12";s:6:"parent";s:0:"";i:5;a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}s:5:"label";a:1:{s:6:"format";s:5:"above";}s:6:"teaser";a:2:{s:6:"format";s:5:"short";s:7:"exclude";i:0;}s:4:"full";a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}i:4;a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}}', 'description' => 'An example datetime field.', 'widget_module' => 'date', @@ -3351,6 +3351,16 @@ 'not null' => FALSE, 'size' => 'big', ), + 'field_test_datestamp_value2' => array( + 'type' => 'int', + 'not null' => FALSE, + 'size' => 'normal', + ), + 'field_test_datetime_value2' => array( + 'type' => 'varchar', + 'not null' => FALSE, + 'length' => '100', + ), ), 'primary key' => array( 'vid', @@ -3392,6 +3402,8 @@ 'field_test_imagefield_list', 'field_test_imagefield_data', 'field_test_text_single_checkbox2_value', + 'field_test_datestamp_value2', + 'field_test_datetime_value2', )) ->values(array( 'nid' => '1', @@ -3403,9 +3415,9 @@ 'field_test_link_url' => 'https://www.drupal.org/project/drupal', 'field_test_link_title' => 'Drupal project page', 'field_test_link_attributes' => 's:32:"a:1:{s:6:"target";s:6:"_blank";}";', - 'field_test_date_value' => NULL, - 'field_test_datestamp_value' => NULL, - 'field_test_datetime_value' => NULL, + 'field_test_date_value' => '2013-01-02T04:05:00', + 'field_test_datestamp_value' => '1391357160', + 'field_test_datetime_value' => '2015-03-04 06:07:00', 'field_test_email_email' => 'PrincessRuwenne@example.com', 'field_test_filefield_fid' => '5', 'field_test_filefield_list' => '1', @@ -3421,6 +3433,8 @@ 'field_test_imagefield_list' => NULL, 'field_test_imagefield_data' => NULL, 'field_test_text_single_checkbox2_value' => 'Hello', + 'field_test_datestamp_value2' => NULL, + 'field_test_datetime_value2' => NULL, )) ->values(array( 'nid' => '1', @@ -3432,9 +3446,9 @@ 'field_test_link_url' => 'https://www.drupal.org/project/drupal', 'field_test_link_title' => 'Drupal project page', 'field_test_link_attributes' => 's:32:"a:1:{s:6:"target";s:6:"_blank";}";', - 'field_test_date_value' => NULL, - 'field_test_datestamp_value' => NULL, - 'field_test_datetime_value' => NULL, + 'field_test_date_value' => '2013-01-02T04:05:00', + 'field_test_datestamp_value' => '1391357160', + 'field_test_datetime_value' => '2015-03-04 06:07:00', 'field_test_email_email' => 'PrincessRuwenne@example.com', 'field_test_filefield_fid' => NULL, 'field_test_filefield_list' => NULL, @@ -3450,6 +3464,8 @@ 'field_test_imagefield_list' => NULL, 'field_test_imagefield_data' => NULL, 'field_test_text_single_checkbox2_value' => NULL, + 'field_test_datestamp_value2' => NULL, + 'field_test_datetime_value2' => NULL, )) ->values(array( 'nid' => '2', @@ -3479,6 +3495,8 @@ 'field_test_imagefield_list' => NULL, 'field_test_imagefield_data' => NULL, 'field_test_text_single_checkbox2_value' => NULL, + 'field_test_datestamp_value2' => NULL, + 'field_test_datetime_value2' => NULL, )) ->values(array( 'nid' => '2', @@ -3508,6 +3526,8 @@ 'field_test_imagefield_list' => NULL, 'field_test_imagefield_data' => NULL, 'field_test_text_single_checkbox2_value' => NULL, + 'field_test_datestamp_value2' => NULL, + 'field_test_datetime_value2' => NULL, )) ->values(array( 'nid' => '9', @@ -3536,7 +3556,9 @@ 'field_test_imagefield_fid' => NULL, 'field_test_imagefield_list' => NULL, 'field_test_imagefield_data' => NULL, - 'field_test_text_single_checkbox2_value' => NULL, + 'field_test_text_single_checkbox2_value' => 'Off', + 'field_test_datestamp_value2' => '1391357160', + 'field_test_datetime_value2' => '2015-03-04 06:07:00', )) ->execute(); diff --git a/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTest.php b/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTest.php index 8ed773f9f336f133ca8c35aa8cf3a1db1970caa2..590064d89fda47fa553da25de5f727cd2b864c62 100644 --- a/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTest.php +++ b/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTest.php @@ -72,6 +72,11 @@ public function testNode() { $this->assertIdentical('1', $node->field_test_identical2->value, 'Integer value is correct'); $this->assertIdentical('This is a field with exclude unset.', $node->field_test_exclude_unset->value, 'Field with exclude unset is correct.'); + // Test that date fields are migrated. + $this->assertSame('2013-01-02T04:05:00', $node->field_test_date->value, 'Date field is correct'); + $this->assertSame('1391357160', $node->field_test_datestamp->value, 'Datestamp field is correct'); + $this->assertSame('2015-03-04T06:07:00', $node->field_test_datetime->value, 'Datetime field is correct'); + // Test that link fields are migrated. $this->assertIdentical('https://www.drupal.org/project/drupal', $node->field_test_link->uri); $this->assertIdentical('Drupal project page', $node->field_test_link->title);