Node migrations are much like term migrations, in terms of mapping a source type to a destination type.

  • source_type: The unique machine name of the legacy node type.
  • destination_type: The unique machine name of the destination node type.
  • user_migration: The machine name of your user migration, used to properly assign authorship of the nodes.
  • default_uid: A default destination uid to use as the default author of nodes where a legacy owner isn't identified (for example, nodes authored by the account with uid 1 in the legacy system, since that account is not migrated).
  • default_language: Default language for the node and the node body. Defaults to LANGUAGE_NONE.
// Use another layer of common arguments to reduce duplication
$node_arguments = $common_arguments + array(
  'user_migration' => 'ExampleUser',
  'default_uid' => 1,
);

$photo_node_arguments = $node_arguments + array(
  'machine_name' => 'ExamplePhotoNode',
  'description' => t('Import Drupal 6 photo nodes'),
  'source_type' => 'photo', 
  'destination_type' => 'photo',
  'dependencies' => array('ExamplePhotoTerm'),
);
// Note we use a custom class here so we can map the term references and
// other fields - see "Extending migrate_d2d classes" below.
Migration::registerMigration('ExamplePhotoNodeMigration', 
  $photo_node_arguments['machine_name'], $photo_node_arguments);

$video_node_arguments = $node_arguments + array(
  'machine_name' => 'ExampleVideoNode',
  'description' => t('Import Drupal 6 video nodes'),
  'source_type' => 'video', 
  'destination_type' => 'video',
  'dependencies' => array('ExampleVideoTerm'),
);
// Note we use a custom class here so we can map the term references and
// other fields - see "Extending migrate_d2d classes" below.
Migration::registerMigration('ExampleVideoNodeMigration', 
  $video_node_arguments['machine_name'], $video_node_arguments);

Comments

alexweber’s picture

The section mentioned in the code comments "Extending migrate_d2d classes", doesn't actually exist in the documentation... there's an example module that ships with migrate_d2d though that can help out with writing Node migrations.

xurizaemon’s picture

texas-bronius’s picture

Just wanted to add that according to #1885914: Create content types/fields, migrate_d2d does *not* current provide the ability to create Content Types at the destination.

--
http://drupaltees.com
80s themed Drupal T-Shirts

mykmallett’s picture

I've been searching for this answer for weeks. Will this module keep the same Node IDs when I migrate the content?

DanChadwick’s picture

The node migration provided in migrate_d2d does not maintain node ids in the destination. The underlying migrate module does, however, provide the means to reflect new node ids in other references by means of mapping references to node ids (or any primary id, for that matter) in dependent migrations. So, for example, you might migrate your files, which will result in new fid identifiers. Image fields which refer to that may be mapped using the sourceMigration('YourSourceMigrationName') chained method, such as:

// in your __constructor:
$this->addFieldMapping('field_image', 'legacy_image_field_name')
     ->sourceMigration('MyFilesMigration);

If it is essential to maintain node (and even vids), you are going to code this yourself. It might be easy -- I'm not sure. I would look at mapping the nid field as a first start.

mykmallett’s picture

Thanks for your response

pm5’s picture

You can add a field mapping to NID if you also set the is_new field to TRUE. So just add

<?php
// In your migration classes
$this->addFieldMapping('is_new')->defaultValue(TRUE);
$this->addFieldMapping('nid', 'nid');
?>

to your usual migration_d2d code.

Louis Delacretaz’s picture

see https://www.drupal.org/node/2287757#comment-9569597 for how to use the d2d ui to preserve migrated nid/uid

araujo.guntin’s picture

I'm migrating from D6 to D7. My D6 has 28 content types... should I create these content types in D7 before migrating?

Thanks,

opdavies’s picture

Yes, you'll need to create your new content types and fields in Drupal 7 before being able to do the migration.

Sunflower’s picture

I want to migrate only images & files associated with nodes. Not all files & images, so I am thinking the "Source Migration" way may not work. How do I achieve this?