1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-30 21:40:43 +02:00

Merge branch 'exreaction/ticket/11881' into develop-ascraeus

* exreaction/ticket/11881:
  [ticket/11881] Move convert_timezones_test to migrator
  [ticket/11881] Fix test filename
  [ticket/11881] Limit to 500
  [ticket/11881] Make sure user_timezone isn't converted twice
  [ticket/11881] Better split the timezone conversion into chunks; add test
  [ticket/11881] Timezone migration can take a long time
This commit is contained in:
Nils Adermann
2014-05-02 14:46:25 +02:00
3 changed files with 210 additions and 11 deletions

View File

@@ -39,24 +39,49 @@ class timezone extends \phpbb\db\migration\migration
);
}
public function update_timezones()
public function update_timezones($start)
{
// Update user timezones
$sql = 'SELECT user_dst, user_timezone
FROM ' . $this->table_prefix . 'users
GROUP BY user_timezone, user_dst';
$result = $this->db->sql_query($sql);
$start = (int) $start;
$limit = 500;
$converted = 0;
$update_blocks = array();
$sql = 'SELECT user_id, user_timezone, user_dst
FROM ' . $this->table_prefix . 'users
ORDER BY user_id ASC';
$result = $this->db->sql_query_limit($sql, $limit, $start);
while ($row = $this->db->sql_fetchrow($result))
{
$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);
$converted++;
// In case this is somehow run twice on a row.
// Otherwise it would just end up as UTC on the second run
if (is_numeric($row['user_timezone']))
{
$update_blocks[$row['user_timezone'] . ':' . $row['user_dst']][] = (int) $row['user_id'];
}
}
$this->db->sql_freeresult($result);
// 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;
}
// Update board default timezone
$sql = 'UPDATE ' . $this->table_prefix . "config
SET config_value = '" . $this->convert_phpbb30_timezone($this->config['board_timezone'], $this->config['board_dst']) . "'