[feature/migrations] 3.0.8-rc1 migration, fix some calls

PHPBB3-9737
This commit is contained in:
Nathaniel Guse 2012-11-10 04:00:38 -06:00 committed by Nathan Guse
parent b999a75528
commit e7389e4c32
3 changed files with 93 additions and 90 deletions

View file

@ -47,7 +47,7 @@ class phpbb_db_migration_v3011rc1 extends phpbb_db_migration
$sql = 'UPDATE ' . USERS_TABLE . ' $sql = 'UPDATE ' . USERS_TABLE . '
SET user_style = ' . (int) $this->config['default_style'] .' SET user_style = ' . (int) $this->config['default_style'] .'
WHERE ' . $this->db->sql_in_set('user_style', $deactivated_style_ids); WHERE ' . $this->db->sql_in_set('user_style', $deactivated_style_ids);
$this->sql_query($sql, $errored, $error_ary); $this->sql_query($sql);
} }
} }
@ -84,7 +84,7 @@ class phpbb_db_migration_v3011rc1 extends phpbb_db_migration
{ {
$sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . '
WHERE ' . $this->db->sql_in_set('msg_id', $delete_pms); WHERE ' . $this->db->sql_in_set('msg_id', $delete_pms);
$this->sql_query($sql, $errored, $error_ary); $this->sql_query($sql);
return true; return true;
} }

View file

@ -20,14 +20,37 @@ class phpbb_db_migration_v308rc1 extends phpbb_db_migration
} }
function update_data() function update_data()
{
return array(
array('custom', array(array(&$this, 'update_file_extension_group_names'))),
array('custom', array(array(&$this, 'update_module_auth'))),
array('custom', array(array(&$this, 'update_bots'))),
array('custom', array(array(&$this, 'delete_orphan_shadow_topics'))),
array('module.add', array(
'post' => array(
'base' => 'board',
'class' => 'acp',
'title' => 'ACP_POST_SETTINGS',
'auth' => 'acl_a_board',
'cat' => 'ACP_MESSAGES',
'after' => array('message', 'ACP_MESSAGE_SETTINGS')
),
)),
array('config.add', array('load_unreads_search', 1)),
array('config.update_if', array(600, 'queue_interval', 60)),
array('config.update_if', array(50, 'email_package_size', 20)),
);
}
function update_file_extension_group_names()
{ {
// Update file extension group names to use language strings. // Update file extension group names to use language strings.
$sql = 'SELECT lang_dir $sql = 'SELECT lang_dir
FROM ' . LANG_TABLE; FROM ' . LANG_TABLE;
$result = $db->sql_query($sql); $result = $this->db->sql_query($sql);
$extension_groups_updated = array(); $extension_groups_updated = array();
while ($lang_dir = $db->sql_fetchfield('lang_dir')) while ($lang_dir = $this->db->sql_fetchfield('lang_dir'))
{ {
$lang_dir = basename($lang_dir); $lang_dir = basename($lang_dir);
@ -37,9 +60,9 @@ class phpbb_db_migration_v308rc1 extends phpbb_db_migration
// On an already updated board, they can also already be in language/.../acp/attachments.php // On an already updated board, they can also already be in language/.../acp/attachments.php
// in the board root. // in the board root.
$lang_files = array( $lang_files = array(
"{$phpbb_root_path}install/update/new/language/$lang_dir/acp/attachments.$phpEx", "{$this->phpbb_root_path}install/update/new/language/$lang_dir/acp/attachments.$this->phpEx",
"{$phpbb_root_path}language/$lang_dir/install.$phpEx", "{$this->phpbb_root_path}language/$lang_dir/install.$this->phpEx",
"{$phpbb_root_path}language/$lang_dir/acp/attachments.$phpEx", "{$this->phpbb_root_path}language/$lang_dir/acp/attachments.$this->phpEx",
); );
foreach ($lang_files as $lang_file) foreach ($lang_files as $lang_file)
@ -64,48 +87,38 @@ class phpbb_db_migration_v308rc1 extends phpbb_db_migration
); );
$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_name = '" . $db->sql_escape($lang_val) . "'"; WHERE group_name = '" . $this->db->sql_escape($lang_val) . "'";
_sql($sql, $errored, $error_ary); $this->sql_query($sql);
$extension_groups_updated[$lang_key] = true; $extension_groups_updated[$lang_key] = true;
} }
} }
} }
$db->sql_freeresult($result); $this->db->sql_freeresult($result);
}
// Install modules function update_module_auth()
$modules_to_install = array( {
'post' => array(
'base' => 'board',
'class' => 'acp',
'title' => 'ACP_POST_SETTINGS',
'auth' => 'acl_a_board',
'cat' => 'ACP_MESSAGES',
'after' => array('message', 'ACP_MESSAGE_SETTINGS')
),
);
_add_modules($modules_to_install);
// update
$sql = 'UPDATE ' . MODULES_TABLE . ' $sql = 'UPDATE ' . MODULES_TABLE . '
SET module_auth = \'cfg_allow_avatar && (cfg_allow_avatar_local || cfg_allow_avatar_remote || cfg_allow_avatar_upload || cfg_allow_avatar_remote_upload)\' SET module_auth = \'cfg_allow_avatar && (cfg_allow_avatar_local || cfg_allow_avatar_remote || cfg_allow_avatar_upload || cfg_allow_avatar_remote_upload)\'
WHERE module_class = \'ucp\' WHERE module_class = \'ucp\'
AND module_basename = \'profile\' AND module_basename = \'profile\'
AND module_mode = \'avatar\''; AND module_mode = \'avatar\'';
_sql($sql, $errored, $error_ary); $this->sql_query($sql);
}
// add Bing Bot function update_bots()
{
$bot_name = 'Bing [Bot]'; $bot_name = 'Bing [Bot]';
$bot_name_clean = utf8_clean_string($bot_name); $bot_name_clean = utf8_clean_string($bot_name);
$sql = 'SELECT user_id $sql = 'SELECT user_id
FROM ' . USERS_TABLE . " FROM ' . USERS_TABLE . "
WHERE username_clean = '" . $db->sql_escape($bot_name_clean) . "'"; WHERE username_clean = '" . $this->db->sql_escape($bot_name_clean) . "'";
$result = $db->sql_query($sql); $result = $this->db->sql_query($sql);
$bing_already_added = (bool) $db->sql_fetchfield('user_id'); $bing_already_added = (bool) $this->db->sql_fetchfield('user_id');
$db->sql_freeresult($result); $this->db->sql_freeresult($result);
if (!$bing_already_added) if (!$bing_already_added)
{ {
@ -114,9 +127,9 @@ class phpbb_db_migration_v308rc1 extends phpbb_db_migration
$sql = 'SELECT group_id, group_colour $sql = 'SELECT group_id, group_colour
FROM ' . GROUPS_TABLE . " FROM ' . GROUPS_TABLE . "
WHERE group_name = 'BOTS'"; WHERE group_name = 'BOTS'";
$result = $db->sql_query($sql); $result = $this->db->sql_query($sql);
$group_row = $db->sql_fetchrow($result); $group_row = $this->db->sql_fetchrow($result);
$db->sql_freeresult($result); $this->db->sql_freeresult($result);
if (!$group_row) if (!$group_row)
{ {
@ -127,7 +140,7 @@ class phpbb_db_migration_v308rc1 extends phpbb_db_migration
if (!function_exists('user_add')) if (!function_exists('user_add'))
{ {
include($phpbb_root_path . 'includes/functions_user.' . $phpEx); include($this->phpbb_root_path . 'includes/functions_user.' . $this->phpEx);
} }
$user_row = array( $user_row = array(
@ -138,16 +151,16 @@ class phpbb_db_migration_v308rc1 extends phpbb_db_migration
'user_password' => '', 'user_password' => '',
'user_colour' => $group_row['group_colour'], 'user_colour' => $group_row['group_colour'],
'user_email' => '', 'user_email' => '',
'user_lang' => $config['default_lang'], 'user_lang' => $this->config['default_lang'],
'user_style' => $config['default_style'], 'user_style' => $this->config['default_style'],
'user_timezone' => 0, 'user_timezone' => 0,
'user_dateformat' => $config['default_dateformat'], 'user_dateformat' => $this->config['default_dateformat'],
'user_allow_massemail' => 0, 'user_allow_massemail' => 0,
); );
$user_id = user_add($user_row); $user_id = user_add($user_row);
$sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $db->sql_build_array('INSERT', array( $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array(
'bot_active' => 1, 'bot_active' => 1,
'bot_name' => (string) $bot_name, 'bot_name' => (string) $bot_name,
'user_id' => (int) $user_id, 'user_id' => (int) $user_id,
@ -155,18 +168,18 @@ class phpbb_db_migration_v308rc1 extends phpbb_db_migration
'bot_ip' => (string) $bot_ip, 'bot_ip' => (string) $bot_ip,
)); ));
_sql($sql, $errored, $error_ary); $this->sql_query($sql);
}
} }
// end Bing Bot addition
function delete_orphan_shadow_topics()
{
// Delete shadow topics pointing to not existing topics // Delete shadow topics pointing to not existing topics
$batch_size = 500; $batch_size = 500;
// Set of affected forums we have to resync // Set of affected forums we have to resync
$sync_forum_ids = array(); $sync_forum_ids = array();
do
{
$sql_array = array( $sql_array = array(
'SELECT' => 't1.topic_id, t1.forum_id', 'SELECT' => 't1.topic_id, t1.forum_id',
'FROM' => array( 'FROM' => array(
@ -181,42 +194,32 @@ class phpbb_db_migration_v308rc1 extends phpbb_db_migration
'WHERE' => 't1.topic_moved_id <> 0 'WHERE' => 't1.topic_moved_id <> 0
AND t2.topic_id IS NULL', AND t2.topic_id IS NULL',
); );
$sql = $db->sql_build_query('SELECT', $sql_array); $sql = $this->db->sql_build_query('SELECT', $sql_array);
$result = $db->sql_query_limit($sql, $batch_size); $result = $this->db->sql_query_limit($sql, $batch_size);
$topic_ids = array(); $topic_ids = array();
while ($row = $db->sql_fetchrow($result)) while ($row = $this->db->sql_fetchrow($result))
{ {
$topic_ids[] = (int) $row['topic_id']; $topic_ids[] = (int) $row['topic_id'];
$sync_forum_ids[(int) $row['forum_id']] = (int) $row['forum_id']; $sync_forum_ids[(int) $row['forum_id']] = (int) $row['forum_id'];
} }
$db->sql_freeresult($result); $this->db->sql_freeresult($result);
if (!empty($topic_ids)) if (!empty($topic_ids))
{ {
$sql = 'DELETE FROM ' . TOPICS_TABLE . ' $sql = 'DELETE FROM ' . TOPICS_TABLE . '
WHERE ' . $db->sql_in_set('topic_id', $topic_ids); WHERE ' . $this->db->sql_in_set('topic_id', $topic_ids);
$db->sql_query($sql); $this->db->sql_query($sql);
}
}
while (sizeof($topic_ids) == $batch_size);
// Sync the forums we have deleted shadow topics from. // Sync the forums we have deleted shadow topics from.
sync('forum', 'forum_id', $sync_forum_ids, true, true); sync('forum', 'forum_id', $sync_forum_ids, true, true);
// Unread posts search load switch return true;
set_config('load_unreads_search', '1'); }
else
// Reduce queue interval to 60 seconds, email package size to 20
if ($config['queue_interval'] == 600)
{ {
set_config('queue_interval', '60'); return false;
}
if ($config['email_package_size'] == 50)
{
set_config('email_package_size', '20');
} }
} }
} }

View file

@ -79,7 +79,7 @@ class phpbb_db_migration_v309rc1 extends phpbb_db_migration
$sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . '
SET ' . $this->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'];
$this->sql_query($sql, $errored, $error_ary); $this->sql_query($sql);
} }
$this->db->sql_freeresult($result); $this->db->sql_freeresult($result);
} }