You are here

public function WordPressAttachment::prepare in WordPress Migrate 7.2

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

Prepare node - called just before file_save().

Parameters

stdClass $node:

stdClass $row:

File

./wordpress_attachment.inc, line 143

Class

WordPressAttachment
Implementation of WordPressMigration, for attachments

Code

public function prepare(stdClass $file, 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->{'dc:creator'}])) {
    $user_map[$row->{'dc:creator'}] = db_select('users', 'u')
      ->fields('u', array(
      'uid',
    ))
      ->condition('name', $row->{'dc:creator'})
      ->execute()
      ->fetchField();
    if (!$user_map[$row->{'dc: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->{'dc:creator'}] = $default_user;
    }
  }
  $file->uid = $user_map[$row->{'dc:creator'}];
}