Hey All,

New to Migrate and found Migrate Extra's provides support in import location data. The only examples I've found are like, http://drupal.org/node/942208, where they manually build the array then call a location save in the hook_prepare and then saves the lid to the CCK field.

In my instance I'm not using location as a CCK field on the Node type and just curious if someone on here could point me in the right direction on how to do this properly using the build integration.

Cheers,
Gene Bernier

Comments

FrequenceBanane’s picture

subscribe

gbernier’s picture

Assigned: Unassigned » gbernier
Status: Active » Fixed

Hey All,

I figured it out but ended up take a page from the example provided when using the CCK Location field.

I decided to look at the Devel output of node type I was trying to import to see what fields the location module added to the node. I found there was a locations(array) and location(single instance). So I created the location as the other exampled showed then saved the location object to both locations and location and it worked.

Here is my prepare method I used:

/**
	 * Prepare function allows for data manipulation after all other prepare statements have been loaded and destination object loaded
	 * @param $account
	 * @param $row
	 * @return unknown_type
	 */
	public function prepare(stdClass $account, stdClass $row) {
 	// The source fields are named address, city, state, and zip.
    // The destination fields are street, city, province, and postal_code.
    $location = array(
              'street' => $row->address,
              'city' => $row->CityName,
              'province' => $row->ProvinceName,
              'postal_code' => $row->postalCode,
              // There are many more available keys, see location_save or location module for more details
              );
     $lid = location_save($location);
    
    //    If you have the devel module, you can uncomment this line and confirm that your location is being populated with your data. It will spit out the full location info, even with drush. 
    //    dpm($location);

    // The destination location CCK field is field_biz_location
    // The [0] is the delta. You'll need to modify this code if you're trying to save multiple locations to a single node.   
    $account->location = $location;
    $account->locations[0] = $location;

	}

As a side note though, if anyone has suggestions on how to get better error messages out as to why records don't import I'd love to here because the number of messages and the number not imported do not match.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.