Development

Changeset 8664

You must first sign up to be able to contribute.

Changeset 8664

Show
Ignore:
Timestamp:
04/28/08 22:42:14 (6 months ago)
Author:
FabianLange
Message:

made sfMySQLSessionStorage more robust by using SQL date functions and no longer injecting php timestamps. MySQL Now() works on both DateTime? and TimeStamp? columns ok and using the native date + INTERVAL $lifetime SECONDS possible time troubles are reduced. (fixes #3394)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0/lib/storage/sfMySQLSessionStorage.class.php

    r7791 r8664  
    124124   * Cleans up old sessions. 
    125125   * 
    126    * @param int The lifetime of a session 
     126   * @param int The lifetime of a session in seconds 
    127127   * 
    128128   * @return boolean true, if old sessions have been cleaned, otherwise an exception is thrown 
     
    132132  public function sessionGC($lifetime) 
    133133  { 
    134     // determine deletable session time 
    135     $time = time() - $lifetime; 
    136  
    137134    // get table/column 
    138135    $db_table    = $this->getParameterHolder()->get('db_table'); 
     
    141138    // delete the record associated with this id 
    142139    $sql = 'DELETE FROM '.$db_table.' '. 
    143            'WHERE '.$db_time_col.' < '.$time
     140           'WHERE '.$db_time_col.' + INTERVAL '.$lifetime.' SECOND < NOW()'
    144141 
    145142    if (@mysql_query($sql, $this->resource)) 
     
    217214      $sql = 'INSERT INTO '.$db_table.' ('.$db_id_col.', ' . 
    218215             $db_data_col.', '.$db_time_col.') VALUES (' . 
    219              '\''.$id.'\', \'\', '.time().')'; 
     216             '\''.$id.'\', \'\', NOW())'; 
    220217 
    221218      if (@mysql_query($sql, $this->resource)) 
     
    257254    $sql = 'UPDATE '.$db_table.' ' . 
    258255           'SET '.$db_data_col.' = \''.$data.'\', ' . 
    259            $db_time_col.' = '.time().' ' . 
     256           $db_time_col.' = NOW() ' . 
    260257           'WHERE '.$db_id_col.' = \''.$id.'\''; 
    261258