/** * Called from the /user/postsave hook with the one argument of the UserModel. * * @param \UserModel $user * @return bool */ public static function ForceSessionSync(\UserModel $user){ // BEFORE I do this, cleanup any old sessions! Session::CleanupExpired(); $me = (\Core\user() && \Core\user()->get('id') == $user->get('id')); foreach(\SessionModel::Find(['user_id = ' . $user->get('id')]) as $sess){ /** @var \SessionModel $sess */ if($me && $sess->get('session_id') == session_id()){ // It's this current session! // Reload this user object :) // Remember, the external data cannot be set from within the same session! Session::SetUser($user); continue; } $dat = $sess->getExternalData(); $dat['user_forcesync'] = true; $sess->setExternalData($dat); $sess->save(); } return true; }