Hi,

I was having an issue with this module and Memecached where the masquerade table wasn't getting updated with the users $session_id if it changed.

The case I found this happening is when there was a switch user link on the users page. When you clicked the link as an administrator you changed user, but on the next page load you were back to being an administrator.

The code below is how I got around it:

<?php
/**
* Implements hook_user().
*
* Updates the masqurade table when the static $old_session_id is empty.
* Probably something to do with memcache.
*/
function apm_masquerade_helper_user($op, &$edit, &$account, $category = NULL) {

      static
$old_session_id;

      switch(
$op) {

      case
'after_update':
        global
$user;

        if (!empty(
$old_session_id) && session_id() != $old_session_id) {
         
db_query("UPDATE {masquerade} SET sid = '%s' WHERE sid = '%s'", session_id(), $old_session_id);
        }
        else {
         
$result = db_fetch_object(db_query("SELECT uid_as FROM {masquerade} WHERE sid = '%s'", $user->sid));

          if (
$result->uid_as == $account->uid) {
           
db_query("UPDATE {masquerade} SET sid = '%s' WHERE sid = '%s'", session_id(), $user->sid);
          }
        }

      break;
}
?>

I can't say definitively if this has been caused by memecached, but thought I would post this up in case anyone gets stuck on it.

Cheers

Tom

Comments

deekayen’s picture