Index: branches/5.2.x/core/kernel/session/session_storage.php =================================================================== --- branches/5.2.x/core/kernel/session/session_storage.php +++ branches/5.2.x/core/kernel/session/session_storage.php @@ -37,6 +37,13 @@ var $PersistentVars = Array (); + /** + * Default persistent vars + * + * @var array + */ + protected $defaultPersistentVars = array(); + var $OriginalData = Array (); var $TimestampField; @@ -337,16 +344,40 @@ function LoadPersistentVars() { $user_id = $this->Session->RecallVar('user_id'); - if ($user_id != USER_GUEST) { - // root & normal users - $sql = 'SELECT VariableValue, VariableName - FROM '.TABLE_PREFIX.'UserPersistentSessionData - WHERE PortalUserId = '.$user_id; - $this->PersistentVars = (array)$this->Conn->GetCol($sql, 'VariableName'); + + if ( $user_id != USER_GUEST ) { + // Root & normal users. + $this->PersistentVars = $this->getPersistentVars($user_id); } else { $this->PersistentVars = Array (); } + + $default_user_id = (int)$this->Application->ConfigValue('DefaultSettingsUserId'); + + if ( !$default_user_id ) { + $default_user_id = USER_ROOT; + } + + if ( $user_id != $default_user_id ) { + $this->defaultPersistentVars = $this->getPersistentVars($default_user_id); + } + } + + /** + * Get persistent vars + * + * @param integer $user_id User Id. + * + * @return array + */ + protected function getPersistentVars($user_id) + { + $sql = 'SELECT VariableValue, VariableName + FROM ' . TABLE_PREFIX . 'UserPersistentSessionData + WHERE PortalUserId = ' . $user_id; + + return $this->Conn->GetCol($sql, 'VariableName'); } /** @@ -412,23 +443,16 @@ return $this->PersistentVars[$var_name]; } elseif ( $default == ALLOW_DEFAULT_SETTINGS ) { - $default_user_id = $this->Application->ConfigValue('DefaultSettingsUserId'); + if ( isset($this->defaultPersistentVars[$var_name]) ) { + $value = $this->defaultPersistentVars[$var_name]; + $this->StorePersistentVar($var_name, $value); - if ( !$default_user_id ) { - $default_user_id = USER_ROOT; + return $value; } - $sql = 'SELECT VariableValue, VariableName - FROM ' . TABLE_PREFIX . 'UserPersistentSessionData - WHERE VariableName = ' . $this->Conn->qstr($var_name) . ' AND PortalUserId = ' . $default_user_id; - $value = $this->Conn->GetOne($sql); - $this->PersistentVars[$var_name] = $value; + $this->PersistentVars[$var_name] = false; - if ( $value !== false ) { - $this->StorePersistentVar($var_name, $value); //storing it, so next time we don't load default user setting - } - - return $value; + return false; } return $default; @@ -525,4 +549,4 @@ throw new BadMethodCallException('Unsupported'); } -} \ No newline at end of file +}