Problem/Motivation
I have a content type with a location field and a geofield field. That geo field's widget is configured to "Geocode from another field" (the location field) using Geocoder. This works fine when editing and saving nodes, the coordinates are retrieved using the set geocoding service.
However, it does not work when migrating nodes using the migrate module, the location is not geocoded.
The address to geocode is extracted from the respective field item in geocoder_widget_parse_locationfield(). It combines the fields name, street, additional, city, province, country and postalcode into a single address string which is then sent to the set geocoding service. Those fields are all set in the field item when saving a node that has been edited e.g. via node edit form.
However, when migrating, the location field item is built by MigrateLocationFieldHandler::prepare() which only returns an array with the lid instead of a fully populated location array. But geocoder_widget_parse_locationfield() cannot create an address string from that and so nothing is geocoded.
Proposed resolution
It works when fixing MigrateLocationFieldHandler::prepare() by merging the actual location data into the returned array with the lid. I attached a patch.
A different solution would be to change geocoder_widget_parse_locationfield() to fetch the location data via location_load_location($field_item['lid']) if only the lid is given. But as other related modules might have the same issues when processing the location data I do favor fixing MigrateLocationFieldHandler::prepare().
| Comment | File | Size | Author |
|---|---|---|---|
| location-fix-migration-geocoding.patch | 532 bytes | ronino |
Comments
Comment #1
cmah commentedMy issue with MigrateLocationFieldHandler::prepare() may not be the same as yours, but I am not sure where else to post this.
I've noticed when migrating into a location field, that geocoding works if I change
$instance_arguments['inhibit_geocode'] = TRUE;to$instance_arguments['inhibit_geocode'] = FALSE;, but I am aware that this would break things for other use cases which need this to remain FALSE.I'm not migrating into a field that is geocoded from another field, I am just using the Location module by itself, extracting the city and state from my legacy CMS.
UPDATE: Now I'm starting to realize how wasteful it is to always go to Google for this information (given the notorious 2500 limit), so what would be really great here is some way to set
$instance_arguments['inhibit_geocode']to FALSE only if you cannot locally grab the lat/lon for a given city/province combination from a previous geocode call. However, the only way I've been able to achieve this is by editing the location.migrate.inc file and changing theprepare()function, which is frustrating, because now I have a local copy of the location module.Comment #2
pieterdt commentedThe patch fixed the errors thrown by geocoder during migration, but it doesn't save the coordinates in the location for me.
The geocoding call is successfull though...
Any thoughts? Thanks for the fix anyways!
Comment #3
alex.bukach commented@Ronino, the patch works! Indeed, it doesn't do anything with location field coordinates (and it isn't supposed to), however it preserves address within migrated node entity.
Comment #4
podarokThanks. Committed.