You are here

function uif_update_user in User Import Framework 7

Same name and namespace in other branches
  1. 6 uif.admin.inc \uif_update_user()

Update an existing user.

2 calls to uif_update_user()
uif_batch_import_users_finished in ./uif.admin.inc
User import batch completion.
uif_import_user in ./uif.admin.inc
Import one user.

File

./uif.admin.inc, line 539
Simple, extensible user import from a CSV file.

Code

function uif_update_user($user_data, $uid, $form_state) {
  $account = user_load($uid);

  // todo: Support update of user mail. This requires optional inclusion of uid column,
  // which would override use of email column as uid lookup method.
  $changes = module_invoke_all('uif_pre_update', $account, $user_data, $form_state);

  // Update the username if it has changed
  if (!empty($user_data['name'])) {
    $username = uif_unique_username($user_data['name'], $uid);
    if ($username != $account->name) {
      $changes['name'] = $username;
    }
  }

  // Update the password if one is provided
  if (!empty($user_data['pass'])) {
    $changes['pass'] = $user_data['pass'];
  }

  // Update roles if present
  if (isset($user_data['roles'])) {
    $changes['roles'] = uif_parse_roles($user_data['roles']);
  }
  $account = user_save($account, $changes);
  module_invoke_all('uif_post_update', $account, $user_data, $form_state);
  return $account;
}