To migrate content into Drupal nodes, use the MigrateDestinationNode class:

$node_options = MigrateDestinationNode::options($language, $text_format);
$this->destination = new MigrateDestinationNode('article', $node_options);
$this->addFieldMapping('title', 'source_title');
$this->addFieldMapping('body', 'source_body');
$this->addFieldMapping('body:summary', 'source_teaser');
...

The first argument is the bundle (content type) you wish to migrate source content into.

Fields

nid - The Drupal node ID. Usually this will be unmapped - the nid will be automatically assigned when the node is created, and the map table will record the source key that generated this ID. You will need to map the nid when the system-of-record is DESTINATION (i.e., the purpose of your migration is updating existing nodes rather than importing new nodes). Also, if you want to maintain the same content ID as you had in the source system, you would map that ID to the nid as well as setting the is_new field.

title - The title of the node.

uid - The Drupal user ID of the account that created the node.

created - The date and time when the node was created. If no value is mapped from the source data, this will default to the time the node is imported by Migrate. Note that while this is ultimately stored as a UNIX timestamp, any absolute date/time string supported by strtotime() can be mapped to this (or generally any other timestamp field).

changed - The date and time when the node was last modified. See also created. Note that if not mapped, it will default to the time the node is imported by Migrate.

status - The node status, 1 for published and 0 for unpublished.

promote - Whether the node is promoted to the front page (1 for promoted, 0 for not promoted).

sticky - Whether the node should be listed at the top of listings by default (1 for sticky, 0 for not sticky).

revision - Whether to create a new revision for the node (1 to create a revision, 0 to overwrite if the node already exists).

log - Log message to store with a revision.

language - The node's language, e.g. "en" for English.

tnid - The translation set ID for the node.

translate - A boolean indicating whether this translation page needs to be updated.

revision_uid - The uid of the user who created a specific node revision.

is_new (Drupal 7 only) - An option that, if set to TRUE, will create a new node using the value mapped to nid as its ID, rather than generated a new sequential ID. Because the Migrate module maintains the mappings of source to destination IDs, and supports automatically substituting them with sourceMigration to maintain relationships, this is rarely necessary (even if you might think you need it at first glance).
Note: In the UI, set the default value to 1 to use the imported nid or uid.

Options

Language

The language option will be applied as the default language for any node fields which are language-dependent. If unspecified, it will default to LANGUAGE_NONE.

Text format

The text format (e.g., 'filtered_html') will be applied as the default text format for any node fields which take a format. If unspecified, the default for the field will be applied. On Drupal 6, this should be set to the numeric text format value (i.e. '1' for Filtered HTML - see the filter_formats table to find the numeric ID) rather than the human readable name for the filter.

Node statistics

If the statistics module is enabled in your destination site, the totalcount, daycount, and timestamp fields are exposed as node destination fields, and can be mapped like any other:

  $this->addFieldMapping('totalcount', 'total_count');
  $this->addFieldMapping('daycount', 'daily_counter');
  $this->addFieldMapping('timestamp', 'last_viewed');

Comments

nerdcore’s picture

This page says

This should be set to the numeric text format value (i.e. '1' for Filtered HTML) rather than the human readable name for the filter.

But where are those values? How do you know that '1' is 'Filtered HTML'?

nerdcore’s picture

Is this even correct?

I used

$text_format = 'filtered_html';

and it seemed to work fine. Could this have been changed from D6 in D7? Here is an excerpt of the schema from my D7 DB:

mysql> describe field_data_body;
+--------------+------------------+------+-----+---------+-------+
| Field        | Type             | Null | Key | Default | Extra |
+--------------+------------------+------+-----+---------+-------+
...
| body_format  | varchar(255)     | YES  | MUL | NULL    |       | 
+--------------+------------------+------+-----+---------+-------+
bdimaggio’s picture

Hey nerdcore -- I had the same reaction, and had to go hunting around to find out that in D7, the filter_formats table uses machine names for "format" where previous versions used ints.

Goldurned young upstarts changin my data types. Why, ints were just fine in my day...

nerdcore’s picture

When I was your age, we didn't need UUIDs. ;)

Thanks for the tip. I'll have a look at filter_formats.

jamesini’s picture

I was having a heckuva time trying to maintain my node ids when migrating content from one D7 install to another. I'm using MySQL on a LAMP stack.

I was only able to get my nids to match up on the destination after I truncated the node and field_data_body tables:

TRUNCATE TABLE node;
TRUNCATE TABLE field_data_body;

The pertinent code in my __constructor is:

// Mapping fields
// ...
// Maintain Node IDs (useful for for in-content links to 'node/<nid>')
$this->addFieldMapping('nid', 'nid');
$this->addFieldMapping('is_new')->defaultValue(TRUE);
swelljoe’s picture

In the migrate_d2d migration configuration, the is_new default value needs to be set to "1" and not "TRUE" as the documentation here indicates. Once saved with a 1 in that field, you'll be able to select the nid or uid as the source for those fields.

killwaffles’s picture

I am getting an Integrity constraint violation when attempting to update content of the same NID using the is_new option and then mapping the NID.

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '3082' for key 'PRIMARY': INSERT INTO {node} (nid, type, language, title, uid, status, created, changed, comment, promote, sticky, tnid, translate, uuid) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13); Array ( [:db_insert_placeholder_0] => 3082 [:db_insert_placeholder_1] => page [:db_insert_placeholder_2] => und [:db_insert_placeholder_3] => Murals on Glass [:db_insert_placeholder_4] => 1 [:db_insert_placeholder_5] => 1 [:db_insert_placeholder_6] => 1343936666 [:db_insert_placeholder_7] => 1460739553 [:db_insert_placeholder_8] => 1 [:db_insert_placeholder_9] => 0 [:db_insert_placeholder_10] => 0 [:db_insert_placeholder_11] => 0 [:db_insert_placeholder_12] => 0 [:db_insert_placeholder_13] => e9cfe98a-e90d-4b54-a982-849832f21e9d ) (/Users/cwahlfeldt/Sites/curb/includes/common.inc:7334)

This is just one of about 200 of the same errors I'm getting. Any ideas? Maybe UUID issue?

Cheers!