see #459236: Location Integration

I still need location cck for importing data.

One crazy idea I have is to use the already written node location to import the data, and then to use rules with some php to copy the node location data to the cck location fields...

on getting a location cck migrate extra in, would a bounty help? I can contribute $100. Contact me.

Thanks.

Comments

YesCT’s picture

YesCT’s picture

I wonder if this snippet, posted in a comment to the lullabot article, might help?

http://www.lullabot.com/articles/drupal-data-imports-migrate-and-table-w...

YesCT’s picture

I tried making a module (called mymodule) and putting just the code from the lullabot comment in it, enabled it, did an import, but none of the location cck fields were filled in.

I did make sure the machine name for it was field_location.

do I need to replace TABLENAME_COLUMNNAME_city etc with specifically my column name?

YesCT’s picture

if my tablename is grouplist
and my city column name is city,
then do I replace it with grouplist_city
or
grouplist_city_city?

here is what I have so far:

function mymodule_migrate_prepare_node(&$node, $tblinfo, $row) {

  // Save a location for location_cck field
  if ($tblinfo->mcsid == 2) { // check that you are in the correct migration content set
    if (!empty($row->grouplist_name)) {
      $location = array(
        'city' => $row->grouplist_city,
        'province' => $row->grouplist_state,
        //'postal_code' => $row->grouplist_zip,        'country' => 'US',
        // There are many more available keys, see location_save or location module for mo
re details
      );
      $lid = location_save($location);
      $node->field_location[0]['lid'] = $lid;
    }
  }
}

I'm unclear about the mcsid

YesCT’s picture

I ended up with this:

and it seemed to work. I does assume the city and state are never empty...

function mymodule_migrate_prepare_node(&$node, $tblinfo, $row) {

  // Save a location for location_cck field
  if ($tblinfo->mcsid == 1) { // check that you are in the correct migration content set
    if (!empty($row->grouplist_name)) {
      if (!empty($row->grouplist_zip)) {
       $location = array(
        'city' => $row->grouplist_city,
        'province' => $row->grouplist_state,
        'postal_code' => $row->grouplist_zip,
        'country' => 'US',
        // There are many more available keys, see location_save or location module for more details
       );
      } else {
       $location = array(
        'city' => $row->grouplist_city,
        'province' => $row->grouplist_state,
        'postal_code' => $row->grouplist_zip,
        'country' => 'US',
        // There are many more available keys, see location_save or location module for more details
       );
      }
      $lid = location_save($location);
      $node->field_location[0]['lid'] = $lid;
    }
  }
}
YesCT’s picture

I'm not sure if I need to test to see if the zip is empty...

I think this works just as well. note, I'm trying to test out a bunch of different ways to do future batches... so thus the 4 or 3 or 2 or 1 for the content sets.

function mymodule_migrate_prepare_node(&$node, $tblinfo, $row) {

  // Save a location for location_cck field 
 if ( ($tblinfo->mcsid == 4) || ($tblinfo->mcsid == 3) || ($tblinfo->mcsid == 2) || ($tblinfo->mcsid == 1) ) { 
// check that you are in the correct migration content set
    if (!empty($row->grouplist2_name)) {
       $location = array(
        'city' => $row->grouplist2_city,
        'province' => $row->grouplist2_state,
        'postal_code' => $row->grouplist2_zip,        'country' => 'US',
        // There are many more available keys, see location_save or location module for more de
tails
       );
      $lid = location_save($location);
      $node->field_location[0]['lid'] = $lid;
    }
  }
}

this is related to #459236: Location Integration
and those tagged location importing http://drupal.org/project/issues/search/migrate_extras?issue_tags=locati...

stella’s picture

Patch at #459236: Location Integration comment #36 may fix this.

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