[feature/migrations] Some migrations data

PHPBB3-9737
This commit is contained in:
Nathaniel Guse 2012-11-09 10:54:33 -06:00 committed by Nathan Guse
parent b1f9ca2f65
commit b999a75528
3 changed files with 65 additions and 45 deletions

View file

@ -21,9 +21,8 @@ class phpbb_db_migration_v3010rc1 extends phpbb_db_migration
function update_data() function update_data()
{ {
if (!isset($config['email_max_chunk_size'])) return array(
{ array('config.add', array('email_max_chunk_size', 50)),
set_config('email_max_chunk_size', '50'); );
}
} }
} }

View file

@ -20,28 +20,39 @@ class phpbb_db_migration_v3011rc1 extends phpbb_db_migration
} }
function update_data() function update_data()
{
return array(
array('custom', array(array(&$this, 'cleanup_deactivated_styles'))),
array('custom', array(array(&$this, 'delete_orphan_private_messages'))),
);
}
function cleanup_deactivated_styles()
{ {
// Updates users having current style a deactivated one // Updates users having current style a deactivated one
$sql = 'SELECT style_id $sql = 'SELECT style_id
FROM ' . STYLES_TABLE . ' FROM ' . STYLES_TABLE . '
WHERE style_active = 0'; WHERE style_active = 0';
$result = $db->sql_query($sql); $result = $this->sql_query($sql);
$deactivated_style_ids = array(); $deactivated_style_ids = array();
while ($style_id = $db->sql_fetchfield('style_id', false, $result)) while ($style_id = $this->db->sql_fetchfield('style_id', false, $result))
{ {
$deactivated_style_ids[] = (int) $style_id; $deactivated_style_ids[] = (int) $style_id;
} }
$db->sql_freeresult($result); $this->db->sql_freeresult($result);
if (!empty($deactivated_style_ids)) if (!empty($deactivated_style_ids))
{ {
$sql = 'UPDATE ' . USERS_TABLE . ' $sql = 'UPDATE ' . USERS_TABLE . '
SET user_style = ' . (int) $config['default_style'] .' SET user_style = ' . (int) $this->config['default_style'] .'
WHERE ' . $db->sql_in_set('user_style', $deactivated_style_ids); WHERE ' . $this->db->sql_in_set('user_style', $deactivated_style_ids);
_sql($sql, $errored, $error_ary); $this->sql_query($sql, $errored, $error_ary);
} }
}
function delete_orphan_private_messages()
{
// Delete orphan private messages // Delete orphan private messages
$batch_size = 500; $batch_size = 500;
@ -58,26 +69,28 @@ class phpbb_db_migration_v3011rc1 extends phpbb_db_migration
), ),
'WHERE' => 't.user_id IS NULL', 'WHERE' => 't.user_id IS NULL',
); );
$sql = $db->sql_build_query('SELECT', $sql_array); $sql = $this->db->sql_build_query('SELECT', $sql_array);
do $result = $this->db->sql_query_limit($sql, $batch_size);
$delete_pms = array();
while ($row = $this->db->sql_fetchrow($result))
{ {
$result = $db->sql_query_limit($sql, $batch_size); $delete_pms[] = (int) $row['msg_id'];
}
$delete_pms = array(); $db->sql_freeresult($result);
while ($row = $db->sql_fetchrow($result))
{ if (!empty($delete_pms))
$delete_pms[] = (int) $row['msg_id']; {
} $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . '
$db->sql_freeresult($result); WHERE ' . $this->db->sql_in_set('msg_id', $delete_pms);
$this->sql_query($sql, $errored, $error_ary);
if (!empty($delete_pms))
{ return true;
$sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' }
WHERE ' . $db->sql_in_set('msg_id', $delete_pms); else
_sql($sql, $errored, $error_ary); {
} return false;
} }
while (sizeof($delete_pms) == $batch_size);
} }
} }

View file

@ -53,46 +53,54 @@ class phpbb_db_migration_v309rc1 extends phpbb_db_migration
function update_data() function update_data()
{ {
set_config('ip_login_limit_max', '50'); return array(
set_config('ip_login_limit_time', '21600'); array('config.add', array('ip_login_limit_max', 50)),
set_config('ip_login_limit_use_forwarded', '0'); array('config.add', array('ip_login_limit_time', 21600)),
array('config.add', array('ip_login_limit_use_forwarded', 0)),
array('custom', array(array(&$this, 'update_file_extension_group_names'))),
array('custom', array(array(&$this, 'fix_firebird_qa_captcha'))),
);
}
function update_file_extension_group_names()
{
// Update file extension group names to use language strings, again. // Update file extension group names to use language strings, again.
$sql = 'SELECT group_id, group_name $sql = 'SELECT group_id, group_name
FROM ' . EXTENSION_GROUPS_TABLE . ' FROM ' . EXTENSION_GROUPS_TABLE . '
WHERE group_name ' . $db->sql_like_expression('EXT_GROUP_' . $db->any_char); WHERE group_name ' . $this->db->sql_like_expression('EXT_GROUP_' . $this->db->any_char);
$result = $db->sql_query($sql); $result = $this->db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) while ($row = $this->db->sql_fetchrow($result))
{ {
$sql_ary = array( $sql_ary = array(
'group_name' => substr($row['group_name'], 10), // Strip off 'EXT_GROUP_' 'group_name' => substr($row['group_name'], 10), // Strip off 'EXT_GROUP_'
); );
$sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . '
SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
WHERE group_id = ' . $row['group_id']; WHERE group_id = ' . $row['group_id'];
_sql($sql, $errored, $error_ary); $this->sql_query($sql, $errored, $error_ary);
} }
$db->sql_freeresult($result); $this->db->sql_freeresult($result);
}
global $db_tools, $table_prefix;
function fix_firebird_qa_captcha()
{
// Recover from potentially broken Q&A CAPTCHA table on firebird // Recover from potentially broken Q&A CAPTCHA table on firebird
// Q&A CAPTCHA was uninstallable, so it's safe to remove these // Q&A CAPTCHA was uninstallable, so it's safe to remove these
// without data loss // without data loss
if ($db_tools->sql_layer == 'firebird') if ($this->db_tools->sql_layer == 'firebird')
{ {
$tables = array( $tables = array(
$table_prefix . 'captcha_questions', $this->table_prefix . 'captcha_questions',
$table_prefix . 'captcha_answers', $this->table_prefix . 'captcha_answers',
$table_prefix . 'qa_confirm', $this->table_prefix . 'qa_confirm',
); );
foreach ($tables as $table) foreach ($tables as $table)
{ {
if ($db_tools->sql_table_exists($table)) if ($this->db_tools->sql_table_exists($table))
{ {
$db_tools->sql_table_drop($table); $this->db_tools->sql_table_drop($table);
} }
} }
} }