function _notify_switch_user in Notify 6
Same name and namespace in other branches
- 5.2 notify.module \_notify_switch_user()
- 5 notify.module \_notify_switch_user()
Switch from original user to mail submission user and back.
NOTE: Copied from mailhandler
Note: You first need to run _notify_switch_user without argument to store the current user. Call _notify_switch_user without argument to set the user back to the original user.
Parameters
$uid The user ID to switch to:
1 call to _notify_switch_user()
- _notify_send in ./notify.module 
- Helper function to send the notification email.
File
- ./notify.module, line 638 
- Notify module sends email digests of new content and comments.
Code
function _notify_switch_user($uid = NULL) {
  global $user;
  static $orig_user = array();
  if (isset($uid)) {
    // Should a user visit cron.php, or should this module be invoked via poormanscron and _notify_send() does not complete,
    // the visitor will end up logged in as the "switched to user" for subsequent requests unless we disable saving the session
    // until we are sure we're the invoking user again.
    session_save_session(FALSE);
    $user = user_load(array(
      'uid' => $uid,
    ));
  }
  elseif (count($orig_user)) {
    $user = array_shift($orig_user);
    array_unshift($orig_user, $user);
    session_save_session(TRUE);
  }
  else {
    $orig_user[] = $user;
  }
}