Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I need to draw from several source fields in order to build a Location. In general, though, I have no idea how I'd go about drawing from several source fields (and mapping it to one destination field).
I could just call a helper method in my Migration's prepare method, I guess, but I'd prefer to be able to code up a nice addition to migrate_extras that will work more generally.
Any pointers would be appreciated!
Comment | File | Size | Author |
---|---|---|---|
#27 | location-migration-field-handler-943178-27.patch | 993 bytes | alexweber |
#14 | location-migrate-943178-14.patch | 4.61 KB | ckng |
#12 | location-migrate-943178-12.patch | 4.67 KB | ckng |
#11 | location-943178-11-migrate-support.patch | 18.03 KB | Alan D. |
#9 | location-migrate_field_handler-943178-9.patch | 8.41 KB | kziv |
Comments
Comment #1
mikeryanSorry for the late response, I've been paying more attention to the Migrate issue queue than Migrate Extras... I haven't used Location before, but the general idea would be to map the primary field, and specify the source fields for the other components using arguments. From migrate_example:
So, if for the location module your primary component is 'gps', and you also have 'title' and 'description' components, you might map the field like:
Of course, your primary concern is implementing the field handler that understands those arguments... My best advice (not having much time at the moment) is to look at the MigrateTextFieldHandler implementation in the migrate module's fields.inc and see how it handles the summary argument (the first parameter to MigrateTextFieldHandler::arguments).
Hope this helps.
Comment #2
mikeryanLet's make this the central Location request issue, superceding the following:
#459236: Location Integration
#735714: location cck (work around or bounty)
#753048: location_user integration
#788724: Migrate Location Fields from Legacy CMS to Node Location
#942208: Location integration does not take into account location fields added through API
#1118132: Working example of how to map source fields to a Location destination field?
Comment #3
mikeryanComment #4
PolI made it here and it's working.
Comment #5
mikeryanThe location_cck_migrate module in that sandbox is based on the content_migrate module, not the migrate module.
Comment #6
thePanz CreditAttribution: thePanz commentedI put my first try with Migrate and FieldHandlers in LocationMigrate module (sandbox).
Only JSON data is handled, as exampled in module homepage.. patches are (super) welcome! :)
Note: do not use for production-level migrations!
Comment #7
fluffy CreditAttribution: fluffy commentedHere is a patch for location field handler, based on geofield.inc and #6, this is for Location 7.x-3.x.
Comment #8
mikeryanThis would best go into the Location module itself. This patch would need the following changes:
1. Add location_migrate_api().
2. Rename location.inc to location.migrate.inc, so hook_migrate_api() can be found automatically.
3. Add location.migrate.inc to location.info.
To take advantage of Migrate 2.4's subfield approach, it'd be nice to implement fields() to document the components ('street', 'city', etc.). Then in your migration class instead of using the arguments array you'll be able to do
Comment #9
kziv CreditAttribution: kziv commentedHere's a patch for the location field handler. I based it on #7, using #8's suggestions. It's for location 7.x-3.x.
Comment #10
Alan D. CreditAttribution: Alan D. commentedDue to the class magic in Migrate (yuk), the test "location_cck.php" needs to be renamed to "location_cck.test" to prevent a fatal class not found error.
I was just trying on a user field (unsuccessfully), before remembering that this is currently broken. However, the MigrateLocationFieldHandler::prepare() was correctly getting all fields and returning a lid.
Mapping used was:
And the source fields were populated via profile quries in Migration::prepareRow($current_row);
Comment #11
Alan D. CreditAttribution: Alan D. commentedAlso, this is not used
The import structure was causing my import to fail, it expects something like:
If this is the norm, then all good. I will update my code. However, this doesn't feel right as that suggests the norm is to be importing individual objects that define a singular component value.
So leaving my mapping the same and changing the prepareRow() to this:
And updating the patch with:
Comment #12
ckngRewrite based on #9 #11, - prepareRow() mentioned in #11 is not required
Comment #13
ckngnote the test file renamed from #11 is in #1844462: Class 'DrupalWebTestCase' not found
Comment #14
ckngFixed Call to undefined method MigrateFieldHandler::fields() in location.migrate.inc
Comment #15
Alan D. CreditAttribution: Alan D. commentedI have just run this on a much larger data set and the geoencoding was painfully slow. As such, maybe inhibit_geocode needs to be an option?
Comment #16
gone404 CreditAttribution: gone404 commentedCan someone give a full example of how to migrate location data? I currently have
Inside my "MemberNodeMigration" class, which extends "MasterMemberMigration", which in turn extends "DynamicMigration".
I've tried changing "field_location_dest", to "location" (which is the table in drupal), but I've been unable to get any locations to actually import. I'm new to the migrate module, but I've gotten everything except the locations to import. This is my first time working with extra handlers. I've applied the patch offered in #12 (location-migrate-943178-12.patch)
Any help would be greatly appreciated.
Comment #17
podarok#1931088: [META] Fixing tests tests were broken, so triggering to active
Comment #18
podarokbot
Comment #19
podarok#14 commited pushed to 7.x-3.x
thanks!!!!
Comment #21
ExTexan CreditAttribution: ExTexan commentedWhere is this? I don't find a location_migrate module, nor anything associated with "migrate" in the location module. And on the project page for migrate_extras, for location it says "requested".
So how to migrate location information from D6 to D7. I'm currently using views to create XML files for import by feed_import. Any help appreciated.
Comment #22
rooby CreditAttribution: rooby commentedIf you get the dev version (should also be in the latest release based on the dates) there is location.migrate.inc in the root directory of the location module.
There is also a brief example of how to implement the migration of locations in the comment block at the top of that file.
Once you have updated to a version of location that has migrate support, make sure you clear the cache and it should work.
Comment #23
rooby CreditAttribution: rooby commentedAlso, if you are migrating from drupal 6 to 7 you should use the migrate_d2d module. it will make things a bit easier for you.
Comment #24
rerooting CreditAttribution: rerooting commentedD5 > D7 - I can migrate to a location destination mapping, however the D5 location cck field is not appearing as a source. Using d2d migrate. Should I open a seperate ticket at this point?
Comment #25
ayalon CreditAttribution: ayalon commentedThe problem with the location import is the following:
location.module:
old
new and working
Comment #26
rooby CreditAttribution: rooby commented@ayalon:
This issue was for adding migrate support and was done and is now closed.
You will need to open a new issue to support the new way of doing migrate handlers.
It's easier to keep track of changes with one change per issue.
Comment #27
alexweber CreditAttribution: alexweber commentedHi, sorry for re-opening this but I couldn't find any other issue to follow this up in.
The issue in #25 is valid and effectively renders the migration field handler un-usable without hacking the module.
Attached is a simple patch that adds that line to the migrate_api implementation and also moves the entire migrate_api hook implementation to the location.migrate.inc
Comment #28
podarok#27 commited pushed to 7.x-3.x
thanks!
Comment #29
alexweber CreditAttribution: alexweber commentedYay! :)
Comment #31
Summit CreditAttribution: Summit commentedHi, I see this is the main and centered issue about Location migration.
I use the latest location.migrate.inc .dev out of the box with a D6-D7 migration with migrate and migrate_d2d.
My contenttype has location node in D6 and NOT location CCK fields.
When I set my new D7 contenttype with Location Node, no source fields and no destination fields are shown in the d2d UI.
When I set my new D7 contenttype with a Location Field, I see the destination fields, but still no source fields.
Is migration of Location Node from D6 to D7 supported? For a lot of old D6 users I think the 'old' way of working with Location node is still valid, so it will be great, but also needed to have regular Location Node D6 to Location Node D7 Migration support.
Of course this needs also to be implemented for use within Migrate_d2d UI.
Does anybody have this working? May be a snippet of code to work from?
Thanks a lot in advance for your reply and as stated in #2 I open this, because this is the central place for Location Migration issues.
Greetings, Martijn
Comment #32
vinothg CreditAttribution: vinothg commentedThe following code worked for me, if anyone is still looking for solution:
Comment #33
kedramonHi,
how you guys deal with migrating nodes where location is not filled in? When node was created without any location information, then location is not stored, looking into migration code there is no way to indicate somehow that there is no lid in source. I'm working on migration now and I have a lot of nodes without locations, after running migration I see a lot of empty records like:
and I don't want empty records in database after migration. Any ideas how to handle this?
Comment #34
ShaunDychko CreditAttribution: ShaunDychko for Bellin commented#32 for the win!
Comment #35
Gleach CreditAttribution: Gleach commentedFYI #32 is close for Location CCK.
XXX stands for the location subfields (see location.migrate.inc):
Simple example for adding just the street: