// Include the files necessary for installation require_once MYBB_ROOT."inc/class_timers.php"; require_once MYBB_ROOT.'inc/class_language.php';
$lang = new MyLanguage(); $lang->set_path(INSTALL_ROOT.'resources/'); $lang->load('language');
// If we're upgrading from an SQLite installation, make sure we still work. if($config['database']['type'] == 'sqlite3' || $config['database']['type'] == 'sqlite2') { $config['database']['type'] = 'sqlite'; }
// Load DB interface require_once MYBB_ROOT."inc/db_base.php"; require_once MYBB_ROOT . 'inc/AbstractPdoDbDriver.php';
require_once MYBB_ROOT."inc/db_{$config['database']['type']}.php"; switch($config['database']['type']) { case "sqlite": $db = new DB_SQLite; break; case "pgsql": $db = new DB_PgSQL; break; case "pgsql_pdo": $db = new PostgresPdoDbDriver(); break; case "mysqli": $db = new DB_MySQLi; break; case "mysql_pdo": $db = new MysqlPdoDbDriver(); break; default: $db = new DB_MySQL; }
// Fix for people who for some specify a trailing slash on the board URL if(substr($settings['bburl'], -1) == "/") { $settings['bburl'] = my_substr($settings['bburl'], 0, -1); }
// Include the installation resources require_once INSTALL_ROOT."resources/output.php"; $output = new installerOutput; $output->script = "upgrade.php"; $output->title = "MyBB Upgrade Wizard";
if(file_exists("lock")) { $output->print_error($lang->locked); } else { $mybb->input['action'] = $mybb->get_input('action'); if($mybb->input['action'] == "logout" && $mybb->user['uid']) { // Check session ID if we have one if($mybb->get_input('logoutkey') !== $mybb->user['logoutkey']) { $output->print_error("Your user ID could not be verified to log you out. This may have been because a malicious Javascript was attempting to log you out automatically. If you intended to log out, please click the Log Out button at the top menu."); }
if(!username_exists($mybb->get_input('username'))) { $output->print_error("The username you have entered appears to be invalid."); } $options = array( 'fields' => array('username', 'password', 'salt', 'loginkey') ); $user = get_user_by_username($mybb->get_input('username'), $options);
if(!$user) { $output->print_error("The username you have entered appears to be invalid."); } else { $user = validate_password_from_uid($user['uid'], $mybb->get_input('password'), $user); if(!$user) { $output->print_error("The password you entered is incorrect. If you have forgotten your password, click <a href=\"../member.php?action=lostpw\">here</a>. Otherwise, go back and try again."); } }
$db->write_query("CREATE TABLE ".TABLE_PREFIX."upgrade_data ( title varchar(30) NOT NULL, contents text NOT NULL, UNIQUE (title) ) {$engine}{$collation};");
// Figure out which version we last updated from (as of 1.6) $version_history = $cache->read("version_history");
// If array is empty then we must be upgrading to 1.6 since that's when this feature was added if(empty($version_history)) { $next_update_version = 17; // 16+1 } else { $next_update_version = (int)(end($version_history)+1); }
if($system_upgrade_detail['revert_all_templates'] > 0) { $db->drop_table("templates"); $db->write_query("CREATE TABLE ".TABLE_PREFIX."templates ( tid int unsigned NOT NULL auto_increment, title varchar(120) NOT NULL default '', template text NOT NULL, sid int(10) NOT NULL default '0', version varchar(20) NOT NULL default '0', status varchar(10) NOT NULL default '', dateline int(10) NOT NULL default '0', PRIMARY KEY (tid) ) ENGINE=MyISAM{$charset};"); }
if($system_upgrade_detail['revert_all_themes'] > 0) { $db->drop_table("themes"); $db->write_query("CREATE TABLE ".TABLE_PREFIX."themes ( tid smallint unsigned NOT NULL auto_increment, name varchar(100) NOT NULL default '', pid smallint unsigned NOT NULL default '0', def smallint(1) NOT NULL default '0', properties text NOT NULL, stylesheets text NOT NULL, allowedgroups text NOT NULL, PRIMARY KEY (tid) ) ENGINE=MyISAM{$charset};");
$db->drop_table("themestylesheets"); $db->write_query("CREATE TABLE ".TABLE_PREFIX."themestylesheets( sid int unsigned NOT NULL auto_increment, name varchar(30) NOT NULL default '', tid int unsigned NOT NULL default '0', attachedto text NOT NULL, stylesheet text NOT NULL, cachefile varchar(100) NOT NULL default '', lastmodified bigint(30) NOT NULL default '0', PRIMARY KEY(sid) ) ENGINE=MyISAM{$charset};");
/** * Update the settings */ function buildsettings() { global $db, $output, $system_upgrade_detail, $lang;
if(!is_writable(MYBB_ROOT."inc/settings.php")) { $output->print_header("Rebuilding Settings"); echo "<p><div class=\"error\"><span style=\"color: red; font-weight: bold;\">Error: Unable to open inc/settings.php</span><h3>Before the upgrade process can continue, you need to changes the permissions of inc/settings.php so it is writable.</h3></div></p>"; $output->print_footer("rebuildsettings"); exit; } $synccount = sync_settings($system_upgrade_detail['revert_all_settings']);
// Rebuild inc/settings.php at the end of the upgrade if(function_exists('rebuild_settings')) { rebuild_settings(); } else { $options = array( "order_by" => "title", "order_dir" => "ASC" );
/** * Determine the next function we need to call * * @param int $from * @param string $func * * @return string */ function next_function($from, $func="dbchanges") { global $oldvers, $system_upgrade_detail, $currentscript, $cache;
load_module("upgrade".$from.".php"); if(function_exists("upgrade".$from."_".$func)) { $function = "upgrade".$from."_".$func; } else { // We're done with our last upgrade script, so add it to the upgrade scripts we've already completed. $version_history = $cache->read("version_history"); $version_history[$from] = $from; $cache->update("version_history", $version_history);
/** * @param int $redo 2 means that all setting tables will be dropped and recreated * * @return array */ function sync_settings($redo=0) { global $db;
$settingcount = $groupcount = 0; $settings = $settinggroups = array(); if($redo == 2) { $db->drop_table("settinggroups"); switch($db->type) { case "pgsql": $db->write_query("CREATE TABLE ".TABLE_PREFIX."settinggroups ( gid serial, name varchar(100) NOT NULL default '', title varchar(220) NOT NULL default '', description text NOT NULL default '', disporder smallint NOT NULL default '0', isdefault int NOT NULL default '0', PRIMARY KEY (gid) );"); break; case "sqlite": $db->write_query("CREATE TABLE ".TABLE_PREFIX."settinggroups ( gid INTEGER PRIMARY KEY, name varchar(100) NOT NULL default '', title varchar(220) NOT NULL default '', description TEXT NOT NULL, disporder smallint NOT NULL default '0', isdefault int(1) NOT NULL default '0' );"); break; case "mysql": default: $db->write_query("CREATE TABLE ".TABLE_PREFIX."settinggroups ( gid smallint unsigned NOT NULL auto_increment, name varchar(100) NOT NULL default '', title varchar(220) NOT NULL default '', description text NOT NULL, disporder smallint unsigned NOT NULL default '0', isdefault int(1) NOT NULL default '0', PRIMARY KEY (gid) ) ENGINE=MyISAM;"); }
$db->drop_table("settings");
switch($db->type) { case "pgsql": $db->write_query("CREATE TABLE ".TABLE_PREFIX."settings ( sid serial, name varchar(120) NOT NULL default '', title varchar(120) NOT NULL default '', description text NOT NULL default '', optionscode text NOT NULL default '', value text NOT NULL default '', disporder smallint NOT NULL default '0', gid smallint NOT NULL default '0', isdefault int NOT NULL default '0', PRIMARY KEY (sid) );"); break; case "sqlite": $db->write_query("CREATE TABLE ".TABLE_PREFIX."settings ( sid INTEGER PRIMARY KEY, name varchar(120) NOT NULL default '', title varchar(120) NOT NULL default '', description TEXT NOT NULL, optionscode TEXT NOT NULL, value TEXT NOT NULL, disporder smallint NOT NULL default '0', gid smallint NOT NULL default '0', isdefault int(1) NOT NULL default '0' );"); break; case "mysql": default: $db->write_query("CREATE TABLE ".TABLE_PREFIX."settings ( sid smallint unsigned NOT NULL auto_increment, name varchar(120) NOT NULL default '', title varchar(120) NOT NULL default '', description text NOT NULL, optionscode text NOT NULL, value text NOT NULL, disporder smallint unsigned NOT NULL default '0', gid smallint unsigned NOT NULL default '0', isdefault int(1) NOT NULL default '0', PRIMARY KEY (sid) ) ENGINE=MyISAM;"); } } else { if($db->type == "mysql" || $db->type == "mysqli") { $wheresettings = "isdefault='1' OR isdefault='yes'"; } else { $wheresettings = "isdefault='1'"; }