You are here

protected function FeedsUserProcessor::entitySave in Feeds 7.2

Save a user account.

Overrides FeedsProcessor::entitySave

File

plugins/FeedsUserProcessor.inc, line 161
Contains FeedsUserProcessor.

Class

FeedsUserProcessor
Feeds processor plugin. Create users from feed items.

Code

protected function entitySave($account) {
  if ($this->config['defuse_mail']) {
    $account->mail = $account->mail . '_test';
  }
  $edit = (array) $account;

  // Remove pass from $edit if the password is unchanged.
  if (isset($account->feeds_original_pass) && $account->pass == $account->feeds_original_pass) {
    unset($edit['pass']);
  }

  // Check if the user ID changed when updating users.
  if (!empty($account->feeds_item->entity_id) && $account->feeds_item->entity_id != $account->uid) {

    // The user ID of the existing user is different. Try to update the user ID.
    db_update('users')
      ->fields(array(
      'uid' => $account->uid,
    ))
      ->condition('uid', $account->feeds_item->entity_id)
      ->execute();
  }
  user_save($account, $edit);

  // If an encrypted password was given, directly set this in the database.
  if ($account->uid && !empty($account->pass_crypted)) {
    db_update('users')
      ->fields(array(
      'pass' => $account->pass_crypted,
    ))
      ->condition('uid', $account->uid)
      ->execute();
  }
  if ($account->uid && !empty($account->openid)) {
    $authmap = array(
      'uid' => $account->uid,
      'module' => 'openid',
      'authname' => $account->openid,
    );
    if (SAVED_UPDATED != drupal_write_record('authmap', $authmap, array(
      'uid',
      'module',
    ))) {
      drupal_write_record('authmap', $authmap);
    }
  }
}