Skip to content

Commit

Permalink
Fix timezone initialization in core.php
Browse files Browse the repository at this point in the history
Prior to this, core.php would trigger a PHP warning on PHP >= 5.3 when
date_default_timezone_get() is not able to determine the timezone and
defaults to UTC (e.g. when php.ini date.timezone is not set).

The timezone is determined in the following order
  1. user preferences
  2. MantisBT configuration ($g_default_timezone)
  3. php.ini setting (date.timezone)
  4. UTC (set by date_default_timezone_get())

Fixes #17747
  • Loading branch information
dregad committed Dec 14, 2014
1 parent f350dbc commit 6d0b96c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
36 changes: 15 additions & 21 deletions core.php
Expand Up @@ -236,33 +236,27 @@ function __autoload( $p_class ) {
$g_login_anonymous = true;
}

# Attempt to set the current timezone to the user's desired value
# Note that PHP 5.1 on RHEL/CentOS doesn't support the timezone functions
# used here so we just skip this action on RHEL/CentOS platforms.
if( function_exists( 'timezone_identifiers_list' ) ) {
if( in_array( config_get_global( 'default_timezone' ), timezone_identifiers_list() ) ) {
# if a default timezone is set in config, set it here, else we use php.ini's value
# having a timezone set avoids a php warning
date_default_timezone_set( config_get_global( 'default_timezone' ) );
} else {
# To ensure proper detection of timezone settings issues, we must not
# initialize the default timezone when executing admin checks
if( basename( $g_short_path ) != 'check' ) {
config_set_global( 'default_timezone', date_default_timezone_get(), true );
}
}

# Set the current timezone
if( !defined( 'MANTIS_MAINTENANCE_MODE' ) ) {
require_api( 'authentication_api.php' );

# To reduce overhead, we assume that the timezone configuration is valid,
# i.e. it exists in timezone_identifiers_list(). If not, a PHP NOTICE will
# be raised. Use admin checks to validate configuration.
@date_default_timezone_set( config_get_global( 'default_timezone' ) );
$t_tz = @date_default_timezone_get();
config_set_global( 'default_timezone', $t_tz, true );

if( auth_is_user_authenticated() ) {
# Determine the current timezone according to user's preferences
require_api( 'user_pref_api.php' );

$t_user_timezone = user_pref_get_pref( auth_get_current_user_id(), 'timezone' );
if( !is_blank( $t_user_timezone ) ) {
date_default_timezone_set( $t_user_timezone );
}
$t_tz = user_pref_get_pref( auth_get_current_user_id(), 'timezone' );
@date_default_timezone_set( $t_tz );
}
unset( $t_tz );
}

# Cache current user's collapse API data
if( !defined( 'MANTIS_MAINTENANCE_MODE' ) ) {
require_api( 'collapse_api.php' );
collapse_cache_token();
Expand Down
4 changes: 4 additions & 0 deletions core/date_api.php
Expand Up @@ -23,18 +23,22 @@
* @copyright Copyright 2002 MantisBT Team - mantisbt-dev@lists.sourceforge.net
* @link http://www.mantisbt.org
*
* @uses authentication_api.php
* @uses config_api.php
* @uses constant_inc.php
* @uses helper_api.php
* @uses html_api.php
* @uses lang_api.php
* @uses user_pref_api.php
*/

require_api( 'authentication_api.php' );
require_api( 'config_api.php' );
require_api( 'constant_inc.php' );
require_api( 'helper_api.php' );
require_api( 'html_api.php' );
require_api( 'lang_api.php' );
require_api( 'user_pref_api.php' );

# Keeps track of whether the external files required for jscalendar to work
# have already been included in the output sent to the client. jscalendar
Expand Down

0 comments on commit 6d0b96c

Please sign in to comment.