Index: branches/5.2.x/core/kernel/session/session_storage.php =================================================================== diff -u -N -r14585 -r14628 --- branches/5.2.x/core/kernel/session/session_storage.php (.../session_storage.php) (revision 14585) +++ branches/5.2.x/core/kernel/session/session_storage.php (.../session_storage.php) (revision 14628) @@ -1,7 +1,7 @@ DirectVars); } - function StoreSession($to_database = true) + /** + * Stores session to database + * + * @param bool $to_database + * + * @return void + * @access public + */ + public function StoreSession($to_database = true) { - if (defined('IS_INSTALL') && IS_INSTALL && $to_database && !$this->Application->TableFound($this->TableName)) { - return false; + if ( defined('IS_INSTALL') && IS_INSTALL && $to_database && !$this->Application->TableFound($this->TableName) ) { + return; } $fields_hash = $this->GetSessionDefaults(); - if ($to_database) { + if ( $to_database ) { $this->Conn->doInsert($fields_hash, $this->TableName); } @@ -206,39 +214,48 @@ //return $this->Conn->Query('UPDATE '.$this->TableName.' SET '.$var_name.' = '.$this->Conn->qstr($value).' WHERE '.$this->IDField.' = '.$this->Conn->qstr($this->Session->GetID()) ); } - function SaveData() + /** + * Saves changes in session to database using single REPLACE query + * + * @return void + * @access public + */ + public function SaveData() { - if(!$this->Session->SID) return false; // can't save without sid + if ( !$this->Session->SID ) { + // can't save without sid + return ; + } + $replace = ''; $ses_data = $this->Session->Data->GetParams(); - $replace = ''; - foreach ($ses_data as $key => $value) - { - if ( isset($this->OriginalData[$key]) && $this->OriginalData[$key] == $value) - { + foreach ($ses_data as $key => $value) { + if ( isset($this->OriginalData[$key]) && $this->OriginalData[$key] == $value ) { continue; //skip unchanged session data } - else - { - $replace .= sprintf("(%s, %s, %s),", - $this->Conn->qstr($this->Session->SID), - $this->Conn->qstr($key), - $this->Conn->qstr($value)); + else { + $replace .= sprintf("(%s, %s, %s),", $this->Conn->qstr($this->Session->SID), $this->Conn->qstr($key), $this->Conn->qstr($value)); } } + $replace = rtrim($replace, ','); - if ($replace != '') { - $query = ' REPLACE INTO '.$this->SessionDataTable. ' ('.$this->IDField.', '.$this->DataVarField.', '.$this->DataValueField.') VALUES '.$replace; + + if ( $replace != '' ) { + $query = ' REPLACE INTO ' . $this->SessionDataTable . ' (' . $this->IDField . ', ' . $this->DataVarField . ', ' . $this->DataValueField . ') VALUES ' . $replace; $this->Conn->Query($query); } - if ($this->ChangedDirectVars) { - $changes = array(); + if ( $this->ChangedDirectVars ) { + $changes = Array (); + foreach ($this->ChangedDirectVars as $var) { - $changes[] = $var.' = '.$this->Conn->qstr($this->DirectVars[$var]); + $changes[] = $var . ' = ' . $this->Conn->qstr($this->DirectVars[$var]); } - $query = 'UPDATE '.$this->TableName.' SET '.implode(',', $changes).' WHERE '.$this->IDField.' = '.$this->Conn->qstr($this->Session->GetID()); + + $query = ' UPDATE ' . $this->TableName . ' + SET ' . implode(',', $changes) . ' + WHERE ' . $this->IDField . ' = ' . $this->Conn->qstr($this->Session->GetID()); $this->Conn->Query($query); } }