You are here

function user_revision_user_presave in User Revision 7

Same name and namespace in other branches
  1. 8 user_revision.module \user_revision_user_presave()
  2. 7.2 user_revision.module \user_revision_user_presave()

Implements hook_user_presave().

File

./user_revision.module, line 369
Enables user revision.

Code

function user_revision_user_presave(&$edit, $account, $category) {
  global $user;
  $edit['log'] = empty($edit['log']) ? '' : $edit['log'];
  $edit = array_merge((array) $account, $edit);
  $edit['timestamp'] = REQUEST_TIME;
  $edit['authorid'] = $user->uid;

  // Loading the old hashed password again.
  if (empty($edit['pass']) && !empty($edit['original']->pass)) {
    $edit['pass'] = $edit['original']->pass;
  }

  // Allow this module to be extended.
  $custom_fields = _user_revision_get_custom_fields($edit);
  foreach ($custom_fields as $field => $value) {
    $edit[$field] = $value;
  }
  $edit = array_merge((array) $custom_fields, $edit);
  if (isset($edit['revision']) && $edit['revision'] == 1 || $account->is_new || !isset($edit['revision']) && variable_get('user_revision_by_default', 1)) {
    if (isset($edit['vid'])) {
      $edit['old_vid'] = $edit['vid'];
      unset($edit['vid']);
    }
    _user_save_revision($edit);
  }
  else {
    _user_save_revision($edit, array(
      'vid',
    ));
  }
}