query('SELECT cur_version FROM '.$db->prefix.'options');
$result2 = $db->query('SELECT conf_value FROM '.$db->prefix.'config WHERE conf_name=\'o_cur_version\'');
$cur_version = ($result1) ? $db->result($result1) : (($result2 && $db->num_rows($result2)) ? $db->result($result2) : 'beta');
if (!in_array($cur_version, $update_from))
error('Version mismatch. This script updates version '.implode(' and ', $update_from).' to version '.$update_to.'. The database \''.$db_name.'\' doesn\'t seem to be running a supported version.', __FILE__, __LINE__);
// Get the forum config
$result = $db->query('SELECT * FROM '.$db->prefix.'config');
while ($cur_config_item = $db->fetch_row($result))
$pun_config[$cur_config_item[0]] = $cur_config_item[1];
if (!isset($_POST['form_sent']))
{
?>
PunBB Update
PunBB Update
query($sql) or error('Unable to create table '.$db_prefix.'forum_perms. Please check MySQL permissions and try again.', __FILE__, __LINE__, $db->error());
$sql = 'CREATE TABLE '.$db_prefix."groups (
g_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
g_title VARCHAR(50) NOT NULL DEFAULT '',
g_user_title VARCHAR(50),
g_read_board TINYINT(1) NOT NULL DEFAULT 1,
g_post_replies TINYINT(1) NOT NULL DEFAULT 1,
g_post_topics TINYINT(1) NOT NULL DEFAULT 1,
g_post_polls TINYINT(1) NOT NULL DEFAULT 1,
g_edit_posts TINYINT(1) NOT NULL DEFAULT 1,
g_delete_posts TINYINT(1) NOT NULL DEFAULT 1,
g_delete_topics TINYINT(1) NOT NULL DEFAULT 1,
g_set_title TINYINT(1) NOT NULL DEFAULT 1,
g_search TINYINT(1) NOT NULL DEFAULT 1,
g_search_users TINYINT(1) NOT NULL DEFAULT 1,
g_edit_subjects_interval SMALLINT(6) NOT NULL DEFAULT 300,
g_post_flood SMALLINT(6) NOT NULL DEFAULT 30,
g_search_flood SMALLINT(6) NOT NULL DEFAULT 30,
PRIMARY KEY (g_id)
) TYPE=MyISAM;";
$db->query($sql) or error('Unable to create table '.$db_prefix.'groups. Please check MySQL permissions and try again.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'posts DROP INDEX '.$db_prefix.'posts_poster_id_idx'); // No error checking here because both index names are possible
$db->query('ALTER TABLE '.$db->prefix.'posts DROP INDEX '.$db_prefix.'posts_posterid_idx');
$db->query('ALTER TABLE '.$db_prefix.'topics ADD INDEX '.$db_prefix.'topics_moved_to_idx(moved_to)') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db_prefix.'online ADD INDEX '.$db_prefix.'online_user_id_idx(user_id)') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db_prefix.'posts ADD INDEX '.$db_prefix.'posts_multi_idx(poster_id, topic_id)') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'online ADD idle TINYINT(1) NOT NULL DEFAULT 0') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'forums ADD redirect_url VARCHAR(100) DEFAULT NULL AFTER forum_desc') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'forums ADD sort_by TINYINT(1) DEFAULT 0 NOT NULL AFTER last_poster') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'forums DROP closed') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'forums DROP admmod_only') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'search_results RENAME '.$db->prefix.'search_cache') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'search_cache DROP INDEX '.$db_prefix.'search_results_ident_idx') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'search_cache ADD INDEX '.$db->prefix.'search_cache_ident_idx(ident(8))') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'search_matches CHANGE word_id word_id MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT 0') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'search_words CHANGE id id MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'subscriptions DROP INDEX '.$db_prefix.'subscriptions_user_id_idx') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'subscriptions DROP INDEX '.$db_prefix.'subscriptions_topic_id_idx') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'subscriptions ADD PRIMARY KEY (user_id, topic_id)') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'posts CHANGE smilies hide_smilies TINYINT(1) DEFAULT 0 NOT NULL') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('UPDATE '.$db->prefix.'posts SET hide_smilies = NOT hide_smilies') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'users CHANGE aim aim VARCHAR(30) DEFAULT NULL') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'users CHANGE yahoo yahoo VARCHAR(30) DEFAULT NULL') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'users ADD show_img_sig TINYINT(1) NOT NULL DEFAULT 1 AFTER show_img') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'users ADD registration_ip VARCHAR(15) NOT NULL DEFAULT \'0.0.0.0\' AFTER registered') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'users ADD group_id INT(10) NOT NULL DEFAULT 4 AFTER id') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'users ADD language VARCHAR(25) NOT NULL DEFAULT \'English\' AFTER timezone') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'users ADD jabber VARCHAR(75) DEFAULT NULL AFTER url') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('UPDATE '.$db->prefix.'users SET group_id=1 WHERE status=2') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('UPDATE '.$db->prefix.'users SET group_id=2 WHERE status=1') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('UPDATE '.$db->prefix.'users SET group_id=3 WHERE id=1') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'users DROP status') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'users DROP link_to_new_win') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'users DROP last_action') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'users CHANGE smilies show_smilies TINYINT(1) DEFAULT 1 NOT NULL') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'users CHANGE timezone timezone FLOAT DEFAULT 0 NOT NULL') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
break;
case 'pgsql':
$sql = 'CREATE TABLE '.$db_prefix."forum_perms (
group_id INT NOT NULL DEFAULT 0,
forum_id INT NOT NULL DEFAULT 0,
read_forum SMALLINT NOT NULL DEFAULT 1,
post_replies SMALLINT NOT NULL DEFAULT 1,
post_topics SMALLINT NOT NULL DEFAULT 1,
PRIMARY KEY (group_id, forum_id)
)";
$db->query($sql) or error('Unable to create table '.$db_prefix.'forum_perms. Please check PostgreSQL permissions and try again.', __FILE__, __LINE__, $db->error());
$sql = 'CREATE TABLE '.$db_prefix."groups (
g_id SERIAL,
g_title VARCHAR(50) NOT NULL DEFAULT '',
g_user_title VARCHAR(50),
g_read_board SMALLINT NOT NULL DEFAULT 1,
g_post_replies SMALLINT NOT NULL DEFAULT 1,
g_post_topics SMALLINT NOT NULL DEFAULT 1,
g_post_polls SMALLINT NOT NULL DEFAULT 1,
g_edit_posts SMALLINT NOT NULL DEFAULT 1,
g_delete_posts SMALLINT NOT NULL DEFAULT 1,
g_delete_topics SMALLINT NOT NULL DEFAULT 1,
g_set_title SMALLINT NOT NULL DEFAULT 1,
g_search SMALLINT NOT NULL DEFAULT 1,
g_search_users SMALLINT NOT NULL DEFAULT 1,
g_edit_subjects_interval SMALLINT NOT NULL DEFAULT 300,
g_post_flood SMALLINT NOT NULL DEFAULT 30,
g_search_flood SMALLINT NOT NULL DEFAULT 30,
PRIMARY KEY (g_id)
)";
$db->query($sql) or error('Unable to create table '.$db_prefix.'groups. Please check PostgreSQL permissions and try again.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'posts DROP INDEX '.$db_prefix.'posts_poster_id_idx'); // No error checking here because both index names are possible
$db->query('ALTER TABLE '.$db->prefix.'posts DROP INDEX '.$db_prefix.'posts_posterid_idx');
$db->query('CREATE INDEX '.$db_prefix.'topics_moved_to_idx ON '.$db_prefix.'topics(moved_to)') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('CREATE INDEX '.$db_prefix.'online_user_id_idx ON '.$db_prefix.'online(user_id)') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('CREATE INDEX '.$db_prefix.'posts_multi_idx ON '.$db_prefix.'posts(poster_id, topic_id)') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'online ADD idle SMALLINT') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'online ALTER idle SET DEFAULT 0') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'forums ADD redirect_url VARCHAR(100)') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'forums ADD sort_by SMALLINT') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('UPDATE '.$db->prefix.'forums SET sort_by=0') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'forums DROP COLUMN closed');
$db->query('ALTER TABLE '.$db->prefix.'forums DROP COLUMN admmod_only');
$db->query('ALTER TABLE '.$db->prefix.'search_results RENAME TO '.$db->prefix.'search_cache') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('DROP INDEX '.$db_prefix.'subscriptions_user_id_idx') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('DROP INDEX '.$db_prefix.'subscriptions_topic_id_idx') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'subscriptions ADD PRIMARY KEY (user_id, topic_id)') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('CREATE INDEX '.$db_prefix.'subscriptions_multi_idx ON '.$db_prefix.'subscriptions(user_id, topic_id)') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'posts RENAME smilies TO hide_smilies') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'posts ALTER hide_smilies SET DEFAULT 0') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('UPDATE '.$db->prefix.'posts SET hide_smilies = (1-hide_smilies)') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'users ADD group_id INT') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'users ALTER group_id SET DEFAULT 4') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'users ADD language VARCHAR(25)') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'users ALTER language SET DEFAULT \'English\'') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('UPDATE '.$db->prefix.'users SET language=\'English\'') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'users ADD jabber VARCHAR(75)') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('UPDATE '.$db->prefix.'users SET group_id=1 WHERE status=2') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('UPDATE '.$db->prefix.'users SET group_id=2 WHERE status=1') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('UPDATE '.$db->prefix.'users SET group_id=4 WHERE status=0') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('UPDATE '.$db->prefix.'users SET group_id=3 WHERE id=1') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'users DROP COLUMN status');
$db->query('ALTER TABLE '.$db->prefix.'users ADD show_img_sig SMALLINT') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'users ALTER show_img_sig SET DEFAULT 1') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'users RENAME smilies TO show_smilies') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'users ADD registration_ip VARCHAR(15)') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'users ALTER registration_ip SET DEFAULT \'0.0.0.0\'') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('ALTER TABLE '.$db->prefix.'users DROP COLUMN link_to_new_win');
$db->query('ALTER TABLE '.$db->prefix.'users DROP COLUMN last_action');
break;
}
$db->query('UPDATE '.$db->prefix.'users SET show_img_sig = show_img') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
// Insert the four preset groups
$db->query('INSERT INTO '.$db->prefix."groups (g_title, g_user_title, g_read_board, g_post_replies, g_post_topics, g_post_polls, g_edit_posts, g_delete_posts, g_delete_topics, g_set_title, g_search, g_search_users, g_edit_subjects_interval, g_post_flood, g_search_flood) VALUES('Administrators', 'Administrator', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0)") or error('Unable to add group', __FILE__, __LINE__, $db->error());
$db->query('INSERT INTO '.$db->prefix."groups (g_title, g_user_title, g_read_board, g_post_replies, g_post_topics, g_post_polls, g_edit_posts, g_delete_posts, g_delete_topics, g_set_title, g_search, g_search_users, g_edit_subjects_interval, g_post_flood, g_search_flood) VALUES('Moderators', 'Moderator', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0)") or error('Unable to add group', __FILE__, __LINE__, $db->error());
$db->query('INSERT INTO '.$db->prefix."groups (g_title, g_user_title, g_read_board, g_post_replies, g_post_topics, g_post_polls, g_edit_posts, g_delete_posts, g_delete_topics, g_set_title, g_search, g_search_users, g_edit_subjects_interval, g_post_flood, g_search_flood) VALUES('Guest', NULL, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0)") or error('Unable to add group', __FILE__, __LINE__, $db->error());
$db->query('INSERT INTO '.$db->prefix."groups (g_title, g_user_title, g_read_board, g_post_replies, g_post_topics, g_post_polls, g_edit_posts, g_delete_posts, g_delete_topics, g_set_title, g_search, g_search_users, g_edit_subjects_interval, g_post_flood, g_search_flood) VALUES('Members', NULL, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 300, 60, 30)") or error('Unable to add group', __FILE__, __LINE__, $db->error());
// Insert new config settings
$db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES(\'p_mod_edit_users\', \'1\')') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES(\'p_mod_rename_users\', \'0\')') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES(\'p_mod_change_passwords\', \'0\')') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES(\'p_mod_ban_users\', \'0\')') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES(\'p_force_guest_email\', \'1\')') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES(\'o_show_version\', \'0\')') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES(\'o_show_user_info\', \'1\')') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES(\'o_default_lang\', \'English\')') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES(\'o_default_user_group\', \'4\')') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
$db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES(\'o_regs_report\', \'0\')') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
// Delete obsolete config settings
$db->query('DELETE FROM '.$db->prefix."config WHERE conf_name IN('o_flood_interval', 'o_search', 'p_guests_read', 'p_guests_post', 'p_guests_post_topic', 'p_guests_search', 'p_users_post', 'p_users_post_topic', 'p_users_edit_post', 'p_users_del_post', 'p_users_del_topic', 'p_users_set_title')") or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error());
// This feels like a good time to synchronize the forums
$result = $db->query('SELECT id FROM '.$db->prefix.'forums') or error('Unable to fetch forum info.', __FILE__, __LINE__, $db->error());
while ($row = $db->fetch_row($result))
update_forum($row[0]);
// We'll empty the search results table as well
$db->query('TRUNCATE TABLE '.$db->prefix.'search_cache') or error('Unable to flush search results.', __FILE__, __LINE__, $db->error());
// Finally, we update the version number
$db->query('UPDATE '.$db->prefix.'config SET conf_value=\''.$update_to.'\' WHERE conf_name=\'o_cur_version\'') or error('Unable to update version.', __FILE__, __LINE__, $db->error());
// Delete all .php files in the cache (someone might have visited the forums while we were updating and thus, generated incorrect cache files)
$d = dir(PUN_ROOT.'cache');
while (($entry = $d->read()) !== false)
{
if (substr($entry, strlen($entry)-4) == '.php')
@unlink(PUN_ROOT.'cache/'.$entry);
}
$d->close();
?>
PunBB Update
Update completed
Update successful! Your forum database has now been updated to version . You should now remove this script from the forum root directory and follow the rest of the instructions in the documentation.