summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2017-04-27 14:01:36 -0400
committerNathaniel Catchpole2017-04-27 14:01:36 -0400
commit10db66234a86d0ad9b3cd9eef883dbe641503e5c (patch)
tree65ec7b035af68e003ee0e28e3e117dc70386b053
parent2afd387268ee73795dd488e38b960d8fda2ffbcf (diff)
Issue #2566779 by quietone, hussainweb, keithm, heddn, kekkis, Shawn DeArmond, Jo Fitzgerald, mlbrgl, phenaproxima, mikeryan, 13jupiters, Gábor Hojtsy: Migration D6 > D8 of CCK date fields
-rw-r--r--core/modules/datetime/src/Plugin/migrate/field/d6/DateField.php79
-rw-r--r--core/modules/datetime/tests/src/Unit/Plugin/migrate/field/d6/DateFieldTest.php35
-rw-r--r--core/modules/field/migration_templates/d6_field.yml6
-rw-r--r--core/modules/field/migration_templates/d6_field_instance_widget_settings.yml1
-rw-r--r--core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceTest.php38
-rw-r--r--core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldTest.php8
-rw-r--r--core/modules/migrate_drupal/tests/fixtures/drupal6.php50
-rw-r--r--core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTest.php5
8 files changed, 202 insertions, 20 deletions
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 0000000..60b1c68
--- /dev/null
+++ b/core/modules/datetime/src/Plugin/migrate/field/d6/DateField.php
@@ -0,0 +1,79 @@
+<?php
+
+namespace Drupal\datetime\Plugin\migrate\field\d6;
+
+use Drupal\migrate\Plugin\MigrationInterface;
+use Drupal\migrate\MigrateException;
+use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
+
+/**
+ * @MigrateField(
+ * id = "date",
+ * type_map = {
+ * "date" = "datetime",
+ * "datestamp" = "timestamp",
+ * "datetime" = "datetime",
+ * },
+ * core = {6}
+ * )
+ */
+class DateField extends FieldPluginBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getFieldWidgetMap() {
+ return [
+ 'date' => '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 0000000..b8b545a
--- /dev/null
+++ b/core/modules/datetime/tests/src/Unit/Plugin/migrate/field/d6/DateFieldTest.php
@@ -0,0 +1,35 @@
+<?php
+
+namespace Drupal\Tests\datetime\Unit\Plugin\migrate\field\d6;
+
+use Drupal\datetime\Plugin\migrate\field\d6\DateField;
+use Drupal\migrate\MigrateException;
+use Drupal\Tests\UnitTestCase;
+
+/**
+ * @group migrate
+ */
+class DateFieldTest extends UnitTestCase {
+
+ /**
+ * @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
+ */
+ protected $plugin;
+
+ /**
+ * @var \Drupal\migrate\Plugin\MigrationInterface
+ */
+ protected $migration;
+
+ /**
+ * Tests an Exception is thrown when the field type is not a known date type.
+ */
+ public function testUnknownDateType() {
+ $this->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 1205b67..f688842 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 46b7d75..8b1fb47 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 089ec49..049a50f 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 @@ class MigrateFieldInstanceTest extends MigrateDrupal6TestBase {
$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 835956c..fd0035d 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 @@ class MigrateFieldTest extends MigrateDrupal6TestBase {
$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 a2fbc81..adb27c7 100644
--- a/core/modules/migrate_drupal/tests/fixtures/drupal6.php
+++ b/core/modules/migrate_drupal/tests/fixtures/drupal6.php
@@ -2602,24 +2602,24 @@ $connection->insert('content_node_field')
->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 @@ $connection->insert('content_node_field_instance')
'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 @@ $connection->insert('content_node_field_instance')
'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 @@ $connection->schema()->createTable('content_type_story', array(
'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 @@ $connection->insert('content_type_story')
'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 @@ $connection->insert('content_type_story')
'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 @@ $connection->insert('content_type_story')
'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 @@ $connection->insert('content_type_story')
'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 @@ $connection->insert('content_type_story')
'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 @@ $connection->insert('content_type_story')
'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 @@ $connection->insert('content_type_story')
'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 @@ $connection->insert('content_type_story')
'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 8ed773f..590064d 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 @@ class MigrateNodeTest extends MigrateNodeTestBase {
$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);