I've discovered that the fields available to Migrate via the location.migrate.inc file are hard-coded and are not compatible with add-in modules that use the Location API to add fields, like Location Phone.

The problem lies here; this array needs to be dynamically generated based on enabled modules that implement hook_locationapi().


/**
 * Implementation of hook_migrate_fields().
 */
function location_migrate_fields_location($type) { 
  $fields = array(
    '[lid]' => t('Location ID'), // Primary Key: Unique location ID.
    //'locpick' => t('Location Chosen By User?'),
    'nid' => t('NID'), // nid
    'vid' => t('VID'), // vid
    //'uid' => t('User ID'),  only used for location_user? (manual ones have uid of 0)
    'genid' => t('Generic reference key'), // Generic reference key.
    'name' => t('Location Name'), // Place Name.
    'street' => t('Street Address'), // Street address, line 1.
    'additional' => t('Additonal info'), // Street address, line 2.      
    'city' => t('City'), // City.
    'province' => t('Province/State'), // State / Province code.
    'postal_code' => t('Postal Code'), // Postal / ZIP code.
    'country' => t('Country (2 letter code)'), // Two letter ISO country code.
    'latitude' => t('Latitude'), // Location latitude (decimal degrees).
    'longitude' => t('Longitude'), // Location longitude (decimal degrees).
    'source' => t('Source'), // Source of the latitude and longitude data (Geocoder, user entered, invalid, etc.)
    'is_primary' => t('Primary Location? (deprecated)'), // Is this the primary location of an object? (unused, civicrm legacy field?)
    'inhibit_geocode' => t('Inhibit Geocoding?'), //
  );
  return $fields;
}
 

Any suggestions as to how to remedy this?

Comments

chiddicks’s picture

One possible solutions is to invoke the hook_locationapi hook within this function to determine extra fields, but that seems like poor form.

Anonymous’s picture

Here is a quick hack, for those who need this functionality now for particular extra fields. In my case, I needed phone and fax, provided by location_phone and location_fax.

This is for 6.x-2.0, I don't know if it will work with Migrate v1.

First, enable location_phone and location_fax modules.
Set them as dependencies in your custom migration module, too. If your module is mymodule, then add these lines to mymodule.info

dependencies[] = location
dependencies[] = location_phone
dependencies[] = location_fax

Now you need to tell Migrate about these new fields. The code in comment #1 is how Migrate Extras tells Migrate about the Location type, so you just copy this code into your own implementation in your own module, and add phone and fax.

In mymodule.module:

function mymodule_migrate_fields_location($type) { 
  $fields = array(
      '[lid]' => t('Location ID'), // Primary Key: Unique location ID.
      //'locpick' => t('Location Chosen By User?'),
      'nid' => t('NID'), // nid
      'vid' => t('VID'), // vid
      //'uid' => t('User ID'),  only used for location_user? (manual ones have uid of 0)
      'genid' => t('Generic reference key'), // Generic reference key.
      'name' => t('Location Name'), // Place Name.
      'street' => t('Street Address'), // Street address, line 1.
      'additional' => t('Additonal info'), // Street address, line 2.      
      'city' => t('City'), // City.
      'province' => t('Province/State'), // State / Province code.
      'postal_code' => t('Postal Code'), // Postal / ZIP code.
      'country' => t('Country (2 letter code)'), // Two letter ISO country code.
      'latitude' => t('Latitude'), // Location latitude (decimal degrees).
      'longitude' => t('Longitude'), // Location longitude (decimal degrees).
      'source' => t('Source'), // Source of the latitude and longitude data (Geocoder, user entered, invalid, etc.)
      'is_primary' => t('Primary Location? (depricated)'), // Is this the primary location of an object? (unused, civicrm legacy field?)
      'inhibit_geocode' => t('Inhibit Geocoding?'), //
      // Add phone and fax fields: need location_phone and location_fax enabled
      'phone' => t('Phone number'), // need location_phone enabled
      'fax' => t('Fax number'), // need location_fax enabled
    );
  return $fields;
}

This is a hack; it will override any future updates in Migrate Extras. But it works for now.

Now you can map your source phone and fax to the Location phone and fax fields. Here is a way that works, though I am not sure it's the best. (See #1118132: Working example of how to map source fields to a Location destination field? for more on this approach to mapping source fields to fax fields.)

This code goes in your Node Migration, outside the _construct function. (E.g., in the example beer.inc for 6.x-2.0, you could put this after the closing bracket on line 341 but before the closing bracket of line 342.

  public function prepare(stdClass $account, stdClass $row) {
    $location = array(
		      'street' => $row->address,
		      'city' => $row->city,
		      'province' => $row->state,
		      'postal_code' => $row->zip,
		      // For phone and fax, provided by location_phone and location_fax,
		      // you need to override location_migrate_fields_location in your module.
		      'phone' => $row->phone,
		      'fax' => $row->fax,
		      );
    $lid = location_save($location);
    $account->field_biz_location[0]['lid'] = $lid;
  }

Hope this helps someone, and/or prompts a better solution. Again, this is a temporary hack until Migrate Extras supports these extra location fields dynamically.

mikeryan’s picture

Status: Active » Closed (duplicate)

Migrate and Migrate Extras V1 are no longer supported. Location support for V2 is now consolidated to the following issue:

#943178: Implementation of Location support for Migrate Extras V2