You are here

function _user_save_revision in User Revision 7.2

Same name and namespace in other branches
  1. 7 user_revision.module \_user_save_revision()

Save record to the database.

1 call to _user_save_revision()
user_revision_user_presave in ./user_revision.module
Implements hook_user_presave().

File

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

Code

function _user_save_revision(&$edit, $update = array()) {
  $picture = NULL;
  if (isset($edit['picture']) && is_object($edit['picture'])) {
    $picture = $edit['picture'];
    $edit['picture'] = $picture->fid;
  }

  // If $update is empty a new revision is created, otherwise the current vid is updated.
  drupal_write_record('user_revision', $edit, $update);

  // Insert each role to user_revision_roles table.
  if (!empty($edit['roles'])) {

    // If updating, delete any existing roles for this revision, as we're going to re-add them all.
    if (!empty($update)) {
      db_delete('user_revision_roles')
        ->condition('uid', $edit['uid'])
        ->condition('vid', $edit['vid'])
        ->execute();
    }
    foreach (array_keys($edit['roles']) as $rid) {

      // Only store real rids, "Authenticated User" is built-in.
      if ($rid != DRUPAL_AUTHENTICATED_RID) {
        user_revision_add_role($edit['uid'], $edit['vid'], $rid);
      }
    }
  }
  if (is_object($picture)) {
    file_usage_add($picture, 'user_revision', 'user', $edit['vid']);
    $edit['picture'] = $picture;
  }
}