Ha- ndle checking for duplicate usernames in chunks (Bug #17285 - Patch by A_Jelly_Doughnut)t)

git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9113 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Nils Adermann 2008-11-24 19:23:23 +00:00
parent 9a7d2a3736
commit 05e8d9ee09
3 changed files with 30 additions and 39 deletions

View file

@ -96,7 +96,7 @@
<li>[Fix] Properly treat punctuation marks after local urls (Bug #37055)</li> <li>[Fix] Properly treat punctuation marks after local urls (Bug #37055)</li>
<li>[Fix] Make searching for members by YIM address work in prosilver</li> <li>[Fix] Make searching for members by YIM address work in prosilver</li>
<li>[Change] Alllow applications to set custom module inclusion path (idea by HoL)</li> <li>[Change] Alllow applications to set custom module inclusion path (idea by HoL)</li>
<li>[Change] Handle checking for duplicate usernames in chunks (Bug #17285 - Patch by A_Jelly_Doughnut)</li>
</ul> </ul>
<a name="v302"></a><h3>1.ii. Changes since 3.0.2</h3> <a name="v302"></a><h3>1.ii. Changes since 3.0.2</h3>

View file

@ -229,6 +229,9 @@ if (!$get_info)
@define('DEFAULT_AVATAR_X_CUSTOM', get_config_value('avatar_max_width')); @define('DEFAULT_AVATAR_X_CUSTOM', get_config_value('avatar_max_width'));
@define('DEFAULT_AVATAR_Y_CUSTOM', get_config_value('avatar_max_height')); @define('DEFAULT_AVATAR_Y_CUSTOM', get_config_value('avatar_max_height'));
// additional table used only during conversion
@define('USERCONV_TABLE', $table_prefix . 'userconv');
/** /**
* Description on how to use the convertor framework. * Description on how to use the convertor framework.
* *
@ -316,7 +319,7 @@ if (!$get_info)
// username_clean in phpBB3 which is not possible, so we'll give the admin a list // username_clean in phpBB3 which is not possible, so we'll give the admin a list
// of user ids and usernames and let him deicde what he wants to do with them // of user ids and usernames and let him deicde what he wants to do with them
'execute_first' => ' 'execute_first' => '
phpbb_check_username_collisions(); phpbb_create_userconv_table();
import_avatar_gallery(); import_avatar_gallery();
if (defined("MOD_ATTACHMENT")) phpbb_import_attach_config(); if (defined("MOD_ATTACHMENT")) phpbb_import_attach_config();
phpbb_insert_forums(); phpbb_insert_forums();
@ -339,6 +342,14 @@ if (!$get_info)
'), '),
'schema' => array( 'schema' => array(
array(
'target' => USERCONV_TABLE,
'query_first' => array('target', $convert->truncate_statement . USERCONV_TABLE),
array('user_id', 'users.user_id', ''),
array('username_clean', 'users.username', array('function1' => 'phpbb_set_encoding', 'function2' => 'utf8_clean_string')),
),
array( array(
'target' => (defined('MOD_ATTACHMENT')) ? ATTACHMENTS_TABLE : '', 'target' => (defined('MOD_ATTACHMENT')) ? ATTACHMENTS_TABLE : '',
@ -419,6 +430,7 @@ if (!$get_info)
array( array(
'target' => BANLIST_TABLE, 'target' => BANLIST_TABLE,
'execute_first' => 'phpbb_check_username_collisions();',
'query_first' => array('target', $convert->truncate_statement . BANLIST_TABLE), 'query_first' => array('target', $convert->truncate_statement . BANLIST_TABLE),
array('ban_ip', 'banlist.ban_ip', 'decode_ban_ip'), array('ban_ip', 'banlist.ban_ip', 'decode_ban_ip'),

View file

@ -1698,7 +1698,7 @@ function phpbb_disallowed_username($username)
* Checks whether there are any usernames on the old board that would map to the same * Checks whether there are any usernames on the old board that would map to the same
* username_clean on phpBB3. Prints out a list if any exist and exits. * username_clean on phpBB3. Prints out a list if any exist and exits.
*/ */
function phpbb_check_username_collisions() function phpbb_create_userconv_table()
{ {
global $db, $src_db, $convert, $table_prefix, $user, $lang; global $db, $src_db, $convert, $table_prefix, $user, $lang;
@ -1735,53 +1735,53 @@ function phpbb_check_username_collisions()
} }
// create a temporary table in which we store the clean usernames // create a temporary table in which we store the clean usernames
$drop_sql = 'DROP TABLE ' . $table_prefix . 'userconv'; $drop_sql = 'DROP TABLE ' . USERCONV_TABLE;
switch ($map_dbms) switch ($map_dbms)
{ {
case 'firebird': case 'firebird':
$create_sql = 'CREATE TABLE ' . $table_prefix . 'userconv ( $create_sql = 'CREATE TABLE ' . USERCONV_TABLE . ' (
user_id INTEGER NOT NULL, user_id INTEGER NOT NULL,
username_clean VARCHAR(255) CHARACTER SET UTF8 DEFAULT \'\' NOT NULL COLLATE UNICODE username_clean VARCHAR(255) CHARACTER SET UTF8 DEFAULT \'\' NOT NULL COLLATE UNICODE
)'; )';
break; break;
case 'mssql': case 'mssql':
$create_sql = 'CREATE TABLE [' . $table_prefix . 'userconv] ( $create_sql = 'CREATE TABLE [' . USERCONV_TABLE . '] (
[user_id] [int] NOT NULL , [user_id] [int] NOT NULL ,
[username_clean] [varchar] (255) DEFAULT (\'\') NOT NULL [username_clean] [varchar] (255) DEFAULT (\'\') NOT NULL
)'; )';
break; break;
case 'mysql_40': case 'mysql_40':
$create_sql = 'CREATE TABLE ' . $table_prefix . 'userconv ( $create_sql = 'CREATE TABLE ' . USERCONV_TABLE . ' (
user_id mediumint(8) NOT NULL, user_id mediumint(8) NOT NULL,
username_clean blob NOT NULL username_clean blob NOT NULL
)'; )';
break; break;
case 'mysql_41': case 'mysql_41':
$create_sql = 'CREATE TABLE ' . $table_prefix . 'userconv ( $create_sql = 'CREATE TABLE ' . USERCONV_TABLE . ' (
user_id mediumint(8) NOT NULL, user_id mediumint(8) NOT NULL,
username_clean varchar(255) DEFAULT \'\' NOT NULL username_clean varchar(255) DEFAULT \'\' NOT NULL
) CHARACTER SET `utf8` COLLATE `utf8_bin`'; ) CHARACTER SET `utf8` COLLATE `utf8_bin`';
break; break;
case 'oracle': case 'oracle':
$create_sql = 'CREATE TABLE ' . $table_prefix . 'userconv ( $create_sql = 'CREATE TABLE ' . USERCONV_TABLE . ' (
user_id number(8) NOT NULL, user_id number(8) NOT NULL,
username_clean varchar2(255) DEFAULT \'\' username_clean varchar2(255) DEFAULT \'\'
)'; )';
break; break;
case 'postgres': case 'postgres':
$create_sql = 'CREATE TABLE ' . $table_prefix . 'userconv ( $create_sql = 'CREATE TABLE ' . USERCONV_TABLE . ' (
user_id INT4 DEFAULT \'0\', user_id INT4 DEFAULT \'0\',
username_clean varchar_ci DEFAULT \'\' NOT NULL username_clean varchar_ci DEFAULT \'\' NOT NULL
)'; )';
break; break;
case 'sqlite': case 'sqlite':
$create_sql = 'CREATE TABLE ' . $table_prefix . 'userconv ( $create_sql = 'CREATE TABLE ' . USERCONV_TABLE . ' (
user_id INTEGER NOT NULL DEFAULT \'0\', user_id INTEGER NOT NULL DEFAULT \'0\',
username_clean varchar(255) NOT NULL DEFAULT \'\' username_clean varchar(255) NOT NULL DEFAULT \'\'
)'; )';
@ -1792,37 +1792,15 @@ function phpbb_check_username_collisions()
$db->sql_query($drop_sql); $db->sql_query($drop_sql);
$db->sql_return_on_error(false); $db->sql_return_on_error(false);
$db->sql_query($create_sql); $db->sql_query($create_sql);
}
// now select all user_ids and usernames and then convert the username (this can take quite a while!) function phpbb_check_username_collisions()
$sql = 'SELECT user_id, username {
FROM ' . $convert->src_table_prefix . 'users'; global $db, $src_db, $convert, $table_prefix, $user, $lang;
$result = $src_db->sql_query($sql);
$insert_ary = array();
$i = 0;
while ($row = $src_db->sql_fetchrow($result))
{
$clean_name = utf8_clean_string(phpbb_set_default_encoding($row['username']));
$insert_ary[] = array('user_id' => (int) $row['user_id'], 'username_clean' => (string) $clean_name);
if ($i % 1000 == 999)
{
$db->sql_multi_insert($table_prefix . 'userconv', $insert_ary);
$insert_ary = array();
}
$i++;
}
$src_db->sql_freeresult($result);
if (sizeof($insert_ary))
{
$db->sql_multi_insert($table_prefix . 'userconv', $insert_ary);
}
unset($insert_ary);
// now find the clean version of the usernames that collide // now find the clean version of the usernames that collide
$sql = 'SELECT username_clean $sql = 'SELECT username_clean
FROM ' . $table_prefix . 'userconv FROM ' . USERCONV_TABLE .'
GROUP BY username_clean GROUP BY username_clean
HAVING COUNT(user_id) > 1'; HAVING COUNT(user_id) > 1';
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
@ -1838,7 +1816,7 @@ function phpbb_check_username_collisions()
if (sizeof($colliding_names)) if (sizeof($colliding_names))
{ {
$sql = 'SELECT user_id, username_clean $sql = 'SELECT user_id, username_clean
FROM ' . $table_prefix . 'userconv FROM ' . USERCONV_TABLE . '
WHERE ' . $db->sql_in_set('username_clean', $colliding_names); WHERE ' . $db->sql_in_set('username_clean', $colliding_names);
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
unset($colliding_names); unset($colliding_names);
@ -1881,6 +1859,7 @@ function phpbb_check_username_collisions()
$convert->p_master->error('<span style="color:red">' . $user->lang['COLLIDING_USERNAMES_FOUND'] . '</span></b><br /><br />' . $list . '<b>', __LINE__, __FILE__); $convert->p_master->error('<span style="color:red">' . $user->lang['COLLIDING_USERNAMES_FOUND'] . '</span></b><br /><br />' . $list . '<b>', __LINE__, __FILE__);
} }
$drop_sql = 'DROP TABLE ' . USERCONV_TABLE;
$db->sql_query($drop_sql); $db->sql_query($drop_sql);
} }