1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-01 14:30:32 +02:00

- allow converting from one database to another, no need for tables to be in one database anylonger (this also allows switching from one DBMS that was used with phpBB2 to another DBMS supported by phpBB3 including new systems available in Olympus only)

- abstracted some installation code that is now relevant to converting as well into functions_install.php (mostly DBMS selection related)
- fixed a weird smiley path problem, no idea why nobody else noticed this, maybe my fix was incorrect?
- forgot to commit a file last time


git-svn-id: file:///svn/phpbb/trunk@6995 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Nils Adermann
2007-02-16 23:06:14 +00:00
parent ec9a091669
commit 7259457701
9 changed files with 1071 additions and 606 deletions

View File

@@ -31,6 +31,12 @@ $convertor_data = array(
'version' => '0.9',
'phpbb_version' => '3.0.0',
'author' => '<a href="http://www.phpbb.com/">phpBB Group</a>',
'dbms' => 'mysql',
'dbhost' => 'localhost',
'dbport' => '',
'dbuser' => 'user',
'dbpasswd' => 'password',
'dbname' => '',
'table_prefix' => 'phpbb_',
'forum_path' => '../forums',
'author_notes' => 'Avatars may be on a different width/height than with the old forum. This is due to dimensions being stored within phpBB3 but not within phpBB2. The default dimension was set to 80x80 for avatars where dimension settings could not be determined. You might wish to instruct your users to check their profiles after the conversion to ensure that the size is correct.',
@@ -210,7 +216,8 @@ if (!$get_info)
* 'schema' Syntax Description
* -> 'target' => Target Table. If not specified the next table will be handled
* -> 'primary' => Primary Key. If this is specified then this table is processed in batches
* -> 'query_first' => Query to execute before beginning the process (if more than one then specified as array)
* -> 'query_first' => array('target' or 'src', Query to execute before beginning the process
* (if more than one then specified as array))
* -> 'function_first' => Function to execute before beginning the process (if more than one then specified as array)
* (This is mostly useful if variables need to be given to the converting process)
* -> 'test_file' => This is not used at the moment but should be filled with a file from the old installation
@@ -276,10 +283,10 @@ if (!$get_info)
// We empty some tables to have clean data available
'query_first' => array(
$convert->truncate_statement . SEARCH_RESULTS_TABLE,
$convert->truncate_statement . SEARCH_WORDLIST_TABLE,
$convert->truncate_statement . SEARCH_WORDMATCH_TABLE,
$convert->truncate_statement . LOG_TABLE,
array('target', $convert->truncate_statement . SEARCH_RESULTS_TABLE),
array('target', $convert->truncate_statement . SEARCH_WORDLIST_TABLE),
array('target', $convert->truncate_statement . SEARCH_WORDMATCH_TABLE),
array('target', $convert->truncate_statement . LOG_TABLE),
),
// with this you are able to import all attachment files on the fly. For large boards this is not an option, therefore commented out by default.
@@ -313,7 +320,7 @@ if (!$get_info)
array(
'target' => (defined('MOD_ATTACHMENT')) ? ATTACHMENTS_TABLE : '',
'primary' => 'attachments.attach_id',
'query_first' => (defined('MOD_ATTACHMENT')) ? $convert->truncate_statement . ATTACHMENTS_TABLE : '',
'query_first' => (defined('MOD_ATTACHMENT')) ? array('target', $convert->truncate_statement . ATTACHMENTS_TABLE) : '',
'autoincrement' => 'attach_id',
array('attach_id', 'attachments.attach_id', ''),
@@ -363,7 +370,7 @@ if (!$get_info)
array(
'target' => (defined('MOD_ATTACHMENT')) ? EXTENSIONS_TABLE : '',
'query_first' => (defined('MOD_ATTACHMENT')) ? $convert->truncate_statement . EXTENSIONS_TABLE : '',
'query_first' => (defined('MOD_ATTACHMENT')) ? array('target', $convert->truncate_statement . EXTENSIONS_TABLE) : '',
'autoincrement' => 'extension_id',
array('extension_id', 'extensions.ext_id', ''),
@@ -373,7 +380,7 @@ if (!$get_info)
array(
'target' => (defined('MOD_ATTACHMENT')) ? EXTENSION_GROUPS_TABLE : '',
'query_first' => (defined('MOD_ATTACHMENT')) ? $convert->truncate_statement . EXTENSION_GROUPS_TABLE : '',
'query_first' => (defined('MOD_ATTACHMENT')) ? array('target', $convert->truncate_statement . EXTENSION_GROUPS_TABLE) : '',
'autoincrement' => 'group_id',
array('group_id', 'extension_groups.group_id', ''),
@@ -389,7 +396,7 @@ if (!$get_info)
array(
'target' => BANLIST_TABLE,
'query_first' => $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_userid', 'banlist.ban_userid', 'phpbb_user_id'),
@@ -410,14 +417,14 @@ if (!$get_info)
array(
'target' => DISALLOW_TABLE,
'query_first' => $convert->truncate_statement . DISALLOW_TABLE,
'query_first' => array('target', $convert->truncate_statement . DISALLOW_TABLE),
array('disallow_username', 'disallow.disallow_username', 'phpbb_disallowed_username'),
),
array(
'target' => RANKS_TABLE,
'query_first' => $convert->truncate_statement . RANKS_TABLE,
'query_first' => array('target', $convert->truncate_statement . RANKS_TABLE),
'autoincrement' => 'rank_id',
array('rank_id', 'ranks.rank_id', ''),
@@ -429,7 +436,7 @@ if (!$get_info)
array(
'target' => TOPICS_TABLE,
'query_first' => $convert->truncate_statement . TOPICS_TABLE,
'query_first' => array('target', $convert->truncate_statement . TOPICS_TABLE),
'primary' => 'topics.topic_id',
'autoincrement' => 'topic_id',
@@ -493,7 +500,7 @@ if (!$get_info)
array(
'target' => TOPICS_WATCH_TABLE,
'primary' => 'topics_watch.topic_id',
'query_first' => $convert->truncate_statement . TOPICS_WATCH_TABLE,
'query_first' => array('target', $convert->truncate_statement . TOPICS_WATCH_TABLE),
array('topic_id', 'topics_watch.topic_id', ''),
array('user_id', 'topics_watch.user_id', 'phpbb_user_id'),
@@ -502,7 +509,7 @@ if (!$get_info)
array(
'target' => SMILIES_TABLE,
'query_first' => $convert->truncate_statement . SMILIES_TABLE,
'query_first' => array('target', $convert->truncate_statement . SMILIES_TABLE),
'autoincrement' => 'smiley_id',
array('smiley_id', 'smilies.smilies_id', ''),
@@ -522,7 +529,7 @@ if (!$get_info)
array(
'target' => POLL_OPTIONS_TABLE,
'primary' => 'vote_results.vote_option_id',
'query_first' => $convert->truncate_statement . POLL_OPTIONS_TABLE,
'query_first' => array('target', $convert->truncate_statement . POLL_OPTIONS_TABLE),
array('poll_option_id', 'vote_results.vote_option_id', ''),
array('topic_id', 'vote_desc.topic_id', ''),
@@ -537,7 +544,7 @@ if (!$get_info)
array(
'target' => POLL_VOTES_TABLE,
'primary' => 'vote_desc.topic_id',
'query_first' => $convert->truncate_statement . POLL_VOTES_TABLE,
'query_first' => array('target', $convert->truncate_statement . POLL_VOTES_TABLE),
array('poll_option_id', 1, ''),
array('topic_id', 'vote_desc.topic_id', ''),
@@ -550,7 +557,7 @@ if (!$get_info)
array(
'target' => WORDS_TABLE,
'primary' => 'words.word_id',
'query_first' => $convert->truncate_statement . WORDS_TABLE,
'query_first' => array('target', $convert->truncate_statement . WORDS_TABLE),
'autoincrement' => 'word_id',
array('word_id', 'words.word_id', ''),
@@ -562,7 +569,7 @@ if (!$get_info)
'target' => POSTS_TABLE,
'primary' => 'posts.post_id',
'autoincrement' => 'post_id',
'query_first' => $convert->truncate_statement . POSTS_TABLE,
'query_first' => array('target', $convert->truncate_statement . POSTS_TABLE),
'execute_first' => '
$config["max_post_chars"] = 0;
',
@@ -607,8 +614,8 @@ if (!$get_info)
'primary' => 'privmsgs.privmsgs_id',
'autoincrement' => 'privmsgs_id',
'query_first' => array(
$convert->truncate_statement . PRIVMSGS_TABLE,
$convert->truncate_statement . PRIVMSGS_RULES_TABLE,
array('target', $convert->truncate_statement . PRIVMSGS_TABLE),
array('target', $convert->truncate_statement . PRIVMSGS_RULES_TABLE),
),
'execute_first' => '
@@ -645,7 +652,7 @@ if (!$get_info)
array(
'target' => PRIVMSGS_FOLDER_TABLE,
'primary' => 'users.user_id',
'query_first' => $convert->truncate_statement . PRIVMSGS_FOLDER_TABLE,
'query_first' => array('target', $convert->truncate_statement . PRIVMSGS_FOLDER_TABLE),
array('user_id', 'users.user_id', 'phpbb_user_id'),
array('folder_name', $user->lang['CONV_SAVED_MESSAGES'], ''),
@@ -658,7 +665,7 @@ if (!$get_info)
array(
'target' => PRIVMSGS_TO_TABLE,
'primary' => 'privmsgs.privmsgs_id',
'query_first' => $convert->truncate_statement . PRIVMSGS_TO_TABLE,
'query_first' => array('target', $convert->truncate_statement . PRIVMSGS_TO_TABLE),
array('msg_id', 'privmsgs.privmsgs_id', ''),
array('user_id', 'privmsgs.privmsgs_to_userid', 'phpbb_user_id'),
@@ -753,7 +760,7 @@ if (!$get_info)
array(
'target' => GROUPS_TABLE,
'autoincrement' => 'group_id',
'query_first' => $convert->truncate_statement . GROUPS_TABLE,
'query_first' => array('target', $convert->truncate_statement . GROUPS_TABLE),
array('group_id', 'groups.group_id', ''),
array('group_type', 'groups.group_type', 'phpbb_convert_group_type'),
@@ -766,7 +773,7 @@ if (!$get_info)
array(
'target' => USER_GROUP_TABLE,
'query_first' => $convert->truncate_statement . USER_GROUP_TABLE,
'query_first' => array('target', $convert->truncate_statement . USER_GROUP_TABLE),
'execute_first' => '
add_default_groups();
',
@@ -795,8 +802,8 @@ if (!$get_info)
'primary' => 'users.user_id',
'autoincrement' => 'user_id',
'query_first' => array(
'DELETE FROM ' . USERS_TABLE . ' WHERE user_id <> ' . ANONYMOUS,
$convert->truncate_statement . BOTS_TABLE
array('target', 'DELETE FROM ' . USERS_TABLE . ' WHERE user_id <> ' . ANONYMOUS),
array('target', $convert->truncate_statement . BOTS_TABLE)
),
array('user_id', 'users.user_id', 'phpbb_user_id'),

View File

@@ -46,16 +46,16 @@ function phpbb_forum_flags()
*/
function phpbb_insert_forums()
{
global $db, $convert, $user, $config;
global $db, $src_db, $same_db, $convert, $user, $config;
$db->sql_query($convert->truncate_statement . FORUMS_TABLE);
// Determine the highest id used within the old forums table (we add the categories after the forum ids)
$sql = 'SELECT MAX(forum_id) AS max_forum_id
FROM ' . $convert->src_table_prefix . 'forums';
$result = $db->sql_query($sql);
$max_forum_id = (int) $db->sql_fetchfield('max_forum_id');
$db->sql_freeresult($result);
$result = $src_db->sql_query($sql);
$max_forum_id = (int) $src_db->sql_fetchfield('max_forum_id');
$src_db->sql_freeresult($result);
$max_forum_id++;
@@ -64,16 +64,16 @@ function phpbb_insert_forums()
FROM ' . $convert->src_table_prefix . 'categories
ORDER BY cat_order';
if ($convert->mysql_convert)
if ($convert->mysql_convert && $same_db)
{
$db->sql_query("SET NAMES 'binary'");
$src_db->sql_query("SET NAMES 'binary'");
}
$result = $db->sql_query($sql);
$result = $src_db->sql_query($sql);
if ($convert->mysql_convert)
if ($convert->mysql_convert && $same_db)
{
$db->sql_query("SET NAMES 'utf8'");
$src_db->sql_query("SET NAMES 'utf8'");
}
switch ($db->sql_layer)
@@ -85,7 +85,7 @@ function phpbb_insert_forums()
}
$cats_added = array();
while ($row = $db->sql_fetchrow($result))
while ($row = $src_db->sql_fetchrow($result))
{
$sql_ary = array(
'forum_id' => $max_forum_id,
@@ -113,17 +113,17 @@ function phpbb_insert_forums()
$cats_added[$row['cat_id']] = $max_forum_id;
$max_forum_id++;
}
$db->sql_freeresult($result);
$src_db->sql_freeresult($result);
// There may be installations having forums with non-existant category ids.
// We try to catch them and add them to an "unknown" category instead of leaving them out.
$sql = 'SELECT cat_id
FROM ' . $convert->src_table_prefix . 'forums
GROUP BY cat_id';
$result = $db->sql_query($sql);
$result = $src_db->sql_query($sql);
$unknown_cat_id = false;
while ($row = $db->sql_fetchrow($result))
while ($row = $src_db->sql_fetchrow($result))
{
// Catch those categories not been added before
if (!isset($cats_added[$row['cat_id']]))
@@ -131,7 +131,7 @@ function phpbb_insert_forums()
$unknown_cat_id = true;
}
}
$db->sql_freeresult($result);
$src_db->sql_freeresult($result);
// Is there at least one category not known?
if ($unknown_cat_id === true)
@@ -171,19 +171,19 @@ function phpbb_insert_forums()
GROUP BY f.forum_id, f.forum_name, f.cat_id, f.forum_desc, f.forum_status, f.prune_enable, f.prune_next, f.forum_order, fp.prune_days, fp.prune_freq
ORDER BY f.cat_id, f.forum_order';
if ($convert->mysql_convert)
if ($convert->mysql_convert && $same_db)
{
$db->sql_query("SET NAMES 'binary'");
$src_db->sql_query("SET NAMES 'binary'");
}
$result = $db->sql_query($sql);
$result = $src_db->sql_query($sql);
if ($convert->mysql_convert)
if ($convert->mysql_convert && $same_db)
{
$db->sql_query("SET NAMES 'utf8'");
$src_db->sql_query("SET NAMES 'utf8'");
}
while ($row = $db->sql_fetchrow($result))
while ($row = $src_db->sql_fetchrow($result))
{
// Some might have forums here with an id not being "possible"...
// To be somewhat friendly we "change" the category id for those to a previously created ghost category
@@ -266,7 +266,7 @@ function phpbb_insert_forums()
$sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
$db->sql_query($sql);
}
$db->sql_freeresult($result);
$src_db->sql_freeresult($result);
switch ($db->sql_layer)
{
@@ -342,14 +342,24 @@ function phpbb_set_encoding($text, $grab_user_lang = true)
}
else if (!empty($convert_row['poster_id']))
{
global $db;
global $src_db, $same_db;
if ($convert->mysql_convert && $same_db)
{
$src_db->sql_query("SET NAMES 'binary'");
}
$sql = 'SELECT user_lang
FROM ' . $convert->src_table_prefix . 'users
WHERE user_id = ' . (int) $convert_row['poster_id'];
$result = $db->sql_query($sql);
$get_lang = (string) $db->sql_fetchfield('user_lang');
$db->sql_freeresult($result);
$result = $src_db->sql_query($sql);
$get_lang = (string) $src_db->sql_fetchfield('user_lang');
$src_db->sql_freeresult($result);
if ($convert->mysql_convert && $same_db)
{
$src_db->sql_query("SET NAMES 'utf8'");
}
$get_lang = (!trim($get_lang)) ? trim(get_config_value('default_lang')) : trim($get_lang);
}
@@ -441,15 +451,25 @@ function phpbb_user_id($user_id)
// Increment user id if the old forum is having a user with the id 1
if (!isset($config['increment_user_id']))
{
global $db, $convert;
global $src_db, $same_db, $convert;
if ($convert->mysql_convert && $same_db)
{
$src_db->sql_query("SET NAMES 'binary'");
}
// Now let us set a temporary config variable for user id incrementing
$sql = "SELECT user_id
FROM {$convert->src_table_prefix}users
WHERE user_id = 1";
$result = $db->sql_query($sql);
$id = (int) $db->sql_fetchfield('user_id');
$db->sql_freeresult($result);
$result = $src_db->sql_query($sql);
$id = (int) $src_db->sql_fetchfield('user_id');
$src_db->sql_freeresult($result);
if ($convert->mysql_convert && $same_db)
{
$src_db->sql_query("SET NAMES 'utf8'");
}
// If there is a user id 1, we need to increment user ids. :/
if ($id === 1)
@@ -484,7 +504,7 @@ function phpbb_copy_table_fields()
*/
function phpbb_convert_authentication($mode)
{
global $db, $convert, $user, $config, $cache;
global $db, $src_db, $same_db, $convert, $user, $config, $cache;
if ($mode == 'start')
{
@@ -494,14 +514,15 @@ function phpbb_convert_authentication($mode)
// What we will do is handling all 2.0.x admins as founder to replicate what is common in 2.0.x.
// After conversion the main admin need to make sure he is removing permissions and the founder status if wanted.
// Grab user ids of users with user_level of ADMIN
$sql = "SELECT user_id
FROM {$convert->src_table_prefix}users
WHERE user_level = 1
ORDER BY user_regdate ASC";
$result = $db->sql_query($sql);
$result = $src_db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
while ($row = $src_db->sql_fetchrow($result))
{
$user_id = (int) phpbb_user_id($row['user_id']);
@@ -511,49 +532,58 @@ function phpbb_convert_authentication($mode)
WHERE user_id = $user_id";
$db->sql_query($sql);
}
$db->sql_freeresult($result);
$src_db->sql_freeresult($result);
}
// Grab forum auth information
$sql = "SELECT *
FROM {$convert->src_table_prefix}forums";
$result = $db->sql_query($sql);
$result = $src_db->sql_query($sql);
$forum_access = array();
while ($row = $db->sql_fetchrow($result))
while ($row = $src_db->sql_fetchrow($result))
{
$forum_access[] = $row;
}
$db->sql_freeresult($result);
$src_db->sql_freeresult($result);
if ($convert->mysql_convert && $same_db)
{
$src_db->sql_query("SET NAMES 'binary'");
}
// Grab user auth information from 2.0.x board
$sql = "SELECT ug.user_id, aa.*
FROM {$convert->src_table_prefix}auth_access aa, {$convert->src_table_prefix}user_group ug, {$convert->src_table_prefix}groups g
WHERE g.group_id = aa.group_id
AND g.group_single_user = 1
AND ug.group_id = g.group_id";
$result = $db->sql_query($sql);
$result = $src_db->sql_query($sql);
$user_access = array();
while ($row = $db->sql_fetchrow($result))
while ($row = $src_db->sql_fetchrow($result))
{
$user_access[$row['forum_id']][] = $row;
}
$db->sql_freeresult($result);
$src_db->sql_freeresult($result);
// Grab group auth information
$sql = "SELECT g.group_id, aa.*
FROM {$convert->src_table_prefix}auth_access aa, {$convert->src_table_prefix}groups g
WHERE g.group_id = aa.group_id
AND g.group_single_user <> 1";
$result = $db->sql_query($sql);
$result = $src_db->sql_query($sql);
$group_access = array();
while ($row = $db->sql_fetchrow($result))
while ($row = $src_db->sql_fetchrow($result))
{
$group_access[$row['forum_id']][] = $row;
}
$db->sql_freeresult($result);
$src_db->sql_freeresult($result);
if ($convert->mysql_convert && $same_db)
{
$src_db->sql_query("SET NAMES 'utf8'");
}
// Add Forum Access List
$auth_map = array(
@@ -852,25 +882,25 @@ function phpbb_convert_authentication($mode)
$sql = 'SELECT user_id FROM ' . $convert->src_table_prefix . 'users
WHERE user_allowavatar = 0
AND user_id > 0';
$result = $db->sql_query($sql);
$result = $src_db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
while ($row = $src_db->sql_fetchrow($result))
{
mass_auth('user_role', 0, (int) phpbb_user_id($row['user_id']), 'USER_NOAVATAR');
}
$db->sql_freeresult($result);
$src_db->sql_freeresult($result);
// And the same for those who have had their PM rights removed
$sql = 'SELECT user_id FROM ' . $convert->src_table_prefix . 'users
WHERE user_allow_pm = 0
AND user_id > 0';
$result = $db->sql_query($sql);
$result = $src_db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
while ($row = $src_db->sql_fetchrow($result))
{
mass_auth('user_role', 0, (int) phpbb_user_id($row['user_id']), 'USER_NOPM');
}
$db->sql_freeresult($result);
$src_db->sql_freeresult($result);
}
else if ($mode == 'third')
{
@@ -1169,21 +1199,30 @@ function phpbb_get_files_dir()
return;
}
global $db, $convert, $user, $config, $cache;
global $src_db, $same_db, $convert, $user, $config, $cache;
if ($convert->mysql_convert && $same_db)
{
$src_db->sql_query("SET NAMES 'binary'");
}
$sql = 'SELECT config_value AS upload_dir
FROM ' . $convert->src_table_prefix . "attachments_config
WHERE config_name = 'upload_dir'";
$result = $db->sql_query($sql);
$upload_path = $db->sql_fetchfield('upload_dir');
$db->sql_freeresult($result);
$result = $src_db->sql_query($sql);
$upload_path = $src_db->sql_fetchfield('upload_dir');
$src_db->sql_freeresult($result);
$sql = 'SELECT config_value AS ftp_upload
FROM ' . $convert->src_table_prefix . "attachments_config
WHERE config_name = 'allow_ftp_upload'";
$result = $db->sql_query($sql);
$ftp_upload = (int) $db->sql_fetchfield('ftp_upload');
$db->sql_freeresult($result);
$result = $src_db->sql_query($sql);
$ftp_upload = (int) $src_db->sql_fetchfield('ftp_upload');
$src_db->sql_freeresult($result);
if ($convert->mysql_convert && $same_db)
{
$src_db->sql_query("SET NAMES 'utf8'");
}
if ($ftp_upload)
{
@@ -1402,18 +1441,28 @@ function phpbb_get_savebox_id($user_id)
*/
function phpbb_import_attach_config()
{
global $db, $convert, $config;
global $db, $src_db, $same_db, $convert, $config;
if ($convert->mysql_convert && $same_db)
{
$src_db->sql_query("SET NAMES 'binary'");
}
$sql = 'SELECT *
FROM ' . $convert->src_table_prefix . 'attachments_config';
$result = $db->sql_query($sql);
$result = $src_db->sql_query($sql);
if ($convert->mysql_convert && $same_db)
{
$src_db->sql_query("SET NAMES 'utf8'");
}
$attach_config = array();
while ($row = $db->sql_fetchrow($result))
while ($row = $src_db->sql_fetchrow($result))
{
$attach_config[$row['config_name']] = $row['config_value'];
}
$db->sql_freeresult($result);
$src_db->sql_freeresult($result);
set_config('allow_attachments', 1);