1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 05:50:42 +02:00

[ticket/11881] Better split the timezone conversion into chunks; add test

PHPBB3-11881
This commit is contained in:
Nathan Guse
2013-10-04 12:10:27 -05:00
parent ee89ede59f
commit 9653276ebc
3 changed files with 195 additions and 13 deletions

View File

@@ -42,28 +42,36 @@ class timezone extends \phpbb\db\migration\migration
public function update_timezones($start)
{
$start = (int) $start;
$limit = 1;
$converted_timezones = 0;
$limit = 5000;
$converted = 0;
// Update user timezones
$sql = 'SELECT user_dst, user_timezone
$update_blocks = array();
$sql = 'SELECT user_id, user_timezone, user_dst
FROM ' . $this->table_prefix . 'users
GROUP BY user_timezone, user_dst';
ORDER BY user_id ASC';
$result = $this->db->sql_query_limit($sql, $limit, $start);
while ($row = $this->db->sql_fetchrow($result))
{
$converted_timezones++;
$converted++;
$sql = 'UPDATE ' . $this->table_prefix . "users
SET user_timezone = '" . $this->db->sql_escape($this->convert_phpbb30_timezone($row['user_timezone'], $row['user_dst'])) . "'
WHERE user_timezone = '" . $this->db->sql_escape($row['user_timezone']) . "'
AND user_dst = " . (int) $row['user_dst'];
$this->sql_query($sql);
$update_blocks[$row['user_timezone'] . ':' . $row['user_dst']][] = (int) $row['user_id'];
}
$this->db->sql_freeresult($result);
if ($converted_timezones == $limit)
// Update blocks of users who share the same timezone/dst
foreach ($update_blocks as $timezone => $user_ids)
{
$timezone = explode(':', $timezone);
$converted_timezone = $this->convert_phpbb30_timezone($timezone[0], $timezone[1]);
$sql = 'UPDATE ' . $this->table_prefix . "users
SET user_timezone = '" . $this->db->sql_escape($converted_timezone) . "'
WHERE " . $this->db->sql_in_set('user_id', $user_ids);
$this->sql_query($sql);
}
if ($converted == $limit)
{
// There are still more to convert
return $start + $limit;