View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0017747 | mantisbt | installation | public | 2014-10-13 03:15 | 2015-03-15 19:58 |
Reporter | vboctor | Assigned To | dregad | ||
Priority | normal | Severity | minor | Reproducibility | have not tried |
Status | closed | Resolution | fixed | ||
Product Version | 1.3.0-beta.1 | ||||
Target Version | 1.3.0-beta.2 | Fixed in Version | 1.3.0-beta.2 | ||
Summary | 0017747: Timezone errors during install | ||||
Description | I hit some timezone related issues when testing on PHP 5.4. The issues occur when running install and when running the SOAP unit tests. It is due to timezone not being set before using date function. See additional information for phpunit errors Should we explicitly set to the timezone to UTC at the top of install.php and as part of bootstrap or somewhere where it runs before the test cases? | ||||
Additional Information | 1) CategoryTest::testAddRenameDeleteCategory /Users/vboctor/php/mantisbt-master/tests/soap/CategoryTest.php:128 2) VersionTest::testAddVersion /Users/vboctor/php/mantisbt-master/tests/soap/SoapBase.php:276 3) VersionTest::testUpdateVersion | ||||
Tags | No tags attached. | ||||
Attached Files | fix-17747-alternative.patch (2,645 bytes)
commit 078aab706d8a41c587519e7a2b362ac00b774c26 Author: Damien Regad <dregad@mantisbt.org> Date: 2014-10-14 16:38:34 +0200 ALT FIX: timezone initialization in core.php This is my original proposed fix, vs the one that was implemented in master which is based on grangeway's proposal. 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 diff --git a/core.php b/core.php index 8c31462..fc53e95 100644 --- a/core.php +++ b/core.php @@ -238,22 +238,31 @@ if( !isset( $g_login_anonymous ) ) { # 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 ); + # Get MantisBT default timezone + $t_default_timezone = config_get_global( 'default_timezone' ); + if( !in_array( $t_default_timezone, timezone_identifiers_list() ) ) { + # If not valid, fallback to system timezone, or UTC if not set + $t_default_timezone = @date_default_timezone_get(); + config_set_global( 'default_timezone', $t_default_timezone, true ); + } + # Now determine current timezone according to user's preferences + require_api( 'authentication_api.php' ); if( auth_is_user_authenticated() ) { # Determine the current timezone according to user's preferences require_api( 'user_pref_api.php' ); - $t_tz = user_pref_get_pref( auth_get_current_user_id(), 'timezone' ); - @date_default_timezone_set( $t_tz ); + $t_user_timezone = user_pref_get_pref( auth_get_current_user_id(), 'timezone' ); + + # fallback to default timezone if not valid + if( in_array( $t_user_timezone, timezone_identifiers_list() ) ) { + $t_user_timezone = $t_default_timezone; + } + } else { + $t_user_timezone = $t_default_timezone; } - unset( $t_tz ); + + date_default_timezone_set( $t_user_timezone ); + unset( $t_user_timezone, $t_default_timezone ); } # Cache current user's collapse API data | ||||
Associated pull request. |
|
This is a valid issue, but I don't think the change proposed in the PR is the right way to fix it. I see 2 problems:
[1] There's another issue with this - see related 0017751 |
|
Please review alternative fix https://github.com/mantisbt/mantisbt/issues/382 |
|
I uploaded the alternative fix I developed to fix this issue, for the record. |
|
MantisBT: master 6d0b96cb 2014-10-14 06:38 Details Diff |
Fix timezone initialization in core.php 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 0017747 |
Affected Issues 0017747 |
|
mod - core.php | Diff File | ||
mod - core/date_api.php | Diff File |