Problem/Motivation
The migration system has no support for migrating node reference fields, with their settings and values, from Drupal 7 to Drupal 8.
The source module is https://www.drupal.org/project/references.
Proposed resolution
Add a field plugin to handle Drupal 7 node reference fields. Currently the patch also adds a field plugin to handle Drupal 7 user reference fields.
Add field plugins, migrate_drupal\Plugin\migrate\field\d7\NodeReference and migrate_drupal\Plugin\migrate\field\d7\NodeReference.
Update Kernel tests d7/MigrateNodeCompleteTest.php and d7/MigrateNodeRevisionTest.php, FieldDiscoveryTest.
Update Functional tests d7/MultilingualReviewPageTest.php, d7/NoMultilingualReviewPageTest.php, and d7/UpgradeTest.php.
Update fixture, add a node and user reference field to the test fixture (added to the article content type). Fixture still works via the D7 UI.
Update migrate_drupal migration state file.
Remaining tasks
Review- Commit the patch
- Jump into a ball pit and roll around happily
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#105 | NodeReferences-2814953-105.patch | 618 bytes | Jeya sundhar |
#96 | 2814953-96.patch | 41.14 KB | quietone |
#96 | interdiff-89-96.txt | 1.03 KB | quietone |
#89 | 2814953-89.patch | 41.38 KB | quietone |
#89 | interdiff-87-89.txt | 459 bytes | quietone |
Comments
Comment #2
phenaproximaPostponing on #2447727: Add base class for migrating reference fields.
Comment #4
davidsickmiller CreditAttribution: davidsickmiller commentedNode reference migration from D6 was implemented in https://www.drupal.org/node/2872660 and https://www.drupal.org/node/2814949. I took a look at how it was done and adapted it for D7 in the attached patch. It works for me, though I'm not sure if there are corner cases that will need to be addressed.
Neither the D6 implementation or my code require the patch from https://www.drupal.org/node/2447727.
I'm not interested in working on #2447727, but if you'd like to go ahead with the approach used in my patch, I would be happy to write some tests for it.
Comment #9
quietone CreditAttribution: quietone as a volunteer commentedAdd source module
Comment #10
nareshrana CreditAttribution: nareshrana as a volunteer commentedQuick Question:
Do we need to apply these patches to drupal8 site before running any migrations?
Comment #11
kriceiq CreditAttribution: kriceiq commentedI'm probably glossing over it but is there an 8.7.x patch for this?
Comment #13
Nathaniel CreditAttribution: Nathaniel commentedAttached a new patch based on #4. Also added support for user_reference fields. Still testing the migration.
Comment #14
Wim LeersNote that https://git.drupalcode.org/project/references is used on 100K Drupal 7 sites (see https://www.drupal.org/project/usage/references), or about 1 in 7 (see https://www.drupal.org/project/usage/drupal). So increasing priority.
P.S.: Running into this too for
wimleers.com
!Comment #15
Wim LeersBumped priority of the blocker that @phenaproxima identified in #2: #2447727: Add base class for migrating reference fields.
Comment #16
Nathaniel CreditAttribution: Nathaniel commentedFixed user_reference by adding target_type to field settings and setting default filter type to _none. Some cleanup. Role filter settings are incomplete. Tested on a test migration with one node reference and one user reference. They were both migrated as expected.
Comment #17
Wim LeersAwesome, thanks @Nathaniel! I will test this on
wimleers.com
.Comment #18
Wim LeersJust wanted to let y'all know I'm making the discovery of this issue for current users of the Drupal 7
references
module easier, by adding this issue to their issue queue: #3096190: FYI: a migration path to Drupal 8 is being worked on in core. It links here :) Hopefully that will also lead to more people testing this patch.Comment #19
heddnTagging for needing tests.
Comment #20
Nathaniel CreditAttribution: Nathaniel commentedMissed a break statement. No change in functionality.
Comment #21
Nathaniel CreditAttribution: Nathaniel commentedUpdated migrate test to include node_reference and user_reference in testFieldProvidersExist.
Comment #22
Nathaniel CreditAttribution: Nathaniel commentedUpdated the migrate_drupal d7/FieldDiscoveryTest and drupal7 fixture. Kudos to anyone who works on those fixtures, what a horrendous task!
If this all goes through the docs will also need to be updated to include the references module:
https://www.drupal.org/docs/8/api/migrate-api/generating-database-fixtur...
Comment #23
huzookaPatch #22 no longer applies.
Rebased patch attached.
Comment #24
huzookaComment #25
huzookaComment #26
huzookaComment #27
iancawthorne CreditAttribution: iancawthorne commentedI was wondering if anyone would be able to provide some steps to attempt a migration for node reference fields with the patch on here in place?
I am running "drush migrate:import d7_field"
For every node reference field I get an error output of:
Attempt to create a field storage field_FIELDNAME with no type.
This applies with or without the patch in place. I'm using the patch at #22 as that appears to be the most recent which will roll to Drupal 8.8, being the version I'm testing migrations on.
Are there some other requirements / steps for this patch to work?
Comment #28
Nathaniel CreditAttribution: Nathaniel commentedI'm currently using #20 before any tests were added. Seems to be working on 8.8.2. Remember to clear cache etc. I find myself restarting migrations often with a fresh install (if possible).
Comment #29
iancawthorne CreditAttribution: iancawthorne commented@Nathaniel, you were absolutely right. I started from scratch with a fresh install and the migration of node references worked. Thanks.
Comment #30
NickDickinsonWildemmph. Should've read from the top instead of from the bottom. Didn't notice the POSTPONED aspect. But in the meantime, here are a couple of re-rolled patches. Same as @huzooka's patchs in #26 but re-rolled for latest 8.9.x. Although it looks to me like #2447727: Add base class for migrating reference fields may be covering both node and user reference anyways and this issue will probably get closed as duplicate.
Comment #31
Nixou CreditAttribution: Nixou at Actency commentedI needed to have this feature for a migration to Drupal 8.8.5.
I reroll the patch for my needs so I attach it for those who need it.
Comment #33
Nixou CreditAttribution: Nixou at Actency commentedReroll for 9.0.0
Comment #34
marcoka CreditAttribution: marcoka commentedApplied #33, fields are in the node but all are empty. No data at all. Drupal 8.9.1, #33 applies flawlessly.
Comment #35
Wim Leers#34: any migration messages?
Comment #36
marcoka CreditAttribution: marcoka commentedMigration always throws a gazillion messages here, but i did not see any that i found useful or related to this.
I ended up moving the field tables by hand, exporting the sql of D7, replaced some stuff and imported it that way.
Comment #37
Wim LeersThat shouldn't happen! 😞 Even though they're often cryptic, they're almost always about problems.
Hm, okay. Perhaps there was one for
d7_field
ord7_field_instance
that related to this though! 🤔Comment #38
mradcliffe#2447727: Add base class for migrating reference fields is done. Changing to Needs work because there is a patch that probably needs a reroll. I added Needs reroll tag.
Comment #39
quietone CreditAttribution: quietone as a volunteer commentedThe latest patch has both node and user reference changes. For now, I am keeping them together.
Comment #40
Wim Leers+1
Comment #41
quietone CreditAttribution: quietone as a volunteer commentedRerolled. I still need to bring up the new fixture in a real D7 site and I haven't reviewed the patch yet myself because I am keen to see what errors are found.
Comment #43
quietone CreditAttribution: quietone as a volunteer commentedNice results, I expected the functional tests to fail.
Now, add some fixes for the functional tests. Also, add migration state information and use the new ReferenceBase.
Ah, there is some work here to do.
And the d6 node and user reference field plugins are in migrate_drupal, the d7 added in this patch are in field. Where should they be?
Comment #45
mradcliffeIf we added 2 migrations, then the failing test in migrate_drupal_ui is a false positive and can be bumped from 76 to 78, right?
Unused use statements.
I think what is happening with the test failure in migrate_drupal is that the test data is too big on a failed assertion, and PHP Unit tries to serialize the trace when there is an object that is too large (the drupal container).
There's an assertion failure in testAddAllFieldProcessesAlters with one (or more) of the new data sets, but not sure which one it is.
Comment #46
quietone CreditAttribution: quietone as a volunteer commented45.1. This is a count of the missing or available modules on the Review page. I missed adding node and user reference in that test.
45.2. Fixed.
45.3. Yes, that is a really unhelpful message. Test fixed.
Comment #47
quietone CreditAttribution: quietone as a volunteer commentedGood passing tests, let's keep it that way.
Still need to do the @todo in the patch, See #43.
Comment #48
quietone CreditAttribution: quietone as a volunteer commentedSort of a bad patch, I commented out part of the dataprovider and left that in the patch.
Comment #50
quietone CreditAttribution: quietone as a volunteer commentedFix the test that I messed up again in #48.
But mostly addressing the @todo to get the field settings for the user_reference field.
Comment #51
mradcliffeNice work. There's a small nit in this review to fix that I missed previously so shifting to needs work. The rest are questions to answer.
Following-up on the question of what module to put these in. If we're considering removing/deprecating migrate_drupal, would it make it easier to remove if these were in migrate_drupal rather than a non-migrate module? I think for consistency with d6 moving these to migrate_drupal makes sense. The d6 ones haven't hit a release yet so I guess there's time to move those instead.
@todo override defineValueProcessPipeline similar to the d6 plugin to do a migration lookup.
The other similar comparisons in this file use
===
except for the preexisting line 39 containing== "entityreference"
(double quotes).Comment #52
quietone CreditAttribution: quietone as a volunteer commented#51.1 Yes, lets keep the node/user references together in migrate drupal. Moved field plugins and migration state data.
#51.2 yes, was planning to that in this round. done now.
#51.3 Of the 3 existing tests only 1 uses '==='. So, no change here. Although I can be convinced to change it.
Changed prepareRow in FieldInstance to get only the roles referenced.
Comment #54
quietone CreditAttribution: quietone as a volunteer commentedForgot to fix MigrateNodeRevisionTest
Comment #55
quietone CreditAttribution: quietone as a volunteer commentedIgnore previous patch.
Comment #57
quietone CreditAttribution: quietone as a volunteer commentedFix the test, again. And some other cleanup and coding standard fixes.
Comment #58
quietone CreditAttribution: quietone as a volunteer commentedClosed #2814957: Support Drupal 7 user reference fields as a duplicate since this has both the node and user reference migrations. The patch isn't too big and the migrations are so similar it was easier to work on them both in the same issue.
Comment #59
mikelutzYea! I am so happy this is finally getting in. All feedback has been addresses as far as I can tell, and I looked through the code and it looks good to me. I'm going to kick off a few more tests against the other databases, but as long as they are green I'm excited to RTBC this one.
Comment #60
pyxio CreditAttribution: pyxio commentedso if i understand correctly this patch will not work for Drupal 8.9 and i must change to 9.1x dev in order to migrate node reference fields from a D7 site? Thanks
Comment #61
quietone CreditAttribution: quietone as a volunteer commented@pyxio, Yes. Also, this relies on #2447727: Add base class for migrating reference fields which was only committed to 9.1.x.
Comment #62
benjifisherThe patch in #57 no longer applies. I hope it is a simple reroll.
Comment #63
quietone CreditAttribution: quietone as a volunteer commentedAnd a reroll.
Comment #65
quietone CreditAttribution: quietone as a volunteer commentedNeeded a reroll
Comment #66
benjifisherI compared the patches in #63 and #65. Here is one hunk from #65:
The patch in #63 added 'Node Reference' after 'Node', keeping the list sorted (alphabetized). Can we keep it that way?
This is just one of several examples.
Comment #67
quietone CreditAttribution: quietone as a volunteer commented66. Sorting fixed. This is a real nuisance. The sort tool in PhpStorm sorts it as in patch #65, as does the String Manipulation plugin, and I just decided to not fight it.
Comment #68
benjifisher@quietone:
Thanks for the update. I compared the patches in #63 and #67. Now that the sorting is consistent, the only differences between the two are metadata (commit hashes and line numbers) and context lines.
Then I realized that #63 was already a reroll, and had not been reviewed. I should really compare the patches in #57 and #67. In addition to the differences above, I see several other changes:
getEntityCounts()
in some of the tests. Since we added two items each to the field and field-instamce config tables, this looks reasonable. Since the tests pass, it must be right.These differences all look reasonable, so based on the review in #59 I am setting the status back to RTBC.
Comment #69
mradcliffe+1 RTBC.
I ran a migration on a drupalcamp site I maintain that used references in drupal 7 for session speakers using the patch in #67 (applied to 9.1.0-alpha1). It successfully migrated user references for 1...N items into a multi-value entity reference field.
Comment #70
quietone CreditAttribution: quietone as a volunteer commented@benjifisher, thanks for noticing the missing comment. Adding a comment as per #68.3 which keeps the file consistency with the commenting of the tests.
Comment #71
quietone CreditAttribution: quietone as a volunteer commentedI've spellchecked the one line comment fix in patch #70. Since it is a one line addition of a comment in a test file and no code changes, I'm setting back to RTBC.
Comment #72
quietone CreditAttribution: quietone as a volunteer commentedJust noticed this should be on the D7 meta.
Comment #73
benjifisher+1 for the update in #70. (edited)
Comment #74
quietone CreditAttribution: quietone as a volunteer commented@benjifisher, thanks !
Comment #75
cosolom CreditAttribution: cosolom commentedActual patch for D8.9.8
Comment #77
quietone CreditAttribution: quietone as a volunteer commentedRestoring RTBC for the patch in #70.
Comment #78
benjifisherIt looks as though the testbot is looking at the wrong patch, so I am re-uploading the one from #70.
Comment #79
quietone CreditAttribution: quietone as a volunteer commented@benjifisher, of course! thanks.
Comment #80
chipway CreditAttribution: chipway at Chipway commentedPatch still applies on 9.1.0.
Comment #81
catchOne very minor question:
Should the path formatter map to the label instead of the ID? Or do we always map to ID if there's no matching formatter?
Same question here.
Comment #82
catchComment #83
quietone CreditAttribution: quietone as a volunteer commented@catch, thanks. I agree.
This makes the changes suggested in #81 and add assertions for the two new components.
Comment #84
benjifisherThe patch in #83 needs a reroll. I think it conflicts with #2565931: Handle long comment bundle names. That is a Novice task.
Comment #85
quietone CreditAttribution: quietone as a volunteer commentedYes, it does need a reroll and here it is.
Comment #86
quietone CreditAttribution: quietone as a volunteer commentedAnother reroll
Comment #87
quietone CreditAttribution: quietone as a volunteer commentedI reviewed the comments since the last RTBC and see that I did not make the change for #81.1. This patch addresses that.
Comment #88
benjifisherWe might have fewer rerolls if we used the MR workflow instead of patches.
I compared the patches from #70 and #87. The changes look appropriate:
_entity_id
to_entity_label
for bothnodereference
anduserreference
fields, as suggested in #81. Corresponding changes in the tests.UpgradeD7Test
. In both patches, the effect is to increase the counts by 2.There is one little problem. Because of the way PHP arrays work, it makes no difference, but it is a little sloppy:
Comment #89
quietone CreditAttribution: quietone as a volunteer commented@benjifisher, Nice find. Thanks.
And here is a fix.
Comment #90
benjifisher@quietone, thanks for the fix! RTBC
Comment #92
benjifisherThat looks like a random fail.
Comment #94
quietone CreditAttribution: quietone as a volunteer commentedAnother random failure, #3099427: [random test failure] FieldLayoutTest::testEntityView()
Comment #95
larowlanJust one question, and one suggestion (feel free to ignore), fine to put back to RTBC with answer to the question
we could replace this with a one-liner
$instance_settings['handler_settings']['target_bundles'] = array_filter($field_data['settings']['referenceable_types'] ?? [])
, in fact it could go straight into the 'target_bundles' in the original array toodoes this need the check for empty options like above?
Comment #96
quietone CreditAttribution: quietone as a volunteer commented95.1 Nice. and fixed.
95.2 Good question. There is not check for empty here because that work has already been done in prepareRow. Why? Because a query on the source database needs to be done to get the roles, and the must be done in the source plugin.
Comment #97
benjifisherI compared the patch in #96 to the one in #87. The changes are as expected. +1
Comment #98
larowlanAdding review credits
Comment #100
larowlanCommitted 2a2f2de and pushed to 9.2.x. Thanks!
Comment #102
Wim LeersDiscovered a bug introduced here: #3198732: Migrating reference fields: target_bundles may never be empty array.
Comment #103
Wim LeersDiscovered another
This contains another bug, fix at #3198732-19: Migrating reference fields: target_bundles may never be empty array.
Comment #104
Gábor HojtsyComment #105
Jeya sundharPatch for node reference fieldsettings
Comment #106
Ralkeon CreditAttribution: Ralkeon commentedRerolled patch #96 including #105 update
Comment #107
Ralkeon CreditAttribution: Ralkeon commentedSorry, removed my last added patch cause I was using an old drupal version. The #105 works fine!