diff --git a/phpBB/install/convertors/convert_phpbb20.php b/phpBB/install/convertors/convert_phpbb20.php index fac58a7d7d..6c55a42440 100644 --- a/phpBB/install/convertors/convert_phpbb20.php +++ b/phpBB/install/convertors/convert_phpbb20.php @@ -314,6 +314,7 @@ if (!$get_info) 'target' => (defined('MOD_ATTACHMENT')) ? ATTACHMENTS_TABLE : '', 'primary' => 'attachments.attach_id', 'query_first' => (defined('MOD_ATTACHMENT')) ? $convert->truncate_statement . ATTACHMENTS_TABLE : '', + 'autoincrement' => 'attach_id', array('attach_id', 'attachments.attach_id', ''), array('post_msg_id', 'attachments.post_id', ''), @@ -338,6 +339,7 @@ if (!$get_info) array( 'target' => (defined('MOD_ATTACHMENT')) ? ATTACHMENTS_TABLE : '', 'primary' => 'attachments.attach_id', + 'autoincrement' => 'attach_id', array('attach_id', 'attachments.attach_id', ''), array('post_msg_id', 'attachments.privmsgs_id', ''), @@ -362,6 +364,7 @@ if (!$get_info) array( 'target' => (defined('MOD_ATTACHMENT')) ? EXTENSIONS_TABLE : '', 'query_first' => (defined('MOD_ATTACHMENT')) ? $convert->truncate_statement . EXTENSIONS_TABLE : '', + 'autoincrement' => 'extension_id', array('extension_id', 'extensions.ext_id', ''), array('group_id', 'extensions.group_id', ''), @@ -371,6 +374,7 @@ if (!$get_info) array( 'target' => (defined('MOD_ATTACHMENT')) ? EXTENSION_GROUPS_TABLE : '', 'query_first' => (defined('MOD_ATTACHMENT')) ? $convert->truncate_statement . EXTENSION_GROUPS_TABLE : '', + 'autoincrement' => 'group_id', array('group_id', 'extension_groups.group_id', ''), array('group_name', 'extension_groups.group_name', array('function1' => 'phpbb_set_encoding', 'function2' => 'utf8_htmlspecialchars')), @@ -414,6 +418,7 @@ if (!$get_info) array( 'target' => RANKS_TABLE, 'query_first' => $convert->truncate_statement . RANKS_TABLE, + 'autoincrement' => 'rank_id', array('rank_id', 'ranks.rank_id', ''), array('rank_title', 'ranks.rank_title', array('function1' => 'phpbb_set_encoding', 'function2' => 'utf8_htmlspecialchars')), @@ -426,6 +431,7 @@ if (!$get_info) 'target' => TOPICS_TABLE, 'query_first' => $convert->truncate_statement . TOPICS_TABLE, 'primary' => 'topics.topic_id', + 'autoincrement' => 'topic_id', array('topic_id', 'topics.topic_id', ''), array('forum_id', 'topics.forum_id', ''), @@ -456,6 +462,7 @@ if (!$get_info) array( 'target' => TOPICS_TABLE, 'primary' => 'topics.topic_id', + 'autoincrement' => 'topic_id', array('topic_id', 'topics.topic_id', ''), array('forum_id', 'topics.forum_id', ''), @@ -496,6 +503,7 @@ if (!$get_info) array( 'target' => SMILIES_TABLE, 'query_first' => $convert->truncate_statement . SMILIES_TABLE, + 'autoincrement' => 'smiley_id', array('smiley_id', 'smilies.smilies_id', ''), array('code', 'smilies.code', 'phpbb_set_encoding'), @@ -543,6 +551,7 @@ if (!$get_info) 'target' => WORDS_TABLE, 'primary' => 'words.word_id', 'query_first' => $convert->truncate_statement . WORDS_TABLE, + 'autoincrement' => 'word_id', array('word_id', 'words.word_id', ''), array('word', 'words.word', 'phpbb_set_encoding'), @@ -552,6 +561,7 @@ if (!$get_info) array( 'target' => POSTS_TABLE, 'primary' => 'posts.post_id', + 'autoincrement' => 'post_id', 'query_first' => $convert->truncate_statement . POSTS_TABLE, 'execute_first' => ' $config["max_post_chars"] = 0; @@ -595,6 +605,7 @@ if (!$get_info) array( 'target' => PRIVMSGS_TABLE, 'primary' => 'privmsgs.privmsgs_id', + 'autoincrement' => 'privmsgs_id', 'query_first' => array( $convert->truncate_statement . PRIVMSGS_TABLE, $convert->truncate_statement . PRIVMSGS_RULES_TABLE, @@ -741,6 +752,7 @@ if (!$get_info) array( 'target' => GROUPS_TABLE, + 'autoincrement' => 'group_id', 'query_first' => $convert->truncate_statement . GROUPS_TABLE, array('group_id', 'groups.group_id', ''), @@ -781,6 +793,7 @@ if (!$get_info) array( 'target' => USERS_TABLE, 'primary' => 'users.user_id', + 'autoincrement' => 'user_id', 'query_first' => array( 'DELETE FROM ' . USERS_TABLE . ' WHERE user_id <> ' . ANONYMOUS, $convert->truncate_statement . BOTS_TABLE diff --git a/phpBB/install/install_convert.php b/phpBB/install/install_convert.php index 4636bbeecc..0d1fec4a1c 100644 --- a/phpBB/install/install_convert.php +++ b/phpBB/install/install_convert.php @@ -910,48 +910,13 @@ class install_convert extends module } } - if ($db->sql_layer === 'postgres') + if (!empty($schema['autoincrement'])) { - $tables = array( - ATTACHMENTS_TABLE => 'attach_id', - ACL_OPTIONS_TABLE => 'auth_option_id', - ACL_ROLES_TABLE => 'role_id', - BANLIST_TABLE => 'ban_id', - BOTS_TABLE => 'bot_id', - DISALLOW_TABLE => 'disallow_id', - DRAFTS_TABLE => 'draft_id', - EXTENSIONS_TABLE => 'extension_id', - EXTENSION_GROUPS_TABLE => 'group_id', - FORUMS_TABLE => 'forum_id', - GROUPS_TABLE => 'group_id', - ICONS_TABLE => 'icons_id', - LANG_TABLE => 'lang_id', - LOG_TABLE => 'log_id', - MODULES_TABLE => 'module_id', - POSTS_TABLE => 'post_id', - PRIVMSGS_TABLE => 'msg_id', - PRIVMSGS_FOLDER_TABLE => 'folder_id', - PRIVMSGS_RULES_TABLE => 'rule_id', - PROFILE_FIELDS_TABLE => 'field_id', - RANKS_TABLE => 'rank_id', - REPORTS_TABLE => 'report_id', - REPORTS_REASONS_TABLE => 'reason_id', - SEARCH_WORDLIST_TABLE => 'word_id', - SITELIST_TABLE => 'site_id', - SMILIES_TABLE => 'smiley_id', - STYLES_TABLE => 'style_id', - STYLES_TEMPLATE_TABLE => 'template_id', - STYLES_TEMPLATE_DATA_TABLE => 'template_id', - STYLES_THEME_TABLE => 'theme_id', - STYLES_IMAGESET_TABLE => 'imageset_id', - TOPICS_TABLE => 'topic_id', - USERS_TABLE => 'user_id', - WARNINGS_TABLE => 'warning_id', - WORDS_TABLE => 'word_id' - ); - if (!empty($tables[$schema['target']])) + switch ($db->sql_layer) { - $db->sql_query("SELECT SETVAL('" . $schema['target'] . "_seq',(select case when max(" . $tables[$schema['target']] . ")>0 then max(" . $tables[$schema['target']] . ")+1 else 1 end from " . $schema['target'] . '));'); + case 'postgres': + $db->sql_query("SELECT SETVAL('" . $schema['target'] . "_seq',(select case when max(" . $schema['autoincrement'] . ")>0 then max(" . $schema['autoincrement'] . ")+1 else 1 end from " . $schema['target'] . '));'); + break; } } } @@ -1051,6 +1016,17 @@ class install_convert extends module $convert->row = $convert_row = array(); + if (!empty($schema['autoincrement'])) + { + switch ($db->sql_layer) + { + case 'mssql': + case 'mssql_odbc': + $db->sql_query('SET IDENTITY_INSERT ' . $schema['target'] . ' ON'); + break; + } + } + // Now handle the rows until time is over or no more rows to process... while (still_on_time()) { @@ -1168,48 +1144,18 @@ class install_convert extends module $waiting_rows = array(); } - if ($db->sql_layer === 'postgres') + if (!empty($schema['autoincrement'])) { - $tables = array( - ATTACHMENTS_TABLE => 'attach_id', - ACL_OPTIONS_TABLE => 'auth_option_id', - ACL_ROLES_TABLE => 'role_id', - BANLIST_TABLE => 'ban_id', - BOTS_TABLE => 'bot_id', - DISALLOW_TABLE => 'disallow_id', - DRAFTS_TABLE => 'draft_id', - EXTENSIONS_TABLE => 'extension_id', - EXTENSION_GROUPS_TABLE => 'group_id', - FORUMS_TABLE => 'forum_id', - GROUPS_TABLE => 'group_id', - ICONS_TABLE => 'icons_id', - LANG_TABLE => 'lang_id', - LOG_TABLE => 'log_id', - MODULES_TABLE => 'module_id', - POSTS_TABLE => 'post_id', - PRIVMSGS_TABLE => 'msg_id', - PRIVMSGS_FOLDER_TABLE => 'folder_id', - PRIVMSGS_RULES_TABLE => 'rule_id', - PROFILE_FIELDS_TABLE => 'field_id', - RANKS_TABLE => 'rank_id', - REPORTS_TABLE => 'report_id', - REPORTS_REASONS_TABLE => 'reason_id', - SEARCH_WORDLIST_TABLE => 'word_id', - SITELIST_TABLE => 'site_id', - SMILIES_TABLE => 'smiley_id', - STYLES_TABLE => 'style_id', - STYLES_TEMPLATE_TABLE => 'template_id', - STYLES_TEMPLATE_DATA_TABLE => 'template_id', - STYLES_THEME_TABLE => 'theme_id', - STYLES_IMAGESET_TABLE => 'imageset_id', - TOPICS_TABLE => 'topic_id', - USERS_TABLE => 'user_id', - WARNINGS_TABLE => 'warning_id', - WORDS_TABLE => 'word_id' - ); - if (!empty($tables[$schema['target']])) + switch ($db->sql_layer) { - $db->sql_query("SELECT SETVAL('" . $schema['target'] . "_seq',(select case when max(" . $tables[$schema['target']] . ")>0 then max(" . $tables[$schema['target']] . ")+1 else 1 end from " . $schema['target'] . '));'); + case 'mssql': + case 'mssql_odbc': + $db->sql_query('SET IDENTITY_INSERT ' . $schema['target'] . ' OFF'); + break; + + case 'postgres': + $db->sql_query("SELECT SETVAL('" . $schema['target'] . "_seq',(select case when max(" . $schema['autoincrement'] . ")>0 then max(" . $schema['autoincrement'] . ")+1 else 1 end from " . $schema['target'] . '));'); + break; } } }