You are here

public function WordPressComment::prepare in WordPress Migrate 7.2

Same name and namespace in other branches
  1. 7 wordpress_comment.inc \WordPressComment::prepare()

Prepare comment - called just before comment_save().

Parameters

stdClass $comment:

stdClass $row:

File

./wordpress_comment.inc, line 253
Support for migrating comments from a WordPress blog into Drupal.

Class

WordPressComment
Implementation of WordPressMigration, for comments

Code

public function prepare(stdClass $comment, stdClass $row) {

  // Match creator email to Drupal account if possible; otherwise, use anonymous
  static $drupal_static_fast;
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast['user_map'] =& drupal_static(__FUNCTION__);
  }
  $user_map =& $drupal_static_fast['user_map'];
  $comment_author_email = $this
    ->xpathValue($row->xml
    ->xpath('wp:comment_author_email'));
  if (!isset($user_map[$comment_author_email])) {
    $user_map[$comment_author_email] = db_select('users', 'u')
      ->fields('u', array(
      'uid',
    ))
      ->condition('mail', $row->{'wp:comment_author_email'})
      ->execute()
      ->fetchField();
    if (!$user_map[$comment_author_email]) {
      $user_map[$comment_author_email] = 0;
    }
  }
  $comment->uid = $user_map[$comment_author_email];
}