You are here

public function WordPressItemMigration::prepare in WordPress Migrate 7

Same name and namespace in other branches
  1. 7.2 wordpress_item.inc \WordPressItemMigration::prepare()

Prepare node - called just before node_save().

Parameters

stdClass $node:

stdClass $row:

File

./wordpress_item.inc, line 555
Support for migrating posts and pages from a WordPress blog into Drupal.

Class

WordPressItemMigration
Intermediate Migration class, implementing behavior common across different types (post_type) of items.

Code

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

  // Match creator username to Drupal username if possible; otherwise, use
  // the user that initiated the import
  static $drupal_static_fast;
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast['user_map'] =& drupal_static(__FUNCTION__);
    $drupal_static_fast['default_user'] =& drupal_static(__FUNCTION__ . 'DefaultUser');
  }
  $user_map =& $drupal_static_fast['user_map'];
  if (!isset($user_map[$row->creator])) {
    $user_map[$row->creator] = db_select('users', 'u')
      ->fields('u', array(
      'uid',
    ))
      ->condition('name', $row->creator)
      ->execute()
      ->fetchField();
    if (!$user_map[$row->creator]) {
      $default_user =& $drupal_static_fast['default_user'];
      if (!isset($default_user)) {
        $default_user = db_select('wordpress_migrate', 'wpm')
          ->fields('wpm', array(
          'uid',
        ))
          ->condition('filename', $this->wxrFile)
          ->execute()
          ->fetchField();
      }
      $user_map[$row->creator] = $default_user;
    }
  }
  $node->uid = $user_map[$row->creator];
}