';
$current_version = str_replace('rc', 'RC', strtolower($config['version']));
$latest_version = str_replace('rc', 'RC', strtolower($updates_to_version));
$orig_version = $config['version'];
// If the latest version and the current version are 'unequal', we will update the version_update_from, else we do not update anything.
if ($inline_update)
{
if ($current_version !== $latest_version)
{
set_config('version_update_from', $orig_version);
}
}
else
{
// If not called from the update script, we will actually remove the traces
$db->sql_query('DELETE FROM ' . CONFIG_TABLE . " WHERE config_name = 'version_update_from'");
}
// Checks/Operations that have to be completed prior to starting the update itself
$exit = false;
if (version_compare($current_version, '3.0.RC8', '<=')) /* && $debug_from_version === false) */
{
// Define missing language entries...
if (!isset($lang['CLEANING_USERNAMES']))
{
$lang = array_merge($lang, array(
'CLEANING_USERNAMES' => 'Cleaning usernames',
'LONG_SCRIPT_EXECUTION' => 'Please note that this can take a while... Please do not stop the script.',
'CHANGE_CLEAN_NAMES' => 'The method used to make sure a username is not used by multiple users has been changed. There are some users which have the same name when compared with the new method. You have to delete or rename these users to make sure that each name is only used by one user before you can proceed.',
'USER_ACTIVE' => 'Active user',
'USER_INACTIVE' => 'Inactive user',
'BOT' => 'Spider/Robot',
'UPDATE_REQUIRES_FILE' => 'The updater requires that the following file is present: %s',
'DELETE_USER_REMOVE' => 'Delete user and remove posts',
'DELETE_USER_RETAIN' => 'Delete user but keep posts',
'EDIT_USERNAME' => 'Edit username',
'KEEP_OLD_NAME' => 'Keep username',
'NEW_USERNAME' => 'New username',
));
}
?>
''));
$new_usernames = request_var('new_usernames', array(0 => ''), true);
// We need this file if someone wants to edit usernames.
include($phpbb_root_path . 'includes/utf/utf_normalizer.' . $phpEx);
if (!class_exists('utf_new_normalizer'))
{
if (!file_exists($phpbb_root_path . 'install/data/new_normalizer.' . $phpEx))
{
global $lang;
trigger_error(sprintf($lang['UPDATE_REQUIRES_FILE'], $phpbb_root_path . 'install/data/new_normalizer.' . $phpEx), E_USER_ERROR);
}
include($phpbb_root_path . 'install/data/new_normalizer.' . $phpEx);
}
// the admin decided to change some usernames
if (sizeof($modify_users) && $submit)
{
$sql = 'SELECT user_id, username, user_type
FROM ' . USERS_TABLE . '
WHERE ' . $db->sql_in_set('user_id', array_keys($modify_users));
$result = $db->sql_query($sql);
$users = 0;
while ($row = $db->sql_fetchrow($result))
{
$users++;
$user_id = (int) $row['user_id'];
if (isset($modify_users[$user_id]))
{
$row['action'] = $modify_users[$user_id];
$modify_users[$user_id] = $row;
}
}
$db->sql_freeresult($result);
// only if all ids really existed
if (sizeof($modify_users) == $users)
{
$user->data['user_id'] = ANONYMOUS;
include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
foreach ($modify_users as $user_id => $row)
{
switch ($row['action'])
{
case 'edit':
if (isset($new_usernames[$user_id]))
{
$data = array('username' => utf8_new_normalize_nfc($new_usernames[$user_id]));
// Need to update config, forum, topic, posting, messages, etc.
if ($data['username'] != $row['username'])
{
$check_ary = array('username' => array(
array('string', false, $config['min_name_chars'], $config['max_name_chars']),
array('username'),
));
// need a little trick for this to work properly
$user->data['username_clean'] = utf8_clean_string($data['username']) . 'a';
$errors = validate_data($data, $check_ary);
if ($errors)
{
include($phpbb_root_path . 'language/' . $language . '/ucp.' . $phpEx);
echo '
::
sql_query($sql);
$colliding_users = $found_names = array();
$echos = 0;
while ($row = $db->sql_fetchrow($result))
{
// Calculate the new clean name. If it differs from the old one we need
// to make sure there is no collision
$clean_name = utf8_new_clean_string($row['username']);
if ($clean_name != $row['username_clean'])
{
// Check if there would be a collission, if not put it up for changing
$user_id = (int) $row['user_id'];
// If this clean name was not the result of another user already ...
if (!isset($found_names[$clean_name]))
{
// then we need to figure out whether there are any other users
// who already had this clean name with the old version
$sql = 'SELECT user_id, username
FROM ' . USERS_TABLE . '
WHERE username_clean = \'' . $db->sql_escape($clean_name) . '\'';
$result2 = $db->sql_query($sql);
$user_ids = array($user_id);
while ($row = $db->sql_fetchrow($result2))
{
// For not trimmed entries this could happen, yes. ;)
if ($row['user_id'] == $user_id)
{
continue;
}
// Make sure this clean name will still be the same with the
// new function. If it is, then we have to add it to the list
// of user ids for this clean name
if (utf8_new_clean_string($row['username']) == $clean_name)
{
$user_ids[] = (int) $row['user_id'];
}
}
$db->sql_freeresult($result2);
// if we already found a collision save it
if (sizeof($user_ids) > 1)
{
$colliding_users[$clean_name] = $user_ids;
$found_names[$clean_name] = true;
}
else
{
// otherwise just mark this name as found
$found_names[$clean_name] = $user_id;
}
}
// Else, if we already found the username
else
{
// If the value in the found_names lookup table is only true ...
if ($found_names[$clean_name] === true)
{
// then the actual data was already added to $colliding_users
// and we only need to append the user_id
$colliding_users[$clean_name][] = $user_id;
}
else
{
// otherwise it still keeps the first user_id for this name
// and we need to move the data to $colliding_users, and set
// the value in the found_names lookup table to true, so
// following users will directly be appended to $colliding_users
$colliding_users[$clean_name] = array($found_names[$clean_name], $user_id);
$found_names[$clean_name] = true;
}
}
}
if (($echos % 1000) == 0)
{
echo '.';
flush();
}
$echos++;
}
$db->sql_freeresult($result);
_write_result(false, $errored, $error_ary);
// now retrieve all information about the users and let the admin decide what to do
if (sizeof($colliding_users))
{
$exit = true;
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include($phpbb_root_path . 'language/' . $language . '/memberlist.' . $phpEx);
include($phpbb_root_path . 'language/' . $language . '/acp/users.' . $phpEx);
// link a few things to the correct place so we don't get any problems
$user->lang = &$lang;
$user->data['user_id'] = ANONYMOUS;
$user->date_format = $config['default_dateformat'];
// a little trick to get all user_ids
$user_ids = call_user_func_array('array_merge', array_values($colliding_users));
$sql = 'SELECT session_user_id, MAX(session_time) AS session_time
FROM ' . SESSIONS_TABLE . '
WHERE session_time >= ' . (time() - $config['session_length']) . '
AND ' . $db->sql_in_set('session_user_id', $user_ids) . '
GROUP BY session_user_id';
$result = $db->sql_query($sql);
$session_times = array();
while ($row = $db->sql_fetchrow($result))
{
$session_times[$row['session_user_id']] = $row['session_time'];
}
$db->sql_freeresult($result);
$sql = 'SELECT *
FROM ' . USERS_TABLE . '
WHERE ' . $db->sql_in_set('user_id', $user_ids);
$result = $db->sql_query($sql);
$users = array();
while ($row = $db->sql_fetchrow($result))
{
if (isset($session_times[$row['user_id']]))
{
$row['session_time'] = $session_times[$row['user_id']];
}
else
{
$row['session_time'] = 0;
}
$users[(int) $row['user_id']] = $row;
}
$db->sql_freeresult($result);
unset($session_times);
// now display a table with all users, some information about them and options
// for the admin: keep name, change name (with text input) or delete user
$u_action = "database_update.$phpEx?language=$language&type=$inline_update";
?>
::
= as the version to be updated to next, we will skip the process
if (version_compare($version, $current_version, '<') && version_compare($current_version, $next_version, '>='))
{
continue;
}
/* if ($debug_from_version !== false)
{
// Applying update schema for version array with key '$version'
// for version '$version' to '$next_version'
continue;
}*/
if (!sizeof($schema_changes))
{
continue;
}
$no_updates = false;
// Change columns?
if (!empty($schema_changes['change_columns']))
{
foreach ($schema_changes['change_columns'] as $table => $columns)
{
foreach ($columns as $column_name => $column_data)
{
sql_column_change($map_dbms, $table, $column_name, $column_data);
}
}
}
// Add columns?
if (!empty($schema_changes['add_columns']))
{
foreach ($schema_changes['add_columns'] as $table => $columns)
{
foreach ($columns as $column_name => $column_data)
{
// Only add the column if it does not exist yet
if (!column_exists($map_dbms, $table, $column_name))
{
sql_column_add($map_dbms, $table, $column_name, $column_data);
}
}
}
}
// Remove keys?
if (!empty($schema_changes['drop_keys']))
{
foreach ($schema_changes['drop_keys'] as $table => $indexes)
{
foreach ($indexes as $index_name)
{
sql_index_drop($map_dbms, $index_name, $table);
}
}
}
// Drop columns?
if (!empty($schema_changes['drop_columns']))
{
foreach ($schema_changes['drop_columns'] as $table => $columns)
{
foreach ($columns as $column)
{
sql_column_remove($map_dbms, $table, $column);
}
}
}
// Add primary keys?
if (!empty($schema_changes['add_primary_keys']))
{
foreach ($schema_changes['add_primary_keys'] as $table => $columns)
{
sql_create_primary_key($map_dbms, $table, $columns);
}
}
// Add unqiue indexes?
if (!empty($schema_changes['add_unique_index']))
{
foreach ($schema_changes['add_unique_index'] as $table => $index_array)
{
foreach ($index_array as $index_name => $column)
{
sql_create_unique_index($map_dbms, $index_name, $table, $column);
}
}
}
// Add indexes?
if (!empty($schema_changes['add_index']))
{
foreach ($schema_changes['add_index'] as $table => $index_array)
{
foreach ($index_array as $index_name => $column)
{
sql_create_index($map_dbms, $index_name, $table, $column);
}
}
}
}
_write_result($no_updates, $errored, $error_ary);
// Data updates
$error_ary = array();
$errored = $no_updates = false;
?>
::
= as the version to be updated to next, we will skip the process
if (version_compare($version, $current_version, '<') && version_compare($current_version, $next_version, '>='))
{
continue;
}
/* if ($debug_from_version !== false)
{
// Applying update schema for version array with key '$version'
// for version '$version' to '$next_version'
continue;
}*/
change_database_data($no_updates, $version);
}
_write_result($no_updates, $errored, $error_ary);
$error_ary = array();
$errored = $no_updates = false;
?>