I would like to import 2 related nodes (Organic Group and OG group content) from 2 CSV files using Migrate module but I cannot find a proper CSV migrate class example or module. I use Drupal 7.

OG Group
  |--OG group content

file formats:

(a) OG Group file
gid | group_title | group_body | group_admin

(b) OG group content
nid | gid | node_title | node_body


{a.gid} 1..(one-to-many)..* {b.gid}
{a.group_admin} *..(many-to-one)..1 {users.uid}  // group admin is one of existing users uid that should have the OG group administration membership rights

Where can I find a sample CSV migration class for Migrate module ?

Migrate OG is for D6 only Migrate Extras contains classes for OG for D7 but I could not find an example for this scenario.

  • You're bringing this in from a CSV file but it's not clear how it will relate to content already on the site. Are you using this as an import mechanism to add members to content already on the site? Are you creating new groups? You should say more about why you're migrating this data.
    – drewish
    Jan 19, 2012 at 15:31

1 Answer 1


Okay so I'm assuming that you haven't used Migrate before. If you'd like some background reading take a look at the slides for the presentation I'll be giving at DrupalCon in Denver: http://denver2012.drupal.org/sites/default/files/slides/Migrate_0.pdf It should help you understand some of the concepts.

One thing that's important to point out is that you'll need two migrations:

  1. Using (a) and MigrateSourceCSV as a source and—assuming the groups will be nodes—MigrateDestinationNode as a destination.
  2. Using (b) and MigrateSourceCSV as a source and MigrateDestinationOGMembership (as you noted part of Migrate Extras) as a destination.

The CSV files are actually really easy to use as a source. You can see an example of it in the Migrate docs: http://drupal.org/node/1152158

In your case you could setup the source for (a) with:

// The definition of the columns. Keys are integers, values are an 
// array of field name then description.
$columns = array(
  0 => array('gid', 'Id'),
  1 => array('group_title', 'Title'),
  2 => array('group_body', 'Body'),
  3 => array('group_admin', 'Admin'),

// Instantiate the class using the path to the CSV file and the columns.
$this->source = new MigrateSourceCSV('path/to/a.csv', $columns);

You'll also need to know something about your source when you setup the Map because it needs to create a field to store the source ids in... since gid's are basically nid's you can just cheat and use that source's schema definition:

$this->map = new MigrateSQLMap($this->machineName,
  • I could import the groups with the node migration. Do you have an example of doing the OG Membership migration? Thanks!
    – uwe
    Feb 20, 2012 at 4:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.