public function WordPressComment::__construct in WordPress Migrate 7.2
Same name and namespace in other branches
- 7 wordpress_comment.inc \WordPressComment::__construct()
Set it up
Overrides WordPressMigration::__construct
File
- ./
wordpress_comment.inc, line 114 - Support for migrating comments from a WordPress blog into Drupal.
Class
- WordPressComment
- Implementation of WordPressMigration, for comments
Code
public function __construct(array $arguments = array()) {
parent::__construct($arguments);
if ($arguments['source_post_type'] == 'page') {
$reader_class = 'WordPressPageCommentXMLReader';
}
else {
$reader_class = 'WordPressPostCommentXMLReader';
}
// comment_id is the unique ID of items in WordPress
$this->map = new MigrateSQLMap($this->machineName, array(
'wp:comment_id' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'WordPress comment ID',
),
), MigrateDestinationComment::getKeySchema());
$fields = array(
'wp:post_id' => 'Unique ID of the item the comment is attached to',
'wp:comment_id' => 'Unique ID of the comment',
'wp:comment_author' => 'Name of comment author',
'wp:comment_author_email' => 'Email address of comment author',
'wp:comment_author_url' => 'URL of comment author',
'wp:comment_author_IP' => 'IP address from which comment was posted',
'wp:comment_date' => 'Date of comment (what timezone?)',
'wp:comment_date_gmt' => 'Date of comment (GMT)',
'wp:comment_content' => 'Body of comment',
'wp:comment_approved' => '1/0/spam - spam comments will not be imported',
'wp:comment_type' => '?',
'wp:comment_parent' => 'comment_id (?) of parent comment',
'wp:comment_user_id' => 'WordPress user ID of commenter (?)',
);
$source_options = array(
'reader_class' => $reader_class,
'cache_counts' => TRUE,
);
$this->source = new MigrateSourceXML($this->wxrFile, '/rss/channel/item/comment', 'wp:comment_id', $fields, $source_options, $this->arguments['namespaces']);
$this->destination = new MigrateDestinationComment('comment_node_' . $arguments['post_type']);
// The basic mappings
$this
->addFieldMapping('nid', 'wp:post_id')
->xpath('wp:post_id')
->sourceMigration($this->arguments['dependencies']);
$this
->addFieldMapping('pid', 'wp:comment_parent')
->xpath('wp:comment_parent')
->sourceMigration($this
->generateMachineName('WordPressComment'));
$this
->addFieldMapping('uid')
->description('Use email to match Drupal account; if no match, default to anonymous');
$this
->addFieldMapping('subject')
->description('No comment subjects in WP')
->issueGroup('DNM');
$this
->addFieldMapping('hostname', 'wp:comment_author_IP')
->xpath('wp:comment_author_IP');
$this
->addFieldMapping('created', 'wp:comment_date')
->xpath('wp:comment_date')
->callbacks('strtotime');
$this
->addFieldMapping('changed', 'wp:comment_date')
->xpath('wp:comment_date')
->callbacks('strtotime');
$this
->addFieldMapping(NULL, 'wp:comment_date_gmt')
->description('Using comment_date')
->issueGroup('DNM');
$this
->addFieldMapping('status', 'wp:comment_approved')
->xpath('wp:comment_approved')
->description('Do not import those with values of "spam"');
$this
->addFieldMapping('thread')
->issueGroup('DNM');
$this
->addFieldMapping('name', 'wp:comment_author')
->xpath('wp:comment_author')
->callbacks(array(
$this,
'truncateName',
));
$this
->addFieldMapping('mail', 'wp:comment_author_email')
->xpath('wp:comment_author_email');
$this
->addFieldMapping('homepage', 'wp:comment_author_url')
->xpath('wp:comment_author_url');
$this
->addFieldMapping('language');
$this
->addFieldMapping(NULL, 'wp:comment_id')
->description('Source primary key')
->issueGroup('DNM');
$this
->addFieldMapping(NULL, 'wp:comment_user_id')
->description('Always 0?')
->issueGroup('DNM');
$this
->addFieldMapping(NULL, 'wp:comment_type')
->description('Always empty?')
->issueGroup('DNM');
$this
->addFieldMapping('comment_body', 'wp:comment_content')
->xpath('wp:comment_content');
$this
->addFieldMapping('comment_body:format')
->defaultValue($arguments['text_format_comment']);
$this
->addFieldMapping('comment_body:language');
}