MigrateDestinationComment

Last updated on
30 April 2025

To migrate content into Drupal comments, use the MigrateDestinationComment class:

$comment_options = MigrateDestinationComment::options($language, $text_format);
$this->destination = new MigrateDestinationComment('comment_node_article', $comment_options);
$this->addFieldMapping('subject', 'source_subject');
$this->addFieldMapping('comment_body', 'source_body');
$this->addFieldMapping('uid', 'user_id')
     ->sourceMigration('MyUserMigration');
$this->addFieldMapping('nid', 'article_id')
     ->sourceMigration('MyArticleMigration');
...

The first argument is the bundle (comment type) you wish to migrate source content into. Note that this is typically the node bundle (content type) whose comments you want to create, with 'comment_node_' prepended.

Fields

cid - The Drupal comment ID. Usually this will be unmapped - the cid will be automatically assigned when the comment is created, and the map table will record the source key that generated this ID. You will need to map the cid when the system-of-record is DESTINATION (i.e., the purpose of your migration is updating existing comments rather than importing new comments).

nid - The Drupal ID of the comment's parent node. This field is required.

uid - The Drupal user ID of the comment's creator, if they have an account (comments may be anonymous, so this need not be specified).

pid - The Drupal comment ID of the comment's parent, if comments are threaded.

subject - The subject (title) of the comment.

comment_body - On Drupal 6, the body of the comment. On Drupal 7, the body is a true field and fully configurable.

created - The date and time when the comment was created. If no value is mapped from the source data, this will default to the time the comment 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 (timestamp on Drupal 6) - The date and time when the comment was last modified. See also created. Note that if not mapped, it will default to the created timestamp.

status - The comment status (1 if published, 0 if not published).

hostname - The hostname or IP address from which the comment was posted.

name - The name provided by an anonymous user; this is not an account username, but free text.

mail - The email address of an anonymous user.

homepage - A URL provided by the commenter.

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

thread - An internal string representing a threaded comment's position in the hierarchy.

Options

Language

The language option will be applied as the default language for any comment 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 comment fields which take a format. If unspecified, the default for the field will be applied.

Help improve this page

Page status: Not set

You can: