You are here

mongodb_session.module in MongoDB 7

MongoDB Session implementation.

File

mongodb_session/mongodb_session.module
View source
<?php

/**
 * @file
 * MongoDB Session implementation.
 */

/**
 * Implements hook_simpletest_alter().
 */
function mongodb_session_simpletest_alter(&$groups) {

  // An alternative session handler module would not want to run the original
  // Session https handling test because it checks the sessions table in the
  // database.
  unset($groups['Session']);
}

/**
 * Implements hook_user_login().
 */
function mongodb_session_user_login($edit, $account) {
  $save = array(
    '$set' => array(
      'login' => (int) $account->login,
    ),
  );
  mongodb_collection('fields_current', 'user')
    ->update(array(
    '_id' => (int) $account->uid,
  ), $save, mongodb_default_write_options(FALSE));
}

/**
 * Obtain the roles for a user.
 *
 * @param object $account
 *   A user account.
 *
 * @return array
 *   The account roles, indexed by role ID.
 */
function _mongodb_session_get_roles($account) {
  $roles = array();
  $roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user';
  $result = db_query("SELECT r.rid, r.name, ur.uid FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid IN (:uids)", array(
    ':uids' => array(
      $account->uid,
    ),
  ));
  foreach ($result as $role) {
    $roles[(int) $role->rid] = $role->name;
  }
  return $roles;
}

Functions