1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-02-24 12:03:21 +01:00

[feature/new-tz-handling] Correctly update user and board timezones on update

PHPBB3-9558
This commit is contained in:
Joas Schilling 2012-07-18 14:48:28 +02:00
parent f4136eacdc
commit 7ce66deca8

View File

@ -2613,25 +2613,24 @@ function change_database_data(&$no_updates, $version)
// If the column exists, we did not yet update the users timezone
if ($db_tools->sql_column_exists(USERS_TABLE, 'user_dst'))
{
// Update timezones
// user_dst is 0 if not in dst and 1 if in dst;
// this happens to be exactly the correction that should be added to the timezone offset
// to obtain dst offset.
// Parenthesize here because we operate on this value later.
$active_offset = '(user_timezone + user_dst)';
// Update user timezones
$sql = 'SELECT user_dst, user_timezone
FROM ' . USERS_TABLE . '
GROUP BY user_timezone, user_dst';
$result = $db->sql_query($sql);
// Now we have a tricky problem of forcing the plus sign into the expression.
// Build it via a conditional since there cannot be a portable printf equivalent in databases.
// Note that active offset is not an absolute value here - it is an expression that will
// be evaluated by the database during query execution.
// We don't print - (minus) here because it will come from active offset.
$sign = $db->sql_conditional("$active_offset < 0", '', '+');
while ($row = $db->sql_fetchrow($result))
{
$sql = 'UPDATE ' . USERS_TABLE . "
SET user_timezone = '" . $db->sql_escape(_convert_phpbb30_timezone($row['user_timezone'], $row['user_dst'])) . "'
WHERE user_timezone = '" . $db->sql_escape($row['user_timezone']) . "'
AND user_dst = " . (int) $row['user_dst'];
_sql($sql, $errored, $error_ary);
}
$db->sql_freeresult($result);
// Use database-specific escaping because strings are quoted differently by different databases.
$new_value = $db->sql_concatenate($db->sql_escape('GMT'), $sign, $active_offset);
$sql = 'UPDATE ' . USERS_TABLE . '
SET user_timezone = ' . $new_value;
_sql($sql, $errored, $error_ary);
// Update board default timezone
set_config('board_timezone', _convert_phpbb30_timezone($config['board_timezone'], $config['board_dst']));
// After we have calculated the timezones we can delete user_dst column from user table.
$db_tools->sql_column_remove(USERS_TABLE, 'user_dst');