Name currently has a migrate handler included with it (NameMigrateFieldHandler) that was added as part of #1734922: Name Field Migrate support with import example (single full name text field separated and split into the individual components).
However, before that issue was opened, Migrate Extras already included a name handler (MigrateNameHandler), added as part of #1468010: Name field support.
The handlers definitely should not exist in both places. Migrate specifically states that handlers should live with the fields themselves.
The handler included with Migrate Extras is better documented, and seems to work better, so I'd recommend using it to replace the current handler provided by Name.
After this is committed, we should open a corresponding issue with Migrate Extra to delete the name handler there, so that it doesn't exist in two places (possibly causing errors if people have both modules enabled).
Patch to follow.
Comment | File | Size | Author |
---|---|---|---|
#16 | name-2221717-16.patch | 4.56 KB | Dane Powell |
Comments
Comment #1
Dane Powell CreditAttribution: Dane Powell commentedComment #2
Alan D. CreditAttribution: Alan D. commentedShould be something like
If you want to insert some Name specific logic, (personally not fussed about this), these can be used.
I would not enforce $minimum_components, possibly unknown / non-existent in the data source. The data can be fixed when the entity is edited.
Filtering by allowed $components could prevent inserting data into the DB that is never accessible.
Finally, the arguments here only appear to support a singular name field item. What happens with multiple value fields?
Comment #3
Dane Powell CreditAttribution: Dane Powell commentedAlan, thanks for the great feedback. I changed the return syntax and added support for components. I also added support for multi-value fields.
I actually haven't had a chance to test this yet, since I'm away from my development machine, but will do so in a few hours.
Comment #4
Dane Powell CreditAttribution: Dane Powell commentedOkay, here's a final cut of this. It's passed code review, and works for me on a few test cases.
This uses the 'given' name as the primary column, and adds the fields() function to support this - I don't think the original version included with migrate_extras quite worked, because it didn't implement fields(). The documentation is also improved to clarify this.
Comment #5
Alan D. CreditAttribution: Alan D. commentedLooking better :)
1) Tidied up the doc comment a bit.
2) I am not sure on functionality of the method, but this should be the same.
3) Since the code could potentially skip an item, this ensures that the returned delta values are consistent (although I think that cores field system does an array_values() here too)
4) I think that the delta variable can be moved into the for loop, as the delta value of the incoming values. 2 less loc
5) Without have a test environment, are the arguments in this structure? All I can say is "Ycks", but no comment on Migrate itself
I have one local migrate environment, but I can not test this as it is a XML feed that uses a JSON encoded request to get a node from the source and the MyClassXMLMigration::prepare($entity, $source_row) simply does this (without all of the special business logic and image / file field handing):
The node entity has about 50 fields, 10 or so with no migrate support, but this just works and handling the business logic required where you have $source _entity and $destination_entity nodes is trivial ;)
Comment #6
Alan D. CreditAttribution: Alan D. commentedI guess that you have come from using MigrateExtras, to just this?
So I wonder what will happen for users using just Name migrate and the Migrate class registry?
Maybe an empty update function that should (hopefully) force any caches to be flushed
[edit]
Actually looking at migrate_get_module_apis() [migrate 7.x-2.6-rc1], this is not needed :)
Comment #7
Dane Powell CreditAttribution: Dane Powell commentedThanks, I'll take a look at this tomorrow. I'm basing this all on existing Migrate code, so if there are problems, they are Migrate's fault, not mine :) Seriously though, I didn't want to change the code too much, so that we can stay "on the reservation" as much as possible. If there are problems with the code potentially skipping items, or a totally fugly arguments structure, we should get that fixed upstream. For now, I'd prefer to get this at least committed, and make improvements later.
Comment #8
Alan D. CreditAttribution: Alan D. commented"totally fugly arguments structure" is by design from memory, I think I have seen these before :/
Happy to commit with #1 - #3
Comment #9
Dane Powell CreditAttribution: Dane Powell commentedAlan you seem to be pretty knowledgeable about Migrate- do you know why the arguments-based approach was chosen, instead of being able to simply map directly to field parts (i.e.
$this->addFieldMapping('field_name:given', 'profile_title');
)?Comment #10
Alan D. CreditAttribution: Alan D. commentedNope, not sure. First time I saw this I thought ffs, not only do you need to know the field schema structure you need to know the wield mapping rules... maybe a work around for the migrate internals?
Comment #11
Dane Powell CreditAttribution: Dane Powell commentedOkay, here's a re-roll of #4 with the improved documentation and $delta fix. Thanks!
Comment #12
Dane Powell CreditAttribution: Dane Powell commentedI opened an issue with Migrate to try to get this question answered: #2223095: Clarify docs around mapping of field parts
Comment #13
Dane Powell CreditAttribution: Dane Powell commentedOkay, now I feel like a bit of an idiot. Just for fun, I tried actually mapping the fields directly (instead of using arguments), and it worked just fine. This seems like a much saner approach- I don't know why I assumed that using arguments was the the only solution. I think it would make sense to rewrite the documentation on the module to use this approach rather than arguments. Do you agree?
Comment #14
Dane Powell CreditAttribution: Dane Powell commentedAlright, here's a patch with updated documentation based on #2223095: Clarify docs around mapping of field parts. I think this is good to commit.
Comment #15
Dane Powell CreditAttribution: Dane Powell commentedComment #16
Dane Powell CreditAttribution: Dane Powell commentedThis patch incorporates the fix from #2155749: Migrate API handler change.
We've been using this quite successfully internally, think you can go ahead and commit it?
Comment #17
Alan D. CreditAttribution: Alan D. commentedCan someone actively using a name migration actual confirm that this will not cause a fatal error due to a potential stale class registry please? I have no active migration environments to test atm :)
@Dane Powell
Does this require a change in anyones migration scripts? If so, a quick short summary would be good to go into the release page when the next one is rolled out would be fantastic!
Comment #18
Dane Powell CreditAttribution: Dane Powell commentedI set up a development site with the stock version of Name, ran an import using a name field, applied the patch in #16, and re-ran the import. It worked fine- no errors. It would be nice if someone else could test, but I don't know how long it'll be before that someone comes along :)
No user intervention should be required. Migrate dynamically finds appropriate handlers for a given field type, so it should automatically start using this one.
However, users of Migrate Extras should disable that module or disable its name handler in the Migrate config UI. Once we commit this patch, I'll submit another to Migrate Extras to remove the duplicate handler.
Comment #19
valthebald@Alan D: I confirm that the patch from #16 does not cause any death screens. We actively use migrations with name fields, and they work only with this patch
Comment #20
jiv_e CreditAttribution: jiv_e as a volunteer and at LilDrop Consulting commentedI have used this patch for a simple use case and it works fine. I have a D7->D7 migration with 'given' and 'family' components.
So the source is a name field on Drupal. I first thought it would work like this for the 'given' component.
...but had to do it like this.
Here's the whole field mapping section:
Comment #21
edvanleeuwenI am interested in this as well. How can I help testing/reviewing? Is there a migration example I could change according to my situation?
Comment #22
edvanleeuwenCould anyone explain why the 'given' part has been chosen as primary and not 'family'?
(Background: I noticed when migrating organizations in CRM Core that the family name is the one displayed. So at first sight, it looks like these contact types have been imported with an empty name. The workaround is to edit the name field and set family name hidden, given name visible).
Comment #23
rmcom CreditAttribution: rmcom commentedCould this patch be included into the next version? Thank you!
I am working with CRM Core (specifically data imports via the Migration module).
Comment #24
rmcom CreditAttribution: rmcom commentedThis patch is necessary for CRM Core imports to run.
Importing data into CRM Core
Comment #25
rmcom CreditAttribution: rmcom commentedComment #26
joelpittetleave the status, patch to be ported is for backporting committed patches to older versions
Comment #28
Alan D. CreditAttribution: Alan D. commentedSuch an old stale issue, but let me know if I need to add a change record or a simple note to the release page itself