I am trying to migrate content using the Migrate module. But it seems that Countries doesn't integrate with Migrate:

$this->addFieldMapping('field_adress_country', 'country');

This is the way to import a field and it works with others. But the Countries field stays empty. You can set it manually:

$node->field_adress_country['und']['0']['value'] = $row->country;

But this doesn't work either. What is necessary to get this working? Nice would be an integration.

Thanks
Lukas

Comments

luksak’s picture

Category: support » feature

I resloved the issue:

$node->field_adress_country['und']['0']['iso2'] = $row->country;

But integration would be nice.

johnv’s picture

alan d.’s picture

There will be a hook to implement to import the data. The resulting code inside this would probably look like:

$node->field_adress_country['und']['0']['iso2'] = $country = countries_country_lookup($row->country) ? $country->iso2 : NULL;

This function tries to load a country without knowing what property is being passed in. So iso2, iso3, number code or even name (if these match) would return an iso2 code.

alan d.’s picture

Title: Migration with Countries » Countries integration with Migrate module
Project: Countries » Migrate Extras
Component: Code » Migrate Extras Features

Bumping queues:

The request is for Countries module support. This module provides a fieldable country bundle that has country fields. This country field information by iso2 value:

/**
 * Implement hook_field_schema().
 */
function countries_field_schema($field) {
  return array(
    'columns' => array(
      'iso2' => array('type' => 'varchar', 'length' => 2)));
}

Internally, this module supports a number of methods to calculate the country iso2 value from other properties.

The method above (in comment #3) is probably the easiest way as it is not dependent on any one property.

I can not see any use-cases where the country entities would ever need importation.

@Lukas von Blarer
There are partially documented processes on the Migrate / Migrate Extras pages if you want to tackle this faster using a custom implementation.

luksak’s picture

Thank you! I will try this.

alan d.’s picture

Status: Active » Closed (duplicate)

This should be handled internally now, see #1378662: Add support for Migrate API