function sess_user_load in Memcache API and Integration 5
Same name and namespace in other branches
- 6 memcache-session.inc \sess_user_load()
2 calls to sess_user_load()
File
- ./
memcache-session.inc, line 146 - User session handling functions.
Code
function sess_user_load($session) {
$user = new stdClass();
// We found the client's session record and they are an authenticated user
if ($session && $session->uid > 0) {
$user = dmemcache_get($session->uid, 'users');
if (!$user->uid && $user->uid != 0) {
$user = db_fetch_object(db_query("SELECT u.* FROM {users} u WHERE u.uid = %d", $session->uid));
$user = drupal_unpack($user);
$user->session = empty($session->session) ? '' : $session->session;
// Add roles element to $user
$user->roles = array();
$user->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user';
$result = db_query("SELECT r.rid, r.name FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = %d", $user->uid);
while ($role = db_fetch_object($result)) {
$user->roles[$role->rid] = $role->name;
}
}
else {
if ($user->uid) {
$user->from_cache = TRUE;
$user->session = empty($session->session) ? '' : $session->session;
}
else {
// This is a rare case that we have a session cached, but no session user object cached.
// This usually only happens if you kill memcached and restart it.
$user = drupal_anonymous_user($session->session);
}
}
}
else {
$session = isset($session->session) ? $session->session : '';
$user = drupal_anonymous_user($session);
}
return $user;
}