Closed (fixed)
Project:
Address
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
22 May 2018 at 21:55 UTC
Updated:
4 Aug 2023 at 18:59 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
ronaldmulero commentedHere's the patch.
Comment #4
ronaldmulero commentedCurse you missing semicolon!
Comment #5
roam2345 commentedLooks like this code assumes the database connection is named 'migrate' for the migration source.
Comment #6
damienmckennaComment #7
damienmckennaMinor changes.
Comment #8
damienmckennaThis can help build out a full migrate plugin, but it needs a lot of work as-is.
Comment #9
papagrandeIt looks like it also needs a D7 source plugin too as the location 'lid' comes from the non-standard 'location_instance' table.
Comment #10
pieterdcThanks for sharing but the patch is unusable in its current state.
Because even if you correct the database connection to your use case, the location id is not fetched, unless you have custom code that's not in this patch. If you do, please share.
As @PapaGrande already stated, it needs a migration source plugin to fetch the correct data.
Documentation: https://www.drupal.org/docs/8/api/migrate-api/migrate-source-plugins/ove...
AFAIK, source plugins can't be set on field, but only on migration level. So, that'd result in a separate migration for the locations requiring the related node migration to have run before it.
Unless that's all not needed with a field migration along the lines of this documentation: https://www.drupal.org/docs/8/api/migrate-api/writing-migrations-for-con...
Comment #11
bob.hinrichs commentedFollowing .. And kind of amazed this is all the activity we have on this issue when 46,000 sites use the location module, and this work was begun over a year ago and no resolution is mentioned. I will need to somehow migrate location data myself so am interested in how people have resolved this?
Comment #12
papagrande@bob.hinrichs, my workaround was to have the client manually copy the 79 addresses to new paragraph fields in D7. Then it was easy to migrate the paragraphs. Obviously not a viable solution for anyone with more than a few location instances, but perhaps you could do something in bulk with SQL at the database level.
Comment #13
bob.hinrichs commentedThis is doable using FieldPluginBase to cause the field to automatically get created during migration. Use AddressField.php in the Address module as your example. The module has an example of migrating other modules' address types into the Address module type. Creating a new field on a destination to hold migrated data is not well-documented but this seems the most straightforward example.
In your custom migration code for your node type, extend the Node migration and override prepareRow(). Add the query in this method to grab the location data on D7.
In the prepareRow() code, set source property for the D7 location data into some custom properties that can be used to pull in the data.
In this example, the keys 'country_code', 'city', 'state', etc. that you see below.
In your node migration yml process block, include these lines:
'field_address/country_code': country_code
'field_address/address_line1': street_address
'field_address/locality': city
'field_address/province': state
'field_address/administrative_area': state
'field_address/postal_code': zip
Comment #14
bogdog400 commentedThx for the basic sketch on how to accomplish this. If anyone can post working code, it would be quite a gift. I'm just starting to try to understand migration templates and functions.
Comment #15
cmah commented@bob.hinrichs, you used FieldPluginBase and extended the Node migration in a custom source plugin?
I was under the impression that the recommended approach was to create a new process plugin rather than a source plugin, extending ProcessPluginBase and putting the query inside the transform() method. I did this to convert Location to Address (and then a second separate process plugin to convert Location to Geofield for the latitude and longitude). If I've done this completely incorrectly, please explain why a source plugin is better -- I am new to this and it is all very overwhelming!
Comment #16
poker.ca commented@cmah: if the method in #15 worked, could you post a patch with that code? Sounds like exactly what I need!
Comment #17
cmah commentedHi @poker.ca, I don't know how to contribute patches to an existing drupal contrib module. All I know how to do is write my own custom modules. However, if it helps you, the code I wrote for the address portion of my custom process plugin was basically like this (which I'm sure I just copied out of @ronaldmulero's patch):
If you also need the Latitude and Longitude in your D8 site and not just the address, make a separate new Geofield for that, and then just make a separate plugin for that and grab only the latitude and longitude.
So after you write those two process plugins you then just do this in your YML:
Again, I can't really vouch for this code, but maybe it will help you anyway. It worked for me -- it's basically the exact same code as what @ronaldmulero already posted, so I'm pretty confused as to why we would need a source plugin instead (or, in addition, perhaps -- that's the part I'm not clear on) -- several people who know a lot more about this stuff than I do have said that this is the case, so I do believe them, but I also know that this code worked for me.
Comment #18
ccjjmartin commentedJust to show another perspective, I have attached a source plugin as opposed to a process plugin. I used it by creating a content type with a field that had machine name "field_address" then added the following migration config, replace CONTENT_TYPE_HERE with your content type:
Seems to work for me. I will say that all of my content only has 1 location associated with it so multiple locations will probably break the migration code but the source plugin code should still return all of the data appropriately. Since the migration code isn't in the patch it shouldn't be an issue.
Comment #19
ccjjmartin commentedComment #20
ccjjmartin commentedI forgot to mention that this requires another migration to run the initial import of the content type and this updates the existing content's address field. Specifically it uses the overwrite_properties option here: https://api.drupal.org/api/drupal/core%21modules%21migrate%21src%21Plugi...
Comment #21
damienmckennaWhile this plugin will be great on its own, I opened a separate issue to tie it into a full field migration: #3173870: Support core migrations for automated update from Location (D7) fields
Comment #22
damienmckennaI also created a separate issue to handle Location Node, which doesn't use Field API: #3173871: Support core migrations for automated update from Location Node (D7) data
Comment #23
huzookaI think that #3173870: Support core migrations for automated update from Location (D7) fields is already good enough to create test coverage for it.
Comment #24
ccjjmartin commentedSo for the address field DamienMcKenna's solution seems like a good approach, I haven't tested it but in theory it is better than the approach I am using. The approach I am using technically supports GeoFields too so I am going to upload a new version that I tweaked to better support node revisions and publishing status.
If anyone is interested in what the migration looks like for integration with the Group module, it looks like this:
The field on the group entity has a machine name of "field_address" and it overwrites the existing Group imported in a separate migration. It took me a while to debug that the id should be called "id" and not "nid" or "gid".
Comment #25
iancawthorne commentedHas anyone tried this module: https://www.drupal.org/project/location_migration
To see if it does what is set out here?
Comment #26
mparker17Now that #3189605: Declare upgrade status from D6, D7 has been committed; here's the patch from #24 with the upgrade status set properly.
Comment #27
wim leersWe’ve worked hard to stabilize https://www.drupal.org/project/location_migration.
It’s been working successfully for many customers for a year now.
Comment #28
damienmckenna+1 for location_migration.
Comment #29
bojanz commentedAwesome, since we now have a tested alternative at https://www.drupal.org/project/location_migration, I am closing this issue as done and giving everyone issue credit.