Assembla home | Assembla project page
 

Changeset 976

Show
Ignore:
Timestamp:
05/09/08 23:42:10 (7 months ago)
Author:
swiss
Message:

The GMT offset was not being stored within the session because session files can get locked when multiple pages are accessing it (when music is playing there are two concurrent pages being requested - the "Now Playing" screen and the streaming page). It is also worth noting that the session variables only gets written when the page ends (which is a long time for the streaming page)

To get around this, the GMT offset is saved to the database instead of the session.

I've also added a "modified" column to both the sys and user preferences tables which gets updated with the time that the preference was last updated. This is then used for the GMT offset to ensure that we only use it if it was calculated less than 24 horus ago so that changes in timezone (eg: in/out of DST) are picked up.

Refs #128.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/swisscenter/base/prefs.php

    r952 r976  
    1212 // ---------------------------------------------------------------------------------- 
    1313 
     14 function get_user_pref_modified_date( $pref, $user_id = '' ) 
     15 { 
     16   if ($user_id == '') 
     17     $user_id = get_current_user_id(); 
     18 
     19   $result = db_value("select modified from user_prefs where user_id = ".$user_id." and name='".strtoupper($pref)."'"); 
     20 
     21   if (!$result || is_null($result)) 
     22     return false; 
     23   else  
     24     return $result; 
     25 } 
     26  
    1427 function get_user_pref( $pref, $default = '', $user_id = '') 
    1528 { 
     
    3447   { 
    3548     db_sqlcommand("delete from user_prefs where name='".strtoupper($name)."' and user_id=".$user); 
    36      $result = db_insert_row('user_prefs', array("USER_ID"=>$user, "NAME"=>strtoupper($name), "VALUE"=>$value) ); 
     49     $result = db_insert_row('user_prefs', array("USER_ID"=>$user, "NAME"=>strtoupper($name), "VALUE"=>$value, "MODIFIED"=>db_datestr()) ); 
    3750 
    3851     if (!$result) 
     
    4861 // SYSTEM preferences 
    4962 // ---------------------------------------------------------------------------------- 
     63 
     64 function get_sys_pref_modified_date( $pref ) 
     65 { 
     66   $result = db_value("select modified from system_prefs where name='".strtoupper($pref)."'"); 
     67 
     68   if (!$result || is_null($result)) 
     69     return false; 
     70   else  
     71     return $result; 
     72 } 
    5073 
    5174 function get_sys_pref( $pref, $default = '' ) 
     
    6588   { 
    6689     db_sqlcommand("delete from system_prefs where name='".strtoupper($name)."'"); 
    67      $result = db_insert_row('system_prefs', array("NAME"=>strtoupper($name), "VALUE"=>$value) ); 
     90     $result = db_insert_row('system_prefs', array("NAME"=>strtoupper($name), "VALUE"=>$value, "MODIFIED"=>db_datestr()) ); 
    6891   
    6992     if (!$result) 
  • trunk/swisscenter/base/utils.php

    r973 r976  
    476476function gmt_time() 
    477477{  
    478   if (!isset($_SESSION['GMT Offset'])) 
    479   { 
     478  $offset = get_sys_pref('GMT_OFFSET',false); 
     479   
     480  // We only trust the stored offset if was calculated less than 24 hours ago. This is to ensure that DST changes take effect. 
     481  if ( $offset === false || get_sys_pref_modified_date('GMT_OFFSET') < db_datestr(time()-86400)) 
     482  {   
    480483    // Get the GMT time from a web service 
    481484    send_to_log(6,'Attempting to get GMT Standard Time from a web service'); 
     
    489492      $date = str_replace('T',' ',$date); 
    490493      $time = strtotime($date); 
    491       // Set GMT offset in SESSION 
    492       $_SESSION['GMT Offset'] = (time() - $time); 
     494       
     495      // Store the offset in the database 
     496      set_sys_pref('GMT_OFFSET', (time()-$time)); 
    493497    } 
    494498    else 
     
    503507  else 
    504508  { 
    505     $time = time() - $_SESSION['GMT Offset']
     509    $time = time() - $offset
    506510    send_to_log(6,'Using previously stored GMT time',date('r',$time)); 
    507511  }