function UpgradeOptions() { global $db_prefix, $command_line, $modSettings, $is_debug, $smcFunc; global $boarddir, $boardurl, $sourcedir, $maintenance, $mmessage, $cachedir, $upcontext, $db_type; $upcontext['sub_template'] = 'upgrade_options'; $upcontext['page_title'] = 'Upgrade Options'; // If we've not submitted then we're done. if (empty($_POST['upcont'])) { return false; } // Firstly, if they're enabling SM stat collection just do it. if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats'])) { // Attempt to register the site etc. $fp = @fsockopen('www.simplemachines.org', 80, $errno, $errstr); if ($fp) { $out = 'GET /smf/stats/register_stats.php?site=' . base64_encode($boardurl) . ' HTTP/1.1' . "\r\n"; $out .= 'Host: www.simplemachines.org' . "\r\n"; $out .= 'Connection: Close' . "\r\n\r\n"; fwrite($fp, $out); $return_data = ''; while (!feof($fp)) { $return_data .= fgets($fp, 128); } fclose($fp); // Get the unique site ID. preg_match('~SITE-ID:\\s(\\w{10})~', $return_data, $ID); if (!empty($ID[1])) { $smcFunc['db_insert']('replace', $db_prefix . 'settings', array('variable' => 'string', 'value' => 'string'), array('allow_sm_stats', $ID[1]), array('variable')); } } } else { $smcFunc['db_query']('', ' DELETE FROM {db_prefix}settings WHERE variable = {string:allow_sm_stats}', array('allow_sm_stats' => 'allow_sm_stats', 'db_error_skip' => true)); } // Emptying the error log? if (!empty($_POST['empty_error'])) { $smcFunc['db_query']('truncate_table', ' TRUNCATE {db_prefix}log_errors', array()); } $changes = array(); // If we're overriding the language follow it through. if (isset($_GET['lang']) && file_exists($boarddir . '/Themes/default/languages/index.' . $_GET['lang'] . '.php')) { $changes['language'] = '\'' . $_GET['lang'] . '\''; } if (!empty($_POST['maint'])) { $changes['maintenance'] = '2'; // Remember what it was... $upcontext['user']['main'] = $maintenance; if (!empty($_POST['maintitle'])) { $changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\''; $changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\''; } else { $changes['mtitle'] = '\'Upgrading the forum...\''; $changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum. It will only be a minute ;).\''; } } if ($command_line) { echo ' * Updating Settings.php...'; } // Backup the current one first. copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php'); // Fix some old paths. if (substr($boarddir, 0, 1) == '.') { $changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\''; } if (substr($sourcedir, 0, 1) == '.') { $changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\''; } if (empty($cachedir) || substr($cachedir, 0, 1) == '.') { $changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\''; } // Not had the database type added before? if (empty($db_type)) { $changes['db_type'] = 'mysql'; } // !!! Maybe change the cookie name if going to 1.1, too? // Update Settings.php with the new settings. changeSettings($changes); if ($command_line) { echo ' Successful.' . "\n"; } // Are we doing debug? if (isset($_POST['debug'])) { $upcontext['upgrade_status']['debug'] = true; $is_debug = true; } // If we're not backing up then jump one. if (empty($_POST['backup'])) { $upcontext['current_step']++; } // If we've got here then let's proceed to the next step! return true; }
/** * Step 1: Do the maintenance and backup. */ function action_upgradeOptions() { global $command_line, $modSettings, $is_debug, $maintenance, $upcontext, $db_type; $upcontext['sub_template'] = 'upgrade_options'; $upcontext['page_title'] = 'Upgrade Options'; // If we've not submitted then we're done. if (empty($_POST['upcont'])) { return false; } // Get hold of our db $db = database(); // No one opts in so why collect incomplete stats $db->query('', ' DELETE FROM {db_prefix}settings WHERE variable = {string:allow_sm_stats}', array('allow_sm_stats' => 'allow_sm_stats', 'db_error_skip' => true)); // Cleanup all the hooks (we are upgrading, so better have everything cleaned up) $db->query('', ' DELETE FROM {db_prefix}settings WHERE variable = {string:integrate}', array('integrate' => 'integrate_%', 'db_error_skip' => true)); // Emptying the error log? if (!empty($_POST['empty_error'])) { $db->query('truncate_table', ' TRUNCATE {db_prefix}log_errors', array()); } $changes = array(); // If we're overriding the language follow it through. if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/' . $_GET['lang'] . '/index.' . $_GET['lang'] . '.php')) { $changes['language'] = '\'' . $_GET['lang'] . '\''; } if (!empty($_POST['maint'])) { $changes['maintenance'] = '2'; // Remember what it was... $upcontext['user']['main'] = $maintenance; if (!empty($_POST['maintitle'])) { $changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\''; $changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\''; } else { $changes['mtitle'] = '\'Upgrading the forum...\''; $changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum. It will only be a minute ;).\''; } } if ($command_line) { echo ' * Updating Settings.php...'; } // Backup the current one first. copy(BOARDDIR . '/Settings.php', BOARDDIR . '/Settings_bak.php'); // Fix some old paths. if (substr(BOARDDIR, 0, 1) == '.') { $changes['boarddir'] = '\'' . fixRelativePath(BOARDDIR) . '\''; } if (substr(SOURCEDIR, 0, 1) == '.') { $changes['sourcedir'] = '\'' . fixRelativePath(SOURCEDIR) . '\''; } if (!defined('CACHEDIR') || substr(CACHEDIR, 0, 1) == '.') { $changes['cachedir'] = '\'' . fixRelativePath(BOARDDIR) . '/cache\''; } // Not had the database type added before? if (empty($db_type)) { $changes['db_type'] = 'mysql'; } // Update Settings.php with the new settings. changeSettings($changes); if ($command_line) { echo ' Successful.' . "\n"; } // Are we doing debug? if (isset($_POST['debug'])) { $upcontext['upgrade_status']['debug'] = true; $is_debug = true; } // If we're not backing up then jump one. if (empty($_POST['backup'])) { $upcontext['current_step']++; } // If we've got here then let's proceed to the next step! return true; }
function doStep1() { global $db_prefix, $command_line, $modSettings; global $boarddir, $boardurl, $sourcedir, $maintenance; // Firstly, if they're enabling SM stat collection just do it. if (!empty($_REQUEST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats'])) { // Attempt to register the site etc. $fp = @fsockopen("www.simplemachines.org", 80, $errno, $errstr); if ($fp) { $out = "GET /smf/stats/register_stats.php?site=" . base64_encode($boardurl) . " HTTP/1.1\r\n"; $out .= "Host: www.simplemachines.org\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); $return_data = ''; while (!feof($fp)) { $return_data .= fgets($fp, 128); } fclose($fp); // Get the unique site ID. preg_match('~SITE-ID:\\s(\\w{10})~', $return_data, $ID); if (!empty($ID[1])) { upgrade_query("\n\t\t\t\t\tREPLACE INTO {$db_prefix}settings\n\t\t\t\t\t\t(variable, value)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t('allow_sm_stats', '{$ID['1']}')"); } } } else { upgrade_query("\n\t\t\tDELETE FROM {$db_prefix}settings\n\t\t\tWHERE variable = 'allow_sm_stats'"); } $endl = $command_line ? "\n" : '<br />' . "\n"; $changes = array(); if (isset($_GET['lang'])) { $changes['language'] = '\'english\''; } if (!empty($_GET['maint'])) { $changes['maintenance'] = '2'; $changes['mtitle'] = '\'Upgrading the forum...\''; $changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum. It will only be a minute ;).\''; } echo $command_line ? ' * ' : '', 'Updating Settings.php...'; copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php'); if (substr($boarddir, 0, 1) == '.') { $changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\''; } if (substr($sourcedir, 0, 1) == '.') { $changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\''; } // !!! Maybe change the cookie name if going to 1.1, too? // Update Settings.php with the new settings. changeSettings($changes); echo ' Successful.', $endl; if (!empty($_GET['backup']) || isset($_GET['t'])) { echo $command_line ? ' * ' : 'Backing up old table data...'; if (preg_match('~^`(.+?)`\\.(.+?)$~', $db_prefix, $match) != 0) { $result = upgrade_query("\n\t\t\t\tSHOW TABLES\n\t\t\t\tFROM `" . strtr($match[1], array('`' => '')) . "`\n\t\t\t\tLIKE '" . str_replace('_', '\\_', $match[2]) . "%'"); } else { $result = upgrade_query("\n\t\t\t\tSHOW TABLES\n\t\t\t\tLIKE '" . str_replace('_', '\\_', $db_prefix) . "%'"); } $table_names = array(); while ($row = mysql_fetch_row($result)) { if (substr($row[0], 0, 7) !== 'backup_') { $table_names[] = $row[0]; } } mysql_free_result($result); for ($substep = $_GET['substep'], $n = count($table_names); $substep < $n; $substep++) { nextSubstep($substep); if (!empty($_GET['debug'])) { if ($command_line) { echo $endl, ' +++ Backing up "' . str_replace($db_prefix, '', $table_names[$substep]) . '"...'; } else { echo '<br /> ', 'Backing up "' . str_replace($db_prefix, '', $table_names[$substep]) . '"...'; } flush(); } $result = upgrade_query("\n\t\t\t\tSHOW CREATE TABLE " . $table_names[$substep]); list(, $create) = mysql_fetch_row($result); mysql_free_result($result); $create = preg_split('/[\\n\\r]/', $create); $auto_inc = ''; // Default engine type. $engine = 'MyISAM'; $charset = ''; $collate = ''; foreach ($create as $k => $l) { // Get the name of the auto_increment column. if (strpos($l, 'auto_increment')) { $auto_inc = trim($l); } // For the engine type, see if we can work out what it is. if (strpos($l, 'ENGINE') !== false || strpos($l, 'TYPE') !== false) { // Extract the engine type. preg_match('~(ENGINE|TYPE)=(\\w+)(\\sDEFAULT)?(\\sCHARSET=(\\w+))?(\\sCOLLATE=(\\w+))?~', $l, $match); if (!empty($match[2])) { $engine = $match[2]; } if (!empty($match[5])) { $charset = $match[5]; } if (!empty($match[7])) { $collate = $match[7]; } } // Skip everything but keys... if (strpos($l, 'KEY') === false) { unset($create[$k]); } } if (!empty($create)) { $create = '( ' . implode(' ', $create) . ')'; } else { $create = ''; } upgrade_query("\n\t\t\t\tDROP TABLE IF EXISTS backup_" . $table_names[$substep]); upgrade_query("\n\t\t\t\tCREATE TABLE backup_" . $table_names[$substep] . " {$create}\n\t\t\t\tTYPE={$engine}" . (empty($charset) ? '' : " CHARACTER SET {$charset}" . (empty($collate) ? '' : " COLLATE {$collate}")) . "\n\t\t\t\tSELECT *\n\t\t\t\tFROM " . $table_names[$substep]); if ($auto_inc != '') { if (preg_match('~\\`(.+?)\\`\\s~', $auto_inc, $match) != 0 && substr($auto_inc, -1, 1) == ',') { $auto_inc = substr($auto_inc, 0, -1); } upgrade_query("\n\t\t\t\t\tALTER TABLE backup_" . $table_names[$substep] . "\n\t\t\t\t\tCHANGE COLUMN {$match['1']} {$auto_inc}"); } if (!empty($_GET['debug'])) { echo ' done.'; } } if (!empty($_GET['debug'])) { echo $endl; flush(); } echo ' Successful.', $endl; } $_GET['substep'] = 0; return doStep2(); }