Commit f7d549d7 authored by webchick's avatar webchick

Issue #3095146 by Wim Leers, heddn: Drupal 7 date fields configured to not...

Issue #3095146 by Wim Leers, heddn: Drupal 7 date fields configured to not collect the hour/minute/second granularities can have a different "settings" structure than the migration assumes

(cherry picked from commit 347624ad)
parent 490201e9
......@@ -53,11 +53,10 @@ public function defineValueProcessPipeline(MigrationInterface $migration, $field
$field_data = unserialize($data['field_definition']['data']);
if (isset($field_data['settings']['granularity'])) {
$granularity = $field_data['settings']['granularity'];
if ($granularity = $field_data['settings']['granularity'] &&
$granularity['hour'] === 0 &&
$granularity['minute'] === 0 &&
$granularity['second'] === 0) {
$collected_date_attributes = is_numeric(array_keys($granularity)[0])
? $granularity
: array_keys(array_filter($granularity));
if (empty(array_intersect($collected_date_attributes, ['hour', 'minute', 'second']))) {
$to_format = DateTimeItemInterface::DATE_STORAGE_FORMAT;
}
}
......
......@@ -70,6 +70,23 @@ public function providerTestDefineValueProcessPipeline() {
'Y-m-d H:i:s',
'Y-m-d',
],
[
[
'type' => 'date',
'field_definition' => [
'data' => serialize([
'settings' => [
'granularity' => [
0 => 'year',
1 => 'month',
],
],
]),
],
],
'Y-m-d\TH:i:s',
'Y-m-d',
],
];
}
......
......@@ -29,9 +29,10 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
case 'date':
case 'datetime':
case 'datestamp':
if ($value['granularity']['hour'] === 0
&& $value['granularity']['minute'] === 0
&& $value['granularity']['second'] === 0) {
$collected_date_attributes = is_numeric(array_keys($value['granularity'])[0])
? $value['granularity']
: array_keys(array_filter($value['granularity']));
if (empty(array_intersect($collected_date_attributes, ['hour', 'minute', 'second']))) {
$value['datetime_type'] = 'date';
}
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment