Changeset 10426
- Timestamp:
- 07/22/08 17:03:31 (4 months ago)
- Files:
-
- branches/1.2/lib/storage/sfDatabaseSessionStorage.class.php (modified) (2 diffs)
- branches/1.2/lib/storage/sfMySQLSessionStorage.class.php (modified) (5 diffs)
- branches/1.2/lib/storage/sfPDOSessionStorage.class.php (modified) (3 diffs)
- branches/1.2/lib/storage/sfPostgreSQLSessionStorage.class.php (modified) (2 diffs)
- branches/1.2/lib/storage/sfSessionStorage.class.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.2/lib/storage/sfDatabaseSessionStorage.class.php
r9663 r10426 103 103 $this->db = $database->getResource(); 104 104 $this->con = $database->getConnection(); 105 105 106 if (is_null($this->db) && is_null($this->con)) 106 107 { … … 157 158 158 159 /** 160 * Regenerates id that represents this storage. 161 * 162 * @param boolean $destroy Destroy session when regenerating? 163 * 164 * @return boolean True if session regenerated, false if error 165 * 166 */ 167 public function regenerate($destroy = false) 168 { 169 if (self::$sessionIdRegenerated) 170 { 171 return; 172 } 173 174 $currentId = session_id(); 175 176 parent::regenerate($destroy); 177 178 $newId = session_id(); 179 180 $this->updateSessionId($currentId, $newId); 181 } 182 183 /** 184 * Updates the session id. 185 * 186 * @param string $currentId The current session id 187 * @param string $newId The new current id 188 * 189 * @return Boolean True if the session id was successfully regenerated 190 * @throws sfDatabaseException if an error occured while regenrating the session id 191 */ 192 abstract protected function updateSessionId($currentId, $newId); 193 194 /** 159 195 * Executes the shutdown procedure. 160 196 * branches/1.2/lib/storage/sfMySQLSessionStorage.class.php
r10116 r10426 86 86 * @param string $id A session ID 87 87 * 88 * @return bool true, if the session was read, otherwise an exception is thrown88 * @return string The session data if the session was read or created, otherwise an exception is thrown 89 89 * 90 90 * @throws <b>sfDatabaseException</b> If the session cannot be read … … 161 161 } 162 162 163 /*! 164 * Execute an SQL Query 163 /** 164 * Updates the session id. 165 * 166 * @param string $currentId The current session id 167 * @param string $newId The new current id 168 * 169 * @return Boolean True if the session id was successfully regenerated 170 * @throws sfDatabaseException if an error occured while regenrating the session id 171 */ 172 protected function updateSessionId($currentId, $newId) 173 { 174 // get table/column 175 $db_table = $this->options['db_table']; 176 $db_id_col = $this->options['db_id_col']; 177 178 // cleanup the session ids, just in case 179 $newId = $this->db_escape($newId); 180 $currentId = $this->db_escape($currentId); 181 182 // update the session id 183 $sql = "UPDATE $db_table SET $db_id_col='$newId' WHERE $db_id_col='$currentId'"; 184 185 if ($this->db_query($sql)) 186 { 187 return true; 188 } 189 190 // failed to write session data 191 throw new sfDatabaseException(sprintf('%s cannot update session id from "%s" to "%s" (%s).', get_class($this), $currentId, $newId, mysql_error())); 192 } 193 194 /** 195 * Executes an SQL Query 165 196 * 166 197 * @param string $query The query to execute … … 172 203 } 173 204 174 /* !175 * Escape a string before using it in a query statement205 /** 206 * Escapes a string before using it in a query statement 176 207 * 177 208 * @param string $string The string to escape … … 183 214 } 184 215 185 /* !186 * Count the rows in a query result216 /** 217 * Counts the rows in a query result 187 218 * 188 219 * @param resource $result Result of a query … … 194 225 } 195 226 196 /* !197 * Extract a row from a query result set227 /** 228 * Extracts a row from a query result set 198 229 * 199 230 * @param resource $result Result of a query branches/1.2/lib/storage/sfPDOSessionStorage.class.php
r9089 r10426 52 52 throw new sfDatabaseException(sprintf('PDOException was thrown when trying to manipulate session data. Message: %s', $e->getMessage())); 53 53 } 54 55 return true; 54 56 } 55 57 … … 89 91 * @param string $id A session ID 90 92 * 91 * @return bool true, if the session was read, otherwise an exception is thrown93 * @return string The session data if the session was read or created, otherwise an exception is thrown 92 94 * 93 95 * @throws <b>DatabaseException</b> If the session cannot be read … … 165 167 } 166 168 167 return false; 169 return true; 170 } 171 172 /** 173 * Updates the session id. 174 * 175 * @param string $currentId The current session id 176 * @param string $newId The new current id 177 * 178 * @return Boolean True if the session id was successfully regenerated 179 * @throws sfDatabaseException if an error occured while regenrating the session id 180 */ 181 protected function updateSessionId($currentId, $newId) 182 { 183 // get table/column 184 $db_table = $this->options['db_table']; 185 $db_id_col = $this->options['db_id_col']; 186 187 // update the session id 188 $sql = "UPDATE $db_table SET $db_id_col=? WHERE $db_id_col=?"; 189 190 try 191 { 192 $stmt = $this->db->prepare($sql); 193 $stmt->bindParam(1, $currentId, PDO::PARAM_STR); 194 $stmt->bindParam(2, $newId, PDO::PARAM_STR); 195 $stmt->execute(); 196 } 197 catch (PDOException $e) 198 { 199 throw new sfDatabaseException(sprintf('PDOException was thrown when trying to manipulate session data. Message: %s', $e->getMessage())); 200 } 201 202 return true; 168 203 } 169 204 } branches/1.2/lib/storage/sfPostgreSQLSessionStorage.class.php
r9089 r10426 84 84 * @param string $id A session ID 85 85 * 86 * @return bool true, if the session was read, otherwise an exception is thrown86 * @return string The session data if the session was read or created, otherwise an exception is thrown 87 87 * 88 88 * @throws <b>sfDatabaseException</b> If the session cannot be read … … 159 159 throw new sfDatabaseException(sprintf('sfPostgreSQLSessionStorage cannot write session data for id "%s".', $id)); 160 160 } 161 162 /** 163 * Updates the session id. 164 * 165 * @param string $currentId The current session id 166 * @param string $newId The new current id 167 * 168 * @return Boolean True if the session id was successfully regenerated 169 * @throws sfDatabaseException if an error occured while regenrating the session id 170 */ 171 protected function updateSessionId($currentId, $newId) 172 { 173 // get table/column 174 $db_table = $this->options['db_table']; 175 $db_id_col = $this->options['db_id_col']; 176 177 // cleanup the session id and data, just in case 178 $currentId = addslashes($currentId); 179 $newId = addslashes($newId); 180 181 // update the session id 182 $sql = "UPDATE $db_table SET $db_id_col=? WHERE $db_id_col=?"; 183 184 if (@pg_query($this->db, $sql)) 185 { 186 return true; 187 } 188 189 // failed to write session data 190 throw new sfDatabaseException(sprintf('% cannot update session id from "%s" to "%s".', get_class($this), $currentId, $newId)); 191 } 161 192 } branches/1.2/lib/storage/sfSessionStorage.class.php
r9942 r10426 27 27 { 28 28 static protected 29 $sessionStarted = false; 29 $sessionIdRegenerated = false, 30 $sessionStarted = false; 30 31 31 32 /** … … 163 164 public function regenerate($destroy = false) 164 165 { 165 // regenerate a new session id 166 if (self::$sessionIdRegenerated) 167 { 168 return; 169 } 170 171 // regenerate a new session id once per object 166 172 session_regenerate_id($destroy); 173 174 self::$sessionIdRegenerated = true; 167 175 } 168 176