In Drupal 7, a date field has a granularity setting that the date attributes to collect: year, month, day, hour, minute, and/or second.
In Drupal 8 there is no longer the granularity setting, instead a datetime field has a datetime_type setting that can be "datetime" for date + time or "date" for just dates.
Expected behavior: When migrating from D7, it seems like date-only fields should have their datetime_type set to "date", and date+time fields should get "datetime".
Actual behavior: Both get datetime_type == "datetime".
This concept was raised elsewhere but hasn't been addressed for upgrades from Drupal 7.
Comment | File | Size | Author |
---|---|---|---|
#44 | 2894068-44.patch | 17.14 KB | alexpott |
#44 | 42-44-interdiff.txt | 859 bytes | alexpott |
#42 | 2894068-42.patch | 16.86 KB | heddn |
Comments
Comment #2
davidsickmiller CreditAttribution: davidsickmiller commentedThe attached patch adds a test demonstrating the problem and a fix for the problem.
Comment #3
davidsickmiller CreditAttribution: davidsickmiller commentedRe-rolled for latest 8.4.x...
Comment #4
davidsickmiller CreditAttribution: davidsickmiller commentedMissed that MigrateUpgrade7Test needed changes too
Comment #5
davidsickmiller CreditAttribution: davidsickmiller commentedComment #6
heddnAssigning to vicky to review this week.
Comment #7
quietone CreditAttribution: quietone as a volunteer commented@davidsickmiller, thanks for patch!
Can we add the D7 field type 'Date (ISO format)' field and thus cover all the date fields?
After running a migration I found that for field_date_with_end_time only the start date is migrated, not the end date. Is this a case for the daterange type?
assertIdentical is deprecated. Should now be assertSame
Why is field_date_with_end_time not tested here
Comment #8
quietone CreditAttribution: quietone as a volunteer commentedComment #9
davidsickmiller CreditAttribution: davidsickmiller commentedOK, I've added separate field_date_without_time and field_datetime_without_time fields.
Maybe! Do you think this is a regression caused by the code I added to FieldSettings.php? If not, could we handle it in a separate issue?
Fixed!
Fixed!
Comment #11
davidsickmiller CreditAttribution: davidsickmiller commentedComment #13
heddnKnown test bot failure: #2828143: Stop tests like LocaleConfigTranslationImportTest from failing if l.d.o becomes unavailable. Back to NR.
Comment #15
jofitz CreditAttribution: jofitz at ComputerMinds commentedAll looks good to me (ignoring the testbot failure) and ready for RTBC. Have run re-tests for 8.4.x and a test against 8.5.x, but not expecting any surprises in the results.
Uploading a test-only version of the patch in #11 (for completeness as much as anything).
If all the tests come back as expected then this can be set to RTBC.
Comment #17
jofitz CreditAttribution: jofitz at ComputerMinds commentedThe d7_field_settings plugin was not catching fields of type "datestamp" (e.g. field_date_with_end_time) and updating the datetime_type setting when appropriate so I have corrected that.
Even so, the datetime_type setting for field_date_with_end_time should not be set because the hour/minute granularities are not 0 so I have also updated the expected to Null in the test.
So we're not quite ready for RTBC, but I think this should take us a step closer.
Comment #18
heddnBack to NW for the remaining tasks. What are those?
Comment #19
jofitz CreditAttribution: jofitz at ComputerMinds commentedThe only remaining task was to understand why field_date_with_end_time did not have a datetime_type setting. This is because it is a datestamp field which becomes a timestamp field (which does not have a datetime_type setting).
Re-rolled the patch (because the patch in #17 no longer applies) and added a comment to explain why we are asserting that the datetime_type setting for field_date_with_end_time is null (I thought this was better than simply ignoring it).
Comment #20
heddnGreat test coverage, comments in #19 makes sense. Reviewed the IS again, do we actually need to collect any settings about 'year, month, day, hour, minute, and/or second' or just collect the type? Back to NW for that, either update the IS to reflect what is going on in this issue or update the patch. And if we do need to collect the settings, should that move to a follow-up? Or take place here? If it is simple, let's do it here. If it isn't, punt to a follow-up.
Comment #21
jofitz CreditAttribution: jofitz at ComputerMinds commentedThe only datetime granularity options in D8 are datetime_type of "datetime" (fields including date & time) and "date" (fields including only date & no time) - there is not the same granularity as D7. I have edited to IS to reflect this.
Comment #22
heddnAh yes, all that is stored on the field formatter now and is in contrib as core doesn't support more fine grain settings. I should have remembered. Great. This is good to go then.
Comment #24
jofitz CreditAttribution: jofitz at ComputerMinds commentedComment #25
yogeshmpawarComment #26
yogeshmpawarRerolled the patch #19 & because it's failed to apply on 8.5.x branch.
Comment #27
heddnThis is a bug, so moving it back to 8.4. And added a test run as well for good measure.
Comment #29
jofitz CreditAttribution: jofitz at ComputerMinds commentedThis patch only increases the number of field_storage_config by 2 so correcting that.
Comment #31
jofitz CreditAttribution: jofitz at ComputerMinds commentedThis patch only increases the number of field_config by 2 so correcting that. We'll get there in the end...
Comment #33
jofitz CreditAttribution: jofitz at ComputerMinds commentedOoops, empty patch file! This is what I meant to upload.
Comment #34
heddnStraight re-roll here, so back to RTBC.
Comment #35
alexpottCrediting @heddn and @quietone as reviewers.
Comment #36
alexpottCommitted and pushed a151cef151 to 8.5.x and d975b8df0f to 8.4.x. Thanks!
Comment #41
xjmThis seems to have broken HEAD, so I've reverted it:
https://www.drupal.org/pift-ci-job/784751
https://www.drupal.org/pift-ci-job/784827
https://www.drupal.org/pift-ci-job/784828
Etc.
Comment #42
heddnHere's a re-roll of #33. Let's see what errors are getting thrown.
Comment #43
alexpottThis is a db-other-mysql issue. If I run
Drupal\Tests\block\Kernel\Migrate\d7\MigrateBlockTest
locally using postgres the test fails...Comment #44
alexpottSo dates in D7 had some fun stuff for different DBs :) See date.install in D7 - http://cgit.drupalcode.org/date/tree/date.install
Comment #45
Yaazkal CreditAttribution: Yaazkal commentedHi, I'm not sure if there is a bug on this or if it is a migrate_plus module issue.
Trying to migrate from Drupal 7.56 to Drupal 8.4.0
On the Drupal 8 site I have installed: migrate, migrate_plus, migrate_tools, migrate_upgrade.
After applying #44 patch, I ran:
drush migrate-upgrade --legacy-db-url=mysql://user:password@server/db --legacy-root=http://example.com --configure-only
drush mi --all
Content was migrated and date field is migrated as only date (the way I want it), but I can't see any date when editing a migrated node. I mean, the field is there but seems to be empty.
So I rollback the migration and ran
drush cex
to check the migration configuration. I have a content type "Norma" (Norma translates as "norm", for law content creation) and this content type has a date field "fecha" which is the spanish word for date.So, in migrate_plus.migration.upgrade_d7_node_norma.yml file I can see:
So I changed
to_format: 'Y-m-d\TH:i:s'
to be liketo_format: 'Y-m-d'
and thendrush cim
and ran again the upgrade, now the dates are correctly shown when editing a migrated node but (and this is the weird part) I get this error (when editing or creating a node of type "norma"):Notice: Undefined index: main-menu in menu_ui_form_node_form_alter() (line 267 of core/modules/menu_ui/menu_ui.module).
So, I went and edit the content type "norma" to asign a menu to see if it fixes and it does... except that the date field "fecha" has now disapeared from the content type, I don't see it listed even in
/admin/reports/fields
Not sure if I'm doing it wrong or where to look at.
Regards.
Comment #46
Yaazkal CreditAttribution: Yaazkal commentedHi, I can confirm that
Notice: Undefined index: main-menu in menu_ui_form_node_form_alter() (line 267 of core/modules/menu_ui/menu_ui.module)
is not related to this issue (sorry for the noise) but is related to https://www.drupal.org/node/2592829 because even if I don't apply #44 I get the error. This happens because I have selected main-menu as an available menu for the content type that I'm migrating (on D7) and in D8 that menu is now 'main', so 'main-menu' not exists from the D8 perspective. Updating the other issue.Comment #47
Yaazkal CreditAttribution: Yaazkal commentedAnyway, It's still the need to change the
to_format: 'Y-m-d\TH:i:s'
toto_format: 'Y-m-d'
in the configuration. I made it as I described before: exporting the configurationdrush cex
, changing the yaml files and then importing the configuration changesdrush cim
but people can do that on a custom module too. Will be great if theto_format
is generated correctly from the beginning.Regards!
Comment #48
heddnAssigning to myself to review in the next week.
Comment #49
heddnThis looks good now. It was already RTBC, just failing on postgress. That is now accommodated in the re-rolled patch. It isn't clear if #45 was with or without this patch. But I can only imagine it was without. Because if it were with the patch, then it would correctly map the fields.
Comment #50
catchCommitted/pushed to 8.5.x and cherry-picked to 8.4.x. Thanks!
Comment #54
juampynr CreditAttribution: juampynr at Lullabot for NBCUniversal commented@Yaazkal: I posted a patch to fix what you described at #45 at #2822801: Date field empty after migration d7 d8.