You are here

public function DrupalUserMigration::prepareRow in Drupal-to-Drupal data migration 7.2

Review a data row after fetch, returning FALSE to skip it.

Parameters

$row:

Return value

bool

Overrides Migration::prepareRow

2 calls to DrupalUserMigration::prepareRow()
DrupalUser5Migration::prepareRow in d5/user.inc
Implementation of Migration::prepareRow().
DrupalUser6Migration::prepareRow in d6/user.inc
Implementation of Migration::prepareRow().
2 methods override DrupalUserMigration::prepareRow()
DrupalUser5Migration::prepareRow in d5/user.inc
Implementation of Migration::prepareRow().
DrupalUser6Migration::prepareRow in d6/user.inc
Implementation of Migration::prepareRow().

File

./user.inc, line 167
Base class for migrating users into Drupal.

Class

DrupalUserMigration
Base class for all user migrations - handles commonalities across all supported source Drupal versions.

Code

public function prepareRow($row) {
  if (parent::prepareRow($row) === FALSE) {
    return FALSE;
  }

  // On initial import, if this email address already exists, just map to the
  // existing uid and don't allow it to be deleted. When updating, we can
  // take the existing uid from the map instead of querying for it. Make sure
  // when updating an imported user that we don't apply this logic.
  if (empty($row->migrate_map_destid1)) {
    $new_uid = db_select('users', 'u')
      ->fields('u', array(
      'uid',
    ))
      ->condition('mail', $row->mail)
      ->execute()
      ->fetchField();

    // If we haven't mapped the admin account based on email address, map it
    // directly to the destination admin account.
    if (!$new_uid && $row->uid == 1) {
      $new_uid = 1;
    }
  }
  elseif ($row->migrate_map_needs_update == MigrateMap::STATUS_IGNORED && $row->migrate_map_rollback_action == MigrateMap::ROLLBACK_PRESERVE) {
    $new_uid = $row->migrate_map_destid1;
  }
  if (!empty($new_uid)) {
    $hash = isset($row->migrate_map_hash) ? $row->migrate_map_hash : NULL;
    $this->map
      ->saveIDMapping($row, array(
      $new_uid,
    ), MigrateMap::STATUS_IGNORED, MigrateMap::ROLLBACK_PRESERVE, $hash);
    $this->rollbackAction = MigrateMap::ROLLBACK_PRESERVE;
    return FALSE;
  }

  // Add the path to the source row, if relevant
  if ($this
    ->moduleExists('path')) {
    $path = $this->version
      ->getPath('user/' . $row->uid);
    if ($path) {
      $row->path = $path;
    }
  }

  // Pick up profile data.
  $this->version
    ->getSourceValues($row, $row->uid);

  // Populate the source roles
  if ($this->roleMigration) {
    $result = Database::getConnection('default', $this->sourceConnection)
      ->select('users_roles', 'ur')
      ->fields('ur', array(
      'rid',
    ))
      ->condition('uid', $row->uid)
      ->execute();
    foreach ($result as $role_row) {
      $row->roles[] = $role_row->rid;
    }
  }
  return TRUE;
}