Download & Extend

Countries integration with Migrate module

Project:Migrate Extras
Version:7.x-2.x-dev
Component:Migrate Extras Features
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

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

#1

Category:support request» feature request

I resloved the issue:

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

But integration would be nice.

#2

#3

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

<?php
$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.

#4

Title:Migration with Countries» Countries integration with Migrate module
Project:Countries» Migrate Extras
Version:7.x-2.x-dev» 7.x-2.x-dev
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:

<?php
/**
* 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.

#5

Thank you! I will try this.

nobody click here