diff --git a/core/modules/field/src/Plugin/migrate/process/d7/FieldSettings.php b/core/modules/field/src/Plugin/migrate/process/d7/FieldSettings.php index dc629a4..bf6dbf3 100644 --- a/core/modules/field/src/Plugin/migrate/process/d7/FieldSettings.php +++ b/core/modules/field/src/Plugin/migrate/process/d7/FieldSettings.php @@ -26,6 +26,14 @@ public function transform($value, MigrateExecutableInterface $migrate_executable } break; + case 'datetime': + if ($value['granularity']['hour'] === 0 + && $value['granularity']['minute'] === 0 + && $value['granularity']['second'] === 0) { + $value['datetime_type'] = 'date'; + } + break; + case 'taxonomy_term_reference': $value['target_type'] = 'taxonomy_term'; break; diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php index ab2fe8e..866aa44 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php @@ -101,6 +101,7 @@ public function testFields() { $this->assertEntity('node.field_node_entityreference', 'entity_reference', TRUE, -1); $this->assertEntity('node.field_user_entityreference', 'entity_reference', TRUE, 1); $this->assertEntity('node.field_term_entityreference', 'entity_reference', TRUE, -1); + $this->assertEntity('node.field_date_without_time', 'datetime', TRUE, 1); // Assert that the taxonomy term reference fields are referencing the // correct entity type. @@ -118,6 +119,12 @@ public function testFields() { $field = FieldStorageConfig::load('node.field_term_entityreference'); $this->assertIdentical('taxonomy_term', $field->getSetting('target_type')); + // Make sure that datetime fields get the right datetime_type setting + $field = FieldStorageConfig::load('node.field_date'); + $this->assertIdentical('datetime', $field->getSetting('datetime_type')); + $field = FieldStorageConfig::load('node.field_date_without_time'); + $this->assertIdentical('date', $field->getSetting('datetime_type')); + // Validate that the source count and processed count match up. /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */ $migration = $this->getMigration('d7_field'); diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal7.php b/core/modules/migrate_drupal/tests/fixtures/drupal7.php index 711d2ad..efef8b6 100644 --- a/core/modules/migrate_drupal/tests/fixtures/drupal7.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php @@ -3441,6 +3441,21 @@ 'translatable' => '0', 'deleted' => '0', )) +->values(array( + 'id' => '26', + 'field_name' => 'field_date_without_time', + 'type' => 'datetime', + 'module' => 'date', + 'active' => '1', + 'storage_type' => 'field_sql_storage', + 'storage_module' => 'field_sql_storage', + 'storage_active' => '1', + 'locked' => '0', + 'data' => 'a:7:{s:12:"translatable";s:1:"0";s:12:"entity_types";a:0:{}s:8:"settings";a:6:{s:11:"granularity";a:6:{s:5:"month";s:5:"month";s:3:"day";s:3:"day";s:4:"hour";i:0;s:6:"minute";i:0;s:4:"year";s:4:"year";s:6:"second";i:0;}s:11:"tz_handling";s:4:"site";s:11:"timezone_db";s:3:"UTC";s:13:"cache_enabled";i:0;s:11:"cache_count";s:1:"4";s:6:"todate";s:0:"";}s:7:"storage";a:5:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";s:1:"1";s:7:"details";a:1:{s:3:"sql";a:2:{s:18:"FIELD_LOAD_CURRENT";a:1:{s:34:"field_data_field_date_without_time";a:1:{s:5:"value";s:29:"field_date_without_time_value";}}s:19:"FIELD_LOAD_REVISION";a:1:{s:38:"field_revision_field_date_without_time";a:1:{s:5:"value";s:29:"field_date_without_time_value";}}}}}s:12:"foreign keys";a:0:{}s:7:"indexes";a:0:{}s:2:"id";s:1:"9";}', + 'cardinality' => '1', + 'translatable' => '0', + 'deleted' => '0', +)) ->execute(); $connection->schema()->createTable('field_config_instance', array( @@ -3861,6 +3876,15 @@ 'data' => 'a:6:{s:5:"label";s:12:"Private file";s:6:"widget";a:5:{s:6:"weight";s:2:"19";s:4:"type";s:12:"file_generic";s:6:"module";s:4:"file";s:6:"active";i:1;s:8:"settings";a:1:{s:18:"progress_indicator";s:8:"throbber";}}s:8:"settings";a:5:{s:14:"file_directory";s:0:"";s:15:"file_extensions";s:3:"txt";s:12:"max_filesize";s:0:"";s:17:"description_field";i:0;s:18:"user_register_form";b:0;}s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:5:"above";s:4:"type";s:12:"file_default";s:8:"settings";a:0:{}s:6:"module";s:4:"file";s:6:"weight";i:18;}}s:8:"required";i:0;s:11:"description";s:0:"";}', 'deleted' => '0', )) +->values(array( + 'id' => '43', + 'field_id' => '26', + 'field_name' => 'field_date_without_time', + 'entity_type' => 'node', + 'bundle' => 'test_content_type', + 'data' => 'a:6:{s:5:"label";s:17:"Date without time";s:6:"widget";a:5:{s:6:"weight";s:1:"2";s:4:"type";s:11:"date_select";s:6:"module";s:4:"date";s:6:"active";i:1;s:8:"settings";a:6:{s:12:"input_format";s:13:"m/d/Y - H:i:s";s:19:"input_format_custom";s:0:"";s:10:"year_range";s:5:"-3:+3";s:9:"increment";s:2:"15";s:14:"label_position";s:5:"above";s:10:"text_parts";a:0:{}}}s:8:"settings";a:5:{s:13:"default_value";s:3:"now";s:18:"default_value_code";s:0:"";s:14:"default_value2";s:4:"same";s:19:"default_value_code2";s:0:"";s:18:"user_register_form";b:0;}s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:5:"above";s:4:"type";s:12:"date_default";s:6:"weight";s:1:"3";s:8:"settings";a:5:{s:11:"format_type";s:4:"long";s:15:"multiple_number";s:0:"";s:13:"multiple_from";s:0:"";s:11:"multiple_to";s:0:"";s:6:"fromto";s:4:"both";}s:6:"module";s:4:"date";}}s:8:"required";i:0;s:11:"description";s:0:"";}', + 'deleted' => '0', +)) ->execute(); $connection->schema()->createTable('field_data_body', array( @@ -4318,6 +4342,91 @@ )) ->execute(); +$connection->schema()->createTable('field_data_field_date_without_time', array( + 'fields' => array( + 'entity_type' => array( + 'type' => 'varchar', + 'not null' => TRUE, + 'length' => '128', + 'default' => '', + ), + 'bundle' => array( + 'type' => 'varchar', + 'not null' => TRUE, + 'length' => '128', + 'default' => '', + ), + 'deleted' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'normal', + 'default' => '0', + ), + 'entity_id' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'normal', + 'unsigned' => TRUE, + ), + 'revision_id' => array( + 'type' => 'int', + 'not null' => FALSE, + 'size' => 'normal', + 'unsigned' => TRUE, + ), + 'language' => array( + 'type' => 'varchar', + 'not null' => TRUE, + 'length' => '32', + 'default' => '', + ), + 'delta' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'normal', + 'unsigned' => TRUE, + ), + 'field_date_without_time_value' => array( + 'type' => 'varchar', + 'not null' => FALSE, + 'length' => '100', + ), + ), + 'primary key' => array( + 'entity_type', + 'deleted', + 'entity_id', + 'language', + 'delta', + ), + 'mysql_character_set' => 'utf8', +)); + +$connection->insert('field_data_field_date_without_time') +->fields(array( + 'entity_type', + 'bundle', + 'deleted', + 'entity_id', + 'revision_id', + 'language', + 'delta', + 'field_date_without_time_value', +)) +->values(array( + 'entity_type' => 'node', + 'bundle' => 'test_content_type', + 'deleted' => '0', + 'entity_id' => '1', + 'revision_id' => '1', + 'language' => 'und', + 'delta' => '0', + 'field_date_without_time_value' => '2015-01-20 00:00:00', +)) +->execute(); + + + $connection->schema()->createTable('field_data_field_email', array( 'fields' => array( 'entity_type' => array( @@ -6664,6 +6773,91 @@ )) ->execute(); +$connection->schema()->createTable('field_revision_field_date_without_time', array( + 'fields' => array( + 'entity_type' => array( + 'type' => 'varchar', + 'not null' => TRUE, + 'length' => '128', + 'default' => '', + ), + 'bundle' => array( + 'type' => 'varchar', + 'not null' => TRUE, + 'length' => '128', + 'default' => '', + ), + 'deleted' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'normal', + 'default' => '0', + ), + 'entity_id' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'normal', + 'unsigned' => TRUE, + ), + 'revision_id' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'normal', + 'unsigned' => TRUE, + ), + 'language' => array( + 'type' => 'varchar', + 'not null' => TRUE, + 'length' => '32', + 'default' => '', + ), + 'delta' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'normal', + 'unsigned' => TRUE, + ), + 'field_date_without_time_value' => array( + 'type' => 'varchar', + 'not null' => FALSE, + 'length' => '100', + ), + ), + 'primary key' => array( + 'entity_type', + 'deleted', + 'entity_id', + 'revision_id', + 'language', + 'delta', + ), + 'mysql_character_set' => 'utf8', +)); + +$connection->insert('field_revision_field_date_without_time') +->fields(array( + 'entity_type', + 'bundle', + 'deleted', + 'entity_id', + 'revision_id', + 'language', + 'delta', + 'field_date_without_time_value', +)) +->values(array( + 'entity_type' => 'node', + 'bundle' => 'test_content_type', + 'deleted' => '0', + 'entity_id' => '1', + 'revision_id' => '1', + 'language' => 'und', + 'delta' => '0', + 'field_date_without_time_value' => '2015-01-20 00:00:00', +)) +->execute(); + + $connection->schema()->createTable('field_revision_field_email', array( 'fields' => array( 'entity_type' => array(