From 71ca8a524a8b04d8db7da547a69882e5b96dc007 Mon Sep 17 00:00:00 2001 From: moparisthebest Date: Sun, 9 Feb 2014 19:28:18 -0600 Subject: [PATCH] delete upgrade files --- upgrade.php | 4528 ----------------------------------------- upgrade_1-0.sql | 2017 ------------------ upgrade_1-1.sql | 2655 ------------------------ upgrade_2-0_mysql.sql | 3166 ---------------------------- 4 files changed, 12366 deletions(-) delete mode 100644 upgrade.php delete mode 100644 upgrade_1-0.sql delete mode 100644 upgrade_1-1.sql delete mode 100644 upgrade_2-0_mysql.sql diff --git a/upgrade.php b/upgrade.php deleted file mode 100644 index 8395201..0000000 --- a/upgrade.php +++ /dev/null @@ -1,4528 +0,0 @@ - array( - 'name' => 'MySQL', - 'version' => '4.0.18', - 'version_check' => 'return min(mysql_get_server_info(), mysql_get_client_info());', - 'utf8_support' => true, - 'utf8_version' => '4.1.0', - 'utf8_version_check' => 'return mysql_get_server_info();', - 'alter_support' => true, - ), - 'postgresql' => array( - 'name' => 'PostgreSQL', - 'version' => '8.0', - 'version_check' => '$version = pg_version(); return $version[\'client\'];', - 'always_has_db' => true, - ), - 'sqlite' => array( - 'name' => 'SQLite', - 'version' => '1', - 'version_check' => 'return 1;', - 'always_has_db' => true, - ), -); - -// General options for the script. -$timeLimitThreshold = 3; -$upgrade_path = dirname(__FILE__); -$upgradeurl = $_SERVER['PHP_SELF']; -// Where the SMF images etc are kept. -$smfsite = 'http://www.simplemachines.org/smf'; -// Disable the need for admins to login? -$disable_security = 0; -// How long, in seconds, must admin be inactive to allow someone else to run? -$upcontext['inactive_timeout'] = 10; - -// All the steps in detail. -// Number,Name,Function,Progress Weight. -$upcontext['steps'] = array( - 0 => array(1, 'Login', 'WelcomeLogin', 2), - 1 => array(2, 'Upgrade Options', 'UpgradeOptions', 2), - 2 => array(3, 'Backup', 'BackupDatabase', 10), - 3 => array(4, 'Database Changes', 'DatabaseChanges', 70), - // This is removed as it doesn't really work right at the moment. - //4 => array(5, 'Cleanup Mods', 'CleanupMods', 10), - 4 => array(5, 'Delete Upgrade', 'DeleteUpgrade', 1), -); -// Just to remember which one has files in it. -$upcontext['database_step'] = 3; -@set_time_limit(600); -// Clean the upgrade path if this is from the client. -if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) - for ($i = 1; $i < $_SERVER['argc']; $i++) - { - if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) - $upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1]; - } - -// Are we from the client? -if (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) -{ - $command_line = true; - $disable_security = 1; -} -else - $command_line = false; - -// Load this now just because we can. -require_once($upgrade_path . '/Settings.php'); - -// Are we logged in? -if (isset($upgradeData)) -{ - $upcontext['user'] = unserialize(base64_decode($upgradeData)); - - // Check for sensible values. - if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) - $upcontext['user']['started'] = time(); - if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) - $upcontext['user']['updated'] = 0; - - $upcontext['started'] = $upcontext['user']['started']; - $upcontext['updated'] = $upcontext['user']['updated']; -} - -// Nothing sensible? -if (empty($upcontext['updated'])) -{ - $upcontext['started'] = time(); - $upcontext['updated'] = 0; - $upcontext['user'] = array( - 'id' => 0, - 'name' => 'Guest', - 'pass' => 0, - 'started' => $upcontext['started'], - 'updated' => $upcontext['updated'], - ); -} - -// Load up some essential data... -loadEssentialData(); - -// Are we going to be mimic'ing SSI at this point? -if (isset($_GET['ssi'])) -{ - require_once($sourcedir . '/Subs.php'); - require_once($sourcedir . '/Errors.php'); - require_once($sourcedir . '/Load.php'); - require_once($sourcedir . '/Security.php'); - require_once($sourcedir . '/Subs-Package.php'); - - loadUserSettings(); - loadPermissions(); -} - -// All the non-SSI stuff. -if (!function_exists('ip2range')) - require_once($sourcedir . '/Subs.php'); - -if (!function_exists('un_htmlspecialchars')) -{ - function un_htmlspecialchars($string) - { - return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES)) + array(''' => '\'', ' ' => ' ')); - } -} - -if (!function_exists('text2words')) -{ - function text2words($text) - { - global $smcFunc; - - // Step 1: Remove entities/things we don't consider words: - $words = preg_replace('~(?:[\x0B\0\xA0\t\r\s\n(){}\\[\\]<>!@$%^*.,:+=`\~\?/\\\\]+|&(?:amp|lt|gt|quot);)+~', ' ', $text); - - // Step 2: Entities we left to letters, where applicable, lowercase. - $words = preg_replace('~([^&\d]|^)[#;]~', '$1 ', un_htmlspecialchars(strtolower($words))); - - // Step 3: Ready to split apart and index! - $words = explode(' ', $words); - $returned_words = array(); - foreach ($words as $word) - { - $word = trim($word, '-_\''); - - if ($word != '') - $returned_words[] = substr($word, 0, 20); - } - - return array_unique($returned_words); - } -} - -if (!function_exists('clean_cache')) -{ - // Empty out the cache folder. - function clean_cache($type = '') - { - global $cachedir, $sourcedir; - - // No directory = no game. - if (!is_dir($cachedir)) - return; - - // Remove the files in SMF's own disk cache, if any - $dh = opendir($cachedir); - while ($file = readdir($dh)) - { - if ($file != '.' && $file != '..' && $file != 'index.php' && $file != '.htaccess' && (!$type || substr($file, 0, strlen($type)) == $type)) - @unlink($cachedir . '/' . $file); - } - closedir($dh); - - // Invalidate cache, to be sure! - // ... as long as Load.php can be modified, anyway. - @touch($sourcedir . '/' . 'Load.php'); - clearstatcache(); - } -} - -// MD5 Encryption. -if (!function_exists('md5_hmac')) -{ - function md5_hmac($data, $key) - { - if (strlen($key) > 64) - $key = pack('H*', md5($key)); - $key = str_pad($key, 64, chr(0x00)); - - $k_ipad = $key ^ str_repeat(chr(0x36), 64); - $k_opad = $key ^ str_repeat(chr(0x5c), 64); - - return md5($k_opad . pack('H*', md5($k_ipad . $data))); - } -} - -// http://www.faqs.org/rfcs/rfc959.html -if (!class_exists('ftp_connection')) -{ - class ftp_connection - { - var $connection = 'no_connection', $error = false, $last_message, $pasv = array(); - - // Create a new FTP connection... - function ftp_connection($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous', $ftp_pass = 'ftpclient@simplemachines.org') - { - if ($ftp_server !== null) - $this->connect($ftp_server, $ftp_port, $ftp_user, $ftp_pass); - } - - function connect($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous', $ftp_pass = 'ftpclient@simplemachines.org') - { - if (substr($ftp_server, 0, 6) == 'ftp://') - $ftp_server = substr($ftp_server, 6); - elseif (substr($ftp_server, 0, 7) == 'ftps://') - $ftp_server = 'ssl://' . substr($ftp_server, 7); - if (substr($ftp_server, 0, 7) == 'http://') - $ftp_server = substr($ftp_server, 7); - $ftp_server = strtr($ftp_server, array('/' => '', ':' => '', '@' => '')); - - // Connect to the FTP server. - $this->connection = @fsockopen($ftp_server, $ftp_port, $err, $err, 5); - if (!$this->connection) - { - $this->error = 'bad_server'; - return; - } - - // Get the welcome message... - if (!$this->check_response(220)) - { - $this->error = 'bad_response'; - return; - } - - // Send the username, it should ask for a password. - fwrite($this->connection, 'USER ' . $ftp_user . "\r\n"); - if (!$this->check_response(331)) - { - $this->error = 'bad_username'; - return; - } - - // Now send the password... and hope it goes okay. - fwrite($this->connection, 'PASS ' . $ftp_pass . "\r\n"); - if (!$this->check_response(230)) - { - $this->error = 'bad_password'; - return; - } - } - - function chdir($ftp_path) - { - if (!is_resource($this->connection)) - return false; - - // No slash on the end, please... - if (substr($ftp_path, -1) == '/' && $ftp_path !== '/') - $ftp_path = substr($ftp_path, 0, -1); - - fwrite($this->connection, 'CWD ' . $ftp_path . "\r\n"); - if (!$this->check_response(250)) - { - $this->error = 'bad_path'; - return false; - } - - return true; - } - - function chmod($ftp_file, $chmod) - { - if (!is_resource($this->connection)) - return false; - - // Convert the chmod value from octal (0777) to text ("777"). - fwrite($this->connection, 'SITE CHMOD ' . decoct($chmod) . ' ' . $ftp_file . "\r\n"); - if (!$this->check_response(200)) - { - $this->error = 'bad_file'; - return false; - } - - return true; - } - - function unlink($ftp_file) - { - // We are actually connected, right? - if (!is_resource($this->connection)) - return false; - - // Delete file X. - fwrite($this->connection, 'DELE ' . $ftp_file . "\r\n"); - if (!$this->check_response(250)) - { - fwrite($this->connection, 'RMD ' . $ftp_file . "\r\n"); - - // Still no love? - if (!$this->check_response(250)) - { - $this->error = 'bad_file'; - return false; - } - } - - return true; - } - - function check_response($desired) - { - // Wait for a response that isn't continued with -, but don't wait too long. - $time = time(); - do - $this->last_message = fgets($this->connection, 1024); - while (substr($this->last_message, 3, 1) != ' ' && time() - $time < 5); - - // Was the desired response returned? - return is_array($desired) ? in_array(substr($this->last_message, 0, 3), $desired) : substr($this->last_message, 0, 3) == $desired; - } - - function passive() - { - // We can't create a passive data connection without a primary one first being there. - if (!is_resource($this->connection)) - return false; - - // Request a passive connection - this means, we'll talk to you, you don't talk to us. - @fwrite($this->connection, 'PASV' . "\r\n"); - $time = time(); - do - $response = fgets($this->connection, 1024); - while (substr($response, 3, 1) != ' ' && time() - $time < 5); - - // If it's not 227, we weren't given an IP and port, which means it failed. - if (substr($response, 0, 4) != '227 ') - { - $this->error = 'bad_response'; - return false; - } - - // Snatch the IP and port information, or die horribly trying... - if (preg_match('~\((\d+),\s*(\d+),\s*(\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+))\)~', $response, $match) == 0) - { - $this->error = 'bad_response'; - return false; - } - - // This is pretty simple - store it for later use ;). - $this->pasv = array('ip' => $match[1] . '.' . $match[2] . '.' . $match[3] . '.' . $match[4], 'port' => $match[5] * 256 + $match[6]); - - return true; - } - - function create_file($ftp_file) - { - // First, we have to be connected... very important. - if (!is_resource($this->connection)) - return false; - - // I'd like one passive mode, please! - if (!$this->passive()) - return false; - - // Seems logical enough, so far... - fwrite($this->connection, 'STOR ' . $ftp_file . "\r\n"); - - // Okay, now we connect to the data port. If it doesn't work out, it's probably "file already exists", etc. - $fp = @fsockopen($this->pasv['ip'], $this->pasv['port'], $err, $err, 5); - if (!$fp || !$this->check_response(150)) - { - $this->error = 'bad_file'; - @fclose($fp); - return false; - } - - // This may look strange, but we're just closing it to indicate a zero-byte upload. - fclose($fp); - if (!$this->check_response(226)) - { - $this->error = 'bad_response'; - return false; - } - - return true; - } - - function list_dir($ftp_path = '', $search = false) - { - // Are we even connected...? - if (!is_resource($this->connection)) - return false; - - // Passive... non-agressive... - if (!$this->passive()) - return false; - - // Get the listing! - fwrite($this->connection, 'LIST -1' . ($search ? 'R' : '') . ($ftp_path == '' ? '' : ' ' . $ftp_path) . "\r\n"); - - // Connect, assuming we've got a connection. - $fp = @fsockopen($this->pasv['ip'], $this->pasv['port'], $err, $err, 5); - if (!$fp || !$this->check_response(array(150, 125))) - { - $this->error = 'bad_response'; - @fclose($fp); - return false; - } - - // Read in the file listing. - $data = ''; - while (!feof($fp)) - $data .= fread($fp, 4096); - fclose($fp); - - // Everything go okay? - if (!$this->check_response(226)) - { - $this->error = 'bad_response'; - return false; - } - - return $data; - } - - function locate($file, $listing = null) - { - if ($listing === null) - $listing = $this->list_dir('', true); - $listing = explode("\n", $listing); - - @fwrite($this->connection, 'PWD' . "\r\n"); - $time = time(); - do - $response = fgets($this->connection, 1024); - while (substr($response, 3, 1) != ' ' && time() - $time < 5); - - // Check for 257! - if (preg_match('~^257 "(.+?)" ~', $response, $match) != 0) - $current_dir = strtr($match[1], array('""' => '"')); - else - $current_dir = ''; - - for ($i = 0, $n = count($listing); $i < $n; $i++) - { - if (trim($listing[$i]) == '' && isset($listing[$i + 1])) - { - $current_dir = substr(trim($listing[++$i]), 0, -1); - $i++; - } - - // Okay, this file's name is: - $listing[$i] = $current_dir . '/' . trim(strlen($listing[$i]) > 30 ? strrchr($listing[$i], ' ') : $listing[$i]); - - if (substr($file, 0, 1) == '*' && substr($listing[$i], -(strlen($file) - 1)) == substr($file, 1)) - return $listing[$i]; - if (substr($file, -1) == '*' && substr($listing[$i], 0, strlen($file) - 1) == substr($file, 0, -1)) - return $listing[$i]; - if (basename($listing[$i]) == $file || $listing[$i] == $file) - return $listing[$i]; - } - - return false; - } - - function create_dir($ftp_dir) - { - // We must be connected to the server to do something. - if (!is_resource($this->connection)) - return false; - - // Make this new beautiful directory! - fwrite($this->connection, 'MKD ' . $ftp_dir . "\r\n"); - if (!$this->check_response(257)) - { - $this->error = 'bad_file'; - return false; - } - - return true; - } - - function detect_path($filesystem_path, $lookup_file = null) - { - $username = ''; - - if (isset($_SERVER['DOCUMENT_ROOT'])) - { - if (preg_match('~^/home[2]?/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match)) - { - $username = $match[1]; - - $path = strtr($_SERVER['DOCUMENT_ROOT'], array('/home/' . $match[1] . '/' => '', '/home2/' . $match[1] . '/' => '')); - - if (substr($path, -1) == '/') - $path = substr($path, 0, -1); - - if (strlen(dirname($_SERVER['PHP_SELF'])) > 1) - $path .= dirname($_SERVER['PHP_SELF']); - } - elseif (substr($filesystem_path, 0, 9) == '/var/www/') - $path = substr($filesystem_path, 8); - else - $path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => '')); - } - else - $path = ''; - - if (is_resource($this->connection) && $this->list_dir($path) == '') - { - $data = $this->list_dir('', true); - - if ($lookup_file === null) - $lookup_file = $_SERVER['PHP_SELF']; - - $found_path = dirname($this->locate('*' . basename(dirname($lookup_file)) . '/' . basename($lookup_file), $data)); - if ($found_path == false) - $found_path = dirname($this->locate(basename($lookup_file))); - if ($found_path != false) - $path = $found_path; - } - elseif (is_resource($this->connection)) - $found_path = true; - - return array($username, $path, isset($found_path)); - } - - function close() - { - // Goodbye! - fwrite($this->connection, 'QUIT' . "\r\n"); - fclose($this->connection); - - return true; - } - } -} - -// Don't do security check if on Yabbse -if (!isset($modSettings['smfVersion'])) - $disable_security = true; - -// This only exists if we're on SMF ;) -if (isset($modSettings['smfVersion'])) -{ - $request = $smcFunc['db_query']('', ' - SELECT variable, value - FROM {db_prefix}themes - WHERE id_theme = {int:id_theme} - AND variable IN ({string:theme_url}, {string:theme_dir}, {string:images_url})', - array( - 'id_theme' => 1, - 'theme_url' => 'theme_url', - 'theme_dir' => 'theme_dir', - 'images_url' => 'images_url', - 'db_error_skip' => true, - ) - ); - while ($row = $smcFunc['db_fetch_assoc']($request)) - $modSettings[$row['variable']] = $row['value']; - $smcFunc['db_free_result']($request); -} - -if (!isset($modSettings['theme_url'])) -{ - $modSettings['theme_dir'] = $boarddir . '/Themes/default'; - $modSettings['theme_url'] = 'Themes/default'; - $modSettings['images_url'] = 'Themes/default/images'; -} -if (!isset($settings['default_theme_url'])) - $settings['default_theme_url'] = $modSettings['theme_url']; -if (!isset($settings['default_theme_dir'])) - $settings['default_theme_dir'] = $modSettings['theme_dir']; - -$upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000; -// Default title... -$upcontext['page_title'] = isset($modSettings['smfVersion']) ? 'Updating Your SMF Install!' : 'Upgrading from YaBB SE!'; - -$upcontext['right_to_left'] = isset($txt['lang_rtl']) ? $txt['lang_rtl'] : false; - -// Have we got tracking data - if so use it (It will be clean!) -if (isset($_GET['data'])) -{ - $upcontext['upgrade_status'] = unserialize(base64_decode($_GET['data'])); - $upcontext['current_step'] = $upcontext['upgrade_status']['curstep']; - $upcontext['language'] = $upcontext['upgrade_status']['lang']; - $upcontext['rid'] = $upcontext['upgrade_status']['rid']; - $is_debug = $upcontext['upgrade_status']['debug']; - $support_js = $upcontext['upgrade_status']['js']; - - // Load the language. - if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) - require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); -} -// Set the defaults. -else -{ - $upcontext['current_step'] = 0; - $upcontext['rid'] = mt_rand(0, 5000); - $upcontext['upgrade_status'] = array( - 'curstep' => 0, - 'lang' => isset($_GET['lang']) ? $_GET['lang'] : basename($language, '.lng'), - 'rid' => $upcontext['rid'], - 'pass' => 0, - 'debug' => 0, - 'js' => 0, - ); - $upcontext['language'] = $upcontext['upgrade_status']['lang']; -} - -// If this isn't the first stage see whether they are logging in and resuming. -if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) - checkLogin(); - -if ($command_line) - cmdStep0(); - -// Don't error if we're using xml. -if (isset($_GET['xml'])) - $upcontext['return_error'] = true; - -// These three checks are necessary to workaround an issue with the upgrade stucking when encountering a db error -if (!isset($context)) -{ - $context = Array(); - $context['error'] = ''; - if (!isset($txt['database_error'])) - $txt['database_error'] = 'Database Error'; -} - -if (!function_exists('allowedTo')) -{ - function allowedTo($p,$b) - { - return true; - } -} - -if (!function_exists('fatal_error')) -{ - function fatal_error($error,$log) - { - return ($error); - } -} - -// Loop through all the steps doing each one as required. -$upcontext['overall_percent'] = 0; -foreach ($upcontext['steps'] as $num => $step) -{ - if ($num >= $upcontext['current_step']) - { - // The current weight of this step in terms of overall progress. - $upcontext['step_weight'] = $step[3]; - // Make sure we reset the skip button. - $upcontext['skip'] = false; - - // We cannot proceed if we're not logged in. - if ($num != 0 && !$disable_security && $upcontext['user']['pass'] != $upcontext['upgrade_status']['pass']) - { - $upcontext['steps'][0][2](); - break; - } - - // Call the step and if it returns false that means pause! - if (function_exists($step[2]) && $step[2]() === false) - break; - elseif (function_exists($step[2])) - $upcontext['current_step']++; - } - $upcontext['overall_percent'] += $step[3]; -} - -upgradeExit(); - -// Exit the upgrade script. -function upgradeExit($fallThrough = false) -{ - global $upcontext, $upgradeurl, $boarddir, $command_line; - - // Save where we are... - if (!empty($upcontext['current_step']) && !empty($upcontext['user']['id'])) - { - $upcontext['user']['step'] = $upcontext['current_step']; - $upcontext['user']['substep'] = $_GET['substep']; - $upcontext['user']['updated'] = time(); - $upgradeData = base64_encode(serialize($upcontext['user'])); - copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php'); - changeSettings(array('upgradeData' => '"' . $upgradeData . '"')); - } - - // Handle the progress of the step, if any. - if (!empty($upcontext['step_progress']) && isset($upcontext['steps'][$upcontext['current_step']])) - { - $upcontext['step_progress'] = round($upcontext['step_progress'], 1); - $upcontext['overall_percent'] += $upcontext['step_progress'] * ($upcontext['steps'][$upcontext['current_step']][3] / 100); - } - $upcontext['overall_percent'] = (int) $upcontext['overall_percent']; - - // We usually dump our templates out. - if (!$fallThrough) - { - // This should not happen my dear... HELP ME DEVELOPERS!! - if (!empty($command_line)) - { - if (function_exists('debug_print_backtrace')) - debug_print_backtrace(); - - echo "\n" . 'Error: Unexpected call to use the ' . (isset($upcontext['sub_template']) ? $upcontext['sub_template'] : '') . ' template. Please copy and paste all the text above and visit the SMF support forum to tell the Developers that they\'ve made a boo boo; they\'ll get you up and running again.'; - flush(); - die(); - } - - if (!isset($_GET['xml'])) - template_upgrade_above(); - else - { - header('Content-Type: text/xml; charset=ISO-8859-1'); - // Sadly we need to retain the $_GET data thanks to the old upgrade scripts. - $upcontext['get_data'] = array(); - foreach ($_GET as $k => $v) - { - if (substr($k, 0, 3) != 'amp' && !in_array($k, array('xml', 'substep', 'lang', 'data', 'step', 'filecount'))) - { - $upcontext['get_data'][$k] = $v; - } - } - template_xml_above(); - } - - // Call the template. - if (isset($upcontext['sub_template'])) - { - $upcontext['upgrade_status']['curstep'] = $upcontext['current_step']; - $upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&substep=' . $_GET['substep'] . '&data=' . base64_encode(serialize($upcontext['upgrade_status'])); - - // Custom stuff to pass back? - if (!empty($upcontext['query_string'])) - $upcontext['form_url'] .= $upcontext['query_string']; - - call_user_func('template_' . $upcontext['sub_template']); - } - - // Was there an error? - if (!empty($upcontext['forced_error_message'])) - echo $upcontext['forced_error_message']; - - // Show the footer. - if (!isset($_GET['xml'])) - template_upgrade_below(); - else - template_xml_below(); - } - - // Bang - gone! - die(); -} - -// Used to direct the user to another location. -function redirectLocation($location, $addForm = true) -{ - global $upgradeurl, $upcontext, $command_line; - - // Command line users can't be redirected. - if ($command_line) - upgradeExit(true); - - // Are we providing the core info? - if ($addForm) - { - $upcontext['upgrade_status']['curstep'] = $upcontext['current_step']; - $location = $upgradeurl . '?step=' . $upcontext['current_step'] . '&substep=' . $_GET['substep'] . '&data=' . base64_encode(serialize($upcontext['upgrade_status'])) . $location; - } - - while (@ob_end_clean()); - header('Location: ' . strtr($location, array('&' => '&'))); - - // Exit - saving status as we go. - upgradeExit(true); -} - -// Load all essential data and connect to the DB as this is pre SSI.php -function loadEssentialData() -{ - global $db_server, $db_user, $db_passwd, $db_name, $db_connection, $db_prefix, $db_character_set, $db_type; - global $modSettings, $sourcedir, $smcFunc, $upcontext; - - // Do the non-SSI stuff... - @set_magic_quotes_runtime(0); - error_reporting(E_ALL); - define('SMF', 1); - - // Start the session. - if (@ini_get('session.save_handler') == 'user') - @ini_set('session.save_handler', 'files'); - @session_start(); - - if (empty($smcFunc)) - $smcFunc = array(); - - // Check we don't need some compatibility. - if (@version_compare(PHP_VERSION, '5') == -1) - require_once($sourcedir . '/Subs-Compat.php'); - - // Initialize everything... - initialize_inputs(); - - // Get the database going! - if (empty($db_type)) - $db_type = 'mysql'; - if (file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) - { - require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); - - // Make the connection... - $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true)); - - // Oh dear god!! - if ($db_connection === null) - die('Unable to connect to database - please check username and password are correct in Settings.php'); - - if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) - $smcFunc['db_query']('', ' - SET NAMES ' . $db_character_set, - array( - 'db_error_skip' => true, - ) - ); - - // Load the modSettings data... - $request = $smcFunc['db_query']('', ' - SELECT variable, value - FROM {db_prefix}settings', - array( - 'db_error_skip' => true, - ) - ); - $modSettings = array(); - while ($row = $smcFunc['db_fetch_assoc']($request)) - $modSettings[$row['variable']] = $row['value']; - $smcFunc['db_free_result']($request); - } - else - { - return throw_error('Cannot find ' . $sourcedir . '/Subs-Db-' . $db_type . '.php' . '. Please check you have uploaded all source files and have the correct paths set.'); - } - - // If they don't have the file, they're going to get a warning anyway so we won't need to clean request vars. - if (file_exists($sourcedir . '/QueryString.php')) - { - require_once($sourcedir . '/QueryString.php'); - cleanRequest(); - } - - if (!isset($_GET['substep'])) - $_GET['substep'] = 0; -} - -function initialize_inputs() -{ - global $sourcedir, $start_time, $upcontext, $db_type; - - $start_time = time(); - - umask(0); - - // Fun. Low PHP version... - if (!isset($_GET)) - { - $GLOBALS['_GET']['step'] = 0; - return; - } - - ob_start(); - - // Better to upgrade cleanly and fall apart than to screw everything up if things take too long. - ignore_user_abort(true); - - // This is really quite simple; if ?delete is on the URL, delete the upgrader... - if (isset($_GET['delete'])) - { - @unlink(__FILE__); - - // And the extra little files ;). - @unlink(dirname(__FILE__) . '/upgrade_1-0.sql'); - @unlink(dirname(__FILE__) . '/upgrade_1-1.sql'); - @unlink(dirname(__FILE__) . '/webinstall.php'); - - $dh = opendir(dirname(__FILE__)); - while ($file = readdir($dh)) - { - if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) - @unlink(dirname(__FILE__) . '/' . $file); - } - closedir($dh); - - header('Location: http://' . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']) . dirname($_SERVER['PHP_SELF']) . '/Themes/default/images/blank.gif'); - exit; - } - - // Are we calling the backup css file? - if (isset($_GET['infile_css'])) - { - header('Content-Type: text/css'); - template_css(); - exit; - } - - // Anybody home? - if (!isset($_GET['xml'])) - { - $upcontext['remote_files_available'] = false; - $test = @fsockopen('www.simplemachines.org', 80, $errno, $errstr, 1); - if ($test) - $upcontext['remote_files_available'] = true; - @fclose($test); - } - - // Something is causing this to happen, and it's annoying. Stop it. - $temp = 'upgrade_php?step'; - while (strlen($temp) > 4) - { - if (isset($_GET[$temp])) - unset($_GET[$temp]); - $temp = substr($temp, 1); - } - - // Force a step, defaulting to 0. - $_GET['step'] = (int) @$_GET['step']; - $_GET['substep'] = (int) @$_GET['substep']; -} - -// Step 0 - Let's welcome them in and ask them to login! -function WelcomeLogin() -{ - global $boarddir, $sourcedir, $db_prefix, $language, $modSettings, $cachedir, $upgradeurl, $upcontext, $disable_security; - global $smcFunc, $db_type, $databases, $txt; - - $upcontext['sub_template'] = 'welcome_message'; - - // Check for some key files - one template, one language, and a new and an old source file. - $check = @file_exists($modSettings['theme_dir'] . '/index.template.php') - && @file_exists($sourcedir . '/QueryString.php') - && @file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php') - && @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql'); - - // Need legacy scripts? - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) - $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql'); - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) - $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql'); - - if (!$check) - // Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb. - return throw_error('The upgrader was unable to find some crucial files.

Please make sure you uploaded all of the files included in the package, including the Themes, Sources, and other directories.'); - - // Do they meet the install requirements? - if (!php_version_check()) - return throw_error('Warning! You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.

Please ask your host to upgrade.'); - - if (!db_version_check()) - return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.

Please ask your host to upgrade.'); - - // Do they have ALTER privileges? - if (!empty($databases[$db_type]['alter_support']) && $smcFunc['db_query']('alter_boards', 'ALTER TABLE {db_prefix}boards ORDER BY id_board', array()) === false) - return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.

Please ask your host to give this user the ALTER, CREATE, and DROP privileges.'); - - // Do a quick version spot check. - $temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096); - preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match); - if (empty($match[1]) || $match[1] != SMF_VERSION) - return throw_error('The upgrader found some old or outdated files.

Please make certain you uploaded the new versions of all the files included in the package.'); - - // What absolutely needs to be writable? - $writable_files = array( - $boarddir . '/Settings.php', - $boarddir . '/Settings_bak.php', - ); - - // Check the cache directory. - $cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir; - if (!file_exists($cachedir_temp)) - @mkdir($cachedir_temp); - if (!file_exists($cachedir_temp)) - return throw_error('The cache directory could not be found.

Please make sure you have a directory called "cache" in your forum directory before continuing.'); - - if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) - return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.
SMF will not work without the primary language files installed.

Please either install them, or use english instead.'); - elseif (!isset($_GET['skiplang'])) - { - $temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096); - preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match); - - if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) - return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.

Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.
   [SKIP] [Try English]'); - } - - // This needs to exist! - if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) - return throw_error('The upgrader could not find the "Install" language file for the forum default language, ' . $upcontext['language'] . '.

Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.
   [Try English]'); - else - require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); - - if (!makeFilesWritable($writable_files)) - return false; - - // Check agreement.txt. (it may not exist, in which case $boarddir must be writable.) - if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) - return throw_error('The upgrader was unable to obtain write access to agreement.txt.

If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.
If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.'); - - // Upgrade the agreement. - elseif (isset($modSettings['agreement'])) - { - $fp = fopen($boarddir . '/agreement.txt', 'w'); - fwrite($fp, $modSettings['agreement']); - fclose($fp); - } - - // We're going to check that their board dir setting is right incase they've been moving stuff around. - if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) - $upcontext['warning'] = ' - It looks as if your board directory settings might be incorrect. Your board directory is currently set to "' . $boarddir . '" but should probably be "' . dirname(__FILE__) . '". Settings.php currently lists your paths as:
- - If these seem incorrect please open Settings.php in a text editor before proceeding with this upgrade. If they are incorrect due to you moving your forum to a new location please download and execute the Repair Settings tool from the Simple Machines website before continuing.'; - - // Either we're logged in or we're going to present the login. - if (checkLogin()) - return true; - - return false; -} - -// Step 0.5: Does the login work? -function checkLogin() -{ - global $boarddir, $sourcedir, $db_prefix, $language, $modSettings, $cachedir, $upgradeurl, $upcontext, $disable_security; - global $smcFunc, $db_type, $databases, $support_js, $txt; - - // Are we trying to login? - if (isset($_POST['contbutt']) && (!empty($_POST['user']) || $disable_security)) - { - // If we've disabled security pick a suitable name! - if (empty($_POST['user'])) - $_POST['user'] = 'Administrator'; - - // Before 2.0 these column names were different! - $oldDB = false; - if (empty($db_type) || $db_type == 'mysql') - { - $request = $smcFunc['db_query']('', ' - SHOW COLUMNS - FROM {db_prefix}members - LIKE {string:member_name}', - array( - 'member_name' => 'memberName', - 'db_error_skip' => true, - ) - ); - if ($smcFunc['db_num_rows']($request) != 0) - $oldDB = true; - $smcFunc['db_free_result']($request); - } - - // Get what we believe to be their details. - if (!$disable_security) - { - if ($oldDB) - $request = $smcFunc['db_query']('', ' - SELECT id_member, memberName AS member_name, passwd, id_group, - additionalGroups AS additional_groups, lngfile - FROM {db_prefix}members - WHERE memberName = {string:member_name}', - array( - 'member_name' => $_POST['user'], - 'db_error_skip' => true, - ) - ); - else - $request = $smcFunc['db_query']('', ' - SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile - FROM {db_prefix}members - WHERE member_name = {string:member_name}', - array( - 'member_name' => $_POST['user'], - 'db_error_skip' => true, - ) - ); - if ($smcFunc['db_num_rows']($request) != 0) - { - list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request); - - $groups = explode(',', $addGroups); - $groups[] = $id_group; - - foreach ($groups as $k => $v) - $groups[$k] = (int) $v; - - // Figure out the password using SMF's encryption - if what they typed is right. - if (isset($_REQUEST['hash_passwrd']) && strlen($_REQUEST['hash_passwrd']) == 40) - { - // Challenge passed. - if ($_REQUEST['hash_passwrd'] == sha1($password . $upcontext['rid'])) - $sha_passwd = $password; - } - else - $sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd'])); - } - else - $upcontext['username_incorrect'] = true; - $smcFunc['db_free_result']($request); - } - $upcontext['username'] = $_POST['user']; - - // Track whether javascript works! - if (!empty($_POST['js_works'])) - { - $upcontext['upgrade_status']['js'] = 1; - $support_js = 1; - } - else - $support_js = 0; - - // Note down the version we are coming from. - if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) - $upcontext['user']['version'] = $modSettings['smfVersion']; - - // Didn't get anywhere? - if ((empty($sha_passwd) || $password != $sha_passwd) && empty($upcontext['username_incorrect']) && !$disable_security) - { - // MD5? - $md5pass = md5_hmac($_REQUEST['passwrd'], strtolower($_POST['user'])); - if ($md5pass != $password) - { - $upcontext['password_failed'] = true; - // Disable the hashing this time. - $upcontext['disable_login_hashing'] = true; - } - } - - if ((empty($upcontext['password_failed']) && !empty($name)) || $disable_security) - { - // Set the password. - if (!$disable_security) - { - // Do we actually have permission? - if (!in_array(1, $groups)) - { - $request = $smcFunc['db_query']('', ' - SELECT permission - FROM {db_prefix}permissions - WHERE id_group IN ({array_int:groups}) - AND permission = {string:admin_forum}', - array( - 'groups' => $groups, - 'admin_forum' => 'admin_forum', - 'db_error_skip' => true, - ) - ); - if ($smcFunc['db_num_rows']($request) == 0) - return throw_error('You need to be an admin to perform an upgrade!'); - $smcFunc['db_free_result']($request); - } - - $upcontext['user']['id'] = $id_member; - $upcontext['user']['name'] = $name; - } - else - { - $upcontext['user']['id'] = 1; - $upcontext['user']['name'] = 'Administrator'; - } - $upcontext['user']['pass'] = mt_rand(0,60000); - // This basically is used to match the GET variables to Settings.php. - $upcontext['upgrade_status']['pass'] = $upcontext['user']['pass']; - - // Set the language to that of the user? - if (isset($user_language) && $user_language != $upcontext['language'] && file_exists($modSettings['theme_dir'] . '/languages/index.' . basename($user_language, '.lng') . '.php')) - { - $user_language = basename($user_language, '.lng'); - $temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096); - preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match); - - if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) - $upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.'; - elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) - $upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the "Install" language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.'; - else - { - // Set this as the new language. - $upcontext['language'] = $user_language; - $upcontext['upgrade_status']['lang'] = $upcontext['language']; - - // Include the file. - require_once($modSettings['theme_dir'] . '/languages/Install.' . $user_language . '.php'); - } - } - - // If we're resuming set the step and substep to be correct. - if (isset($_POST['cont'])) - { - $upcontext['current_step'] = $upcontext['user']['step']; - $_GET['substep'] = $upcontext['user']['substep']; - } - - return true; - } - } - - return false; -} - -// Step 1: Do the maintenance and backup. -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($modSettings['theme_dir'] . '/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; -} - -// Backup the database - why not... -function BackupDatabase() -{ - global $upcontext, $db_prefix, $command_line, $is_debug, $support_js, $file_steps, $smcFunc; - - $upcontext['sub_template'] = isset($_GET['xml']) ? 'backup_xml' : 'backup_database'; - $upcontext['page_title'] = 'Backup Database'; - - // Done it already - js wise? - if (!empty($_POST['backup_done'])) - return true; - - // Some useful stuff here. - db_extend(); - - // Get all the table names. - $filter = str_replace('_', '\_', preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) != 0 ? $match[2] : $db_prefix) . '%'; - $db = preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) != 0 ? strtr($match[1], array('`' => '')) : false; - $tables = $smcFunc['db_list_tables']($db, $filter); - - $table_names = array(); - foreach ($tables as $table) - if (substr($table, 0, 7) !== 'backup_') - $table_names[] = $table; - - $upcontext['table_count'] = count($table_names); - $upcontext['cur_table_num'] = $_GET['substep']; - $upcontext['cur_table_name'] = str_replace($db_prefix, '', isset($table_names[$_GET['substep']]) ? $table_names[$_GET['substep']] : $table_names[0]); - $upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100); - // For non-java auto submit... - $file_steps = $upcontext['table_count']; - - // What ones have we already done? - foreach ($table_names as $id => $table) - if ($id < $_GET['substep']) - $upcontext['previous_tables'][] = $table; - - if ($command_line) - echo 'Backing Up Tables.'; - - // If we don't support javascript we backup here. - if (!$support_js || isset($_GET['xml'])) - { - // Backup each table! - for ($substep = $_GET['substep'], $n = count($table_names); $substep < $n; $substep++) - { - $upcontext['cur_table_name'] = str_replace($db_prefix, '', (isset($table_names[$substep + 1]) ? $table_names[$substep + 1] : $table_names[$substep])); - $upcontext['cur_table_num'] = $substep + 1; - - $upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100); - - // Do we need to pause? - nextSubstep($substep); - - backupTable($table_names[$substep]); - - // If this is XML to keep it nice for the user do one table at a time anyway! - if (isset($_GET['xml'])) - return upgradeExit(); - } - - if ($is_debug && $command_line) - { - echo "\n" . ' Successful.\'' . "\n"; - flush(); - } - $upcontext['step_progress'] = 100; - - $_GET['substep'] = 0; - // Make sure we move on! - return true; - } - - // Either way next place to post will be database changes! - $_GET['substep'] = 0; - return false; -} - -// Backup one table... -function backupTable($table) -{ - global $is_debug, $command_line, $db_prefix, $smcFunc; - - if ($is_debug && $command_line) - { - echo "\n" . ' +++ Backing up \"' . str_replace($db_prefix, '', $table) . '"...'; - flush(); - } - - $smcFunc['db_backup_table']($table, 'backup_' . $table); - - if ($is_debug && $command_line) - echo ' done.'; -} - -// Step 2: Everything. -function DatabaseChanges() -{ - global $db_prefix, $modSettings, $command_line, $smcFunc; - global $language, $boardurl, $sourcedir, $boarddir, $upcontext, $support_js, $db_type; - - // Have we just completed this? - if (!empty($_POST['database_done'])) - return true; - - $upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes'; - $upcontext['page_title'] = 'Database Changes'; - - // All possible files. - // Name, 'string', 'value' => 'string'), - array('smfVersion', $file[2]), - array('variable') - ); - - $modSettings['smfVersion'] = $file[2]; - } - - // If this is XML we only do this stuff once. - if (isset($_GET['xml'])) - { - // Flag to move on to the next. - $upcontext['completed_step'] = true; - // Did we complete the whole file? - if ($nextFile) - $upcontext['current_debug_item_num'] = -1; - return upgradeExit(); - } - elseif ($support_js) - break; - } - // Set the progress bar to be right as if we had - even if we hadn't... - $upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100; - } - } - - $_GET['substep'] = 0; - // So the template knows we're done. - if (!$support_js) - { - $upcontext['changes_complete'] = true; - - // If this is the command line we can't do any more. - if ($command_line) - return DeleteUpgrade(); - - return true; - } - return false; -} - -// Clean up any mods installed... -function CleanupMods() -{ - global $db_prefix, $modSettings, $upcontext, $boarddir, $sourcedir, $settings, $smcFunc, $command_line; - - // Sorry. Not supported for command line users. - if ($command_line) - return true; - - // Skipping first? - if (!empty($_POST['skip'])) - { - unset($_POST['skip']); - return true; - } - - // If we get here withOUT SSI we need to redirect to ensure we get it! - if (!isset($_GET['ssi']) || !function_exists('mktree')) - redirectLocation('&ssi=1'); - - $upcontext['sub_template'] = 'clean_mods'; - $upcontext['page_title'] = 'Cleanup Modifications'; - - // This can be skipped. - $upcontext['skip'] = true; - - // If we're on the second redirect continue... - if (isset($_POST['cleandone2'])) - return true; - - // Do we already know about some writable files? - if (isset($_POST['writable_files'])) - { - $writable_files = unserialize(base64_decode($_POST['writable_files'])); - if (!makeFilesWritable($writable_files)) - { - // What have we left? - $upcontext['writable_files'] = $writable_files; - return false; - } - } - - // Load all theme paths.... - $request = $smcFunc['db_query']('', ' - SELECT id_theme, variable, value - FROM {db_prefix}themes - WHERE id_member = {int:id_member} - AND variable IN ({string:theme_dir}, {string:images_url})', - array( - 'id_member' => 0, - 'theme_dir' => 'theme_dir', - 'images_url' => 'images_url', - 'db_error_skip' => true, - ) - ); - $theme_paths = array(); - while ($row = $smcFunc['db_fetch_assoc']($request)) - { - if ($row['id_theme'] == 1) - $settings['default_' . $row['variable']] = $row['value']; - elseif ($row['variable'] == 'theme_dir') - $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; - } - $smcFunc['db_free_result']($request); - - // Are there are mods installed that may need uninstalling? - $request = $smcFunc['db_query']('', ' - SELECT id_install, filename, name, themes_installed, version - FROM {db_prefix}log_packages - WHERE install_state = {int:installed} - ORDER BY time_installed DESC', - array( - 'installed' => 1, - 'db_error_skip' => true, - ) - ); - $upcontext['packages'] = array(); - while ($row = $smcFunc['db_fetch_assoc']($request)) - { - // Work out the status. - if (!file_exists($boarddir . '/Packages/' . $row['filename'])) - { - $status = 'Missing'; - $status_color = 'red'; - $result = 'Removed'; - } - else - { - $status = 'Installed'; - $status_color = 'green'; - $result = 'No Action Needed'; - } - - $upcontext['packages'][$row['id_install']] = array( - 'id' => $row['id_install'], - 'themes' => explode(',', $row['themes_installed']), - 'name' => $row['name'], - 'filename' => $row['filename'], - 'missing_file' => file_exists($boarddir . '/Packages/' . $row['filename']) ? 0 : 1, - 'files' => array(), - 'file_count' => 0, - 'status' => $status, - 'result' => $result, - 'color' => $status_color, - 'version' => $row['version'], - 'needs_removing' => false, - ); - } - $smcFunc['db_free_result']($request); - - // Don't carry on if there are none. - if (empty($upcontext['packages'])) - return true; - - // Setup some basics. - if (!empty($upcontext['user']['version'])) - $_SESSION['version_emulate'] = $upcontext['user']['version']; - - // Before we get started, don't report notice errors. - $oldErrorReporting = error_reporting(E_ALL ^ E_NOTICE); - - if (!mktree($boarddir . '/Packages/temp', 0755)) - { - deltree($boarddir . '/Packages/temp', false); - if (!mktree($boarddir . '/Packages/temp', 0777)) - { - deltree($boarddir . '/Packages/temp', false); - //!!! Error here - plus chmod! - } - } - - // Anything which reinstalled should not have its entry removed. - $reinstall_worked = array(); - - // We're gonna be doing some removin' - $test = isset($_POST['cleandone']) ? false : true; - foreach ($upcontext['packages'] as $id => $package) - { - // Can't do anything about this.... - if ($package['missing_file']) - continue; - - // Not testing *and* this wasn't checked? - if (!$test && (!isset($_POST['remove']) || !isset($_POST['remove'][$id]))) - continue; - - // What are the themes this was installed into? - $cur_theme_paths = array(); - foreach ($theme_paths as $tid => $data) - if ($tid != 1 && in_array($tid, $package['themes'])) - $cur_theme_paths[$tid] = $data; - - // Get the modifications data if applicable. - $filename = $package['filename']; - $packageInfo = getPackageInfo($filename); - if (!is_array($packageInfo)) - continue; - - $info = parsePackageInfo($packageInfo['xml'], $test, 'uninstall'); - // Also get the reinstall details... - if (isset($_POST['remove'])) - $infoInstall = parsePackageInfo($packageInfo['xml'], true); - - if (is_file($boarddir . '/Packages/' . $filename)) - read_tgz_file($boarddir . '/Packages/' . $filename, $boarddir . '/Packages/temp'); - else - copytree($boarddir . '/Packages/' . $filename, $boarddir . '/Packages/temp'); - - // Work out how we uninstall... - $files = array(); - foreach ($info as $change) - { - // Work out two things: - // 1) Whether it's installed at the moment - and if so whether its fully installed, and: - // 2) Whether it could be installed on the new version. - if ($change['type'] == 'modification') - { - $contents = @file_get_contents($boarddir . '/Packages/temp/' . $upcontext['base_path'] . $change['filename']); - if ($change['boardmod']) - $results = parseBoardMod($contents, $test, $change['reverse'], $cur_theme_paths); - else - $results = parseModification($contents, $test, $change['reverse'], $cur_theme_paths); - - foreach ($results as $action) - { - // Something we can remove? Probably means it existed! - if (($action['type'] == 'replace' || $action['type'] == 'append' || (!empty($action['filename']) && $action['type'] == 'failure')) && !in_array($action['filename'], $files)) - $files[] = $action['filename']; - if ($action['type'] == 'failure') - { - $upcontext['packages'][$id]['needs_removing'] = true; - $upcontext['packages'][$id]['status'] = 'Reinstall Required'; - $upcontext['packages'][$id]['color'] = '#FD6435'; - } - } - } - } - - // Store this info for the template as appropriate. - $upcontext['packages'][$id]['files'] = $files; - $upcontext['packages'][$id]['file_count'] = count($files); - - // If we've done something save the changes! - if (!$test) - package_flush_cache(); - - // Are we attempting to reinstall this thing? - if (isset($_POST['remove']) && !$test && isset($infoInstall)) - { - // Need to extract again I'm afraid. - if (is_file($boarddir . '/Packages/' . $filename)) - read_tgz_file($boarddir . '/Packages/' . $filename, $boarddir . '/Packages/temp'); - else - copytree($boarddir . '/Packages/' . $filename, $boarddir . '/Packages/temp'); - - $errors = false; - $upcontext['packages'][$id]['result'] = 'Removed'; - foreach ($infoInstall as $change) - { - if ($change['type'] == 'modification') - { - $contents = @file_get_contents($boarddir . '/Packages/temp/' . $upcontext['base_path'] . $change['filename']); - if ($change['boardmod']) - $results = parseBoardMod($contents, true, $change['reverse'], $cur_theme_paths); - else - $results = parseModification($contents, true, $change['reverse'], $cur_theme_paths); - - // Are there any errors? - foreach ($results as $action) - if ($action['type'] == 'failure') - $errors = true; - } - } - if (!$errors) - { - $reinstall_worked[] = $id; - $upcontext['packages'][$id]['result'] = 'Reinstalled'; - $upcontext['packages'][$id]['color'] = 'green'; - foreach ($infoInstall as $change) - { - if ($change['type'] == 'modification') - { - $contents = @file_get_contents($boarddir . '/Packages/temp/' . $upcontext['base_path'] . $change['filename']); - if ($change['boardmod']) - $results = parseBoardMod($contents, false, $change['reverse'], $cur_theme_paths); - else - $results = parseModification($contents, false, $change['reverse'], $cur_theme_paths); - } - } - - // Save the changes. - package_flush_cache(); - } - } - } - - // Put errors back on a sec. - error_reporting($oldErrorReporting); - - // Check everything is writable. - if ($test && !empty($upcontext['packages'])) - { - $writable_files = array(); - foreach ($upcontext['packages'] as $package) - { - if (!empty($package['files'])) - foreach ($package['files'] as $file) - $writable_files[] = $file; - } - - if (!empty($writable_files)) - { - $writable_files = array_unique($writable_files); - $upcontext['writable_files'] = $writable_files; - - if (!makeFilesWritable($writable_files)) - return false; - } - } - - if (file_exists($boarddir . '/Packages/temp')) - deltree($boarddir . '/Packages/temp'); - - // Removing/Reinstalling any packages? - if (isset($_POST['remove'])) - { - $deletes = array(); - foreach ($_POST['remove'] as $id => $dummy) - { - if (!in_array((int) $id, $reinstall_worked)) - $deletes[] = (int) $id; - } - - if (!empty($deletes)) - upgrade_query( ' - UPDATE ' . $db_prefix . 'log_packages - SET install_state = 0 - WHERE id_install IN (' . implode(',', $deletes) . ')'); - - // Ensure we don't lose our changes! - package_put_contents($boarddir . '/Packages/installed.list', time()); - - $upcontext['sub_template'] = 'cleanup_done'; - return false; - } - else - { - $allgood = true; - // Is there actually anything that needs our attention? - foreach ($upcontext['packages'] as $package) - if ($package['color'] != 'green') - $allgood = false; - - if ($allgood) - return true; - } - - $_GET['substep'] = 0; - return isset($_POST['cleandone']) ? true : false; -} - - -// Delete the damn thing! -function DeleteUpgrade() -{ - global $command_line, $language, $upcontext, $boarddir, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type; - - // Now it's nice to have some of the basic SMF source files. - if (!isset($_GET['ssi']) && !$command_line) - redirectLocation('&ssi=1'); - - $upcontext['sub_template'] = 'upgrade_complete'; - $upcontext['page_title'] = 'Upgrade Complete'; - - $endl = $command_line ? "\n" : '
' . "\n"; - - $changes = array( - 'language' => '\'' . (substr($language, -4) == '.lng' ? substr($language, 0, -4) : $language) . '\'', - 'db_error_send' => '1', - 'upgradeData' => '#remove#', - ); - - // Are we in maintenance mode? - if (isset($upcontext['user']['main'])) - { - if ($command_line) - echo ' * '; - $upcontext['removed_maintenance'] = true; - $changes['maintenance'] = $upcontext['user']['main']; - } - // Otherwise if somehow we are in 2 let's go to 1. - elseif (!empty($maintenance) && $maintenance == 2) - $changes['maintenance'] = 1; - - // Wipe this out... - $upcontext['user'] = array(); - - // Make a backup of Settings.php first as otherwise earlier changes are lost. - copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php'); - changeSettings($changes); - - // Clean any old cache files away. - clean_cache(); - - // Can we delete the file? - $upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__); - - // Now is the perfect time to fetch the SM files. - if ($command_line) - cli_scheduled_fetchSMfiles(); - else - { - require_once($sourcedir . '/ScheduledTasks.php'); - $forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us. - scheduled_fetchSMfiles(); // Now go get those files! - } - - // Log what we've done. - if (empty($user_info['id'])) - $user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0; - - // Log the action manually, so CLI still works. - $smcFunc['db_insert']('', - '{db_prefix}log_actions', - array( - 'log_time' => 'int', 'id_log' => 'int', 'id_member' => 'int', 'ip' => 'string-16', 'action' => 'string', - 'id_board' => 'int', 'id_topic' => 'int', 'id_msg' => 'int', 'extra' => 'string-65534', - ), - array( - time(), 3, $user_info['id'], $command_line ? '127.0.0.1' : $user_info['ip'], 'upgrade', - 0, 0, 0, serialize(array('version' => $forum_version, 'member' => $user_info['id'])), - ), - array('id_action') - ); - $user_info['id'] = 0; - - // Save the current database version. - $server_version = $smcFunc['db_server_info'](); - if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) - updateSettings(array('db_mysql_group_by_fix' => '1')); - - if ($command_line) - { - echo $endl; - echo 'Upgrade Complete!', $endl; - echo 'Please delete this file as soon as possible for security reasons.', $endl; - exit; - } - - // Make sure it says we're done. - $upcontext['overall_percent'] = 100; - if (isset($upcontext['step_progress'])) - unset($upcontext['step_progress']); - - $_GET['substep'] = 0; - return false; -} - -// Just like the built in one, but setup for CLI to not use themes. -function cli_scheduled_fetchSMfiles() -{ - global $sourcedir, $txt, $language, $settings, $forum_version, $modSettings, $smcFunc; - - if (empty($modSettings['time_format'])) - $modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p'; - - // What files do we want to get - $request = $smcFunc['db_query']('', ' - SELECT id_file, filename, path, parameters - FROM {db_prefix}admin_info_files', - array( - ) - ); - - $js_files = array(); - while ($row = $smcFunc['db_fetch_assoc']($request)) - { - $js_files[$row['id_file']] = array( - 'filename' => $row['filename'], - 'path' => $row['path'], - 'parameters' => sprintf($row['parameters'], $language, urlencode($modSettings['time_format']), urlencode($forum_version)), - ); - } - $smcFunc['db_free_result']($request); - - // We're gonna need fetch_web_data() to pull this off. - require_once($sourcedir . '/Subs-Package.php'); - - foreach ($js_files as $ID_FILE => $file) - { - // Create the url - $server = empty($file['path']) || substr($file['path'], 0, 7) != 'http://' ? 'http://www.simplemachines.org' : ''; - $url = $server . (!empty($file['path']) ? $file['path'] : $file['path']) . $file['filename'] . (!empty($file['parameters']) ? '?' . $file['parameters'] : ''); - - // Get the file - $file_data = fetch_web_data($url); - - // If we got an error - give up - the site might be down. - if ($file_data === false) - return throw_error(sprintf('Could not retrieve the file %1$s.', $url)); - - // Save the file to the database. - $smcFunc['db_query']('substring', ' - UPDATE {db_prefix}admin_info_files - SET data = SUBSTRING({string:file_data}, 1, 65534) - WHERE id_file = {int:id_file}', - array( - 'id_file' => $ID_FILE, - 'file_data' => $file_data, - ) - ); - } - return true; -} - -function convertSettingsToTheme() -{ - global $db_prefix, $modSettings, $smcFunc; - - $values = array( - 'show_latest_member' => @$GLOBALS['showlatestmember'], - 'show_bbc' => isset($GLOBALS['showyabbcbutt']) ? $GLOBALS['showyabbcbutt'] : @$GLOBALS['showbbcbutt'], - 'show_modify' => @$GLOBALS['showmodify'], - 'show_user_images' => @$GLOBALS['showuserpic'], - 'show_blurb' => @$GLOBALS['showusertext'], - 'show_gender' => @$GLOBALS['showgenderimage'], - 'show_newsfader' => @$GLOBALS['shownewsfader'], - 'display_recent_bar' => @$GLOBALS['Show_RecentBar'], - 'show_member_bar' => @$GLOBALS['Show_MemberBar'], - 'linktree_link' => @$GLOBALS['curposlinks'], - 'show_profile_buttons' => @$GLOBALS['profilebutton'], - 'show_mark_read' => @$GLOBALS['showmarkread'], - 'show_board_desc' => @$GLOBALS['ShowBDescrip'], - 'newsfader_time' => @$GLOBALS['fadertime'], - 'use_image_buttons' => empty($GLOBALS['MenuType']) ? 1 : 0, - 'enable_news' => @$GLOBALS['enable_news'], - 'linktree_inline' => @$modSettings['enableInlineLinks'], - 'return_to_post' => @$modSettings['returnToPost'], - ); - - $themeData = array(); - foreach ($values as $variable => $value) - { - if (!isset($value) || $value === null) - $value = 0; - - $themeData[] = array(0, 1, $variable, $value); - } - if (!empty($themeData)) - { - $smcFunc['db_insert']('ignore', - $db_prefix . 'themes', - array('id_member' => 'int', 'id_theme' => 'int', 'variable' => 'string', 'value' => 'string'), - $themeData, - array('id_member', 'id_theme', 'variable') - ); - } -} - -// This function only works with MySQL but that's fine as it is only used for v1.0. -function convertSettingstoOptions() -{ - global $db_prefix, $modSettings, $smcFunc; - - // Format: new_setting -> old_setting_name. - $values = array( - 'calendar_start_day' => 'cal_startmonday', - 'view_newest_first' => 'viewNewestFirst', - 'view_newest_pm_first' => 'viewNewestFirst', - ); - - foreach ($values as $variable => $value) - { - if (empty($modSettings[$value[0]])) - continue; - - $smcFunc['db_query']('', ' - INSERT IGNORE INTO {db_prefix}themes - (id_member, id_theme, variable, value) - SELECT id_member, 1, {string:variable}, {string:value} - FROM {db_prefix}members', - array( - 'variable' => $variable, - 'value' => $modSettings[$value[0]], - 'db_error_skip' => true, - ) - ); - - $smcFunc['db_query']('', ' - INSERT IGNORE INTO {db_prefix}themes - (id_member, id_theme, variable, value) - VALUES (-1, 1, {string:variable}, {string:value})', - array( - 'variable' => $variable, - 'value' => $modSettings[$value[0]], - 'db_error_skip' => true, - ) - ); - } -} - -function changeSettings($config_vars) -{ - global $boarddir; - - $settingsArray = file($boarddir . '/Settings_bak.php'); - - if (count($settingsArray) == 1) - $settingsArray = preg_split('~[\r\n]~', $settingsArray[0]); - - for ($i = 0, $n = count($settingsArray); $i < $n; $i++) - { - // Don't trim or bother with it if it's not a variable. - if (substr($settingsArray[$i], 0, 1) == '$') - { - $settingsArray[$i] = trim($settingsArray[$i]) . "\n"; - - foreach ($config_vars as $var => $val) - { - if (isset($settingsArray[$i]) && strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) - { - if ($val == '#remove#') - unset($settingsArray[$i]); - else - { - $comment = strstr(substr($settingsArray[$i], strpos($settingsArray[$i], ';')), '#'); - $settingsArray[$i] = '$' . $var . ' = ' . $val . ';' . ($comment != '' ? "\t\t" . $comment : "\n"); - } - - unset($config_vars[$var]); - } - } - } - if (isset($settingsArray[$i])) - { - if (trim(substr($settingsArray[$i], 0, 2)) == '?' . '>') - $end = $i; - } - } - - // Assume end-of-file if the end wasn't found. - if (empty($end) || $end < 10) - $end = count($settingsArray); - - if (!empty($config_vars)) - { - $settingsArray[$end++] = ''; - foreach ($config_vars as $var => $val) - { - if ($val != '#remove#') - $settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n"; - } - } - // This should be the last line and even last bytes of the file. - $settingsArray[$end] = '?' . '>'; - - // Blank out the file - done to fix a oddity with some servers. - $fp = fopen($boarddir . '/Settings.php', 'w'); - fclose($fp); - - $fp = fopen($boarddir . '/Settings.php', 'r+'); - for ($i = 0; $i < $end; $i++) - { - if (isset($settingsArray[$i])) - fwrite($fp, strtr($settingsArray[$i], "\r", '')); - } - fwrite($fp, rtrim($settingsArray[$i])); - fclose($fp); -} - -function php_version_check() -{ - $minver = explode('.', $GLOBALS['required_php_version']); - $curver = explode('.', PHP_VERSION); - - return !(($curver[0] <= $minver[0]) && ($curver[1] <= $minver[1]) && ($curver[1] <= $minver[1]) && ($curver[2][0] < $minver[2][0])); -} - -function db_version_check() -{ - global $db_type, $databases; - - $curver = eval($databases[$db_type]['version_check']); - $curver = preg_replace('~\-.+?$~', '', $curver); - - return version_compare($databases[$db_type]['version'], $curver) <= 0; -} - -function getMemberGroups() -{ - global $db_prefix, $smcFunc; - static $member_groups = array(); - - if (!empty($member_groups)) - return $member_groups; - - $request = $smcFunc['db_query']('', ' - SELECT group_name, id_group - FROM {db_prefix}membergroups - WHERE id_group = {int:admin_group} OR id_group > {int:old_group}', - array( - 'admin_group' => 1, - 'old_group' => 7, - 'db_error_skip' => true, - ) - ); - if ($request === false) - { - $request = $smcFunc['db_query']('', ' - SELECT membergroup, id_group - FROM {db_prefix}membergroups - WHERE id_group = {int:admin_group} OR id_group > {int:old_group}', - array( - 'admin_group' => 1, - 'old_group' => 7, - 'db_error_skip' => true, - ) - ); - } - while ($row = $smcFunc['db_fetch_row']($request)) - $member_groups[trim($row[0])] = $row[1]; - $smcFunc['db_free_result']($request); - - return $member_groups; -} - -function fixRelativePath($path) -{ - global $install_path; - - // Fix the . at the start, clear any duplicate slashes, and fix any trailing slash... - return addslashes(preg_replace(array('~^\.([/\\\]|$)~', '~[/]+~', '~[\\\]+~', '~[/\\\]$~'), array($install_path . '$1', '/', '\\', ''), $path)); -} - -function parse_sql($filename) -{ - global $db_prefix, $db_collation, $boarddir, $boardurl, $command_line, $file_steps, $step_progress, $custom_warning; - global $upcontext, $support_js, $is_debug, $smcFunc, $db_connection, $databases, $db_type, $db_character_set; - -/* - Failure allowed on: - - INSERT INTO but not INSERT IGNORE INTO. - - UPDATE IGNORE but not UPDATE. - - ALTER TABLE and ALTER IGNORE TABLE. - - DROP TABLE. - Yes, I realize that this is a bit confusing... maybe it should be done differently? - - If a comment... - - begins with --- it is to be output, with a break only in debug mode. (and say successful\n\n if there was one before.) - - begins with ---# it is a debugging statement, no break - only shown at all in debug. - - is only ---#, it is "done." and then a break - only shown in debug. - - begins with ---{ it is a code block terminating at ---}. - - Every block of between "--- ..."s is a step. Every "---#" section represents a substep. - - Replaces the following variables: - - {$boarddir} - - {$boardurl} - - {$db_prefix} - - {$db_collation} -*/ - - // May want to use extended functionality. - db_extend(); - db_extend('packages'); - - // Our custom error handler - does nothing but does stop public errors from XML! - if (!function_exists('sql_error_handler')) - { - function sql_error_handler($errno, $errstr, $errfile, $errline) - { - global $support_js; - - if ($support_js) - return true; - else - echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline; - } - } - - // Make our own error handler. - set_error_handler('sql_error_handler'); - - // If we're on MySQL supporting collations then let's find out what the members table uses and put it in a global var - to allow upgrade script to match collations! - if (!empty($databases[$db_type]['utf8_support']) && version_compare($databases[$db_type]['utf8_version'], eval($databases[$db_type]['utf8_version_check'])) != 1) - { - $request = $smcFunc['db_query']('', ' - SHOW TABLE STATUS - LIKE {string:table_name}', - array( - 'table_name' => "{$db_prefix}members", - 'db_error_skip' => true, - ) - ); - if ($smcFunc['db_num_rows']($request) === 0) - die('Unable to find members table!'); - $table_status = $smcFunc['db_fetch_assoc']($request); - $smcFunc['db_free_result']($request); - - if (!empty($table_status['Collation'])) - { - $request = $smcFunc['db_query']('', ' - SHOW COLLATION - LIKE {string:collation}', - array( - 'collation' => $table_status['Collation'], - 'db_error_skip' => true, - ) - ); - // Got something? - if ($smcFunc['db_num_rows']($request) !== 0) - $collation_info = $smcFunc['db_fetch_assoc']($request); - $smcFunc['db_free_result']($request); - - // Excellent! - if (!empty($collation_info['Collation']) && !empty($collation_info['Charset'])) - $db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation']; - } - } - if (empty($db_collation)) - $db_collation = ''; - - $endl = $command_line ? "\n" : '
' . "\n"; - - $lines = file($filename); - - $current_type = 'sql'; - $current_data = ''; - $substep = 0; - $last_step = ''; - - // Make sure all newly created tables will have the proper characters set. - if (isset($db_character_set) && $db_character_set === 'utf8') - $lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines); - - // Count the total number of steps within this file - for progress. - $file_steps = substr_count(implode('', $lines), '---#'); - $upcontext['total_items'] = substr_count(implode('', $lines), '--- '); - $upcontext['debug_items'] = $file_steps; - $upcontext['current_item_num'] = 0; - $upcontext['current_item_name'] = ''; - $upcontext['current_debug_item_num'] = 0; - $upcontext['current_debug_item_name'] = ''; - // This array keeps a record of what we've done in case java is dead... - $upcontext['actioned_items'] = array(); - - $done_something = false; - - foreach ($lines as $line_number => $line) - { - $do_current = $substep >= $_GET['substep']; - - // Get rid of any comments in the beginning of the line... - if (substr(trim($line), 0, 2) === '/*') - $line = preg_replace('~/\*.+?\*/~', '', $line); - - // Always flush. Flush, flush, flush. Flush, flush, flush, flush! FLUSH! - if ($is_debug && !$support_js && $command_line) - flush(); - - if (trim($line) === '') - continue; - - if (trim(substr($line, 0, 3)) === '---') - { - $type = substr($line, 3, 1); - - // An error?? - if (trim($current_data) != '' && $type !== '}') - { - $upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl; - if ($command_line) - echo $upcontext['error_message']; - } - - if ($type == ' ') - { - if (!$support_js && $do_current && $_GET['substep'] != 0 && $command_line) - { - echo ' Successful.', $endl; - flush(); - } - - $last_step = htmlspecialchars(rtrim(substr($line, 4))); - $upcontext['current_item_num']++; - $upcontext['current_item_name'] = $last_step; - - if ($do_current) - { - $upcontext['actioned_items'][] = $last_step; - if ($command_line) - echo ' * '; - } - } - elseif ($type == '#') - { - $upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps; - - $upcontext['current_debug_item_num']++; - if (trim($line) != '---#') - $upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4))); - - // Have we already done something? - if (isset($_GET['xml']) && $done_something) - { - restore_error_handler(); - return $upcontext['current_debug_item_num'] >= $upcontext['debug_items'] ? true : false; - } - - if ($do_current) - { - if (trim($line) == '---#' && $command_line) - echo ' done.', $endl; - elseif ($command_line) - echo ' +++ ', rtrim(substr($line, 4)); - elseif (trim($line) != '---#') - { - if ($is_debug) - $upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4))); - } - } - - if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep']) - { - if ($command_line) - echo ' * '; - else - $upcontext['actioned_items'][] = $last_step; - } - - // Small step - only if we're actually doing stuff. - if ($do_current) - nextSubstep(++$substep); - else - $substep++; - } - elseif ($type == '{') - $current_type = 'code'; - elseif ($type == '}') - { - $current_type = 'sql'; - - if (!$do_current) - { - $current_data = ''; - continue; - } - - if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false) - { - $upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl; - if ($command_line) - echo $upcontext['error_message']; - } - - // Done with code! - $current_data = ''; - $done_something = true; - } - - continue; - } - - $current_data .= $line; - if (substr(rtrim($current_data), -1) === ';' && $current_type === 'sql') - { - if ((!$support_js || isset($_GET['xml']))) - { - if (!$do_current) - { - $current_data = ''; - continue; - } - - $current_data = strtr(substr(rtrim($current_data), 0, -1), array('{$db_prefix}' => $db_prefix, '{$boarddir}' => $boarddir, '{$sboarddir}' => addslashes($boarddir), '{$boardurl}' => $boardurl, '{$db_collation}' => $db_collation)); - - upgrade_query($current_data); - - // !!! This will be how it kinda does it once mysql all stripped out - needed for postgre (etc). - /* - $result = $smcFunc['db_query']('', $current_data, false, false); - // Went wrong? - if (!$result) - { - // Bit of a bodge - do we want the error? - if (!empty($upcontext['return_error'])) - { - $upcontext['error_message'] = $smcFunc['db_error']($db_connection); - return false; - } - }*/ - $done_something = true; - } - $current_data = ''; - } - // If this is xml based and we're just getting the item name then that's grand. - elseif ($support_js && !isset($_GET['xml']) && $upcontext['current_debug_item_name'] != '' && $do_current) - { - restore_error_handler(); - return false; - } - - // Clean up by cleaning any step info. - $step_progress = array(); - $custom_warning = ''; - } - - // Put back the error handler. - restore_error_handler(); - - if ($command_line) - { - echo ' Successful.' . "\n"; - flush(); - } - - $_GET['substep'] = 0; - return true; -} - -function upgrade_query($string, $unbuffered = false) -{ - global $db_connection, $db_server, $db_user, $db_passwd, $db_type, $command_line, $upcontext, $upgradeurl, $modSettings; - global $db_name, $db_unbuffered, $smcFunc; - - // Get the query result - working around some SMF specific security - just this once! - $modSettings['disableQueryCheck'] = true; - $db_unbuffered = $unbuffered; - $result = $smcFunc['db_query']('', $string, Array('security_override'=>1,'db_error_skip'=>1)); - $db_unbuffered = false; - - // Failure?! - if ($result !== false) - return $result; - - $db_error_message = $smcFunc['db_error']($db_connection); - // If MySQL we do something more clever. - if ($db_type == 'mysql') - { - $mysql_errno = mysql_errno($db_connection); - $error_query = in_array(substr(trim($string), 0, 11), array('INSERT INTO', 'UPDATE IGNO', 'ALTER TABLE', 'DROP TABLE ', 'ALTER IGNOR')); - - // Error numbers: - // 1016: Can't open file '....MYI' - // 1050: Table already exists. - // 1054: Unknown column name. - // 1060: Duplicate column name. - // 1061: Duplicate key name. - // 1062: Duplicate entry for unique key. - // 1068: Multiple primary keys. - // 1072: Key column '%s' doesn't exist in table. - // 1091: Can't drop key, doesn't exist. - // 1146: Table doesn't exist. - // 2013: Lost connection to server during query. - - if ($mysql_errno == 1016) - { - if (preg_match('~\'([^\.\']+)~', $db_error_message, $match) != 0 && !empty($match[1])) - mysql_query( ' - REPAIR TABLE `' . $match[1] . '`'); - - $result = mysql_query($string); - if ($result !== false) - return $result; - } - elseif ($mysql_errno == 2013) - { - $db_connection = mysql_connect($db_server, $db_user, $db_passwd); - mysql_select_db($db_name, $db_connection); - - if ($db_connection) - { - $result = mysql_query($string); - - if ($result !== false) - return $result; - } - } - // Duplicate column name... should be okay ;). - elseif (in_array($mysql_errno, array(1060, 1061, 1068, 1091))) - return false; - // Duplicate insert... make sure it's the proper type of query ;). - elseif (in_array($mysql_errno, array(1054, 1062, 1146)) && $error_query) - return false; - // Creating an index on a non-existent column. - elseif ($mysql_errno == 1072) - return false; - elseif ($mysql_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') - return false; - } - // If a table already exists don't go potty. - else - { - if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I'))) - { - if (strpos($db_error_message, 'exist') !== false) - return true; - // SQLite - if (strpos($db_error_message, 'missing') !== false) - return true; - } - elseif (strpos(trim($string), 'INSERT ') !== false) - { - if (strpos($db_error_message, 'duplicate') !== false) - return true; - } - } - - // Get the query string so we pass everything. - $query_string = ''; - foreach ($_GET as $k => $v) - $query_string .= ';' . $k . '=' . $v; - if (strlen($query_string) != 0) - $query_string = '?' . substr($query_string, 1); - - if ($command_line) - { - echo 'Unsuccessful! Database error message:', "\n", $db_error_message, "\n"; - die; - } - - // Bit of a bodge - do we want the error? - if (!empty($upcontext['return_error'])) - { - $upcontext['error_message'] = $db_error_message; - return false; - } - - // Otherwise we have to display this somewhere appropriate if possible. - $upcontext['forced_error_message'] = ' - Unsuccessful!
- -
- This query: -
' . nl2br(htmlspecialchars(trim($string))) . ';
- - Caused the error: -
' . nl2br(htmlspecialchars($db_error_message)) . '
-
- -
- -
- '; - - upgradeExit(); -} - -// This performs a table alter, but does it unbuffered so the script can time out professionally. -function protected_alter($change, $substep, $is_test = false) -{ - global $db_prefix, $smcFunc; - - db_extend('packages'); - - // Firstly, check whether the current index/column exists. - $found = false; - if ($change['type'] === 'column') - { - $columns = $smcFunc['db_list_columns']('{db_prefix}' . $change['table'], true); - foreach ($columns as $column) - { - // Found it? - if ($column['name'] === $change['name']) - { - $found |= 1; - // Do some checks on the data if we have it set. - if (isset($change['col_type'])) - $found &= $change['col_type'] === $column['type']; - if (isset($change['null_allowed'])) - $found &= $column['null'] == $change['null_allowed']; - if (isset($change['default'])) - $found &= $change['default'] === $column['default']; - } - } - } - elseif ($change['type'] === 'index') - { - $request = upgrade_query( ' - SHOW INDEX - FROM ' . $db_prefix . $change['table']); - if ($request !== false) - { - $cur_index = array(); - - while ($row = $smcFunc['db_fetch_assoc']($request)) - if ($row['Key_name'] === $change['name']) - $cur_index[(int) $row['Seq_in_index']] = $row['Column_name']; - - ksort($cur_index, SORT_NUMERIC); - $found = array_values($cur_index) === $change['target_columns']; - - $smcFunc['db_free_result']($request); - } - } - - // If we're trying to add and it's added, we're done. - if ($found && in_array($change['method'], array('add', 'change'))) - return true; - // Otherwise if we're removing and it wasn't found we're also done. - elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) - return true; - // Otherwise is it just a test? - elseif ($is_test) - return false; - - // Not found it yet? Bummer! How about we see if we're currently doing it? - $running = false; - $found = false; - while (1 == 1) - { - $request = upgrade_query(' - SHOW FULL PROCESSLIST'); - while ($row = $smcFunc['db_fetch_assoc']($request)) - { - if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) - $found = true; - } - - // Can't find it? Then we need to run it fools! - if (!$found && !$running) - { - $smcFunc['db_free_result']($request); - - $success = upgrade_query(' - ALTER TABLE ' . $db_prefix . $change['table'] . ' - ' . $change['text'], true) !== false; - - if (!$success) - return false; - - // Return - $running = true; - } - // What if we've not found it, but we'd ran it already? Must of completed. - elseif (!$found) - { - $smcFunc['db_free_result']($request); - return true; - } - - // Pause execution for a sec or three. - sleep(3); - - // Can never be too well protected. - nextSubstep($substep); - } - - // Protect it. - nextSubstep($substep); -} - -// Alter a text column definition preserving its character set. -function textfield_alter($change, $substep) -{ - global $db_prefix, $databases, $db_type, $smcFunc; - - // Versions of MySQL < 4.1 wouldn't benefit from character set detection. - if (empty($databases[$db_type]['utf8_support']) || version_compare($databases[$db_type]['utf8_version'], eval($databases[$db_type]['utf8_version_check'])) > 0) - { - $column_fix = true; - $null_fix = !$change['null_allowed']; - } - else - { - $request = $smcFunc['db_query']('', ' - SHOW FULL COLUMNS - FROM {db_prefix}' . $change['table'] . ' - LIKE {string:column}', - array( - 'column' => $change['column'], - 'db_error_skip' => true, - ) - ); - if ($smcFunc['db_num_rows']($request) === 0) - die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']); - $table_row = $smcFunc['db_fetch_assoc']($request); - $smcFunc['db_free_result']($request); - - // If something of the current column definition is different, fix it. - $column_fix = $table_row['Type'] !== $change['type'] || (strtolower($table_row['Null']) === 'yes') !== $change['null_allowed'] || ($table_row['Default'] == NULL) !== !isset($change['default']) || (isset($change['default']) && $change['default'] !== $table_row['Default']); - - // Columns that previously allowed null, need to be converted first. - $null_fix = strtolower($table_row['Null']) === 'yes' && !$change['null_allowed']; - - // Get the character set that goes with the collation of the column. - if ($column_fix && !empty($table_row['Collation'])) - { - $request = $smcFunc['db_query']('', ' - SHOW COLLATION - LIKE {string:collation}', - array( - 'collation' => $table_row['Collation'], - 'db_error_skip' => true, - ) - ); - // No results? Just forget it all together. - if ($smcFunc['db_num_rows']($request) === 0) - unset($table_row['Collation']); - else - $collation_info = $smcFunc['db_fetch_assoc']($request); - $smcFunc['db_free_result']($request); - } - } - - if ($column_fix) - { - // Make sure there are no NULL's left. - if ($null_fix) - $smcFunc['db_query']('', ' - UPDATE {db_prefix}' . $change['table'] . ' - SET ' . $change['column'] . ' = {string:default} - WHERE ' . $change['column'] . ' IS NULL', - array( - 'default' => isset($change['default']) ? $change['default'] : '', - 'db_error_skip' => true, - ) - ); - - // Do the actual alteration. - $smcFunc['db_query']('', ' - ALTER TABLE {db_prefix}' . $change['table'] . ' - CHANGE COLUMN ' . $change['column'] . ' ' . $change['column'] . ' ' . $change['type'] . (isset($collation_info['Charset']) ? ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'] : '') . ($change['null_allowed'] ? '' : ' NOT NULL') . (isset($change['default']) ? ' default {string:default}' : ''), - array( - 'default' => isset($change['default']) ? $change['default'] : '', - 'db_error_skip' => true, - ) - ); - } - nextSubstep($substep); -} - -// Check if we need to alter this query. -function checkChange(&$change) -{ - global $smcFunc, $db_type, $databases; - static $database_version, $where_field_support; - - // Attempt to find a database_version. - if (empty($database_version)) - { - $database_version = $databases[$db_type]['version_check']; - $where_field_support = $db_type == 'mysql' && version_compare('5.0', $database_version) <= 0; - } - - // Not a column we need to check on? - if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) - return; - - // Break it up you (six|seven). - $temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text'])); - - // Can we support a shortcut method? - if ($where_field_support) - { - // Get the details about this change. - $request = $smcFunc['db_query']('', ' - SHOW FIELDS - FROM {db_prefix}{raw:table} - WHERE Field = {string:old_name} OR Field = {string:new_name}', - array( - 'table' => $change['table'], - 'old_name' => $temp[1], - 'new_name' => $temp[2], - )); - if ($smcFunc['db_num_rows'] != 1) - return; - - list (, $current_type) = $smcFunc['db_fetch_assoc']($request); - $smcFunc['db_free_result']($request); - } - else - { - // Do this the old fashion, sure method way. - $request = $smcFunc['db_query']('', ' - SHOW FIELDS - FROM {db_prefix}{raw:table}', - array( - 'table' => $change['table'], - )); - // Mayday! - if ($smcFunc['db_num_rows'] == 0) - return; - - // Oh where, oh where has my little field gone. Oh where can it be... - while ($row = $smcFunc['db_query']($request)) - if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2]) - { - $current_type = $row['Type']; - break; - } - } - - // If this doesn't match, the column may of been altered for a reason. - if (trim($current_type) != trim($temp[3])) - $temp[3] = $current_type; - - // Piece this back together. - $change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp)); -} - -// The next substep. -function nextSubstep($substep) -{ - global $start_time, $timeLimitThreshold, $command_line, $file_steps, $modSettings, $custom_warning; - global $step_progress, $is_debug, $upcontext; - - if ($_GET['substep'] < $substep) - $_GET['substep'] = $substep; - - if ($command_line) - { - if (time() - $start_time > 1 && empty($is_debug)) - { - echo '.'; - $start_time = time(); - } - return; - } - - @set_time_limit(300); - if (function_exists('apache_reset_timeout')) - @apache_reset_timeout(); - - if (time() - $start_time <= $timeLimitThreshold) - return; - - // Do we have some custom step progress stuff? - if (!empty($step_progress)) - { - $upcontext['substep_progress'] = 0; - $upcontext['substep_progress_name'] = $step_progress['name']; - if ($step_progress['current'] > $step_progress['total']) - $upcontext['substep_progress'] = 99.9; - else - $upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100; - - // Make it nicely rounded. - $upcontext['substep_progress'] = round($upcontext['substep_progress'], 1); - } - - // If this is XML we just exit right away! - if (isset($_GET['xml'])) - return upgradeExit(); - - // We're going to pause after this! - $upcontext['pause'] = true; - - $upcontext['query_string'] = ''; - foreach ($_GET as $k => $v) - { - if ($k != 'data' && $k != 'substep' && $k != 'step') - $upcontext['query_string'] .= ';' . $k . '=' . $v; - } - - // Custom warning? - if (!empty($custom_warning)) - $upcontext['custom_warning'] = $custom_warning; - - upgradeExit(); -} - -function cmdStep0() -{ - global $boarddir, $sourcedir, $db_prefix, $language, $modSettings, $start_time, $cachedir, $databases, $db_type, $smcFunc, $upcontext; - global $language, $is_debug, $txt; - $start_time = time(); - - ob_end_clean(); - ob_implicit_flush(true); - @set_time_limit(600); - - if (!isset($_SERVER['argv'])) - $_SERVER['argv'] = array(); - $_GET['maint'] = 1; - - foreach ($_SERVER['argv'] as $i => $arg) - { - if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) - $_GET['lang'] = $match[1]; - elseif (preg_match('~^--path=(.+)$~', $arg) != 0) - continue; - elseif ($arg == '--no-maintenance') - $_GET['maint'] = 0; - elseif ($arg == '--debug') - $is_debug = true; - elseif ($arg == '--backup') - $_POST['backup'] = 1; - elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) - $_GET['conv'] = 1; - elseif ($i != 0) - { - echo 'SMF Command-line Upgrader -Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]... - - --language=LANG Reset the forum\'s language to LANG. - --no-maintenance Don\'t put the forum into maintenance mode. - --debug Output debugging information. - --backup Create backups of tables with "backup_" prefix.'; - echo "\n"; - exit; - } - } - - if (!php_version_check()) - print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true); - if (!db_version_check()) - print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true); - - if (!empty($databases[$db_type]['alter_support']) && $smcFunc['db_query']('alter_boards', 'ALTER TABLE {db_prefix}boards ORDER BY id_board', array()) === false) - print_error('Error: The ' . $databases[$db_type]['name'] . ' account in Settings.php does not have sufficient privileges.', true); - - $check = @file_exists($modSettings['theme_dir'] . '/index.template.php') - && @file_exists($sourcedir . '/QueryString.php') - && @file_exists($sourcedir . '/ManageBoards.php'); - if (!$check && !isset($modSettings['smfVersion'])) - print_error('Error: Some files are missing or out-of-date.', true); - - // Do a quick version spot check. - $temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096); - preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match); - if (empty($match[1]) || $match[1] != SMF_VERSION) - print_error('Error: Some files have not yet been updated properly.'); - - // Make sure Settings.php is writable. - if (!is_writable($boarddir . '/Settings.php')) - @chmod($boarddir . '/Settings.php', 0777); - if (!is_writable($boarddir . '/Settings.php')) - print_error('Error: Unable to obtain write access to "Settings.php".', true); - - // Make sure Settings.php is writable. - if (!is_writable($boarddir . '/Settings_bak.php')) - @chmod($boarddir . '/Settings_bak.php', 0777); - if (!is_writable($boarddir . '/Settings_bak.php')) - print_error('Error: Unable to obtain write access to "Settings_bak.php".'); - - if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) - print_error('Error: Unable to obtain write access to "agreement.txt".'); - elseif (isset($modSettings['agreement'])) - { - $fp = fopen($boarddir . '/agreement.txt', 'w'); - fwrite($fp, $modSettings['agreement']); - fclose($fp); - } - - // Make sure Themes is writable. - if (!is_writable($modSettings['theme_dir'])) - @chmod($modSettings['theme_dir'], 0777); - - if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) - print_error('Error: Unable to obtain write access to "Themes".'); - - // Make sure cache directory exists and is writable! - $cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir; - if (!file_exists($cachedir_temp)) - @mkdir($cachedir_temp); - - if (!is_writable($cachedir_temp)) - @chmod($cachedir_temp, 0777); - - if (!is_writable($cachedir_temp)) - print_error('Error: Unable to obtain write access to "cache".', true); - - if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) - print_error('Error: Unable to find language files!', true); - else - { - $temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096); - preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match); - - if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) - print_error('Error: Language files out of date.', true); - if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) - print_error('Error: Install language is missing for selected language.', true); - - // Otherwise include it! - require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); - } - - // Make sure we skip the HTML for login. - $_POST['upcont'] = true; - $upcontext['current_step'] = 1; -} - -function print_error($message, $fatal = false) -{ - static $fp = null; - - if ($fp === null) - $fp = fopen('php://stderr', 'wb'); - - fwrite($fp, $message . "\n"); - - if ($fatal) - exit; -} - -function throw_error($message) -{ - global $upcontext; - - $upcontext['error_msg'] = $message; - $upcontext['sub_template'] = 'error_message'; - - return false; -} - -// Check files are writable - make them writable if necessary... -function makeFilesWritable(&$files) -{ - global $upcontext, $boarddir; - - if (empty($files)) - return true; - - $failure = false; - // On linux, it's easy - just use is_writable! - if (substr(__FILE__, 1, 2) != ':\\') - { - foreach ($files as $k => $file) - { - if (!is_writable($file)) - { - @chmod($file, 0755); - - // Well, 755 hopefully worked... if not, try 777. - if (!is_writable($file) && !@chmod($file, 0777)) - $failure = true; - // Otherwise remove it as it's good! - else - unset($files[$k]); - } - else - unset($files[$k]); - } - } - // Windows is trickier. Let's try opening for r+... - else - { - foreach ($files as $k => $file) - { - // Folders can't be opened for write... but the index.php in them can ;). - if (is_dir($file)) - $file .= '/index.php'; - - // Funny enough, chmod actually does do something on windows - it removes the read only attribute. - @chmod($file, 0777); - $fp = @fopen($file, 'r+'); - - // Hmm, okay, try just for write in that case... - if (!$fp) - $fp = @fopen($file, 'w'); - - if (!$fp) - $failure = true; - else - unset($files[$k]); - @fclose($fp); - } - } - - if (empty($files)) - return true; - - if (!isset($_SERVER)) - return !$failure; - - // What still needs to be done? - $upcontext['chmod']['files'] = $files; - - // If it's windows it's a mess... - if ($failure && substr(__FILE__, 1, 2) == ':\\') - { - $upcontext['chmod']['ftp_error'] = 'total_mess'; - - return false; - } - // We're going to have to use... FTP! - elseif ($failure) - { - // Load any session data we might have... - if (!isset($_POST['ftp_username']) && isset($_SESSION['installer_temp_ftp'])) - { - $upcontext['chmod']['server'] = $_SESSION['installer_temp_ftp']['server']; - $upcontext['chmod']['port'] = $_SESSION['installer_temp_ftp']['port']; - $upcontext['chmod']['username'] = $_SESSION['installer_temp_ftp']['username']; - $upcontext['chmod']['password'] = $_SESSION['installer_temp_ftp']['password']; - $upcontext['chmod']['path'] = $_SESSION['installer_temp_ftp']['path']; - } - // Or have we submitted? - elseif (isset($_POST['ftp_username'])) - { - $upcontext['chmod']['server'] = $_POST['ftp_server']; - $upcontext['chmod']['port'] = $_POST['ftp_port']; - $upcontext['chmod']['username'] = $_POST['ftp_username']; - $upcontext['chmod']['password'] = $_POST['ftp_password']; - $upcontext['chmod']['path'] = $_POST['ftp_path']; - } - - if (isset($upcontext['chmod']['username'])) - { - $ftp = new ftp_connection($upcontext['chmod']['server'], $upcontext['chmod']['port'], $upcontext['chmod']['username'], $upcontext['chmod']['password']); - - if ($ftp->error === false) - { - // Try it without /home/abc just in case they messed up. - if (!$ftp->chdir($upcontext['chmod']['path'])) - { - $upcontext['chmod']['ftp_error'] = $ftp->last_message; - $ftp->chdir(preg_replace('~^/home[2]?/[^/]+?~', '', $upcontext['chmod']['path'])); - } - } - } - - if (!isset($ftp) || $ftp->error !== false) - { - if (!isset($ftp)) - $ftp = new ftp_connection(null); - // Save the error so we can mess with listing... - elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error'])) - $upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message; - - list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__)); - - if ($found_path || !isset($upcontext['chmod']['path'])) - $upcontext['chmod']['path'] = $detect_path; - - if (!isset($upcontext['chmod']['username'])) - $upcontext['chmod']['username'] = $username; - - return false; - } - else - { - // We want to do a relative path for FTP. - if (!in_array($upcontext['chmod']['path'], array('', '/'))) - { - $ftp_root = strtr($boarddir, array($upcontext['chmod']['path'] => '')); - if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || substr($upcontext['chmod']['path'], 0, 1) == '/')) - $ftp_root = substr($ftp_root, 0, -1); - } - else - $ftp_root = $boarddir; - - // Save the info for next time! - $_SESSION['installer_temp_ftp'] = array( - 'server' => $upcontext['chmod']['server'], - 'port' => $upcontext['chmod']['port'], - 'username' => $upcontext['chmod']['username'], - 'password' => $upcontext['chmod']['password'], - 'path' => $upcontext['chmod']['path'], - 'root' => $ftp_root, - ); - - foreach ($files as $k => $file) - { - if (!is_writable($file)) - $ftp->chmod($file, 0755); - if (!is_writable($file)) - $ftp->chmod($file, 0777); - - // Assuming that didn't work calculate the path without the boarddir. - if (!is_writable($file)) - { - if (strpos($file, $boarddir) === 0) - { - $ftp_file = strtr($file, array($_SESSION['installer_temp_ftp']['root'] => '')); - $ftp->chmod($ftp_file, 0755); - if (!is_writable($file)) - $ftp->chmod($ftp_file, 0777); - // Sometimes an extra slash can help... - $ftp_file = '/' . $ftp_file; - if (!is_writable($file)) - $ftp->chmod($ftp_file, 0755); - if (!is_writable($file)) - $ftp->chmod($ftp_file, 0777); - } - } - - if (is_writable($file)) - unset($files[$k]); - } - - $ftp->close(); - } - } - - // What remains? - $upcontext['chmod']['files'] = $files; - - if (empty($files)) - return true; - - return false; -} - -/****************************************************************************** -******************* Templates are below this point **************************** -******************************************************************************/ - -// This is what is displayed if there's any chmod to be done. If not it returns nothing... -function template_chmod() -{ - global $upcontext, $upgradeurl, $settings; - - // Don't call me twice! - if (!empty($upcontext['chmod_called'])) - return; - - $upcontext['chmod_called'] = true; - - // Nothing? - if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) - return; - - //!!! Temporary! - $txt['error_ftp_no_connect'] = 'Unable to connect to FTP server with this combination of details.'; - $txt['ftp_login'] = 'Your FTP connection information'; - $txt['ftp_login_info'] = 'This web installer needs your FTP information in order to automate the installation for you. Please note that none of this information is saved in your installation, it is just used to setup SMF.'; - $txt['ftp_server'] = 'Server'; - $txt['ftp_server_info'] = 'The address (often localhost) and port for your FTP server.'; - $txt['ftp_port'] = 'Port'; - $txt['ftp_username'] = 'Username'; - $txt['ftp_username_info'] = 'The username to login with. This will not be saved anywhere.'; - $txt['ftp_password'] = 'Password'; - $txt['ftp_password_info'] = 'The password to login with. This will not be saved anywhere.'; - $txt['ftp_path'] = 'Install Path'; - $txt['ftp_path_info'] = 'This is the relative path you use in your FTP client (more help).'; - $txt['ftp_path_found_info'] = 'The path in the box above was automatically detected.'; - $txt['ftp_path_help'] = 'Your FTP path is the path you see when you log in to your FTP client. It commonly starts with "www", "public_html", or "httpdocs" - but it should include the directory SMF is in too, such as "/public_html/forum". It is different from your URL and full path.

Files in this path may be overwritten, so make sure it\'s correct.'; - $txt['ftp_path_help_close'] = 'Close'; - $txt['ftp_connect'] = 'Connect'; - - // Was it a problem with Windows? - if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess') - { - echo ' -
-
The following files need to be writable to continue the upgrade. Please ensure the Windows permissions are correctly set to allow this:
-
    -
  • ' . implode('
  • -
  • ', $upcontext['chmod']['files']). '
  • -
-
'; - - return false; - } - - echo ' -
-

Your FTP connection information

-

The upgrader can fix any issues with file permissions to make upgrading as simple as possible. Simply enter your connection information below or alternatively click here for a list of files which need to be changed.

- '; - - if (!empty($upcontext['chmod']['ftp_error'])) - echo ' -
-
- The following error was encountered when trying to connect:
-
- ', $upcontext['chmod']['ftp_error'], ' -
-
-
'; - - if (empty($upcontext['chmod_in_form'])) - echo ' -
'; - - echo ' - - - - - - - - - - - - - - -
-
- -
', $txt['ftp_server_info'], '
-
- -
', $txt['ftp_username_info'], '
-
- -
', $txt['ftp_password_info'], '
-
- -
', !empty($upcontext['chmod']['path']) ? $txt['ftp_path_found_info'] : $txt['ftp_path_info'], '
-
- -
-
'; - - if (empty($upcontext['chmod_in_form'])) - echo ' - '; -} - -function template_upgrade_above() -{ - global $modSettings, $txt, $smfsite, $settings, $upcontext, $upgradeurl; - - echo ' - - - - - ', $txt['upgrade_upgrade_utility'], ' - - - - - - - -
-
-
-

', $txt['upgrade_progress'], '

-
    '; - - foreach ($upcontext['steps'] as $num => $step) - echo ' -
  • ', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '
  • '; - - echo ' -
-
-
-
-
', $upcontext['overall_percent'], '%
-
 
-
', $txt['upgrade_overall_progress'], '
-
- '; - - if (isset($upcontext['step_progress'])) - echo ' -
-
', $upcontext['step_progress'], '%
-
 
-
', $txt['upgrade_step_progress'], '
-
- '; - - echo ' -
', isset($upcontext['substep_progress_name']) ? trim(strtr($upcontext['substep_progress_name'], array('.' => ''))) : '', ':
-
-
', isset($upcontext['substep_progress']) ? $upcontext['substep_progress'] : '', '%
-
 
-
'; - - // How long have we been running this? - $elapsed = time() - $upcontext['started']; - $mins = (int) ($elapsed / 60); - $seconds = $elapsed - $mins * 60; - echo ' -
', $txt['upgrade_time_elapsed'], ': - ', $mins, ' ', $txt['upgrade_time_mins'], ', ', $seconds, ' ', $txt['upgrade_time_secs'], '. -
'; - echo ' -
-
-

', $upcontext['page_title'], '

-
-
'; -} - -function template_upgrade_below() -{ - global $upcontext, $txt; - - if (!empty($upcontext['pause'])) - echo ' - ', $txt['upgrade_incomplete'], '.
- -

', $txt['upgrade_not_quite_done'], '

-

- ', $txt['upgrade_paused_overload'], ' -

'; - - if (!empty($upcontext['custom_warning'])) - echo ' -
-
!!
- ', $txt['upgrade_note'], '
-
', $upcontext['custom_warning'], '
-
'; - - echo ' -
'; - - if (!empty($upcontext['continue'])) - echo ' - '; - if (!empty($upcontext['skip'])) - echo ' - '; - - echo ' -
- -
-
-
-
-
- - -'; - - // Are we on a pause? - if (!empty($upcontext['pause'])) - { - echo ' - '; - } -} - -function template_xml_above() -{ - global $upcontext; - - echo '<', '?xml version="1.0" encoding="ISO-8859-1"?', '> - '; - - if (!empty($upcontext['get_data'])) - foreach ($upcontext['get_data'] as $k => $v) - echo ' - ', $v, ''; -} - -function template_xml_below() -{ - global $upcontext; - - echo ' - '; -} - -function template_error_message() -{ - global $upcontext; - - echo ' -
-
- ', $upcontext['error_msg'], ' -
-
- Click here to try again. -
'; -} - -function template_welcome_message() -{ - global $upcontext, $modSettings, $upgradeurl, $disable_security, $settings, $txt; - - echo ' - - -

', sprintf($txt['upgrade_ready_proceed'], SMF_VERSION), '

-
- '; - - $upcontext['chmod_in_form'] = true; - template_chmod(); - - // For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade! - if ($upcontext['is_large_forum']) - echo ' -
-
!!
- ', $txt['upgrade_warning'], '
-
- ', $txt['upgrade_warning_lots_data'], ' -
-
'; - - // A warning message? - if (!empty($upcontext['warning'])) - echo ' -
-
!!
- ', $txt['upgrade_warning'], '
-
- ', $upcontext['warning'], ' -
-
'; - - // Paths are incorrect? - echo ' -
-
!!
- ', $txt['upgrade_critical_error'], '
-
- ', $txt['upgrade_error_script_js'], ' -
-
'; - - // Is there someone already doing this? - if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600)) - { - $ago = time() - $upcontext['started']; - if ($ago < 60) - $ago = $ago . ' seconds'; - elseif ($ago < 3600) - $ago = (int) ($ago / 60) . ' minutes'; - else - $ago = (int) ($ago / 3600) . ' hours'; - - $active = time() - $upcontext['updated']; - if ($active < 60) - $updated = $active . ' seconds'; - elseif ($active < 3600) - $updated = (int) ($active / 60) . ' minutes'; - else - $updated = (int) ($active / 3600) . ' hours'; - - echo ' -
-
!!
- ', $txt['upgrade_warning'], '
-
- "', $upcontext['user']['name'], '" has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.'; - - if ($active < 600) - echo ' - We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.'; - - if ($active > $upcontext['inactive_timeout']) - echo ' -

You can choose to either run the upgrade again from the beginning - or alternatively continue from the last step reached during the last upgrade.'; - else - echo ' -

This upgrade script cannot be run until ', $upcontext['user']['name'], ' has been inactive for at least ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!'); - - echo ' -
-
'; - } - - echo ' - Admin Login: ', $disable_security ? '(DISABLED)' : '', ' -

For security purposes please login with your admin account to proceed with the upgrade.

- - - - - - - - - '; - - // Can they continue? - if (!empty($upcontext['user']['id']) && time() - $upcontext['user']['updated'] >= $upcontext['inactive_timeout'] && $upcontext['user']['step'] > 1) - { - echo ' - - - '; - } - - echo ' -
Username: - '; - - if (!empty($upcontext['username_incorrect'])) - echo ' -
Username Incorrect
'; - - echo ' -
Password: - - '; - - if (!empty($upcontext['password_failed'])) - echo ' -
Password Incorrect
'; - - echo ' -
- -

- - Note: If necessary the above security check can be bypassed for users who may administrate a server but not have admin rights on the forum. In order to bypass the above check simply open "upgrade.php" in a text editor and replace "$disable_security = 0;" with "$disable_security = 1;" and refresh this page. - - - '; - - // Say we want the continue button! - $upcontext['continue'] = !empty($upcontext['user']['id']) && time() - $upcontext['user']['updated'] < $upcontext['inactive_timeout'] ? 2 : 1; - - // This defines whether javascript is going to work elsewhere :D - echo ' - '; -} - -function template_upgrade_options() -{ - global $upcontext, $modSettings, $upgradeurl, $disable_security, $settings, $boarddir, $db_prefix, $mmessage, $mtitle, $db_type; - - echo ' -

Before the upgrade gets underway please review the options below - and hit continue when you\'re ready to begin.

- '; - - // Warning message? - if (!empty($upcontext['upgrade_options_warning'])) - echo ' -
-
!!
- Warning!
-
- ', $upcontext['upgrade_options_warning'], ' -
-
'; - - echo ' - - - - - - - - - - - - - - - - - - - - - -
- - - ', isset($modSettings['smfVersion']) ? '' : ' (recommended!)', ' -
- - - (Customize) - -
- - - -
- - - -
- - - -
- '; - - // We need a normal continue button here! - $upcontext['continue'] = 1; -} - -// Template for the database backup tool/ -function template_backup_database() -{ - global $upcontext, $modSettings, $upgradeurl, $disable_security, $settings, $support_js, $is_debug; - - echo ' -

Please wait while a backup is created. For large forums this may take some time!

'; - - echo ' - - - Completed ', $upcontext['cur_table_num'], ' out of ', $upcontext['table_count'], ' tables. - '; - - // Dont any tables so far? - if (!empty($upcontext['previous_tables'])) - foreach ($upcontext['previous_tables'] as $table) - echo ' -
Completed Table: "', $table, '".'; - - echo ' -

Current Table: "', $upcontext['cur_table_name'], '"

-
Backup Complete! Click Continue to Proceed.'; - - // Continue please! - $upcontext['continue'] = $support_js ? 2 : 1; - - // If javascript allows we want to do this using XML. - if ($support_js) - { - echo ' - '; - } -} - -function template_backup_xml() -{ - global $upcontext, $settings, $options, $txt; - - echo ' - ', $upcontext['cur_table_name'], '
'; -} - -// Here is the actual "make the changes" template! -function template_database_changes() -{ - global $upcontext, $modSettings, $upgradeurl, $disable_security, $settings, $support_js, $is_debug, $timeLimitThreshold; - - echo ' -

Executing database changes

-

Please be patient - this may take some time on large forums. The time elapsed increments from the server to show progress is being made!

'; - - echo ' - - '; - - // No javascript looks rubbish! - if (!$support_js) - { - foreach ($upcontext['actioned_items'] as $num => $item) - { - if ($num != 0) - echo ' Successful!'; - echo '
' . $item; - } - if (!empty($upcontext['changes_complete'])) - echo ' Successful!

Database Updates Complete! Click Continue to Proceed.
'; - } - else - { - // Tell them how many files we have in total. - if ($upcontext['file_count'] > 1) - echo ' - Executing upgrade script ', $upcontext['cur_file_num'], ' of ', $upcontext['file_count'], '.'; - - echo ' -

Executing: "', $upcontext['current_item_name'], '" (', $upcontext['current_item_num'], ' of ', $upcontext['total_items'], '', $upcontext['file_count'] > 1 ? ' - of this script' : '', ')

-
Database Updates Complete! Click Continue to Proceed.'; - - if ($is_debug) - { - echo ' -
- -
'; - } - } - - // Place for the XML error message. - echo ' -
-
!!
- Error!
-
', isset($upcontext['error_message']) ? $upcontext['error_message'] : 'Unknown Error!', '
-
'; - - // We want to continue at some point! - $upcontext['continue'] = $support_js ? 2 : 1; - - // If javascript allows we want to do this using XML. - if ($support_js) - { - echo ' - '; - } - return; -} - -function template_database_xml() -{ - global $upcontext, $settings, $options, $txt; - - echo ' - ', $upcontext['cur_file_name'], ' - ', $upcontext['current_item_name'], ' - ', $upcontext['current_debug_item_name'], ''; - - if (!empty($upcontext['error_message'])) - echo ' - ', $upcontext['error_message'], ''; -} - -function template_clean_mods() -{ - global $upcontext, $modSettings, $upgradeurl, $disable_security, $settings, $boarddir, $db_prefix, $boardurl; - - $upcontext['chmod_in_form'] = true; - - echo ' -

SMF has detected some packages which were installed but not fully removed prior to upgrade. We recommend you remove the following mods and reinstall upon completion of the upgrade.

- '; - - // In case it's required. - template_chmod(); - - echo ' - - - - - - - - '; - - foreach ($upcontext['packages'] as $package) - { - echo ' - - - - - - - '; - } - echo ' -
Modification NameVersionFiles AffectedStatusFix?
', $package['name'], '', $package['version'], '', $package['file_count'], ' [details]', $package['status'], ' - - -
- '; - - // Files to make writable? - if (!empty($upcontext['writable_files'])) - echo ' - '; - - // We'll want a continue button... - if (empty($upcontext['chmod']['files'])) - $upcontext['continue'] = 1; -} - -// Finished with the mods - let them know what we've done. -function template_cleanup_done() -{ - global $upcontext, $modSettings, $upgradeurl, $disable_security, $settings, $boarddir, $db_prefix, $boardurl; - - echo ' -

SMF has attempted to fix and reinstall mods as required. We recommend you visit the package manager upon completing upgrade to check the status of your modifications.

- - - - - '; - - foreach ($upcontext['packages'] as $package) - { - echo ' - - - '; - } - echo ' -
Actions Completed:
', $package['name'], '... ', $package['result'], '
- '; - - // We'll want a continue button... - $upcontext['continue'] = 1; -} - -// Do they want to upgrade their templates? -function template_upgrade_templates() -{ - global $upcontext, $modSettings, $upgradeurl, $disable_security, $settings, $boarddir, $db_prefix, $boardurl; - - echo ' -

There have been numerous language and template changes since the previous version of SMF. On this step the upgrader can attempt to automatically make these changes in your templates to save you from doing so manually.

- '; - - // Any files need to be writable? - $upcontext['chmod_in_form'] = true; - template_chmod(); - - // Language/Template files need an update? - if ($upcontext['temp_progress'] == 0 && !$upcontext['is_test'] && (!empty($upcontext['languages']) || !empty($upcontext['themes']))) - { - echo ' - The following template files will be updated to ensure they are compatible with this version of SMF. Note that this can only fix a limited number of compatibility issues and in general you should seek out the latest version of these themes/language files. - - - - - '; - - foreach ($upcontext['languages'] as $language) - { - echo ' - - - - '; - } - - foreach ($upcontext['themes'] as $theme) - { - echo ' - - - - '; - } - - echo ' -
AreaChanges Required
- "', $language['name'], '" Language Pack -
('; - - foreach ($language['files'] as $k => $file) - echo $file['name'], $k + 1 != count($language['files']) ? ', ' : ')'; - - echo ' -
-
', $language['edit_count'] == 0 ? 1 : $language['edit_count'], '
- "', $theme['name'], '" Theme -
('; - - foreach ($theme['files'] as $k => $file) - echo $file['name'], $k + 1 != count($theme['files']) ? ', ' : ')'; - - echo ' -
-
', $theme['edit_count'] == 0 ? 1 : $theme['edit_count'], '
'; - } - else - { - $langFiles = 0; - $themeFiles = 0; - if (!empty($upcontext['languages'])) - foreach ($upcontext['languages'] as $lang) - $langFiles += count($lang['files']); - if (!empty($upcontext['themes'])) - foreach ($upcontext['themes'] as $theme) - $themeFiles += count($theme['files']); - echo sprintf('Found %d language files and %d templates requiring an update so far.', $langFiles, $themeFiles) . '
'; - - // What we're currently doing? - if (!empty($upcontext['current_message'])) - echo ' - ', $upcontext['current_message']; - } - - echo ' - '; - - if (!empty($upcontext['languages'])) - echo ' - '; - if (!empty($upcontext['themes'])) - echo ' - '; - if (!empty($upcontext['writable_files'])) - echo ' - '; - - // Offer them the option to upgrade from YaBB SE? - if (!empty($upcontext['can_upgrade_yabbse'])) - echo ' -

'; - - // We'll want a continue button... assuming chmod is OK (Otherwise let them use connect!) - if (empty($upcontext['chmod']['files']) || $upcontext['is_test']) - $upcontext['continue'] = 1; -} - -function template_upgrade_complete() -{ - global $upcontext, $modSettings, $upgradeurl, $disable_security, $settings, $boarddir, $db_prefix, $boardurl; - - echo ' -

That wasn\'t so hard, was it? Now you are ready to use your installation of SMF. Hope you like it!

- '; - - if (!empty($upcontext['can_delete_script'])) - echo ' - (doesn\'t work on all servers.) - -
'; - - echo '
- If you had any problems with this upgrade, or have any problems using SMF, please don\'t hesitate to look to us for assistance.
-
- Best of luck,
- Simple Machines'; -} - -?> \ No newline at end of file diff --git a/upgrade_1-0.sql b/upgrade_1-0.sql deleted file mode 100644 index 89349c3..0000000 --- a/upgrade_1-0.sql +++ /dev/null @@ -1,2017 +0,0 @@ -/* ATTENTION: You don't need to run or use this file! The upgrade.php script does everything for you! */ - -/******************************************************************************/ ---- Creating new tables and inserting default data... -/******************************************************************************/ - ----# Creating "themes"... -CREATE TABLE IF NOT EXISTS {$db_prefix}themes ( - ID_MEMBER mediumint(8) NOT NULL default '0', - ID_THEME tinyint(4) unsigned NOT NULL default '1', - variable tinytext NOT NULL default '', - value text NOT NULL default '', - PRIMARY KEY (ID_MEMBER, ID_THEME, variable(30)) -) ENGINE=MyISAM; - -ALTER TABLE {$db_prefix}themes -CHANGE COLUMN ID_MEMBER ID_MEMBER mediumint(8) NOT NULL default '0'; - -ALTER TABLE {$db_prefix}themes -CHANGE COLUMN value value text NOT NULL default ''; - -INSERT IGNORE INTO {$db_prefix}themes - (ID_MEMBER, ID_THEME, variable, value) -VALUES (0, 1, 'name', 'SMF Default Theme'), - (0, 1, 'theme_url', '{$boardurl}/Themes/default'), - (0, 1, 'images_url', '{$boardurl}/Themes/default/images'), - (0, 1, 'theme_dir', '{$sboarddir}/Themes/default'), - (0, 1, 'allow_no_censored', '0'), - (0, 1, 'additional_options_collapsable', '1'), - (0, 2, 'name', 'Classic YaBB SE Theme'), - (0, 2, 'theme_url', '{$boardurl}/Themes/classic'), - (0, 2, 'images_url', '{$boardurl}/Themes/classic/images'), - (0, 2, 'theme_dir', '{$sboarddir}/Themes/classic'); ----# - ----# Creating "collapsed_categories"... -CREATE TABLE IF NOT EXISTS {$db_prefix}collapsed_categories ( - ID_CAT tinyint(4) unsigned NOT NULL default '0', - ID_MEMBER mediumint(8) unsigned NOT NULL default '0', - PRIMARY KEY (ID_CAT, ID_MEMBER) -) ENGINE=MyISAM; ----# - ----# Creating and verifying "permissions"... -CREATE TABLE IF NOT EXISTS {$db_prefix}permissions ( - ID_GROUP smallint(6) NOT NULL default '0', - permission varchar(30) NOT NULL default '', - addDeny tinyint(4) NOT NULL default '1', - PRIMARY KEY (ID_GROUP, permission) -) ENGINE=MyISAM; - -ALTER TABLE {$db_prefix}permissions -ADD addDeny tinyint(4) NOT NULL default '1'; -ALTER TABLE {$db_prefix}permissions -CHANGE COLUMN permission permission varchar(30) NOT NULL default ''; - -UPDATE IGNORE {$db_prefix}permissions -SET - permission = REPLACE(permission, 'profile_own_identity', 'profile_identity_own'), - permission = REPLACE(permission, 'profile_any_identity', 'profile_identity_any'), - permission = REPLACE(permission, 'profile_own_extra', 'profile_extra_own'), - permission = REPLACE(permission, 'profile_any_extra', 'profile_extra_any'), - permission = REPLACE(permission, 'profile_own_title', 'profile_title_own'), - permission = REPLACE(permission, 'profile_any_title', 'profile_title_any'), - permission = REPLACE(permission, 'im_read', 'pm_read'), - permission = REPLACE(permission, 'im_send', 'pm_send'); ----# - ----# Inserting data into "permissions"... -INSERT INTO {$db_prefix}permissions - (ID_GROUP, permission) -VALUES (-1, 'search_posts'), (-1, 'calendar_view'), (-1, 'view_stats'), (-1, 'profile_view_any'), - (2, 'calendar_post'), (2, 'calendar_edit_any'), (2, 'calendar_edit_own'); ----# - ----# Creating and verifying "board_permissions"... -CREATE TABLE IF NOT EXISTS {$db_prefix}board_permissions ( - ID_GROUP smallint(6) NOT NULL default '0', - ID_BOARD smallint(5) unsigned NOT NULL default '0', - permission varchar(30) NOT NULL default '', - addDeny tinyint(4) NOT NULL default '1', - PRIMARY KEY (ID_GROUP, ID_BOARD, permission) -) ENGINE=MyISAM; - -ALTER TABLE {$db_prefix}board_permissions -ADD addDeny tinyint(4) NOT NULL default '1'; -ALTER TABLE {$db_prefix}board_permissions -CHANGE COLUMN permission permission varchar(30) NOT NULL default ''; ----# - ----# Inserting data into "board_permissions"... -INSERT INTO {$db_prefix}board_permissions - (ID_GROUP, ID_BOARD, permission) -VALUES (-1, 0, 'poll_view'), (3, 0, 'make_sticky'), (3, 0, 'lock_any'), - (3, 0, 'remove_any'), (3, 0, 'move_any'), (3, 0, 'merge_any'), (3, 0, 'split_any'), - (3, 0, 'delete_any'), (3, 0, 'modify_any'), (2, 0, 'make_sticky'), (2, 0, 'lock_any'), - (2, 0, 'remove_any'), (2, 0, 'move_any'), (2, 0, 'merge_any'), (2, 0, 'split_any'), - (2, 0, 'delete_any'), (2, 0, 'modify_any'), (2, 0, 'poll_lock_any'), (2, 0, 'poll_lock_any'), - (2, 0, 'poll_add_any'), (2, 0, 'poll_remove_any'), (2, 0, 'poll_remove_any'); -INSERT IGNORE INTO {$db_prefix}board_permissions - (ID_GROUP, ID_BOARD, permission) -VALUES (3, 0, 'moderate_board'), (2, 0, 'moderate_board'); ----# - ----# Creating "moderators"... -CREATE TABLE IF NOT EXISTS {$db_prefix}moderators ( - ID_BOARD smallint(5) unsigned NOT NULL default '0', - ID_MEMBER mediumint(8) unsigned NOT NULL default '0', - PRIMARY KEY (ID_BOARD, ID_MEMBER) -) ENGINE=MyISAM; ----# - ----# Creating "attachments"... -CREATE TABLE IF NOT EXISTS {$db_prefix}attachments ( - ID_ATTACH int(11) unsigned NOT NULL auto_increment, - ID_MSG int(10) unsigned NOT NULL default '0', - ID_MEMBER int(10) unsigned NOT NULL default '0', - filename tinytext NOT NULL default '', - size int(10) unsigned NOT NULL default '0', - downloads mediumint(8) unsigned NOT NULL default '0', - PRIMARY KEY (ID_ATTACH), - UNIQUE ID_MEMBER (ID_MEMBER, ID_ATTACH), - KEY ID_MSG (ID_MSG) -) ENGINE=MyISAM; ----# - ----# Creating "log_notify"... -CREATE TABLE IF NOT EXISTS {$db_prefix}log_notify ( - ID_MEMBER mediumint(8) unsigned NOT NULL default '0', - ID_TOPIC mediumint(8) unsigned NOT NULL default '0', - ID_BOARD smallint(5) unsigned NOT NULL default '0', - sent tinyint(1) unsigned NOT NULL default '0', - PRIMARY KEY (ID_MEMBER, ID_TOPIC, ID_BOARD) -) ENGINE=MyISAM; ----# - ----# Creating "log_polls"... -CREATE TABLE IF NOT EXISTS {$db_prefix}log_polls ( - ID_POLL mediumint(8) unsigned NOT NULL default '0', - ID_MEMBER mediumint(8) unsigned NOT NULL default '0', - ID_CHOICE tinyint(4) unsigned NOT NULL default '0', - PRIMARY KEY (ID_POLL, ID_MEMBER, ID_CHOICE) -) ENGINE=MyISAM; ----# - ----# Creating "log_actions"... -CREATE TABLE IF NOT EXISTS {$db_prefix}log_actions ( - ID_ACTION int(10) unsigned NOT NULL auto_increment, - logTime int(10) unsigned NOT NULL default '0', - ID_MEMBER mediumint(8) unsigned NOT NULL default '0', - IP tinytext NOT NULL default '', - action varchar(30) NOT NULL default '', - extra text NOT NULL default '', - PRIMARY KEY (ID_ACTION), - KEY logTime (logTime), - KEY ID_MEMBER (ID_MEMBER) -) ENGINE=MyISAM; ----# - ----# Creating "poll_choices"... -CREATE TABLE IF NOT EXISTS {$db_prefix}poll_choices ( - ID_POLL mediumint(8) unsigned NOT NULL default '0', - ID_CHOICE tinyint(4) unsigned NOT NULL default '0', - label tinytext NOT NULL default '', - votes smallint(5) unsigned NOT NULL default '0', - PRIMARY KEY (ID_POLL, ID_CHOICE) -) ENGINE=MyISAM; ----# - ----# Creating "smileys"... -CREATE TABLE IF NOT EXISTS {$db_prefix}smileys ( - id_smiley smallint(5) unsigned NOT NULL auto_increment, - code varchar(30) NOT NULL default '', - filename varchar(48) NOT NULL default '', - description varchar(80) NOT NULL default '', - smileyRow tinyint(4) unsigned NOT NULL default '0', - smileyOrder tinyint(4) unsigned NOT NULL default '0', - hidden tinyint(4) unsigned NOT NULL default '0', - PRIMARY KEY (id_smiley), - KEY smileyOrder (smileyOrder) -) ENGINE=MyISAM; ----# - ----# Loading default smileys... -INSERT IGNORE INTO {$db_prefix}smileys - (id_smiley, code, filename, description, smileyOrder, hidden) -VALUES (1, ':)', 'smiley.gif', 'Smiley', 0, 0), - (2, ';)', 'wink.gif', 'Wink', 1, 0), - (3, ':D', 'cheesy.gif', 'Cheesy', 2, 0), - (4, ';D', 'grin.gif', 'Grin', 3, 0), - (5, '>:(', 'angry.gif', 'Angry', 4, 0), - (6, ':(', 'sad.gif', 'Sad', 5, 0), - (7, ':o', 'shocked.gif', 'Shocked', 6, 0), - (8, '8)', 'cool.gif', 'Cool', 7, 0), - (9, '???', 'huh.gif', 'Huh', 8, 0), - (10, '::)', 'rolleyes.gif', 'Roll Eyes', 9, 0), - (11, ':P', 'tongue.gif', 'Tongue', 10, 0), - (12, ':-[', 'embarassed.gif', 'Embarrassed', 11, 0), - (13, ':-X', 'lipsrsealed.gif', 'Lips Sealed', 12, 0), - (14, ':-\\', 'undecided.gif', 'Undecided', 13, 0), - (15, ':-*', 'kiss.gif', 'Kiss', 14, 0), - (16, ':\'(', 'cry.gif', 'Cry', 15, 0), - (17, '>:D', 'evil.gif', 'Evil', 16, 1), - (18, '^-^', 'azn.gif', 'Azn', 17, 1), - (19, 'O0', 'afro.gif', 'Afro', 18, 1); ----# - ----# Dropping "log_search" and recreating it... -DROP TABLE IF EXISTS {$db_prefix}log_search; -CREATE TABLE {$db_prefix}log_search ( - ID_SEARCH tinyint(3) unsigned NOT NULL default '0', - ID_TOPIC mediumint(8) unsigned NOT NULL default '0', - ID_MSG int(10) unsigned NOT NULL default '0', - relevance smallint(5) unsigned NOT NULL default '0', - num_matches smallint(5) unsigned NOT NULL default '0', - PRIMARY KEY (ID_SEARCH, ID_TOPIC) -) ENGINE=MyISAM; ----# - ----# Dropping "sessions" and recreating it... -DROP TABLE IF EXISTS {$db_prefix}sessions; -CREATE TABLE {$db_prefix}sessions ( - session_id char(32) NOT NULL, - last_update int(10) unsigned NOT NULL, - data text NOT NULL, - PRIMARY KEY (session_id) -) ENGINE=MyISAM; ----# - ----# Verifying "settings"... -ALTER IGNORE TABLE {$db_prefix}settings -DROP PRIMARY KEY, -ADD PRIMARY KEY (variable(30)); ----# - -/******************************************************************************/ ---- Converting activity logs... -/******************************************************************************/ - ----# Converting "log_online"... -DROP TABLE IF EXISTS {$db_prefix}log_online; -CREATE TABLE {$db_prefix}log_online ( - session char(32) NOT NULL default ' ', - logTime timestamp, - ID_MEMBER mediumint(8) unsigned NOT NULL default '0', - ip int(11) unsigned NOT NULL default '0', - url text NOT NULL default '', - PRIMARY KEY (session), - KEY online (logTime, ID_MEMBER), - KEY ID_MEMBER (ID_MEMBER) -) ENGINE=MyISAM; ----# - ----# Converting "log_floodcontrol"... -DROP TABLE IF EXISTS {$db_prefix}log_floodcontrol; -CREATE TABLE {$db_prefix}log_floodcontrol ( - ip tinytext NOT NULL default '', - logTime int(10) unsigned NOT NULL default '0', - PRIMARY KEY (ip(16)), - KEY logTime (logTime) -) ENGINE=MyISAM; ----# - ----# Converting "log_karma"... -DROP TABLE IF EXISTS {$db_prefix}log_karma; -CREATE TABLE {$db_prefix}log_karma ( - ID_TARGET mediumint(8) unsigned NOT NULL default '0', - ID_EXECUTOR mediumint(8) unsigned NOT NULL default '0', - logTime int(10) unsigned NOT NULL default '0', - action tinyint(4) NOT NULL default '0', - PRIMARY KEY (ID_TARGET, ID_EXECUTOR), - KEY logTime (logTime) -) ENGINE=MyISAM; ----# - ----# Retiring "log_clicks"... -DROP TABLE IF EXISTS {$db_prefix}log_clicks; ----# - ----# Converting "log_notify"... -INSERT INTO {$db_prefix}log_notify -SELECT ID_MEMBER, ID_TOPIC, 0, notificationSent -FROM {$db_prefix}log_topics -WHERE notificationSent != 0; - -ALTER TABLE {$db_prefix}log_topics -DROP notificationSent; ----# - ----# Converting "log_errors"... -ALTER TABLE {$db_prefix}log_errors -CHANGE COLUMN ID_ERROR ID_ERROR mediumint(8) unsigned NOT NULL auto_increment, -ADD session char(32) NOT NULL default ' '; ----# - ----# Converting "log_boards"... ----{ -$request = upgrade_query(" - SELECT lmr.ID_BOARD, lmr.ID_MEMBER, lmr.logTime - FROM {$db_prefix}log_mark_read AS lmr - LEFT JOIN {$db_prefix}log_boards AS lb ON (lb.ID_BOARD = lmr.ID_BOARD AND lb.ID_MEMBER = lmr.ID_MEMBER) - WHERE lb.logTime < lmr.logTime"); -$replaceRows = ''; -while ($row = mysql_fetch_assoc($request)) - $replaceRows .= "($row[ID_BOARD], $row[ID_MEMBER], $row[logTime]),"; -mysql_free_result($request); -if (!empty($replaceRows)) -{ - $replaceRows = substr($replaceRows, 0, -1); - - upgrade_query(" - REPLACE INTO {$db_prefix}log_boards - (ID_BOARD, ID_MEMBER, logTime) - VALUES $replaceRows"); -} ----} ----# - ----# Converting "log_activity"... -ALTER TABLE {$db_prefix}log_activity -ADD date date NOT NULL default '0001-01-01'; - -ALTER TABLE {$db_prefix}log_activity -DROP PRIMARY KEY; - -UPDATE IGNORE {$db_prefix}log_activity -SET date = year * 10000 + month * 100 + day; - -ALTER TABLE {$db_prefix}log_activity -DROP day, -DROP month, -DROP year; - -ALTER TABLE {$db_prefix}log_activity -ADD INDEX hits (hits); -ALTER TABLE {$db_prefix}log_activity -ADD PRIMARY KEY (date); - -ALTER TABLE {$db_prefix}log_activity -CHANGE COLUMN hits hits mediumint(8) unsigned NOT NULL default '0', -CHANGE COLUMN topics topics smallint(5) unsigned NOT NULL default '0', -CHANGE COLUMN posts posts smallint(5) unsigned NOT NULL default '0', -CHANGE COLUMN registers registers smallint(5) unsigned NOT NULL default '0', -CHANGE COLUMN most_on most_on smallint(5) unsigned NOT NULL default '0'; ----# - -/******************************************************************************/ ---- Converting Boards and Categories... -/******************************************************************************/ - ----# Adding new columns to "boards"... -ALTER TABLE {$db_prefix}boards -CHANGE COLUMN count countPosts tinyint(4) NOT NULL default '0', -ADD lastUpdated int(11) unsigned NOT NULL default '0', -ADD ID_PARENT smallint(5) unsigned NOT NULL default '0', -ADD ID_LAST_MSG int(10) unsigned NOT NULL default '0', -ADD childLevel tinyint(4) unsigned NOT NULL default '0'; ----# - ----# Updating the structure of "boards"... -ALTER TABLE {$db_prefix}boards -CHANGE COLUMN boardOrder boardOrder smallint(5) NOT NULL default '0'; - -ALTER TABLE {$db_prefix}boards -DROP isAnnouncement; -ALTER TABLE {$db_prefix}boards -ADD ID_THEME tinyint(4) unsigned NOT NULL default '0'; -ALTER TABLE {$db_prefix}boards -ADD use_local_permissions tinyint(4) unsigned NOT NULL default '0'; -ALTER TABLE {$db_prefix}boards -ADD override_theme tinyint(4) unsigned NOT NULL default '0'; ----# - ----# Reindexing "boards" (part 1)... -ALTER TABLE {$db_prefix}boards -DROP INDEX ID_CAT, -DROP ID_LAST_TOPIC; -ALTER TABLE {$db_prefix}boards -DROP INDEX memberGroups; ----# - ----# Reindexing "boards" (part 2)... -ALTER TABLE {$db_prefix}boards -ADD INDEX lastUpdated (lastUpdated), -ADD INDEX memberGroups (memberGroups(48)), -ADD UNIQUE INDEX categories (ID_CAT, ID_BOARD); ----# - ----# Updating the column sizes on "boards"... -ALTER TABLE {$db_prefix}boards -DROP PRIMARY KEY, -CHANGE COLUMN ID_CAT ID_CAT tinyint(4) unsigned NOT NULL default '0', -CHANGE COLUMN numTopics numTopics mediumint(8) unsigned NOT NULL default '0', -CHANGE COLUMN numPosts numPosts mediumint(8) unsigned NOT NULL default '0', -CHANGE COLUMN description description text NOT NULL default '', -CHANGE COLUMN ID_BOARD ID_BOARD smallint(5) unsigned NOT NULL auto_increment PRIMARY KEY; ----# - ----# Updating access permissions... ----{ -$member_groups = getMemberGroups(); - -$result = upgrade_query(" - ALTER TABLE {$db_prefix}boards - ADD memberGroups varchar(128) NOT NULL default '-1,0'"); -if ($result !== false) -{ - $result = upgrade_query(" - SELECT TRIM(memberGroups) AS memberGroups, ID_CAT - FROM {$db_prefix}categories"); - while ($row = mysql_fetch_assoc($result)) - { - if (trim($row['memberGroups']) == '') - $groups = '-1,0,2'; - else - { - $memberGroups = array_unique(explode(',', $row['memberGroups'])); - $groups = array(2); - foreach ($memberGroups as $k => $check) - { - $memberGroups[$k] = trim($memberGroups[$k]); - if ($memberGroups[$k] == '' || !isset($member_groups[$memberGroups[$k]]) || $member_groups[$memberGroups[$k]] == 8) - continue; - - $groups[] = $member_groups[$memberGroups[$k]]; - } - - $groups = implode(',', array_unique($groups)); - } - - upgrade_query(" - UPDATE {$db_prefix}boards - SET memberGroups = '$groups', lastUpdated = " . time() . " - WHERE ID_CAT = $row[ID_CAT]"); - } -} ----} - -ALTER TABLE {$db_prefix}categories -DROP memberGroups; - -ALTER TABLE {$db_prefix}boards -CHANGE COLUMN memberGroups memberGroups varchar(128) NOT NULL default '-1,0'; ----# - ----# Converting "categories"... -ALTER TABLE {$db_prefix}categories -DROP PRIMARY KEY, -ADD canCollapse tinyint(1) NOT NULL default '1', -CHANGE COLUMN ID_CAT ID_CAT tinyint(4) unsigned NOT NULL auto_increment PRIMARY KEY; ----# - ----# Converting announcement permissions... ----{ -$request = upgrade_query(" - SHOW COLUMNS - FROM {$db_prefix}boards - LIKE 'notifyAnnouncements'"); -if (mysql_num_rows($request) > 0) -{ - $conversions = array( - 'moderate_forum' => array('manage_membergroups', 'manage_bans'), - 'admin_forum' => array('manage_permissions'), - 'edit_forum' => array('manage_boards', 'manage_smileys', 'manage_attachments'), - ); - foreach ($conversions as $original_permission => $new_permissions) - { - $setString = ''; - $result = upgrade_query(" - SELECT ID_GROUP, addDeny - FROM {$db_prefix}permissions - WHERE permission = '$original_permission'"); - while ($row = mysql_fetch_assoc($result)) - $setString .= " - ('" . implode("', $row[ID_GROUP], $row[addDeny]), - ('", $new_permissions) . "', $row[ID_GROUP], $row[addDeny]),"; - mysql_free_result($result); - - if ($setString != '') - upgrade_query(" - INSERT IGNORE INTO {$db_prefix}permissions - (permission, ID_GROUP, addDeny) - VALUES" . substr($setString, 0, -1)); - } -} -mysql_free_result($request); ----} - -DELETE FROM {$db_prefix}permissions -WHERE permission = 'edit_forum'; - -ALTER TABLE {$db_prefix}boards -DROP COLUMN notifyAnnouncements; ----# - ----# Converting board statistics... ----{ -$result = upgrade_query(" - SELECT MAX(m.ID_MSG) AS ID_LAST_MSG, t.ID_BOARD - FROM ({$db_prefix}messages AS m, {$db_prefix}topics AS t) - WHERE m.ID_MSG = t.ID_LAST_MSG - GROUP BY t.ID_BOARD"); -$last_msgs = array(); -while ($row = mysql_fetch_assoc($result)) - $last_msgs[] = $row['ID_LAST_MSG']; -mysql_free_result($result); - -if (!empty($last_msgs)) -{ - $result = upgrade_query(" - SELECT m.ID_MSG, m.posterTime, t.ID_BOARD - FROM ({$db_prefix}messages AS m, {$db_prefix}topics AS t) - WHERE t.ID_TOPIC = m.ID_TOPIC - AND m.ID_MSG IN (" . implode(',', $last_msgs) . ") - LIMIT " . count($last_msgs)); - while ($row = mysql_fetch_assoc($result)) - { - upgrade_query(" - UPDATE {$db_prefix}boards - SET ID_LAST_MSG = $row[ID_MSG], lastUpdated = " . (int) $row['posterTime'] . " - WHERE ID_BOARD = $row[ID_BOARD] - LIMIT 1"); - } - mysql_free_result($result); -} ----} ----# - ----# Converting "moderators"... ----{ -$request = upgrade_query(" - SHOW COLUMNS - FROM {$db_prefix}boards - LIKE 'moderators'"); -$do_moderators = mysql_num_rows($request) > 0; -mysql_free_result($request); - -if ($do_moderators) -{ - $result = upgrade_query(" - SELECT TRIM(moderators) AS moderators, ID_BOARD - FROM {$db_prefix}boards - WHERE TRIM(moderators) != ''"); - while ($row = mysql_fetch_assoc($result)) - { - $moderators = array_unique(explode(',', $row['moderators'])); - foreach ($moderators as $k => $dummy) - { - $moderators[$k] = addslashes(trim($moderators[$k])); - if ($moderators[$k] == '') - unset($moderators[$k]); - } - - if (!empty($moderators)) - { - upgrade_query(" - INSERT IGNORE INTO {$db_prefix}moderators - (ID_BOARD, ID_MEMBER) - SELECT $row[ID_BOARD], ID_MEMBER - FROM {$db_prefix}members - WHERE memberName IN ('" . implode("', '", $moderators) . "') - LIMIT " . count($moderators)); - } - } -} ----} - -ALTER TABLE {$db_prefix}boards -DROP moderators; ----# - ----# Updating board order... ----{ -$request = upgrade_query(" - SELECT c.ID_CAT, c.catOrder, b.ID_BOARD, b.boardOrder - FROM {$db_prefix}categories AS c - LEFT JOIN {$db_prefix}boards AS b ON (b.ID_CAT = c.ID_CAT) - ORDER BY c.catOrder, b.childLevel, b.boardOrder, b.ID_BOARD"); -$catOrder = -1; -$boardOrder = -1; -$curCat = -1; -while ($row = mysql_fetch_assoc($request)) -{ - if ($curCat != $row['ID_CAT']) - { - $curCat = $row['ID_CAT']; - if (++$catOrder != $row['catOrder']) - upgrade_query(" - UPDATE {$db_prefix}categories - SET catOrder = $catOrder - WHERE ID_CAT = $row[ID_CAT] - LIMIT 1"); - } - if (!empty($row['ID_BOARD']) && ++$boardOrder != $row['boardOrder']) - upgrade_query(" - UPDATE {$db_prefix}boards - SET boardOrder = $boardOrder - WHERE ID_BOARD = $row[ID_BOARD] - LIMIT 1"); -} -mysql_free_result($request); ----} ----# - ----# Fixing possible issues with board access (part 1)... ----{ -if (empty($modSettings['smfVersion']) || (substr($modSettings['smfVersion'], 0, 9) == '1.0 Beta ' && $modSettings['smfVersion'][9] <= 5)) -{ - $all_groups = array(); - $result = upgrade_query(" - SELECT ID_GROUP - FROM {$db_prefix}membergroups"); - while ($row = mysql_fetch_assoc($result)) - $all_groups[] = $row['ID_GROUP']; - mysql_free_result($result); - - $result = upgrade_query(" - SELECT ID_BOARD, memberGroups - FROM {$db_prefix}boards - WHERE FIND_IN_SET(0, memberGroups)"); - while ($row = mysql_fetch_assoc($result)) - { - upgrade_query(" - UPDATE {$db_prefix}boards - SET memberGroups = '" . implode(',', array_unique(array_merge(explode(',', $row['memberGroups']), $all_groups))) . "' - WHERE ID_BOARD = $row[ID_BOARD] - LIMIT 1"); - } - mysql_free_result($result); -} ----} ----# - ----# Fixing possible issues with board access. (part 2).. -UPDATE {$db_prefix}boards -SET memberGroups = SUBSTRING(memberGroups, 2) -WHERE SUBSTRING(memberGroups, 1, 1) = ','; - -UPDATE {$db_prefix}boards -SET memberGroups = SUBSTRING(memberGroups, 1, LENGTH(memberGroups) - 1) -WHERE SUBSTRING(memberGroups, LENGTH(memberGroups)) = ','; - -UPDATE {$db_prefix}boards -SET memberGroups = REPLACE(',,', ',', REPLACE(',,', ',', memberGroups)) -WHERE LOCATE(',,', memberGroups); ----# - -/******************************************************************************/ ---- Converting attachments, topics, and messages... -/******************************************************************************/ - ----# Converting "attachments"... -INSERT INTO {$db_prefix}attachments - (ID_MSG, filename, size) -SELECT ID_MSG, SUBSTRING(attachmentFilename, 1, 255), attachmentSize -FROM {$db_prefix}messages -WHERE attachmentFilename IS NOT NULL - AND attachmentFilename != ''; - -ALTER TABLE {$db_prefix}messages -DROP attachmentSize, -DROP attachmentFilename; ----# - ----# Updating "attachments"... -ALTER TABLE {$db_prefix}attachments -DROP INDEX ID_MEMBER, -ADD UNIQUE ID_MEMBER (ID_MEMBER, ID_ATTACH); - -ALTER TABLE {$db_prefix}attachments -CHANGE COLUMN size size int(10) unsigned NOT NULL default '0'; ----# - ----# Updating columns on "messages" (part 1)... -ALTER TABLE {$db_prefix}messages -DROP PRIMARY KEY, -CHANGE COLUMN ID_MSG ID_MSG int(10) unsigned NOT NULL auto_increment PRIMARY KEY; ----# - ----# Updating columns on "messages" (part 2)... -ALTER TABLE {$db_prefix}messages -CHANGE COLUMN ID_TOPIC ID_TOPIC mediumint(8) unsigned NOT NULL default '0'; -ALTER TABLE {$db_prefix}messages -CHANGE COLUMN smiliesEnabled smileysEnabled tinyint(4) NOT NULL default '1'; ----# - ----# Updating columns on "messages" (part 3)... -ALTER TABLE {$db_prefix}messages -CHANGE COLUMN posterTime posterTime int(10) unsigned NOT NULL default '0', -CHANGE COLUMN modifiedTime modifiedTime int(10) unsigned NOT NULL default '0'; - -ALTER TABLE {$db_prefix}messages -ADD INDEX participation (ID_MEMBER, ID_TOPIC); -ALTER TABLE {$db_prefix}messages -ADD INDEX ipIndex (posterIP(15), ID_TOPIC); ----# - ----# Updating columns on "messages" (part 4)... -ALTER TABLE {$db_prefix}messages -CHANGE COLUMN ID_MEMBER ID_MEMBER mediumint(8) unsigned NOT NULL default '0', -CHANGE COLUMN icon icon varchar(16) NOT NULL default 'xx'; - -ALTER TABLE {$db_prefix}messages -ADD INDEX ID_MEMBER (ID_MEMBER); -ALTER TABLE {$db_prefix}messages -ADD UNIQUE INDEX topic (ID_TOPIC, ID_MSG); ----# - ----# Updating columns on "messages" (part 5)... -ALTER TABLE {$db_prefix}messages -ADD COLUMN ID_BOARD smallint(5) unsigned NOT NULL default '0'; ----# - ----# Updating data in "messages"... ----{ -while (true) -{ - nextSubstep($substep); - - $request = upgrade_query(" - SELECT DISTINCT t.ID_BOARD, t.ID_TOPIC - FROM ({$db_prefix}messages AS m, {$db_prefix}topics AS t) - WHERE t.ID_TOPIC = m.ID_TOPIC - AND m.ID_BOARD = 0 - LIMIT 1400"); - $boards = array(); - while ($row = mysql_fetch_assoc($request)) - $boards[$row['ID_BOARD']][] = $row['ID_TOPIC']; - - foreach ($boards as $board => $topics) - upgrade_query(" - UPDATE {$db_prefix}messages - SET ID_BOARD = $board - WHERE ID_TOPIC IN (" . implode(', ', $topics) . ')'); - - if (mysql_num_rows($request) < 1400) - break; - - mysql_free_result($request); -} ----} ----# - ----# Cleaning up "messages"... -ALTER TABLE {$db_prefix}messages -ADD INDEX ID_BOARD (ID_BOARD); - -ALTER TABLE {$db_prefix}messages -DROP INDEX posterTime_2; -ALTER TABLE {$db_prefix}messages -DROP INDEX posterTime_3; - -ALTER TABLE {$db_prefix}messages -DROP INDEX ID_MEMBER_2; -ALTER TABLE {$db_prefix}messages -DROP INDEX ID_MEMBER_3; ----# - ----# Updating indexes on "topics" (part 1)... -ALTER TABLE {$db_prefix}topics -DROP INDEX ID_FIRST_MSG; - -ALTER TABLE {$db_prefix}topics -DROP INDEX ID_LAST_MSG; - -ALTER TABLE {$db_prefix}topics -ADD INDEX isSticky (isSticky); ----# - ----# Updating indexes on "topics" (part 2)... -ALTER IGNORE TABLE {$db_prefix}topics -ADD UNIQUE INDEX lastMessage (ID_LAST_MSG, ID_BOARD), -ADD UNIQUE INDEX firstMessage (ID_FIRST_MSG, ID_BOARD), -ADD UNIQUE INDEX poll (ID_POLL, ID_TOPIC); ----# - ----# Updating columns on "topics" (part 1)... -ALTER TABLE {$db_prefix}topics -DROP PRIMARY KEY, -CHANGE COLUMN ID_TOPIC ID_TOPIC mediumint(8) unsigned NOT NULL auto_increment PRIMARY KEY, -CHANGE COLUMN ID_BOARD ID_BOARD smallint(5) unsigned NOT NULL default '0'; ----# - ----# Updating columns on "topics" (part 2)... -ALTER TABLE {$db_prefix}topics -CHANGE COLUMN ID_MEMBER_STARTED ID_MEMBER_STARTED mediumint(8) unsigned NOT NULL default '0', -CHANGE COLUMN ID_MEMBER_UPDATED ID_MEMBER_UPDATED mediumint(8) unsigned NOT NULL default '0'; ----# - ----# Updating columns on "topics" (part 3)... -ALTER TABLE {$db_prefix}topics -CHANGE COLUMN ID_FIRST_MSG ID_FIRST_MSG int(10) unsigned NOT NULL default '0', -CHANGE COLUMN ID_LAST_MSG ID_LAST_MSG int(10) unsigned NOT NULL default '0'; ----# - ----# Updating columns on "topics" (part 4)... -ALTER TABLE {$db_prefix}topics -CHANGE COLUMN ID_POLL ID_POLL mediumint(8) unsigned NOT NULL default '0'; ----# - -/******************************************************************************/ ---- Converting members and personal messages... -/******************************************************************************/ - ----# Updating data in "members" (part 1)... -UPDATE IGNORE {$db_prefix}members -SET im_ignore_list = '*' -WHERE im_ignore_list RLIKE '([\n,]|^)[*]([\n,]|$)'; ----# - ----# Updating data in "members" (part 2)... ----{ -$request = upgrade_query(" - SHOW COLUMNS - FROM {$db_prefix}members - LIKE 'im_ignore_list'"); -$do_it = mysql_num_rows($request) != 0; -mysql_free_result($request); - -while ($do_it) -{ - nextSubstep($substep); - - $request = upgrade_query(" - SELECT ID_MEMBER, im_ignore_list - FROM {$db_prefix}members - WHERE im_ignore_list RLIKE '[a-z]' - LIMIT 512"); - while ($row = mysql_fetch_assoc($request)) - { - $request2 = upgrade_query(" - SELECT ID_MEMBER - FROM {$db_prefix}members - WHERE FIND_IN_SET(memberName, '" . addslashes($row['im_ignore_list']) . "')"); - $im_ignore_list = ''; - while ($row2 = mysql_fetch_assoc($request2)) - $im_ignore_list .= ',' . $row2['ID_MEMBER']; - mysql_free_result($request2); - - upgrade_query(" - UPDATE {$db_prefix}members - SET im_ignore_list = '" . substr($im_ignore_list, 1) . "' - WHERE ID_MEMBER = $row[ID_MEMBER] - LIMIT 1"); - } - if (mysql_num_rows($request) < 512) - break; - mysql_free_result($request); -} ----} ----# - ----# Updating data in "members" (part 3)... -UPDATE {$db_prefix}members -SET realName = memberName -WHERE IFNULL(realName, '') = ''; ----# - ----# Updating data in "members" (part 4)... -UPDATE {$db_prefix}members -SET lngfile = REPLACE(lngfile, '.lng', '') -WHERE lngfile LIKE '%.lng'; ----# - ----# Cleaning up "members"... -ALTER TABLE {$db_prefix}members -DROP INDEX memberID; -ALTER TABLE {$db_prefix}members -DROP INDEX memberID_2; ----# - ----# Adding new columns to "members"... -ALTER TABLE {$db_prefix}members -DROP PRIMARY KEY, -CHANGE COLUMN ID_MEMBER ID_MEMBER mediumint(8) unsigned NOT NULL auto_increment PRIMARY KEY, -ADD instantMessages smallint(5) NOT NULL default 0, -ADD unreadMessages smallint(5) NOT NULL default 0, -ADD ID_THEME tinyint(4) unsigned NOT NULL default 0, -ADD ID_GROUP smallint(5) unsigned NOT NULL default 0, -ADD is_activated tinyint(3) unsigned NOT NULL default '1', -ADD validation_code varchar(10) NOT NULL default '', -ADD ID_MSG_LAST_VISIT int(10) unsigned NOT NULL default '0', -ADD additionalGroups tinytext NOT NULL default ''; ----# - ----# Updating columns on "members"... -ALTER TABLE {$db_prefix}members -CHANGE COLUMN ID_THEME ID_THEME tinyint(4) unsigned NOT NULL default 0; -ALTER TABLE {$db_prefix}members -ADD showOnline tinyint(4) NOT NULL default '1'; -ALTER TABLE {$db_prefix}members -ADD smileySet varchar(48) NOT NULL default ''; -ALTER TABLE {$db_prefix}members -ADD totalTimeLoggedIn int(10) unsigned NOT NULL default '0'; -ALTER TABLE {$db_prefix}members -ADD passwordSalt varchar(5) NOT NULL default ''; ----# - ----# Updating data in "members" (part 5)... -UPDATE {$db_prefix}members -SET gender = CASE gender - WHEN '0' THEN 0 - WHEN 'Male' THEN 1 - WHEN 'Female' THEN 2 - ELSE 0 END, secretAnswer = IF(secretAnswer = '', '', MD5(secretAnswer)) -WHERE gender NOT IN ('0', '1', '2'); ----# - ----# Updating data in "members" (part 6)... ----{ -$member_groups = getMemberGroups(); - -foreach ($member_groups as $name => $id) -{ - upgrade_query(" - UPDATE IGNORE {$db_prefix}members - SET ID_GROUP = $id - WHERE memberGroup = '" . addslashes($name) . "'"); - - nextSubstep($substep); -} ----} -UPDATE IGNORE {$db_prefix}members -SET ID_GROUP = 1 -WHERE memberGroup = 'Administrator'; -UPDATE IGNORE {$db_prefix}members -SET ID_GROUP = 2 -WHERE memberGroup = 'Global Moderator'; - -ALTER TABLE {$db_prefix}members -DROP memberGroup; ----# - ----# Changing column sizes on "members" (part 1)... -ALTER TABLE {$db_prefix}members -CHANGE COLUMN timeOffset timeOffset float NOT NULL default '0', -CHANGE COLUMN posts posts mediumint(8) unsigned NOT NULL default '0', -CHANGE COLUMN timeFormat timeFormat varchar(80) NOT NULL default '', -CHANGE COLUMN lastLogin lastLogin int(11) NOT NULL default '0', -CHANGE COLUMN karmaBad karmaBad smallint(5) unsigned NOT NULL default '0', -CHANGE COLUMN karmaGood karmaGood smallint(5) unsigned NOT NULL default '0', -CHANGE COLUMN gender gender tinyint(4) unsigned NOT NULL default '0', -CHANGE COLUMN hideEmail hideEmail tinyint(4) NOT NULL default '0'; ----# - ----# Changing column sizes on "members" (part 2)... -ALTER TABLE {$db_prefix}members -DROP INDEX realName; - -ALTER TABLE {$db_prefix}members -CHANGE COLUMN AIM AIM varchar(16) NOT NULL default '', -CHANGE COLUMN YIM YIM varchar(32) NOT NULL default '', -CHANGE COLUMN ICQ ICQ tinytext NOT NULL default '', -CHANGE COLUMN realName realName tinytext NOT NULL default '', -CHANGE COLUMN emailAddress emailAddress tinytext NOT NULL default '', -CHANGE COLUMN dateRegistered dateRegistered int(10) unsigned NOT NULL default '0', -CHANGE COLUMN passwd passwd varchar(64) NOT NULL default '', -CHANGE COLUMN personalText personalText tinytext NOT NULL default '', -CHANGE COLUMN websiteTitle websiteTitle tinytext NOT NULL default ''; ----# - ----# Changing column sizes on "members" (part 3)... -ALTER TABLE {$db_prefix}members -DROP INDEX lngfile; - -ALTER TABLE {$db_prefix}members -CHANGE COLUMN websiteUrl websiteUrl tinytext NOT NULL default '', -CHANGE COLUMN location location tinytext NOT NULL default '', -CHANGE COLUMN avatar avatar tinytext NOT NULL default '', -CHANGE COLUMN im_ignore_list im_ignore_list tinytext NOT NULL default '', -CHANGE COLUMN usertitle usertitle tinytext NOT NULL default '', -CHANGE COLUMN lngfile lngfile tinytext NOT NULL default '', -CHANGE COLUMN MSN MSN tinytext NOT NULL default '', -CHANGE COLUMN memberIP memberIP tinytext NOT NULL default '', -ADD INDEX lngfile (lngfile(24)); ----# - ----# Updating keys on "members"... -ALTER TABLE {$db_prefix}members -ADD INDEX ID_GROUP (ID_GROUP), -ADD INDEX birthdate (birthdate), -ADD INDEX lngfile (lngfile(30)); ----# - ----# Converting member statistics... -REPLACE INTO {$db_prefix}settings - (variable, value) -SELECT 'latestMember', ID_MEMBER -FROM {$db_prefix}members -ORDER BY ID_MEMBER DESC -LIMIT 1; - -REPLACE INTO {$db_prefix}settings - (variable, value) -SELECT 'latestRealName', IFNULL(realName, memberName) -FROM {$db_prefix}members -ORDER BY ID_MEMBER DESC -LIMIT 1; - -REPLACE INTO {$db_prefix}settings - (variable, value) -SELECT 'maxMsgID', ID_MSG -FROM {$db_prefix}messages -ORDER BY ID_MSG DESC -LIMIT 1; ----# - ----# Adding new columns to "instant_messages"... -ALTER IGNORE TABLE {$db_prefix}instant_messages -ADD COLUMN deletedBySender tinyint(3) unsigned NOT NULL default '0' AFTER ID_MEMBER_FROM; ----# - ----# Changing column sizes on "instant_messages" (part 1)... -ALTER TABLE {$db_prefix}instant_messages -CHANGE COLUMN ID_MEMBER_FROM ID_MEMBER_FROM mediumint(8) unsigned NOT NULL default 0, -CHANGE COLUMN msgtime msgtime int(10) unsigned NOT NULL default '0', -CHANGE COLUMN subject subject tinytext NOT NULL; -ALTER TABLE {$db_prefix}instant_messages -DROP INDEX fromName, -DROP INDEX ID_MEMBER_FROM; ----# - ----# Changing column sizes on "instant_messages" (part 2)... -ALTER TABLE {$db_prefix}instant_messages -DROP PRIMARY KEY, -CHANGE COLUMN ID_IM ID_PM int(10) unsigned NOT NULL auto_increment PRIMARY KEY; -ALTER TABLE {$db_prefix}instant_messages -ADD INDEX msgtime (msgtime); ----# - ----# Cleaning up "instant_messages"... -ALTER TABLE {$db_prefix}instant_messages -DROP INDEX ID_MEMBER_FROM_2; -ALTER TABLE {$db_prefix}instant_messages -DROP INDEX ID_MEMBER_FROM_3; -ALTER TABLE {$db_prefix}instant_messages -DROP INDEX ID_MEMBER_FROM_4; -ALTER TABLE {$db_prefix}instant_messages -DROP INDEX ID_MEMBER_FROM_5; -ALTER TABLE {$db_prefix}instant_messages -DROP INDEX ID_MEMBER_TO_2; -ALTER TABLE {$db_prefix}instant_messages -DROP INDEX ID_MEMBER_TO_3; -ALTER TABLE {$db_prefix}instant_messages -DROP INDEX ID_MEMBER_TO_4; -ALTER TABLE {$db_prefix}instant_messages -DROP INDEX ID_MEMBER_TO_5; -ALTER TABLE {$db_prefix}instant_messages -DROP INDEX deletedBy_2; -ALTER TABLE {$db_prefix}instant_messages -DROP INDEX deletedBy_3; -ALTER TABLE {$db_prefix}instant_messages -DROP INDEX deletedBy_4; -ALTER TABLE {$db_prefix}instant_messages -DROP INDEX deletedBy_5; ----# - ----# Creating "im_recipients"... -CREATE TABLE IF NOT EXISTS {$db_prefix}im_recipients ( - ID_PM int(10) unsigned NOT NULL default '0', - ID_MEMBER mediumint(8) unsigned NOT NULL default '0', - bcc tinyint(3) unsigned NOT NULL default '0', - is_read tinyint(3) unsigned NOT NULL default '0', - deleted tinyint(3) unsigned NOT NULL default '0', - PRIMARY KEY (ID_PM, ID_MEMBER), - KEY ID_MEMBER (ID_MEMBER, deleted) -) ENGINE=MyISAM; ----# - ----# Updating "im_recipients"... -ALTER TABLE {$db_prefix}im_recipients -DROP PRIMARY KEY, -CHANGE COLUMN ID_IM ID_PM int(10) unsigned NOT NULL default '0', -ADD PRIMARY KEY (ID_PM, ID_MEMBER); ----# - ----# Updating data in "instant_messages" (part 1)... ----{ -$request = mysql_query(" - SHOW COLUMNS - FROM {$db_prefix}instant_messages - LIKE 'readBy'"); -$do_it = $request !== false; - -if ($do_it) -{ - $adv_im = mysql_num_rows($request) == 0; - mysql_free_result($request); - - mysql_query(" - INSERT IGNORE INTO {$db_prefix}im_recipients - (ID_PM, ID_MEMBER, bcc, is_read, deleted) - SELECT ID_PM, ID_MEMBER_TO, 0, IF(" . (!$adv_im ? 'readBy' : 'alerted') . " != 0, 1, 0), IF(deletedBy = '1', 1, 0) - FROM {$db_prefix}instant_messages"); -} ----} - -UPDATE IGNORE {$db_prefix}instant_messages -SET deletedBySender = 1 -WHERE deletedBy = 0; ----# - ----# Updating data in "instant_messages" (part 2)... -ALTER TABLE {$db_prefix}instant_messages -DROP INDEX ID_MEMBER_TO; -ALTER TABLE {$db_prefix}instant_messages -DROP INDEX deletedBy; -ALTER TABLE {$db_prefix}instant_messages -DROP INDEX readBy; - -ALTER TABLE {$db_prefix}instant_messages -DROP COLUMN ID_MEMBER_TO, -DROP COLUMN deletedBy, -DROP COLUMN toName, -DROP COLUMN readBy; - -ALTER TABLE {$db_prefix}instant_messages -ADD INDEX ID_MEMBER (ID_MEMBER_FROM, deletedBySender); ----# - ----# Recounting personal message totals... ----{ -$request = mysql_query(" - SHOW CREATE TABLE {$db_prefix}instant_messages"); -$do_it = $request !== false; -@mysql_free_result($request); - -$request = upgrade_query(" - SELECT COUNT(*) - FROM {$db_prefix}members"); -list ($totalMembers) = mysql_fetch_row($request); -mysql_free_result($request); - -$_GET['m'] = (int) @$_GET['m']; - -while ($_GET['m'] < $totalMembers && $do_it) -{ - nextSubstep($substep); - - $mrequest = upgrade_query(" - SELECT mem.ID_MEMBER, COUNT(pmr.ID_PM) AS instantMessages_real, mem.instantMessages - FROM {$db_prefix}members AS mem - LEFT JOIN {$db_prefix}im_recipients AS pmr ON (pmr.ID_MEMBER = mem.ID_MEMBER AND pmr.deleted = 0) - WHERE mem.ID_MEMBER > $_GET[m] - AND mem.ID_MEMBER <= $_GET[m] + 512 - GROUP BY mem.ID_MEMBER - HAVING instantMessages_real != instantMessages - LIMIT 512"); - while ($row = mysql_fetch_assoc($mrequest)) - { - upgrade_query(" - UPDATE {$db_prefix}members - SET instantMessages = $row[instantMessages_real] - WHERE ID_MEMBER = $row[ID_MEMBER] - LIMIT 1"); - } - - $_GET['m'] += 512; -} -unset($_GET['m']); ----} ----{ -$request = mysql_query(" - SHOW CREATE TABLE {$db_prefix}instant_messages"); -$do_it = $request !== false; -@mysql_free_result($request); - -$request = upgrade_query(" - SELECT COUNT(*) - FROM {$db_prefix}members"); -list ($totalMembers) = mysql_fetch_row($request); -mysql_free_result($request); - -$_GET['m'] = (int) @$_GET['m']; - -while ($_GET['m'] < $totalMembers && $do_it) -{ - nextSubstep($substep); - - $mrequest = upgrade_query(" - SELECT mem.ID_MEMBER, COUNT(pmr.ID_PM) AS unreadMessages_real, mem.unreadMessages - FROM {$db_prefix}members AS mem - LEFT JOIN {$db_prefix}im_recipients AS pmr ON (pmr.ID_MEMBER = mem.ID_MEMBER AND pmr.deleted = 0 AND pmr.is_read = 0) - WHERE mem.ID_MEMBER > $_GET[m] - AND mem.ID_MEMBER <= $_GET[m] + 512 - GROUP BY mem.ID_MEMBER - HAVING unreadMessages_real != unreadMessages - LIMIT 512"); - while ($row = mysql_fetch_assoc($mrequest)) - { - upgrade_query(" - UPDATE {$db_prefix}members - SET unreadMessages = $row[unreadMessages_real] - WHERE ID_MEMBER = $row[ID_MEMBER] - LIMIT 1"); - } - - $_GET['m'] += 512; -} -unset($_GET['m']); ----} ----# - ----# Converting "membergroups"... ----{ -global $JrPostNum, $FullPostNum, $SrPostNum, $GodPostNum; - -$result = mysql_query(" - SELECT minPosts - FROM {$db_prefix}membergroups - LIMIT 1"); -if ($result === false) -{ - upgrade_query(" - RENAME TABLE {$db_prefix}membergroups TO {$db_prefix}old_membergroups"); - - upgrade_query(" - CREATE TABLE {$db_prefix}membergroups ( - ID_GROUP smallint(5) unsigned NOT NULL auto_increment, - groupName varchar(80) NOT NULL default '', - onlineColor varchar(20) NOT NULL default '', - minPosts mediumint(9) NOT NULL default '-1', - maxMessages smallint(5) unsigned NOT NULL default '0', - stars tinytext NOT NULL default '', - PRIMARY KEY (ID_GROUP), - KEY minPosts (minPosts) - ) ENGINE=MyISAM"); - - upgrade_query(" - INSERT INTO {$db_prefix}membergroups - (ID_GROUP, groupName, onlineColor, minPosts, stars) - SELECT ID_GROUP, membergroup, '#FF0000', -1, '5#staradmin.gif' - FROM {$db_prefix}old_membergroups - WHERE ID_GROUP = 1"); - - upgrade_query(" - INSERT INTO {$db_prefix}membergroups - (ID_GROUP, groupName, onlineColor, minPosts, stars) - SELECT 2, membergroup, '#0000FF', -1, '5#stargmod.gif' - FROM {$db_prefix}old_membergroups - WHERE ID_GROUP = 8"); - - upgrade_query(" - INSERT INTO {$db_prefix}membergroups - (ID_GROUP, groupName, onlineColor, minPosts, stars) - SELECT 3, membergroup, '', -1, '5#starmod.gif' - FROM {$db_prefix}old_membergroups - WHERE ID_GROUP = 2"); - - upgrade_query(" - INSERT INTO {$db_prefix}membergroups - (ID_GROUP, groupName, onlineColor, minPosts, stars) - SELECT - ID_GROUP + 1, membergroup, '', CASE ID_GROUP - WHEN 3 THEN 0 - WHEN 4 THEN '$JrPostNum' - WHEN 5 THEN '$FullPostNum' - WHEN 6 THEN '$SrPostNum' - WHEN 7 THEN '$GodPostNum' - END, CONCAT(ID_GROUP - 2, '#star.gif') - FROM {$db_prefix}old_membergroups - WHERE ID_GROUP IN (3, 4, 5, 6, 7)"); - - upgrade_query(" - INSERT INTO {$db_prefix}membergroups - (ID_GROUP, groupName, onlineColor, minPosts, stars) - SELECT ID_GROUP, membergroup, '', -1, '' - FROM {$db_prefix}old_membergroups - WHERE ID_GROUP > 8"); - - upgrade_query(" - DROP TABLE IF EXISTS {$db_prefix}old_membergroups"); - - $permissions = array( - 'view_mlist', - 'search_posts', - 'profile_view_own', - 'profile_view_any', - 'pm_read', - 'pm_send', - 'calendar_view', - 'view_stats', - 'who_view', - 'profile_identity_own', - 'profile_extra_own', - 'profile_remote_avatar', - 'profile_remove_own', - ); - - foreach ($permissions as $perm) - upgrade_query(" - INSERT INTO {$db_prefix}permissions - (ID_GROUP, permission) - SELECT IF(ID_GROUP = 1, 0, ID_GROUP), '$perm' - FROM {$db_prefix}membergroups - WHERE ID_GROUP != 3 - AND minPosts = -1"); - - $board_permissions = array( - 'remove_own', - 'lock_own', - 'mark_any_notify', - 'mark_notify', - 'modify_own', - 'poll_add_own', - 'poll_edit_own', - 'poll_lock_own', - 'poll_post', - 'poll_view', - 'poll_vote', - 'post_attachment', - 'post_new', - 'post_reply_any', - 'post_reply_own', - 'delete_own', - 'report_any', - 'send_topic', - 'view_attachments', - ); - - foreach ($board_permissions as $perm) - upgrade_query(" - INSERT INTO {$db_prefix}board_permissions - (ID_GROUP, permission) - SELECT IF(ID_GROUP = 1, 0, ID_GROUP), '$perm' - FROM {$db_prefix}membergroups - WHERE minPosts = -1"); -} ----} ----# - ----# Converting "reserved_names"... ----{ -$request = mysql_query(" - SELECT setting, value - FROM {$db_prefix}reserved_names"); -if ($request !== false) -{ - $words = array(); - $match_settings = array(); - while ($row = mysql_fetch_assoc($request)) - { - if (substr($row['setting'], 0, 5) == 'match') - $match_settings[$row['setting']] = $row['value']; - else - $words[] = $row['value']; - } - mysql_free_result($request); - - upgrade_query(" - INSERT IGNORE INTO {$db_prefix}settings - VALUES ('reserveWord', '" . (int) @$match_settings['matchword'] . "'), - ('reserveCase', '" . (int) @$match_settings['matchcase'] . "'), - ('reserveUser', '" . (int) @$match_settings['matchuser'] . "'), - ('reserveName', '" . (int) @$match_settings['matchname'] . "'), - ('reserveNames', '" . implode("\n", $words) . "')"); - - upgrade_query(" - DROP TABLE {$db_prefix}reserved_names"); -} ----} ----# - ----# Converting member's groups... -ALTER TABLE {$db_prefix}members -ADD COLUMN ID_POST_GROUP smallint(5) unsigned NOT NULL default '0', -ADD INDEX ID_POST_GROUP (ID_POST_GROUP); - ----{ -$request = upgrade_query(" - SELECT ID_GROUP, minPosts - FROM {$db_prefix}membergroups - WHERE minPosts != -1 - ORDER BY minPosts DESC"); -$post_groups = array(); -while ($row = mysql_fetch_assoc($request)) - $post_groups[$row['minPosts']] = $row['ID_GROUP']; -mysql_free_result($request); - -$request = upgrade_query(" - SELECT ID_MEMBER, posts - FROM {$db_prefix}members"); -$mg_updates = array(); -while ($row = mysql_fetch_assoc($request)) -{ - $group = 4; - foreach ($post_groups as $min_posts => $group_id) - if ($row['posts'] > $min_posts) - { - $group = $group_id; - break; - } - - $mg_updates[$group][] = $row['ID_MEMBER']; -} -mysql_free_result($request); - -foreach ($mg_updates as $group_to => $update_members) - upgrade_query(" - UPDATE {$db_prefix}members - SET ID_POST_GROUP = $group_to - WHERE ID_MEMBER IN (" . implode(', ', $update_members) . ") - LIMIT " . count($update_members)); ----} ----# - -/******************************************************************************/ ---- Converting the calendar, notifications, and miscellaneous... -/******************************************************************************/ - ----# Converting censored words... ----{ -if (!isset($modSettings['censor_vulgar']) || !isset($modSettings['censor_proper'])) -{ - $request = upgrade_query(" - SELECT vulgar, proper - FROM {$db_prefix}censor"); - $censor_vulgar = array(); - $censor_proper = array(); - while ($row = mysql_fetch_row($request)) - { - $censor_vulgar[] = trim($row[0]); - $censor_proper[] = trim($row[1]); - } - mysql_free_result($request); - - $modSettings['censor_vulgar'] = addslashes(implode("\n", $censor_vulgar)); - $modSettings['censor_proper'] = addslashes(implode("\n", $censor_proper)); - - upgrade_query(" - INSERT IGNORE INTO {$db_prefix}settings - (variable, value) - VALUES - ('censor_vulgar', '$modSettings[censor_vulgar]'), - ('censor_proper', '$modSettings[censor_proper]')"); - - upgrade_query(" - DROP TABLE IF EXISTS {$db_prefix}censor"); -} ----} ----# - ----# Converting topic notifications... ----{ -$result = mysql_query(" - SELECT COUNT(*) - FROM {$db_prefix}topics - WHERE notifies != ''"); -if ($result !== false) -{ - list ($numNotifies) = mysql_fetch_row($result); - mysql_free_result($result); - - $_GET['t'] = (int) @$_GET['t']; - - while ($_GET['t'] < $numNotifies) - { - nextSubstep($substep); - - upgrade_query(" - INSERT IGNORE INTO {$db_prefix}log_notify - (ID_MEMBER, ID_TOPIC) - SELECT mem.ID_MEMBER, t.ID_TOPIC - FROM ({$db_prefix}topics AS t, {$db_prefix}members AS mem) - WHERE FIND_IN_SET(mem.ID_MEMBER, t.notifies) - AND t.notifies != '' - LIMIT $_GET[t], 512"); - - $_GET['t'] += 512; - } - unset($_GET['t']); -} ----} - -ALTER TABLE {$db_prefix}topics -DROP notifies; ----# - ----# Converting "banned"... ----{ -$request = mysql_query(" - SELECT type, value - FROM {$db_prefix}banned - WHERE type = 'ip'"); -if ($request !== false) -{ - $insertEntries = array(); - while ($row = mysql_fetch_assoc($request)) - { - if (preg_match('~^\d{1,3}\.(\d{1,3}|\*)\.(\d{1,3}|\*)\.(\d{1,3}|\*)$~', $row['value']) == 0) - continue; - - $ip_parts = ip2range($row['value']); - $insertEntries[] = "('ip_ban', {$ip_parts[0]['low']}, {$ip_parts[0]['high']}, {$ip_parts[1]['low']}, {$ip_parts[1]['high']}, {$ip_parts[2]['low']}, {$ip_parts[2]['high']}, {$ip_parts[3]['low']}, {$ip_parts[3]['high']}, '', '', 0, " . time() . ", NULL, 'full_ban', '', 'Imported from YaBB SE')"; - } - mysql_free_result($request); - - upgrade_query(" - CREATE TABLE IF NOT EXISTS {$db_prefix}banned2 ( - id_ban mediumint(8) unsigned NOT NULL auto_increment, - ban_type varchar(30) NOT NULL default '', - ip_low1 tinyint(3) unsigned NOT NULL default '0', - ip_high1 tinyint(3) unsigned NOT NULL default '0', - ip_low2 tinyint(3) unsigned NOT NULL default '0', - ip_high2 tinyint(3) unsigned NOT NULL default '0', - ip_low3 tinyint(3) unsigned NOT NULL default '0', - ip_high3 tinyint(3) unsigned NOT NULL default '0', - ip_low4 tinyint(3) unsigned NOT NULL default '0', - ip_high4 tinyint(3) unsigned NOT NULL default '0', - hostname tinytext NOT NULL default '', - email_address tinytext NOT NULL default '', - ID_MEMBER mediumint(8) unsigned NOT NULL default '0', - ban_time int(10) unsigned NOT NULL default '0', - expire_time int(10) unsigned, - restriction_type varchar(30) NOT NULL default '', - reason tinytext NOT NULL default '', - notes text NOT NULL default '', - PRIMARY KEY (id_ban) - ) ENGINE=MyISAM"); - - upgrade_query(" - INSERT INTO {$db_prefix}banned2 - (ban_type, ip_low1, ip_high1, ip_low2, ip_high2, ip_low3, ip_high3, ip_low4, ip_high4, hostname, email_address, ID_MEMBER, ban_time, expire_time, restriction_type, reason, notes) - SELECT 'email_ban', 0, 0, 0, 0, 0, 0, 0, 0, '', value, 0, " . time() . ", NULL, 'full_ban', '', 'Imported from YaBB SE' - FROM {$db_prefix}banned - WHERE type = 'email'"); - - upgrade_query(" - INSERT INTO {$db_prefix}banned2 - (ban_type, ip_low1, ip_high1, ip_low2, ip_high2, ip_low3, ip_high3, ip_low4, ip_high4, hostname, email_address, ID_MEMBER, ban_time, expire_time, restriction_type, reason, notes) - SELECT 'user_ban', 0, 0, 0, 0, 0, 0, 0, 0, '', '', mem.ID_MEMBER, " . time() . ", NULL, 'full_ban', '', 'Imported from YaBB SE' - FROM ({$db_prefix}banned AS ban, {$db_prefix}members AS mem) - WHERE ban.type = 'username' - AND mem.memberName = ban.value"); - - upgrade_query(" - DROP TABLE {$db_prefix}banned"); - upgrade_query(" - RENAME TABLE {$db_prefix}banned2 TO {$db_prefix}banned"); - - if (!empty($insertEntries)) - { - upgrade_query(" - INSERT INTO {$db_prefix}banned - (ban_type, ip_low1, ip_high1, ip_low2, ip_high2, ip_low3, ip_high3, ip_low4, ip_high4, hostname, email_address, ID_MEMBER, ban_time, expire_time, restriction_type, reason, notes) - VALUES " . implode(',', $insertEntries)); - } -} ----} ----# - ----# Updating "log_banned"... -ALTER TABLE {$db_prefix}log_banned -CHANGE COLUMN logTime logTime int(10) unsigned NOT NULL default '0'; -ALTER TABLE {$db_prefix}log_banned -ADD COLUMN id_ban_log mediumint(8) unsigned NOT NULL auto_increment PRIMARY KEY FIRST, -ADD COLUMN ID_MEMBER mediumint(8) unsigned NOT NULL default '0' AFTER id_ban_log, -ADD INDEX logTime (logTime); ----# - ----# Updating columns on "calendar"... -ALTER TABLE {$db_prefix}calendar -DROP PRIMARY KEY, -CHANGE COLUMN id ID_EVENT smallint(5) unsigned NOT NULL auto_increment PRIMARY KEY, -CHANGE COLUMN id_board ID_BOARD smallint(5) unsigned NOT NULL default '0', -CHANGE COLUMN id_topic ID_TOPIC mediumint(8) unsigned NOT NULL default '0', -CHANGE COLUMN id_member ID_MEMBER mediumint(8) unsigned NOT NULL default '0'; -ALTER TABLE {$db_prefix}calendar -CHANGE COLUMN title title varchar(48) NOT NULL default ''; - -ALTER TABLE {$db_prefix}calendar -ADD eventDate date NOT NULL default '0000-00-00'; ----# - ----# Updating indexes on "calendar"... -ALTER TABLE {$db_prefix}calendar -DROP INDEX idx_year_month; -ALTER TABLE {$db_prefix}calendar -DROP INDEX year; ----# - ----# Updating data in "calendar"... -UPDATE IGNORE {$db_prefix}calendar -SET eventDate = CONCAT(year, '-', month + 1, '-', day); - -ALTER TABLE {$db_prefix}calendar -DROP year, -DROP month, -DROP day, -ADD INDEX eventDate (eventDate); ----# - ----# Updating structure on "calendar_holidays"... -CREATE TABLE IF NOT EXISTS {$db_prefix}calendar_holidays ( - ID_HOLIDAY smallint(5) unsigned NOT NULL auto_increment, - eventDate date NOT NULL default '0000-00-00', - title varchar(30) NOT NULL default '', - PRIMARY KEY (ID_HOLIDAY), - KEY eventDate (eventDate) -) ENGINE=MyISAM; ----# - ----# Updating data in "calendar_holidays"... ----{ -$result = upgrade_query(" - SELECT COUNT(*) - FROM {$db_prefix}calendar_holidays"); -list ($size) = mysql_fetch_row($result); -mysql_free_result($result); - -if (empty($size)) -{ - upgrade_query(" - INSERT INTO {$db_prefix}calendar_holidays - (eventDate, title) - SELECT IF(year IS NULL, CONCAT('0000-', month, '-', day), CONCAT(year, '-', month, '-', day)), title - FROM {$db_prefix}calendar_holiday"); - - upgrade_query(" - INSERT INTO {$db_prefix}calendar_holidays - (eventDate, title) - VALUES ('0000-06-06', 'D-Day')"); -} ----} - -UPDATE {$db_prefix}calendar_holidays -SET title = 'New Year\'s' -WHERE title = 'New Years'; ----# - -/******************************************************************************/ ---- Converting polls and choices... -/******************************************************************************/ - ----# Converting data to "poll_choices"... -INSERT INTO {$db_prefix}poll_choices - (ID_POLL, ID_CHOICE, label, votes) -SELECT ID_POLL, 0, option1, votes1 -FROM {$db_prefix}polls; - -INSERT INTO {$db_prefix}poll_choices - (ID_POLL, ID_CHOICE, label, votes) -SELECT ID_POLL, 1, option2, votes2 -FROM {$db_prefix}polls; - -INSERT INTO {$db_prefix}poll_choices - (ID_POLL, ID_CHOICE, label, votes) -SELECT ID_POLL, 2, option3, votes3 -FROM {$db_prefix}polls; - -INSERT INTO {$db_prefix}poll_choices - (ID_POLL, ID_CHOICE, label, votes) -SELECT ID_POLL, 3, option4, votes4 -FROM {$db_prefix}polls; - -INSERT INTO {$db_prefix}poll_choices - (ID_POLL, ID_CHOICE, label, votes) -SELECT ID_POLL, 4, option5, votes5 -FROM {$db_prefix}polls; - -INSERT INTO {$db_prefix}poll_choices - (ID_POLL, ID_CHOICE, label, votes) -SELECT ID_POLL, 5, option6, votes6 -FROM {$db_prefix}polls; - -INSERT INTO {$db_prefix}poll_choices - (ID_POLL, ID_CHOICE, label, votes) -SELECT ID_POLL, 6, option7, votes7 -FROM {$db_prefix}polls; - -INSERT INTO {$db_prefix}poll_choices - (ID_POLL, ID_CHOICE, label, votes) -SELECT ID_POLL, 7, option8, votes8 -FROM {$db_prefix}polls; ----# - ----# Converting data to "log_polls"... ----{ -$query = mysql_query(" - SELECT ID_POLL, votedMemberIDs - FROM {$db_prefix}polls"); -if ($query !== false) -{ - $setStringLog = ''; - while ($row = mysql_fetch_assoc($query)) - { - $members = explode(',', $row['votedMemberIDs']); - foreach ($members as $member) - if (is_numeric($member) && !empty($member)) - $setStringLog .= " - ($row[ID_POLL], $member, 0),"; - } - - if (!empty($setStringLog)) - { - upgrade_query(" - INSERT IGNORE INTO {$db_prefix}log_polls - (ID_POLL, ID_MEMBER, ID_CHOICE) - VALUES " . substr($setStringLog, 0, -1)); - } -} ----} ----# - ----# Updating "polls"... -ALTER TABLE {$db_prefix}polls -DROP option1, DROP option2, DROP option3, DROP option4, DROP option5, DROP option6, DROP option7, DROP option8, -DROP votes1, DROP votes2, DROP votes3, DROP votes4, DROP votes5, DROP votes6, DROP votes7, DROP votes8, -DROP votedMemberIDs, -DROP PRIMARY KEY, -CHANGE COLUMN ID_POLL ID_POLL mediumint(8) unsigned NOT NULL auto_increment PRIMARY KEY, -CHANGE COLUMN votingLocked votingLocked tinyint(1) NOT NULL default '0', -CHANGE COLUMN question question tinytext NOT NULL default '', -ADD maxVotes tinyint(4) unsigned NOT NULL default '1', -ADD expireTime int(10) unsigned NOT NULL default '0', -ADD hideResults tinyint(4) unsigned NOT NULL default '0'; - -ALTER TABLE {$db_prefix}polls -ADD ID_MEMBER mediumint(8) unsigned NOT NULL default '0', -ADD posterName tinytext NOT NULL default ''; -ALTER TABLE {$db_prefix}polls -ADD changeVote tinyint(4) unsigned NOT NULL default '0'; ----# - ----# Updating data in "polls"... ----{ -$result = upgrade_query(" - SELECT p.ID_POLL, t.ID_MEMBER_STARTED - FROM ({$db_prefix}topics AS t, {$db_prefix}messages AS m, {$db_prefix}polls AS p) - WHERE m.ID_MSG = t.ID_FIRST_MSG - AND p.ID_POLL = t.ID_POLL - AND p.ID_MEMBER = 0 - AND t.ID_MEMBER_STARTED != 0"); -while ($row = mysql_fetch_assoc($result)) -{ - upgrade_query(" - UPDATE {$db_prefix}polls - SET ID_MEMBER = $row[ID_MEMBER_STARTED] - WHERE ID_POLL = $row[ID_POLL] - LIMIT 1"); -} -mysql_free_result($result); ----} ----# - -/******************************************************************************/ ---- Converting settings... -/******************************************************************************/ - ----# Updating news... ----{ -if (!isset($modSettings['smfVersion'])) -{ - upgrade_query(" - REPLACE INTO {$db_prefix}settings - (variable, value) - VALUES - ('news', SUBSTRING('" . htmlspecialchars(stripslashes($modSettings['news']), ENT_QUOTES) . "', 1, 65534))"); -} ----} ----# - ----# Updating "themes"... ----{ -convertSettingsToTheme(); - -$insertRows = ''; -$request = upgrade_query(" - SELECT ID_THEME, IF(value = '2', 5, value) AS value - FROM {$db_prefix}themes - WHERE variable = 'display_recent_bar'"); -while ($row = mysql_fetch_assoc($request)) - $insertRows .= "($row[ID_THEME], 'number_recent_posts', '$row[value]'),"; -mysql_free_result($request); -if (!empty($insertRows)) -{ - $insertRows = substr($insertRows, 0, -1); - upgrade_query(" - INSERT IGNORE INTO {$db_prefix}themes - (ID_THEME, variable, value) - VALUES $insertRows"); -} ----} ----# - ----# Updating "settings"... -ALTER TABLE {$db_prefix}settings -DROP INDEX variable; - -UPDATE IGNORE {$db_prefix}settings -SET variable = 'guest_hideContacts' -WHERE variable = 'guest_hideEmail' -LIMIT 1; ----# - ----# Adding new settings (part 1)... -INSERT IGNORE INTO {$db_prefix}settings - (variable, value) -VALUES - ('news', ''), - ('compactTopicPagesContiguous', '5'), - ('compactTopicPagesEnable', '1'), - ('enableStickyTopics', '1'), - ('todayMod', '1'), - ('karmaMode', '0'), - ('karmaTimeRestrictAdmins', '1'), - ('enablePreviousNext', '1'), - ('pollMode', '1'), - ('enableVBStyleLogin', '1'), - ('enableCompressedOutput', '1'), - ('karmaWaitTime', '1'), - ('karmaMinPosts', '0'), - ('karmaLabel', 'Karma:'), - ('karmaSmiteLabel', '[smite]'), - ('karmaApplaudLabel', '[applaud]'), - ('attachmentSizeLimit', '128'), - ('attachmentPostLimit', '192'), - ('attachmentNumPerPostLimit', '4'), - ('attachmentDirSizeLimit', '10240'), - ('attachmentUploadDir', '{$sboarddir}/attachments'), - ('attachmentExtensions', 'txt,doc,pdf,jpg,gif,mpg,png'), - ('attachmentCheckExtensions', '1'), - ('attachmentShowImages', '1'), - ('attachmentEnable', '1'), - ('attachmentEncryptFilenames', '1'), - ('censorIgnoreCase', '1'), - ('mostOnline', '1'); -INSERT IGNORE INTO {$db_prefix}settings - (variable, value) -VALUES - ('mostOnlineToday', '1'), - ('mostDate', UNIX_TIMESTAMP()), - ('trackStats', '1'), - ('userLanguage', '1'), - ('titlesEnable', '1'), - ('topicSummaryPosts', '15'), - ('enableErrorLogging', '1'), - ('onlineEnable', '0'), - ('cal_holidaycolor', '000080'), - ('cal_bdaycolor', '920AC4'), - ('cal_eventcolor', '078907'), - ('cal_enabled', '0'), - ('cal_maxyear', '2010'), - ('cal_minyear', '2002'), - ('cal_daysaslink', '0'), - ('cal_defaultboard', ''), - ('cal_showeventsonindex', '0'), - ('cal_showbdaysonindex', '0'), - ('cal_showholidaysonindex', '0'), - ('cal_showweeknum', '0'), - ('cal_maxspan', '7'), - ('smtp_host', ''), - ('smtp_username', ''), - ('smtp_password', ''), - ('mail_type', '0'), - ('timeLoadPageEnable', '0'), - ('totalTopics', '1'), - ('totalMessages', '1'), - ('simpleSearch', '0'), - ('censor_vulgar', ''), - ('censor_proper', ''), - ('mostOnlineToday', '1'), - ('enablePostHTML', '0'), - ('theme_allow', '1'), - ('theme_default', '1'), - ('theme_guests', '1'), - ('enableEmbeddedFlash', '0'), - ('xmlnews_enable', '1'), - ('xmlnews_maxlen', '255'), - ('hotTopicPosts', '15'), - ('hotTopicVeryPosts', '25'), - ('allow_editDisplayName', '1'), - ('number_format', '1234.00'), - ('attachmentEncryptFilenames', '1'), - ('autoLinkUrls', '1'); -INSERT IGNORE INTO {$db_prefix}settings - (variable, value) -VALUES - ('avatar_allow_server_stored', '1'), - ('avatar_check_size', '0'), - ('avatar_action_too_large', 'option_user_resize'), - ('avatar_resize_upload', '1'), - ('avatar_download_png', '1'), - ('failed_login_threshold', '3'), - ('edit_wait_time', '90'), - ('autoFixDatabase', '1'), - ('autoOptDatabase', '7'), - ('autoOptMaxOnline', '0'), - ('autoOptLastOpt', '0'), - ('enableParticipation', '1'), - ('recycle_enable', '0'), - ('recycle_board', '0'), - ('banLastUpdated', '0'), - ('enableAllMessages', '0'), - ('fixLongWords', '0'), - ('knownThemes', '1,2'), - ('who_enabled', '1'), - ('lastActive', '15'), - ('allow_hideOnline', '1'), - ('guest_hideContacts', '0'); ----# - ----# Adding new settings (part 2)... ----{ -upgrade_query(" - INSERT IGNORE INTO {$db_prefix}settings - (variable, value) - VALUES - ('registration_method', '" . (!empty($modSettings['registration_disabled']) ? 3 : (!empty($modSettings['approve_registration']) ? 2 : (!empty($GLOBALS['emailpassword']) || !empty($modSettings['send_validation']) ? 1 : 0))) . "'), - ('send_validation_onChange', '" . @$GLOBALS['emailnewpass'] . "'), - ('send_welcomeEmail', '" . @$GLOBALS['emailwelcome'] . "'), - ('allow_hideEmail', '" . @$GLOBALS['allow_hide_email'] . "'), - ('allow_guestAccess', '" . @$GLOBALS['guestaccess'] . "'), - ('time_format', '" . (!empty($GLOBALS['timeformatstring']) ? $GLOBALS['timeformatstring'] : '%B %d, %Y, %I:%M:%S %p') . "'), - ('enableBBC', '" . (!isset($GLOBALS['enable_ubbc']) ? 1 : $GLOBALS['enable_ubbc']) . "'), - ('max_messageLength', '" . (empty($GLOBALS['MaxMessLen']) ? 10000 : $GLOBALS['MaxMessLen']) . "'), - ('max_signatureLength', '" . @$GLOBALS['MaxSigLen'] . "'), - ('spamWaitTime', '" . @$GLOBALS['timeout'] . "'), - ('avatar_directory', '" . (isset($GLOBALS['facesdir']) ? fixRelativePath($GLOBALS['facesdir']) : fixRelativePath('./avatars')) . "'), - ('avatar_url', '" . @$GLOBALS['facesurl'] . "'), - ('avatar_max_height_external', '" . @$GLOBALS['userpic_height'] . "'), - ('avatar_max_width_external', '" . @$GLOBALS['userpic_width'] . "'), - ('avatar_max_height_upload', '" . @$GLOBALS['userpic_height'] . "'), - ('avatar_max_width_upload', '" . @$GLOBALS['userpic_width'] . "'), - ('defaultMaxMessages', '" . (empty($GLOBALS['maxmessagedisplay']) ? 15 : $GLOBALS['maxmessagedisplay']) . "'), - ('defaultMaxTopics', '" . (empty($GLOBALS['maxdisplay']) ? 20 : $GLOBALS['maxdisplay']) . "'), - ('defaultMaxMembers', '" . (empty($GLOBALS['MembersPerPage']) ? 20 : $GLOBALS['MembersPerPage']) . "'), - ('time_offset', '" . @$GLOBALS['timeoffset'] . "'), - ('cookieTime', '" . (empty($GLOBALS['Cookie_Length']) ? 60 : $GLOBALS['Cookie_Length']) . "'), - ('requireAgreement', '" . @$GLOBALS['RegAgree'] . "')"); ----} - -INSERT IGNORE INTO {$db_prefix}settings - (variable, value) -VALUES - ('smileys_dir', '{$sboarddir}/Smileys'), - ('smileys_url', '{$boardurl}/Smileys'), - ('smiley_sets_known', 'default,classic'), - ('smiley_sets_names', 'Default\nClassic'), - ('smiley_sets_default', 'default'), - ('censorIgnoreCase', '1'), - ('cal_days_for_index', '7'), - ('unapprovedMembers', '0'), - ('default_personalText', ''), - ('attachmentPostLimit', '192'), - ('attachmentNumPerPostLimit', '4'), - ('package_make_backups', '1'), - ('databaseSession_loose', '1'), - ('databaseSession_lifetime', '2880'), - ('smtp_port', '25'), - ('search_cache_size', '50'), - ('search_results_per_page', '30'), - ('search_weight_frequency', '30'), - ('search_weight_age', '25'), - ('search_weight_length', '20'), - ('search_weight_subject', '15'), - ('search_weight_first_message', '10'); - -DELETE FROM {$db_prefix}settings -WHERE variable = 'agreement' -LIMIT 1; ----# - ----# Converting settings to options... ----{ -convertSettingsToOptions(); ----} ----# - ----# Updating statistics... -REPLACE INTO {$db_prefix}settings - (variable, value) -SELECT 'latestMember', ID_MEMBER -FROM {$db_prefix}members -ORDER BY ID_MEMBER DESC -LIMIT 1; - -REPLACE INTO {$db_prefix}settings - (variable, value) -SELECT 'latestRealName', IFNULL(realName, memberName) -FROM {$db_prefix}members -ORDER BY ID_MEMBER DESC -LIMIT 1; - -REPLACE INTO {$db_prefix}settings - (variable, value) -SELECT 'maxMsgID', ID_MSG -FROM {$db_prefix}messages -ORDER BY ID_MSG DESC -LIMIT 1; - -REPLACE INTO {$db_prefix}settings - (variable, value) -SELECT 'totalMembers', COUNT(*) -FROM {$db_prefix}members; - -REPLACE INTO {$db_prefix}settings - (variable, value) -SELECT 'unapprovedMembers', COUNT(*) -FROM {$db_prefix}members -WHERE is_activated = 0 - AND validation_code = ''; - -REPLACE INTO {$db_prefix}settings - (variable, value) -SELECT 'totalMessages', COUNT(*) -FROM {$db_prefix}messages; - -REPLACE INTO {$db_prefix}settings - (variable, value) -SELECT 'totalTopics', COUNT(*) -FROM {$db_prefix}topics; - -REPLACE INTO {$db_prefix}settings - (variable, value) -VALUES ('cal_today_updated', '00000000'); ----# \ No newline at end of file diff --git a/upgrade_1-1.sql b/upgrade_1-1.sql deleted file mode 100644 index 0575ae3..0000000 --- a/upgrade_1-1.sql +++ /dev/null @@ -1,2655 +0,0 @@ -/* ATTENTION: You don't need to run or use this file! The upgrade.php script does everything for you! */ - -/******************************************************************************/ ---- Updating and creating indexes... -/******************************************************************************/ - ----# Updating indexes on "messages"... ----{ -$request = upgrade_query(" - SHOW KEYS - FROM {$db_prefix}messages"); -$found = false; -while ($row = mysql_fetch_assoc($request)) - $found |= $row['Key_name'] == 'ID_BOARD' && $row['Column_name'] == 'ID_MSG'; -mysql_free_result($request); - -if (!$found) - upgrade_query(" - ALTER TABLE {$db_prefix}messages - DROP INDEX ID_BOARD"); ----} ----# - ----# Updating table indexes... ----{ -$_GET['mess_ind'] = isset($_GET['mess_ind']) ? (int) $_GET['mess_ind'] : 0; -$step_progress['name'] = 'Updating table indexes'; -$step_progress['current'] = $_GET['mess_ind']; -$custom_warning = 'On a very large board these indexes may take a few minutes to create.'; - -$index_changes = array( - array( - 'table' => 'log_errors', - 'type' => 'index', - 'method' => 'add', - 'name' => 'ID_MEMBER', - 'target_columns' => array('ID_MEMBER'), - 'text' => 'ADD INDEX ID_MEMBER (ID_MEMBER)', - ), - array( - 'table' => 'log_errors', - 'type' => 'index', - 'method' => 'add', - 'name' => 'IP', - 'target_columns' => array('IP'), - 'text' => 'ADD INDEX IP (IP(15))', - ), - array( - 'table' => 'log_online', - 'type' => 'index', - 'method' => 'add', - 'name' => 'logTime', - 'target_columns' => array('logTime'), - 'text' => 'ADD INDEX logTime (logTime)', - ), - array( - 'table' => 'log_online', - 'type' => 'index', - 'method' => 'remove', - 'name' => 'online', - 'target_columns' => array('online'), - 'text' => 'DROP INDEX online', - ), - array( - 'table' => 'smileys', - 'type' => 'index', - 'method' => 'remove', - 'name' => 'smileyOrder', - 'target_columns' => array('smileyOrder'), - 'text' => 'DROP INDEX smileyOrder', - ), - array( - 'table' => 'boards', - 'type' => 'index', - 'method' => 'add', - 'name' => 'ID_PARENT', - 'target_columns' => array('ID_PARENT'), - 'text' => 'ADD INDEX ID_PARENT (ID_PARENT)', - ), - array( - 'table' => 'boards', - 'type' => 'index', - 'method' => 'remove', - 'name' => 'children', - 'target_columns' => array('children'), - 'text' => 'DROP INDEX children', - ), - array( - 'table' => 'boards', - 'type' => 'index', - 'method' => 'remove', - 'name' => 'boardOrder', - 'target_columns' => array('boardOrder'), - 'text' => 'DROP INDEX boardOrder', - ), - array( - 'table' => 'categories', - 'type' => 'index', - 'method' => 'remove', - 'name' => 'catOrder', - 'target_columns' => array('catOrder'), - 'text' => 'DROP INDEX catOrder', - ), - array( - 'table' => 'messages', - 'type' => 'index', - 'method' => 'add', - 'name' => 'ID_TOPIC', - 'target_columns' => array('ID_TOPIC'), - 'text' => 'ADD INDEX ID_TOPIC (ID_TOPIC)', - ), - array( - 'table' => 'messages', - 'type' => 'index', - 'method' => 'remove', - 'name' => 'ID_MEMBER', - 'target_columns' => array('ID_MEMBER'), - 'text' => 'DROP INDEX ID_MEMBER', - ), - array( - 'table' => 'messages', - 'type' => 'index', - 'method' => 'add', - 'name' => 'ID_BOARD', - 'target_columns' => array('ID_BOARD', 'ID_MSG'), - 'text' => 'ADD UNIQUE ID_BOARD (ID_BOARD, ID_MSG)', - ), - array( - 'table' => 'messages', - 'type' => 'index', - 'method' => 'add', - 'name' => 'ID_MEMBER', - 'target_columns' => array('ID_MEMBER', 'ID_MSG'), - 'text' => 'ADD UNIQUE ID_MEMBER (ID_MEMBER, ID_MSG)', - ), - array( - 'table' => 'messages', - 'type' => 'index', - 'method' => 'add', - 'name' => 'showPosts', - 'target_columns' => array('ID_MEMBER', 'ID_BOARD'), - 'text' => 'ADD INDEX showPosts (ID_MEMBER, ID_BOARD)', - ), -); - -$step_progress['total'] = count($index_changes); - -// Now we loop through the changes and work out where the hell we are. -foreach ($index_changes as $ind => $change) -{ - // Already done it? - if ($_GET['mess_ind'] > $ind) - continue; - - // Make the index, with all the protection and all. - protected_alter($change, $substep); - - // Store this for the next table. - $_GET['mess_ind']++; - $step_progress['current'] = $_GET['mess_ind']; -} - -// Clean up. -unset($_GET['mess_ind']); ----} ----# - ----# Reordering boards and categories... -ALTER TABLE {$db_prefix}categories -ORDER BY catOrder; - -ALTER TABLE {$db_prefix}boards -ORDER BY boardOrder; ----# - ----# Updating indexes and data on "smileys"... -ALTER TABLE {$db_prefix}smileys -CHANGE COLUMN smileyOrder smileyOrder smallint(5) unsigned NOT NULL default '0'; - -UPDATE {$db_prefix}smileys -SET filename = 'embarrassed.gif' -WHERE filename = 'embarassed.gif'; ----# - ----# Updating indexes on "log_boards"... -ALTER TABLE {$db_prefix}log_boards -DROP PRIMARY KEY, -ADD PRIMARY KEY (ID_MEMBER, ID_BOARD); ----# - ----# Updating indexes on "log_mark_read"... -ALTER TABLE {$db_prefix}log_mark_read -DROP PRIMARY KEY, -ADD PRIMARY KEY (ID_MEMBER, ID_BOARD); ----# - ----# Updating indexes on "themes"... -ALTER TABLE {$db_prefix}themes -DROP PRIMARY KEY, -ADD PRIMARY KEY (ID_THEME, ID_MEMBER, variable(30)), -ADD INDEX ID_MEMBER (ID_MEMBER); ----# - -/******************************************************************************/ ---- Reorganizing configuration settings... -/******************************************************************************/ - ----# Updating data in "settings"... -REPLACE INTO {$db_prefix}settings - (variable, value) -SELECT 'totalMembers', COUNT(*) -FROM {$db_prefix}members; - -UPDATE {$db_prefix}settings -SET variable = 'notify_new_registration' -WHERE variable = 'notify_on_new_registration' -LIMIT 1; - -UPDATE IGNORE {$db_prefix}settings -SET variable = 'max_image_width' -WHERE variable = 'maxwidth' -LIMIT 1; - -UPDATE IGNORE {$db_prefix}settings -SET variable = 'max_image_height' -WHERE variable = 'maxheight' -LIMIT 1; - -UPDATE {$db_prefix}settings -SET value = IF(value = 'sendmail' OR value = '0', '0', '1') -WHERE variable = 'mail_type' -LIMIT 1; - -UPDATE IGNORE {$db_prefix}settings -SET variable = 'search_method' -WHERE variable = 'search_match_complete_words' -LIMIT 1; - -UPDATE IGNORE {$db_prefix}settings -SET variable = 'allow_disableAnnounce' -WHERE variable = 'notifyAnncmnts_UserDisable' -LIMIT 1; ----# - ----# Adding new settings... -INSERT IGNORE INTO {$db_prefix}settings - (variable, value) -VALUES ('edit_disable_time', '0'), - ('oldTopicDays', '120'), - ('cal_showeventsoncalendar', '1'), - ('cal_showbdaysoncalendar', '1'), - ('cal_showholidaysoncalendar', '1'), - ('allow_disableAnnounce', '1'), - ('attachmentThumbnails', '1'), - ('attachmentThumbWidth', '150'), - ('attachmentThumbHeight', '150'), - ('max_pm_recipients', '10'); - ----{ -if (@$modSettings['smfVersion'] < '1.1') -{ - // Hopefully 90 days is enough? - upgrade_query(" - INSERT INTO {$db_prefix}settings - (variable, value) - VALUES ('disableHashTime', " . (time() + 7776000) . ")"); -} - -if (isset($modSettings['smfVersion']) && $modSettings['smfVersion'] <= '1.1 Beta 4') -{ - // Enable the buddy list for those used to it. - upgrade_query(" - INSERT INTO {$db_prefix}settings - (variable, value) - VALUES ('enable_buddylist', '1')"); -} ----} ----# - ----# Adding PM spam protection settings. ----{ -if (empty($modSettings['pm_spam_settings'])) -{ - if (isset($modSettings['max_pm_recipients'])) - $modSettings['pm_spam_settings'] = (int) $modSettings['max_pm_recipients'] . ',5,20'; - else - $modSettings['pm_spam_settings'] = '10,5,20'; - - upgrade_query(" - INSERT IGNORE INTO {$db_prefix}settings - (variable, value) - VALUES - ('pm_spam_settings', '$modSettings[pm_spam_settings]')"); -} -upgrade_query(" - DELETE FROM {$db_prefix}settings - WHERE variable = 'max_pm_recipients'"); ----} ----# - ----# Cleaning old values from "settings"... -DELETE FROM {$db_prefix}settings -WHERE variable IN ('modlog_enabled', 'localCookies', 'globalCookies', 'send_welcomeEmail', 'search_method', 'notify_new_registration', 'removeNestedQuotes', 'smiley_enable', 'smiley_sets_enable') - AND value = '0'; - -DELETE FROM {$db_prefix}settings -WHERE variable IN ('allow_guestAccess', 'userLanguage', 'allow_editDisplayName', 'allow_hideOnline', 'allow_hideEmail', 'guest_hideContacts', 'titlesEnable', 'search_match_complete_words') - AND value = '0'; - -DELETE FROM {$db_prefix}settings -WHERE variable IN ('cal_allowspan', 'hitStats', 'queryless_urls', 'disableHostnameLookup', 'messageIcons_enable', 'disallow_sendBody', 'censorWholeWord') - AND value = '0'; - -DELETE FROM {$db_prefix}settings -WHERE variable IN ( - 'totalMessag', - 'redirectMetaRefresh', - 'memberCount', - 'cal_today_u', - 'approve_registration', - 'registration_disabled', - 'requireRegistrationVerification', - 'returnToPost', - 'send_validation', - 'search_max_cached_results', - 'disableTemporaryTables', - 'search_cache_size', - 'enableReportToMod' -); ----# - ----# Encoding SMTP password... ----{ -// Can't do this more than once, we just can't... -if ((!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && empty($modSettings['dont_repeat_smtp'])) -{ - if (!empty($modSettings['smtp_password'])) - { - upgrade_query(" - UPDATE {$db_prefix}settings - SET value = '" . base64_encode($modSettings['smtp_password']) . "' - WHERE variable = 'smtp_password'"); - } - // Don't let this run twice! - upgrade_query(" - REPLACE INTO {$db_prefix}settings - (variable, value) - VALUES - ('dont_repeat_smtp', '1')"); -} - ----} ----# - ----# Adjusting timezone settings... ----{ - if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set')) - { - $server_offset = mktime(0, 0, 0, 1, 1, 1970); - $timezone_id = 'Etc/GMT' . ($server_offset > 0 ? '+' : '') . ($server_offset / 3600); - if (date_default_timezone_set($timezone_id)) - upgrade_query(" - REPLACE INTO {$db_prefix}settings - (variable, value) - VALUES - ('default_timezone', '$timezone_id')"); - } ----} ----# - -/******************************************************************************/ ---- Installing new default theme... -/******************************************************************************/ - ----# Installing theme settings... ----{ -// This is Grudge's secret "I'm not a developer" theme install code - keep this quiet ;) - -// Firstly, I'm going out of my way to not do this twice! -if ((!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && empty($modSettings['dont_repeat_theme'])) -{ - // Check it's not already here, just incase. - $theme_request = upgrade_query(" - SELECT ID_THEME - FROM {$db_prefix}themes - WHERE variable = 'theme_dir' - AND value LIKE '%babylon'"); - // Only do the upgrade if it doesn't find the theme already. - if (mysql_num_rows($theme_request) == 0) - { - // Try to get some settings from the current default theme. - $request = upgrade_query(" - SELECT t1.value AS theme_dir, t2.value AS theme_url, t3.value AS images_url - FROM ({$db_prefix}themes AS t1, {$db_prefix}themes AS t2, {$db_prefix}themes AS t3) - WHERE t1.ID_THEME = 1 - AND t1.ID_MEMBER = 0 - AND t1.variable = 'theme_dir' - AND t2.ID_THEME = 1 - AND t2.ID_MEMBER = 0 - AND t2.variable = 'theme_url' - AND t3.ID_THEME = 1 - AND t3.ID_MEMBER = 0 - AND t3.variable = 'images_url' - LIMIT 1"); - if (mysql_num_rows($request) != 0) - { - $core = mysql_fetch_assoc($request); - - if (substr_count($core['theme_dir'], 'default') === 1) - $babylon['theme_dir'] = strtr($core['theme_dir'], array('default' => 'babylon')); - if (substr_count($core['theme_url'], 'default') === 1) - $babylon['theme_url'] = strtr($core['theme_url'], array('default' => 'babylon')); - if (substr_count($core['images_url'], 'default') === 1) - $babylon['images_url'] = strtr($core['images_url'], array('default' => 'babylon')); - } - mysql_free_result($request); - - if (!isset($babylon['theme_dir'])) - $babylon['theme_dir'] = addslashes($GLOBALS['boarddir']) . '/Themes/babylon'; - if (!isset($babylon['theme_url'])) - $babylon['theme_url'] = $GLOBALS['boardurl'] . '/Themes/babylon'; - if (!isset($babylon['images_url'])) - $babylon['images_url'] = $GLOBALS['boardurl'] . '/Themes/babylon/images'; - - // Get an available ID_THEME first... - $request = upgrade_query(" - SELECT MAX(ID_THEME) + 1 - FROM {$db_prefix}themes"); - list ($ID_OLD_THEME) = mysql_fetch_row($request); - mysql_free_result($request); - - // Insert the babylon theme into the tables. - upgrade_query(" - INSERT INTO {$db_prefix}themes - (ID_MEMBER, ID_THEME, variable, value) - VALUES - (0, $ID_OLD_THEME, 'name', 'Babylon Theme'), - (0, $ID_OLD_THEME, 'theme_url', '$babylon[theme_url]'), - (0, $ID_OLD_THEME, 'images_url', '$babylon[images_url]'), - (0, $ID_OLD_THEME, 'theme_dir', '$babylon[theme_dir]')"); - - $newSettings = array(); - // Now that we have the old theme details - switch anyone who used the default to it (Make sense?!) - if (!empty($modSettings['theme_default']) && $modSettings['theme_default'] == 1) - $newSettings[] = "('theme_default', $ID_OLD_THEME)"; - // Did guests use to use the default? - if (!empty($modSettings['theme_guests']) && $modSettings['theme_guests'] == 1) - $newSettings[] = "('theme_guests', $ID_OLD_THEME)"; - - // If known themes aren't set, let's just pick all themes available. - if (empty($modSettings['knownThemes'])) - { - $request = upgrade_query(" - SELECT DISTINCT ID_THEME - FROM {$db_prefix}themes"); - $themes = array(); - while ($row = mysql_fetch_assoc($request)) - $themes[] = $row['ID_THEME']; - $modSettings['knownThemes'] = implode(',', $themes); - upgrade_query(" - UPDATE {$db_prefix}settings - SET value = '$modSettings[knownThemes]' - WHERE variable = 'knownThemes'"); - } - - // Known themes. - $allThemes = explode(',', $modSettings['knownThemes']); - $allThemes[] = $ID_OLD_THEME; - $newSettings[] = "('knownThemes', '" . implode(',', $allThemes) . "')"; - - upgrade_query(" - REPLACE INTO {$db_prefix}settings - (variable, value) - VALUES - " . implode(', ', $newSettings)); - - // What about members? - upgrade_query(" - UPDATE {$db_prefix}members - SET ID_THEME = $ID_OLD_THEME - WHERE ID_THEME = 1"); - - // Boards? - upgrade_query(" - UPDATE {$db_prefix}boards - SET ID_THEME = $ID_OLD_THEME - WHERE ID_THEME = 1"); - - // The other themes used to use babylon as their base theme. - if (isset($babylon['theme_dir']) && isset($babylon['theme_url'])) - { - $babylonBasedThemes = array_diff($allThemes, array(1)); - - // Exclude the themes that already have a base_theme_dir. - $request = upgrade_query(" - SELECT DISTINCT ID_THEME - FROM {$db_prefix}themes - WHERE variable = 'base_theme_dir'"); - while ($row = mysql_fetch_assoc($request)) - $babylonBasedThemes = array_diff($babylonBasedThemes, array($row['ID_THEME'])); - mysql_free_result($request); - - // Only base themes if there are templates that need a fall-back. - $insertRows = array(); - $request = upgrade_query(" - SELECT ID_THEME, value AS theme_dir - FROM {$db_prefix}themes - WHERE ID_THEME IN (" . implode(', ', $babylonBasedThemes) . ") - AND ID_MEMBER = 0 - AND variable = 'theme_dir'"); - while ($row = mysql_fetch_assoc($request)) - { - if (!file_exists($row['theme_dir'] . '/BoardIndex.template.php') || !file_exists($row['theme_dir'] . '/Display.template.php') || !file_exists($row['theme_dir'] . '/index.template.php') || !file_exists($row['theme_dir'] . '/MessageIndex.template.php') || !file_exists($row['theme_dir'] . '/Settings.template.php')) - { - $insertRows[] = "(0, $row[ID_THEME], 'base_theme_dir', '" . addslashes($babylon['theme_dir']) . "')"; - $insertRows[] = "(0, $row[ID_THEME], 'base_theme_url', '" . addslashes($babylon['theme_url']) . "')"; - } - } - mysql_free_result($request); - - if (!empty($insertRows)) - upgrade_query(" - INSERT IGNORE INTO {$db_prefix}themes - (ID_MEMBER, ID_THEME, variable, value) - VALUES - " . implode(', - ', $insertRows)); - } - } - mysql_free_result($theme_request); - - // This ain't running twice either - not with the risk of log_tables timing us all out! - upgrade_query(" - REPLACE INTO {$db_prefix}settings - (variable, value) - VALUES - ('dont_repeat_theme', '1')"); -} - ----} ----# - -/******************************************************************************/ ---- Adding and updating member data... -/******************************************************************************/ - ----# Renaming personal message tables... -RENAME TABLE {$db_prefix}instant_messages -TO {$db_prefix}personal_messages; - -RENAME TABLE {$db_prefix}im_recipients -TO {$db_prefix}pm_recipients; ----# - ----# Updating indexes on "pm_recipients"... -ALTER TABLE {$db_prefix}pm_recipients -DROP INDEX ID_MEMBER, -ADD UNIQUE ID_MEMBER (ID_MEMBER, deleted, ID_PM); ----# - ----# Updating columns on "pm_recipients"... -ALTER TABLE {$db_prefix}pm_recipients -ADD COLUMN labels varchar(60) NOT NULL default '-1'; - -ALTER TABLE {$db_prefix}pm_recipients -CHANGE COLUMN labels labels varchar(60) NOT NULL default '-1'; - -UPDATE {$db_prefix}pm_recipients -SET labels = '-1' -WHERE labels NOT RLIKE '[0-9,\-]' OR labels = ''; ----# - ----# Updating columns on "members"... -ALTER TABLE {$db_prefix}members -ADD COLUMN messageLabels text NOT NULL, -ADD COLUMN buddy_list tinytext NOT NULL, -ADD COLUMN notifySendBody tinyint(4) NOT NULL default '0', -ADD COLUMN notifyTypes tinyint(4) NOT NULL default '2', -CHANGE COLUMN im_ignore_list pm_ignore_list tinytext NOT NULL, -CHANGE COLUMN im_email_notify pm_email_notify tinyint(4) NOT NULL default '0'; ----# - ----# Updating columns on "members" - part 2... -ALTER TABLE {$db_prefix}members -CHANGE COLUMN secretAnswer secretAnswer varchar(64) NOT NULL default ''; - -ALTER TABLE {$db_prefix}members -ADD COLUMN memberIP2 tinytext NOT NULL; ----# - ----# Updating member approval... ----{ -// Although it *shouldn't* matter, best to do it just once to be sure. -if (@$modSettings['smfVersion'] < '1.1') -{ - upgrade_query(" - UPDATE {$db_prefix}members - SET is_activated = 3 - WHERE validation_code = '' - AND is_activated = 0"); -} ----} ----# - -/******************************************************************************/ ---- Updating holidays and calendar... -/******************************************************************************/ - ----# Adding new holidays... ----{ -$result = upgrade_query(" - SELECT ID_HOLIDAY - FROM {$db_prefix}calendar_holidays - WHERE YEAR(eventDate) > 2010 - LIMIT 1"); -$do_it = mysql_num_rows($result) == 0; -mysql_free_result($result); - -if ($do_it) -{ - upgrade_query(" - INSERT INTO {$db_prefix}calendar_holidays - (title, eventDate) - VALUES - ('Mother\\'s Day', '2011-05-08'), - ('Mother\\'s Day', '2012-05-13'), - ('Mother\\'s Day', '2013-05-12'), - ('Mother\\'s Day', '2014-05-11'), - ('Mother\\'s Day', '2015-05-10'), - ('Mother\\'s Day', '2016-05-08'), - ('Mother\\'s Day', '2017-05-14'), - ('Mother\\'s Day', '2018-05-13'), - ('Mother\\'s Day', '2019-05-12'), - ('Mother\\'s Day', '2020-05-10'), - ('Father\\'s Day', '2011-06-19'), - ('Father\\'s Day', '2012-06-17'), - ('Father\\'s Day', '2013-06-16'), - ('Father\\'s Day', '2014-06-15'), - ('Father\\'s Day', '2015-06-21'), - ('Father\\'s Day', '2016-06-19'), - ('Father\\'s Day', '2017-06-18'), - ('Father\\'s Day', '2018-06-17'), - ('Father\\'s Day', '2019-06-16'), - ('Father\\'s Day', '2020-06-21'), - ('Summer Solstice', '2011-06-21'), - ('Summer Solstice', '2012-06-20'), - ('Summer Solstice', '2013-06-21'), - ('Summer Solstice', '2014-06-21'), - ('Summer Solstice', '2015-06-21'), - ('Summer Solstice', '2016-06-20'), - ('Summer Solstice', '2017-06-20'), - ('Summer Solstice', '2018-06-21'), - ('Summer Solstice', '2019-06-21'), - ('Summer Solstice', '2020-06-20'), - ('Vernal Equinox', '2011-03-20'), - ('Vernal Equinox', '2012-03-20'), - ('Vernal Equinox', '2013-03-20'), - ('Vernal Equinox', '2014-03-20'), - ('Vernal Equinox', '2015-03-20'), - ('Vernal Equinox', '2016-03-19'), - ('Vernal Equinox', '2017-03-20'), - ('Vernal Equinox', '2018-03-20'), - ('Vernal Equinox', '2019-03-20'), - ('Vernal Equinox', '2020-03-19'), - ('Winter Solstice', '2011-12-22'), - ('Winter Solstice', '2012-12-21'), - ('Winter Solstice', '2013-12-21'), - ('Winter Solstice', '2014-12-21'), - ('Winter Solstice', '2015-12-21'), - ('Winter Solstice', '2016-12-21'), - ('Winter Solstice', '2017-12-21'), - ('Winter Solstice', '2018-12-21'), - ('Winter Solstice', '2019-12-21'), - ('Winter Solstice', '2020-12-21'), - ('Autumnal Equinox', '2011-09-23'), - ('Autumnal Equinox', '2012-09-22'), - ('Autumnal Equinox', '2013-09-22'), - ('Autumnal Equinox', '2014-09-22'), - ('Autumnal Equinox', '2015-09-23'), - ('Autumnal Equinox', '2016-09-22'), - ('Autumnal Equinox', '2017-09-22'), - ('Autumnal Equinox', '2018-09-22'), - ('Autumnal Equinox', '2019-09-23'), - ('Autumnal Equinox', '2020-09-22'), - ('Thanksgiving', '2011-11-24'), - ('Thanksgiving', '2012-11-22'), - ('Thanksgiving', '2013-11-21'), - ('Thanksgiving', '2014-11-20'), - ('Thanksgiving', '2015-11-26'), - ('Thanksgiving', '2016-11-24'), - ('Thanksgiving', '2017-11-23'), - ('Thanksgiving', '2018-11-22'), - ('Thanksgiving', '2019-11-21'), - ('Thanksgiving', '2020-11-26'), - ('Memorial Day', '2011-05-30'), - ('Memorial Day', '2012-05-28'), - ('Memorial Day', '2013-05-27'), - ('Memorial Day', '2014-05-26'), - ('Memorial Day', '2015-05-25'), - ('Memorial Day', '2016-05-30'), - ('Memorial Day', '2017-05-29'), - ('Memorial Day', '2018-05-28'), - ('Memorial Day', '2019-05-27'), - ('Memorial Day', '2020-05-25'), - ('Labor Day', '2011-09-05'), - ('Labor Day', '2012-09-03'), - ('Labor Day', '2013-09-09'), - ('Labor Day', '2014-09-08'), - ('Labor Day', '2015-09-07'), - ('Labor Day', '2016-09-05'), - ('Labor Day', '2017-09-04'), - ('Labor Day', '2018-09-03'), - ('Labor Day', '2019-09-09'), - ('Labor Day', '2020-09-07')"); -} ----} ----# - ----# Updating event start and end dates... -ALTER TABLE {$db_prefix}calendar -DROP INDEX eventDate; - -ALTER TABLE {$db_prefix}calendar -CHANGE COLUMN eventDate startDate date NOT NULL default '0001-01-01'; - -ALTER TABLE {$db_prefix}calendar -CHANGE COLUMN startDate startDate date NOT NULL default '0001-01-01'; - -UPDATE {$db_prefix}calendar -SET startDate = '0001-01-01' -WHERE startDate = '0000-00-00'; - -ALTER TABLE {$db_prefix}calendar -ADD COLUMN endDate date NOT NULL default '0001-01-01'; - -ALTER TABLE {$db_prefix}calendar -CHANGE COLUMN endDate endDate date NOT NULL default '0001-01-01'; - -UPDATE {$db_prefix}calendar -SET endDate = startDate -WHERE endDate = '0001-01-01' - OR endDate = '0000-00-00'; - -ALTER TABLE {$db_prefix}calendar -ADD INDEX startDate (startDate), -ADD INDEX endDate (endDate); - -ALTER TABLE {$db_prefix}calendar -DROP INDEX ID_TOPIC; - -ALTER TABLE {$db_prefix}calendar -ADD INDEX topic (ID_TOPIC, ID_MEMBER); - -ALTER TABLE {$db_prefix}calendar_holidays -CHANGE COLUMN eventDate eventDate date NOT NULL default '0001-01-01'; - -UPDATE {$db_prefix}calendar_holidays -SET eventDate = '0001-01-01' -WHERE eventDate = '0000-00-00'; - -UPDATE {$db_prefix}calendar_holidays -SET eventDate = CONCAT('0004-', MONTH(eventDate), '-', DAYOFMONTH(eventDate)) -WHERE YEAR(eventDate) = 0; ----# - ----# Converting other date columns... -ALTER TABLE {$db_prefix}log_activity -CHANGE COLUMN startDate date date NOT NULL default '0001-01-01'; - -ALTER TABLE {$db_prefix}log_activity -CHANGE COLUMN date date date NOT NULL default '0001-01-01'; - -UPDATE {$db_prefix}log_activity -SET date = '0001-01-01' -WHERE date = '0000-00-00'; - -ALTER TABLE {$db_prefix}members -CHANGE COLUMN birthdate birthdate date NOT NULL default '0001-01-01'; - -UPDATE {$db_prefix}members -SET birthdate = '0001-01-01' -WHERE birthdate = '0000-00-00'; - -UPDATE {$db_prefix}members -SET birthdate = CONCAT('0004-', MONTH(birthdate), '-', DAYOFMONTH(birthdate)) -WHERE YEAR(birthdate) = 0; ----# - -/******************************************************************************/ ---- Adding custom message icons... -/******************************************************************************/ - ----# Checking for an old table... ----{ -$request = mysql_query(" - SHOW COLUMNS - FROM {$db_prefix}message_icons"); -$test = false; -while ($request && $row = mysql_fetch_row($request)) - $test |= $row[0] == 'Name'; -if ($request) - mysql_free_result($request); - -if ($test) -{ - upgrade_query(" - ALTER TABLE {$db_prefix}message_icons - DROP PRIMARY KEY, - CHANGE COLUMN id_icon id_icon smallint(5) unsigned NOT NULL auto_increment PRIMARY KEY, - CHANGE COLUMN Name filename varchar(80) NOT NULL default '', - CHANGE COLUMN Description title varchar(80) NOT NULL default '', - CHANGE COLUMN ID_BOARD ID_BOARD mediumint(8) unsigned NOT NULL default '0', - DROP INDEX id_icon, - ADD COLUMN iconOrder smallint(5) unsigned NOT NULL default '0'"); -} ----} ----# - ----# Creating "message_icons"... -CREATE TABLE IF NOT EXISTS {$db_prefix}message_icons ( - id_icon smallint(5) unsigned NOT NULL auto_increment, - title varchar(80) NOT NULL default '', - filename varchar(80) NOT NULL default '', - ID_BOARD mediumint(8) unsigned NOT NULL default 0, - iconOrder smallint(5) unsigned NOT NULL default 0, - PRIMARY KEY (id_icon), - KEY ID_BOARD (ID_BOARD) -) ENGINE=MyISAM; ----# - ----# Inserting "message_icons"... ----{ -// We do not want to do this twice! -if (@$modSettings['smfVersion'] < '1.1') -{ - upgrade_query(" - INSERT INTO {$db_prefix}message_icons - (filename, title, iconOrder) - VALUES ('xx', 'Standard', '0'), - ('thumbup', 'Thumb Up', '1'), - ('thumbdown', 'Thumb Down', '2'), - ('exclamation', 'Exclamation point', '3'), - ('question', 'Question mark', '4'), - ('lamp', 'Lamp', '5'), - ('smiley', 'Smiley', '6'), - ('angry', 'Angry', '7'), - ('cheesy', 'Cheesy', '8'), - ('grin', 'Grin', '9'), - ('sad', 'Sad', '10'), - ('wink', 'Wink', '11')"); -} ----} ----# - -/******************************************************************************/ ---- Adding package servers... -/******************************************************************************/ - ----# Creating "package_servers"... -CREATE TABLE IF NOT EXISTS {$db_prefix}package_servers ( - id_server smallint(5) unsigned NOT NULL auto_increment, - name tinytext NOT NULL, - url tinytext NOT NULL, - PRIMARY KEY (id_server) -) ENGINE=MyISAM; ----# - ----# Inserting "package_servers"... -INSERT IGNORE INTO {$db_prefix}package_servers - (id_server, name, url) -VALUES - (1, 'Simple Machines Third-party Mod Site', 'http://mods.simplemachines.org'); ----# - -/******************************************************************************/ ---- Cleaning up database... -/******************************************************************************/ - ----# Updating flood control log... -ALTER IGNORE TABLE {$db_prefix}log_floodcontrol -CHANGE COLUMN ip ip char(16) NOT NULL default ' '; - -ALTER TABLE {$db_prefix}log_floodcontrol -DROP INDEX logTime; ----# - ----# Updating ip address storage... -ALTER IGNORE TABLE {$db_prefix}log_actions -CHANGE COLUMN IP ip char(16) NOT NULL default ' '; - -ALTER IGNORE TABLE {$db_prefix}log_banned -CHANGE COLUMN IP ip char(16) NOT NULL default ' '; - -ALTER IGNORE TABLE {$db_prefix}log_banned -DROP COLUMN ban_ids; - -ALTER IGNORE TABLE {$db_prefix}log_errors -DROP INDEX IP, -CHANGE COLUMN IP ip char(16) NOT NULL default ' ', -ADD INDEX ip (ip(16)); ----# - ----# Converting "log_online"... -DROP TABLE IF EXISTS {$db_prefix}log_online; -CREATE TABLE {$db_prefix}log_online ( - session char(32) NOT NULL default ' ', - logTime timestamp /*!40102 NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP */, - ID_MEMBER mediumint(8) unsigned NOT NULL default '0', - ip int(10) unsigned NOT NULL default '0', - url text NOT NULL, - PRIMARY KEY (session), - KEY online (logTime, ID_MEMBER), - KEY ID_MEMBER (ID_MEMBER) -) ENGINE=MyISAM; ----# - ----# Updating poll column sizes... -ALTER TABLE {$db_prefix}polls -CHANGE COLUMN maxVotes maxVotes tinyint(3) unsigned NOT NULL default '1', -CHANGE COLUMN hideResults hideResults tinyint(3) unsigned NOT NULL default '0', -CHANGE COLUMN changeVote changeVote tinyint(3) unsigned NOT NULL default '0'; - -ALTER TABLE {$db_prefix}poll_choices -CHANGE COLUMN ID_CHOICE ID_CHOICE tinyint(3) unsigned NOT NULL default '0'; - -ALTER TABLE {$db_prefix}log_polls -CHANGE COLUMN ID_CHOICE ID_CHOICE tinyint(3) unsigned NOT NULL default '0'; ----# - ----# Updating attachments table... -ALTER TABLE {$db_prefix}attachments -DROP PRIMARY KEY, -CHANGE COLUMN ID_ATTACH ID_ATTACH int(10) unsigned NOT NULL auto_increment PRIMARY KEY; ----# - ----# Updating boards and topics... -ALTER TABLE {$db_prefix}topics -CHANGE COLUMN numReplies numReplies int(10) unsigned NOT NULL default 0, -CHANGE COLUMN numViews numViews int(10) unsigned NOT NULL default 0; ----# - ----# Updating members... -ALTER TABLE {$db_prefix}members -CHANGE COLUMN lastLogin lastLogin int(10) unsigned NOT NULL default 0; ----# - ----# Recounting member pm totals (step 1)... ----{ -$request = upgrade_query(" - SELECT COUNT(*) - FROM {$db_prefix}members"); -list ($totalMembers) = mysql_fetch_row($request); -mysql_free_result($request); - -$_GET['m'] = isset($_GET['m']) ? (int) $_GET['m'] : 0; - -while ($_GET['m'] < $totalMembers) -{ - nextSubstep($substep); - - $mrequest = upgrade_query(" - SELECT mem.ID_MEMBER, COUNT(pmr.ID_PM) AS instantMessages_real, mem.instantMessages - FROM {$db_prefix}members AS mem - LEFT JOIN {$db_prefix}pm_recipients AS pmr ON (pmr.ID_MEMBER = mem.ID_MEMBER AND pmr.deleted = 0) - WHERE mem.ID_MEMBER > $_GET[m] - AND mem.ID_MEMBER <= $_GET[m] + 128 - GROUP BY mem.ID_MEMBER - HAVING instantMessages_real != instantMessages - LIMIT 256"); - while ($row = mysql_fetch_assoc($mrequest)) - { - upgrade_query(" - UPDATE {$db_prefix}members - SET instantMessages = $row[instantMessages_real] - WHERE ID_MEMBER = $row[ID_MEMBER] - LIMIT 1"); - } - - $_GET['m'] += 128; -} -unset($_GET['m']); ----} ----# - ----# Recounting member pm totals (step 2)... ----{ -$request = upgrade_query(" - SELECT COUNT(*) - FROM {$db_prefix}members"); -list ($totalMembers) = mysql_fetch_row($request); -mysql_free_result($request); - -$_GET['m'] = isset($_GET['m']) ? (int) $_GET['m'] : 0; - -while ($_GET['m'] < $totalMembers) -{ - nextSubstep($substep); - - $mrequest = upgrade_query(" - SELECT mem.ID_MEMBER, COUNT(pmr.ID_PM) AS unreadMessages_real, mem.unreadMessages - FROM {$db_prefix}members AS mem - LEFT JOIN {$db_prefix}pm_recipients AS pmr ON (pmr.ID_MEMBER = mem.ID_MEMBER AND pmr.deleted = 0 AND pmr.is_read = 0) - WHERE mem.ID_MEMBER > $_GET[m] - AND mem.ID_MEMBER <= $_GET[m] + 128 - GROUP BY mem.ID_MEMBER - HAVING unreadMessages_real != unreadMessages - LIMIT 256"); - while ($row = mysql_fetch_assoc($mrequest)) - { - upgrade_query(" - UPDATE {$db_prefix}members - SET unreadMessages = $row[unreadMessages_real] - WHERE ID_MEMBER = $row[ID_MEMBER] - LIMIT 1"); - } - - $_GET['m'] += 128; -} -unset($_GET['m']); ----} ----# - -/******************************************************************************/ ---- Converting avatar permissions... -/******************************************************************************/ - ----# Converting server stored setting... ----{ -if (!empty($modSettings['avatar_allow_server_stored'])) -{ - // Create permissions for existing membergroups. - upgrade_query(" - INSERT INTO {$db_prefix}permissions - (ID_GROUP, permission) - SELECT IF(ID_GROUP = 1, 0, ID_GROUP), 'profile_server_avatar' - FROM {$db_prefix}membergroups - WHERE ID_GROUP != 3 - AND minPosts = -1"); -} ----} ----# - ----# Converting avatar upload setting... ----{ -// Do the same, but for uploading avatars. -if (!empty($modSettings['avatar_allow_upload'])) -{ - // Put in these permissions - upgrade_query(" - INSERT INTO {$db_prefix}permissions - (ID_GROUP, permission) - SELECT IF(ID_GROUP = 1, 0, ID_GROUP), 'profile_upload_avatar' - FROM {$db_prefix}membergroups - WHERE ID_GROUP != 3 - AND minPosts = -1"); -} ----} ----# - -/******************************************************************************/ ---- Adjusting uploadable avatars... -/******************************************************************************/ - ----# Updating attachments... -ALTER TABLE {$db_prefix}attachments -CHANGE COLUMN ID_MEMBER ID_MEMBER mediumint(8) unsigned NOT NULL default '0'; ----# - ----# Updating settings... -DELETE FROM {$db_prefix}settings -WHERE variable IN ('avatar_allow_external_url', 'avatar_check_size', 'avatar_allow_upload', 'avatar_allow_server_stored'); ----# - -/******************************************************************************/ ---- Updating thumbnails... -/******************************************************************************/ - ----# Registering thumbs... ----{ -// Checkout the current structure of the attachment table. -$request = mysql_query(" - SHOW COLUMNS - FROM {$db_prefix}attachments"); -$has_customAvatarDir_column = false; -$has_attachmentType_column = false; -while ($row = mysql_fetch_assoc($request)) -{ - $has_customAvatarDir_column |= $row['Field'] == 'customAvatarDir'; - $has_attachmentType_column |= $row['Field'] == 'attachmentType'; -} -mysql_free_result($request); - -// Post SMF 1.1 Beta 1. -if ($has_customAvatarDir_column) - $request = upgrade_query(" - ALTER TABLE {$db_prefix}attachments - CHANGE COLUMN customAvatarDir attachmentType tinyint(3) unsigned NOT NULL default '0'"); -// Pre SMF 1.1. -elseif (!$has_attachmentType_column) - $request = upgrade_query(" - ALTER TABLE {$db_prefix}attachments - ADD COLUMN attachmentType tinyint(3) unsigned NOT NULL default '0'"); - -if (!$has_attachmentType_column) -{ - $request = upgrade_query(" - ALTER TABLE {$db_prefix}attachments - ADD COLUMN id_thumb int(10) unsigned NOT NULL default '0' AFTER ID_ATTACH, - ADD COLUMN width mediumint(8) unsigned NOT NULL default '0', - ADD COLUMN height mediumint(8) unsigned NOT NULL default '0'"); - - // Get a list of attachments currently stored in the database. - $request = upgrade_query(" - SELECT ID_ATTACH, ID_MSG, filename - FROM {$db_prefix}attachments"); - $filenames = array(); - $encrypted_filenames = array(); - $ID_MSG = array(); - while ($row = mysql_fetch_assoc($request)) - { - $clean_name = strtr($row['filename'], '', 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy'); - $clean_name = strtr($clean_name, array('' => 'TH', '' => 'th', '' => 'DH', '' => 'dh', '' => 'ss', '' => 'OE', '' => 'oe', '' => 'AE', '' => 'ae', '' => 'u')); - $clean_name = preg_replace(array('/\s/', '/[^\w_\.\-]/'), array('_', ''), $clean_name); - $enc_name = $row['ID_ATTACH'] . '_' . strtr($clean_name, '.', '_') . md5($clean_name); - $clean_name = preg_replace('~\.[\.]+~', '.', $clean_name); - - if (file_exists($modSettings['attachmentUploadDir'] . '/' . $enc_name)) - $filename = $enc_name; - elseif (file_exists($modSettings['attachmentUploadDir'] . '/' . $clean_name)) - $filename = $clean_name; - else - $filename = $row['filename']; - - $filenames[$row['ID_ATTACH']] = $clean_name; - $encrypted_filenames[$row['ID_ATTACH']] = $filename; - $ID_MSG[$row['ID_ATTACH']] = $row['ID_MSG']; - } - mysql_free_result($request); - - // Let's loop through the attachments - if (is_dir($modSettings['attachmentUploadDir']) && $dir = @opendir($modSettings['attachmentUploadDir'])) - { - while ($file = readdir($dir)) - { - if (substr($file, -6) == '_thumb') - { - // We found a thumbnail, now find the attachment it represents. - $attach_realFilename = substr($file, 0, -6); - if (in_array($attach_realFilename, $filenames)) - { - $attach_id = array_search($attach_realFilename, $filenames); - $attach_filename = $attach_realFilename; - } - elseif (in_array($attach_realFilename, $encrypted_filenames)) - { - $attach_id = array_search($attach_realFilename, $encrypted_filenames); - $attach_filename = $filenames[$attach_id]; - } - else - continue; - - // No need to register thumbs of non-existent attachments. - if (!file_exists($modSettings['attachmentUploadDir'] . '/' . $attach_realFilename) || strlen($attach_filename) > 249) - continue; - - // Determine the dimensions of the thumb. - list ($thumb_width, $thumb_height) = @getimagesize($modSettings['attachmentUploadDir'] . '/' . $file); - $thumb_size = filesize($modSettings['attachmentUploadDir'] . '/' . $file); - $thumb_filename = $attach_filename . '_thumb'; - - // Insert the thumbnail in the attachment database. - upgrade_query(" - INSERT INTO {$db_prefix}attachments - (ID_MSG, attachmentType, filename, size, width, height) - VALUES (" . $ID_MSG[$attach_id] . ", 3, '$thumb_filename', " . (int) $thumb_size . ', ' . (int) $thumb_width . ', ' . (int) $thumb_height . ')'); - $thumb_attach_id = mysql_insert_id(); - - // Determine the dimensions of the original attachment. - $attach_width = $attach_height = 0; - list ($attach_width, $attach_height) = @getimagesize($modSettings['attachmentUploadDir'] . '/' . $attach_realFilename); - - // Link the original attachment to its thumb. - upgrade_query(" - UPDATE {$db_prefix}attachments - SET - id_thumb = $thumb_attach_id, - width = " . (int) $attach_width . ", - height = " . (int) $attach_height . " - WHERE ID_ATTACH = $attach_id - LIMIT 1"); - - // Since it's an attachment now, we might as well encrypt it. - if (!empty($modSettings['attachmentEncryptFilenames'])) - @rename($modSettings['attachmentUploadDir'] . '/' . $file, $modSettings['attachmentUploadDir'] . '/' . $thumb_attach_id . '_' . strtr($thumb_filename, '.', '_') . md5($thumb_filename)); - } - } - closedir($dir); - } -} ----} ----# - ----# Adding image dimensions... ----{ -// Now add dimension to the images that have no thumb (yet). -$request = upgrade_query(" - SELECT ID_ATTACH, filename, attachmentType - FROM {$db_prefix}attachments - WHERE id_thumb = 0 - AND (RIGHT(filename, 4) IN ('.gif', '.jpg', '.png', '.bmp') OR RIGHT(filename, 5) = '.jpeg') - AND width = 0 - AND height = 0"); -while ($row = mysql_fetch_assoc($request)) -{ - if ($row['attachmentType'] == 1) - $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; - else - { - $clean_name = strtr($row['filename'], '', 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy'); - $clean_name = strtr($clean_name, array('' => 'TH', '' => 'th', '' => 'DH', '' => 'dh', '' => 'ss', '' => 'OE', '' => 'oe', '' => 'AE', '' => 'ae', '' => 'u')); - $clean_name = preg_replace(array('/\s/', '/[^\w_\.\-]/'), array('_', ''), $clean_name); - $enc_name = $row['ID_ATTACH'] . '_' . strtr($clean_name, '.', '_') . md5($clean_name); - $clean_name = preg_replace('~\.[\.]+~', '.', $clean_name); - - if (file_exists($modSettings['attachmentUploadDir'] . '/' . $enc_name)) - $filename = $modSettings['attachmentUploadDir'] . '/' . $enc_name; - elseif (file_exists($modSettings['attachmentUploadDir'] . '/' . $clean_name)) - $filename = $modSettings['attachmentUploadDir'] . '/' . $clean_name; - else - $filename = $modSettings['attachmentUploadDir'] . '/' . $row['filename']; - } - - $width = 0; - $height = 0; - list ($width, $height) = @getimagesize($filename); - if (!empty($width) && !empty($height)) - upgrade_query(" - UPDATE {$db_prefix}attachments - SET - width = $width, - height = $height - WHERE ID_ATTACH = $row[ID_ATTACH] - LIMIT 1"); -} -mysql_free_result($request); ----} ----# - -/******************************************************************************/ ---- Updating ban system... -/******************************************************************************/ - ----# Splitting ban table... ----{ -// Checkout the current structure of the attachment table. -$request = mysql_query(" - SHOW TABLES - LIKE '{$db_prefix}banned'"); -$upgradeBanTable = mysql_num_rows($request) == 1; -mysql_free_result($request); - -if ($upgradeBanTable) -{ - upgrade_query(" - RENAME TABLE {$db_prefix}banned - TO {$db_prefix}ban_groups"); - upgrade_query(" - ALTER TABLE {$db_prefix}ban_groups - CHANGE COLUMN id_ban id_ban_group mediumint(8) unsigned NOT NULL auto_increment"); - - upgrade_query(" - CREATE TABLE IF NOT EXISTS {$db_prefix}ban_items ( - id_ban mediumint(8) unsigned NOT NULL auto_increment, - id_ban_group smallint(5) unsigned NOT NULL default '0', - ip_low1 tinyint(3) unsigned NOT NULL default '0', - ip_high1 tinyint(3) unsigned NOT NULL default '0', - ip_low2 tinyint(3) unsigned NOT NULL default '0', - ip_high2 tinyint(3) unsigned NOT NULL default '0', - ip_low3 tinyint(3) unsigned NOT NULL default '0', - ip_high3 tinyint(3) unsigned NOT NULL default '0', - ip_low4 tinyint(3) unsigned NOT NULL default '0', - ip_high4 tinyint(3) unsigned NOT NULL default '0', - hostname tinytext NOT NULL, - email_address tinytext NOT NULL, - ID_MEMBER mediumint(8) unsigned NOT NULL default '0', - hits mediumint(8) unsigned NOT NULL default '0', - PRIMARY KEY (id_ban), - KEY id_ban_group (id_ban_group) - ) ENGINE=MyISAM"); - - upgrade_query(" - INSERT INTO {$db_prefix}ban_items - (id_ban_group, ip_low1, ip_high1, ip_low2, ip_high2, ip_low3, ip_high3, ip_low4, ip_high4, hostname, email_address, ID_MEMBER) - SELECT id_ban_group, ip_low1, ip_high1, ip_low2, ip_high2, ip_low3, ip_high3, ip_low4, ip_high4, hostname, email_address, ID_MEMBER - FROM {$db_prefix}ban_groups"); - - upgrade_query(" - ALTER TABLE {$db_prefix}ban_groups - DROP COLUMN ban_type, - DROP COLUMN ip_low1, - DROP COLUMN ip_high1, - DROP COLUMN ip_low2, - DROP COLUMN ip_high2, - DROP COLUMN ip_low3, - DROP COLUMN ip_high3, - DROP COLUMN ip_low4, - DROP COLUMN ip_high4, - DROP COLUMN hostname, - DROP COLUMN email_address, - DROP COLUMN ID_MEMBER, - ADD COLUMN cannot_access tinyint(3) unsigned NOT NULL default '0' AFTER expire_time, - ADD COLUMN cannot_register tinyint(3) unsigned NOT NULL default '0' AFTER cannot_access, - ADD COLUMN cannot_post tinyint(3) unsigned NOT NULL default '0' AFTER cannot_register, - ADD COLUMN cannot_login tinyint(3) unsigned NOT NULL default '0' AFTER cannot_post"); - - // Generate names for existing bans. - upgrade_query(" - ALTER TABLE {$db_prefix}ban_groups - ADD COLUMN name varchar(20) NOT NULL default '' AFTER id_ban_group"); - - $request = mysql_query(" - SELECT id_ban_group, restriction_type - FROM {$db_prefix}ban_groups - ORDER BY ban_time ASC"); - $ban_names = array( - 'full_ban' => 1, - 'cannot_register' => 1, - 'cannot_post' => 1, - ); - if ($request != false) - { - while ($row = mysql_fetch_assoc($request)) - upgrade_query(" - UPDATE {$db_prefix}ban_groups - SET name = '" . $row['restriction_type'] . '_' . str_pad($ban_names[$row['restriction_type']]++, 3, '0', STR_PAD_LEFT) . "' - WHERE id_ban_group = $row[id_ban_group]"); - mysql_free_result($request); - } - - // Move each restriction type to its own column. - mysql_query(" - UPDATE {$db_prefix}ban_groups - SET - cannot_access = IF(restriction_type = 'full_ban', 1, 0), - cannot_register = IF(restriction_type = 'cannot_register', 1, 0), - cannot_post = IF(restriction_type = 'cannot_post', 1, 0)"); - upgrade_query(" - ALTER TABLE {$db_prefix}ban_groups - DROP COLUMN restriction_type"); - - // Make sure everybody's ban situation is re-evaluated. - upgrade_query(" - UPDATE {$db_prefix}settings - SET value = '" . time() . "' - WHERE variable = 'banLastUpdated'"); -} ----} ----# - ----# Updating ban statistics... ----{ - $request = upgrade_query(" - SELECT mem.ID_MEMBER, mem.is_activated + 10 AS new_value - FROM ({$db_prefix}ban_groups AS bg, {$db_prefix}ban_items AS bi, {$db_prefix}members AS mem) - WHERE bg.id_ban_group = bi.id_ban_group - AND bg.cannot_access = 1 - AND (bg.expire_time IS NULL OR bg.expire_time > " . time() . ") - AND (mem.ID_MEMBER = bi.ID_MEMBER OR mem.emailAddress LIKE bi.email_address) - AND mem.is_activated < 10"); - $updates = array(); - while ($row = mysql_fetch_assoc($request)) - $updates[$row['new_value']][] = $row['ID_MEMBER']; - mysql_free_result($request); - - // Find members that are wrongfully marked as banned. - $request = upgrade_query(" - SELECT mem.ID_MEMBER, mem.is_activated - 10 AS new_value - FROM {$db_prefix}members AS mem - LEFT JOIN {$db_prefix}ban_items AS bi ON (bi.ID_MEMBER = mem.ID_MEMBER OR mem.emailAddress LIKE bi.email_address) - LEFT JOIN {$db_prefix}ban_groups AS bg ON (bg.id_ban_group = bi.id_ban_group AND bg.cannot_access = 1 AND (bg.expire_time IS NULL OR bg.expire_time > " . time() . ")) - WHERE (bi.id_ban IS NULL OR bg.id_ban_group IS NULL) - AND mem.is_activated >= 10"); - while ($row = mysql_fetch_assoc($request)) - $updates[$row['new_value']][] = $row['ID_MEMBER']; - mysql_free_result($request); - - if (!empty($updates)) - foreach ($updates as $newStatus => $members) - upgrade_query(" - UPDATE {$db_prefix}members - SET is_activated = $newStatus - WHERE ID_MEMBER IN (" . implode(', ', $members) . ") - LIMIT " . count($members)); ----} ----# - -/******************************************************************************/ ---- Updating permissions... -/******************************************************************************/ - ----# Deleting some very old permissions... -DELETE FROM {$db_prefix}board_permissions -WHERE permission IN ('view_threads', 'poll_delete_own', 'poll_delete_any', 'profile_edit_own', 'profile_edit_any'); ----# - ----# Renaming permissions... ----{ -// We *cannot* do this twice! -if (@$modSettings['smfVersion'] < '1.1') -{ - upgrade_query(" - UPDATE {$db_prefix}board_permissions - SET - permission = REPLACE(permission, 'remove_replies', 'delete_replies'), - permission = REPLACE(permission, 'remove_own', 'delete2_own'), - permission = REPLACE(permission, 'remove_any', 'delete2_any')"); - upgrade_query(" - UPDATE {$db_prefix}board_permissions - SET - permission = REPLACE(permission, 'delete_own', 'remove_own'), - permission = REPLACE(permission, 'delete_any', 'remove_any')"); - upgrade_query(" - UPDATE {$db_prefix}board_permissions - SET - permission = REPLACE(permission, 'delete2_own', 'delete_own'), - permission = REPLACE(permission, 'delete2_any', 'delete_any')"); -} ----} ----# - ----# Upgrading "deny"-permissions... ----{ -if (!isset($modSettings['permission_enable_deny'])) -{ - // Only disable if no deny permissions are used. - $request = upgrade_query(" - SELECT permission - FROM {$db_prefix}permissions - WHERE addDeny = 0 - LIMIT 1"); - $disable_deny_permissions = mysql_num_rows($request) == 0; - mysql_free_result($request); - - // Still wanna disable deny permissions? Check board permissions. - if ($disable_deny_permissions) - { - $request = upgrade_query(" - SELECT permission - FROM {$db_prefix}board_permissions - WHERE addDeny = 0 - LIMIT 1"); - $disable_deny_permissions &= mysql_num_rows($request) == 0; - mysql_free_result($request); - } - - $request = upgrade_query(" - INSERT INTO {$db_prefix}settings - (variable, value) - VALUES ('permission_enable_deny', '" . ($disable_deny_permissions ? '0' : '1') . "')"); -} ----} ----# - ----# Upgrading post based group permissions... ----{ -if (!isset($modSettings['permission_enable_postgroups'])) -{ - // Only disable if no post group permissions are used. - $disable_postgroup_permissions = true; - $request = upgrade_query(" - SELECT p.permission - FROM ({$db_prefix}permissions AS p, {$db_prefix}membergroups AS mg) - WHERE mg.ID_GROUP = p.ID_GROUP - AND mg.minPosts != -1 - LIMIT 1"); - $disable_postgroup_permissions &= mysql_num_rows($request) == 0; - mysql_free_result($request); - - // Still wanna disable postgroup permissions? Check board permissions. - if ($disable_postgroup_permissions) - { - $request = upgrade_query(" - SELECT bp.permission - FROM ({$db_prefix}board_permissions AS bp, {$db_prefix}membergroups AS mg) - WHERE mg.ID_GROUP = bp.ID_GROUP - AND mg.minPosts != -1 - LIMIT 1"); - $disable_postgroup_permissions &= mysql_num_rows($request) == 0; - mysql_free_result($request); - } - - $request = upgrade_query(" - INSERT INTO {$db_prefix}settings - (variable, value) - VALUES ('permission_enable_postgroups', '" . ($disable_postgroup_permissions ? '0' : '1') . "')"); -} ----} ----# - ----# Upgrading by-board permissions... -ALTER TABLE {$db_prefix}boards -CHANGE COLUMN use_local_permissions permission_mode tinyint(4) unsigned NOT NULL default '0'; - ----{ -if (!isset($modSettings['permission_enable_by_board'])) -{ - // Enable by-board permissions if there's >= 1 local permission board. - $request = upgrade_query(" - SELECT ID_BOARD - FROM {$db_prefix}boards - WHERE permission_mode = 1 - LIMIT 1"); - $enable_by_board = mysql_num_rows($request) == 1 ? '1' : '0'; - mysql_free_result($request); - - $request = upgrade_query(" - INSERT INTO {$db_prefix}settings - (variable, value) - VALUES ('permission_enable_by_board', '$enable_by_board')"); -} ----} ----# - ----# Removing all guest deny permissions... -DELETE FROM {$db_prefix}permissions -WHERE ID_GROUP = -1 - AND addDeny = 0; - -DELETE FROM {$db_prefix}board_permissions -WHERE ID_GROUP = -1 - AND addDeny = 0; ----# - ----# Removing guest admin permissions (if any)... -DELETE FROM {$db_prefix}permissions -WHERE ID_GROUP = -1 - AND permission IN ('admin_forum', 'manage_boards', 'manage_attachments', 'manage_smileys', 'edit_news', 'moderate_forum', 'manage_membergroups', 'manage_permissions', 'manage_bans', 'send_mail'); - -DELETE FROM {$db_prefix}board_permissions -WHERE ID_GROUP = -1 - AND permission IN ('admin_forum', 'manage_boards', 'manage_attachments', 'manage_smileys', 'edit_news', 'moderate_forum', 'manage_membergroups', 'manage_permissions', 'manage_bans', 'send_mail'); ----# - -/******************************************************************************/ ---- Updating search cache... -/******************************************************************************/ - ----# Creating search cache tables... -DROP TABLE IF EXISTS {$db_prefix}log_search_fulltext; -DROP TABLE IF EXISTS {$db_prefix}log_search_messages; -DROP TABLE IF EXISTS {$db_prefix}log_search_topics; -DROP TABLE IF EXISTS {$db_prefix}log_search; - -CREATE TABLE IF NOT EXISTS {$db_prefix}log_search_messages ( - id_search tinyint(3) unsigned NOT NULL default '0', - ID_MSG int(10) NOT NULL default '0', - PRIMARY KEY (id_search, ID_MSG) -) ENGINE=MyISAM; - -CREATE TABLE IF NOT EXISTS {$db_prefix}log_search_topics ( - id_search tinyint(3) unsigned NOT NULL default '0', - ID_TOPIC mediumint(9) NOT NULL default '0', - PRIMARY KEY (id_search, ID_TOPIC) -) ENGINE=MyISAM; - -CREATE TABLE IF NOT EXISTS {$db_prefix}log_search_results ( - id_search tinyint(3) unsigned NOT NULL default '0', - ID_TOPIC mediumint(8) unsigned NOT NULL default '0', - ID_MSG int(10) unsigned NOT NULL default '0', - relevance smallint(5) unsigned NOT NULL default '0', - num_matches smallint(5) unsigned NOT NULL default '0', - PRIMARY KEY (id_search, ID_TOPIC), - KEY relevance (relevance) -) ENGINE=MyISAM; - -CREATE TABLE IF NOT EXISTS {$db_prefix}log_search_subjects ( - word varchar(20) NOT NULL default '', - ID_TOPIC mediumint(8) unsigned NOT NULL default '0', - PRIMARY KEY (word, ID_TOPIC), - KEY ID_TOPIC (ID_TOPIC) -) ENGINE=MyISAM; ----# - ----# Rebuilding fulltext index... ----{ -$request = upgrade_query(" - SHOW KEYS - FROM {$db_prefix}messages"); -$found = false; -while ($row = mysql_fetch_assoc($request)) - $found |= $row['Key_name'] == 'subject' && $row['Column_name'] == 'subject'; -mysql_free_result($request); -if ($found) -{ - $request = upgrade_query(" - ALTER TABLE {$db_prefix}messages - DROP INDEX subject, - DROP INDEX body, - ADD FULLTEXT body (body)"); -} ----} ----# - ----# Indexing topic subjects... ----{ -$request = upgrade_query(" - SELECT COUNT(*) - FROM {$db_prefix}log_search_subjects"); -list ($numIndexedWords) = mysql_fetch_row($request); -mysql_free_result($request); -if ($numIndexedWords == 0 || isset($_GET['lt'])) -{ - $request = upgrade_query(" - SELECT COUNT(*) - FROM {$db_prefix}topics"); - list ($maxTopics) = mysql_fetch_row($request); - mysql_free_result($request); - - $_GET['lt'] = isset($_GET['lt']) ? (int) $_GET['lt'] : 0; - $step_progress['name'] = 'Indexing Topic Subjects'; - $step_progress['current'] = $_GET['lt']; - $step_progress['total'] = $maxTopics; - - while ($_GET['lt'] <= $maxTopics) - { - $request = upgrade_query(" - SELECT t.ID_TOPIC, m.subject - FROM ({$db_prefix}topics AS t, {$db_prefix}messages AS m) - WHERE m.ID_MSG = t.ID_FIRST_MSG - LIMIT $_GET[lt], 250"); - $inserts = array(); - while ($row = mysql_fetch_assoc($request)) - { - foreach (text2words($row['subject']) as $word) - $inserts[] = "'" . mysql_real_escape_string($word) . "', $row[ID_TOPIC]"; - } - mysql_free_result($request); - - if (!empty($inserts)) - upgrade_query(" - INSERT INTO {$db_prefix}log_search_subjects - (word, ID_TOPIC) - VALUES (" . implode('), - (', array_unique($inserts)) . ")"); - - $_GET['lt'] += 250; - $step_progress['current'] = $_GET['lt']; - nextSubstep($substep); - } - unset($_GET['lt']); -} ----} ----# - ----# Converting settings... ----{ -if (isset($modSettings['search_method'])) -{ - if (!empty($modSettings['search_method'])) - $request = upgrade_query(" - INSERT INTO {$db_prefix}settings - (variable, value) - VALUES - ('search_match_words', '1')"); - - if ($modSettings['search_method'] > 1) - $request = upgrade_query(" - INSERT INTO {$db_prefix}settings - (variable, value) - VALUES - ('search_index', 'fulltext')"); - - if ($modSettings['search_method'] == 3) - $request = upgrade_query(" - INSERT INTO {$db_prefix}settings - (variable, value) - VALUES - ('search_force_index', '1')"); - - $request = upgrade_query(" - DELETE FROM {$db_prefix}settings - WHERE variable = 'search_method'"); -} ----} ----# - -/******************************************************************************/ ---- Upgrading log system... -/******************************************************************************/ - ----# Creating log table indexes (this might take some time!)... ----{ -$request = upgrade_query(" - SHOW COLUMNS - FROM {$db_prefix}log_topics"); -$upgradeLogTable = false; -while ($request && $row = mysql_fetch_row($request)) - $upgradeLogTable |= $row[0] == 'logTime'; -if ($request !== false) - mysql_free_result($request); - -if ($upgradeLogTable) -{ - $_GET['preprep_lt'] = isset($_GET['preprep_lt']) ? (int) $_GET['preprep_lt'] : 0; - $step_progress['name'] = 'Creating index\'s for log table'; - $step_progress['current'] = $_GET['preprep_lt']; - $custom_warning = 'On a very large board these index\'s may take a few minutes to create.'; - - $log_additions = array( - array( - 'table' => 'log_boards', - 'type' => 'index', - 'method' => 'add', - 'name' => 'logTime', - 'target_columns' => array('logTime'), - 'text' => 'ADD INDEX logTime (logTime)', - ), - array( - 'table' => 'log_mark_read', - 'type' => 'index', - 'method' => 'add', - 'name' => 'logTime', - 'target_columns' => array('logTime'), - 'text' => 'ADD INDEX logTime (logTime)', - ), - array( - 'table' => 'messages', - 'type' => 'index', - 'method' => 'add', - 'name' => 'modifiedTime', - 'target_columns' => array('modifiedTime'), - 'text' => 'ADD INDEX modifiedTime (modifiedTime)', - ), - ); - - $step_progress['total'] = count($log_additions); - - // Now we loop through the changes and work out where the hell we are. - foreach ($log_additions as $ind => $change) - { - // Already done it? - if ($_GET['preprep_lt'] > $ind) - continue; - - // Make the index, with all the protection and all. - protected_alter($change, $substep); - - // Store this for the next table. - $_GET['preprep_lt']++; - $step_progress['current'] = $_GET['preprep_lt']; - } - - // Clean up. - unset($_GET['preprep_lt']); -} ----} ----# - ----# Preparing log table upgrade... ----{ -$request = upgrade_query(" - SHOW COLUMNS - FROM {$db_prefix}log_topics"); -$upgradeLogTable = false; -while ($request && $row = mysql_fetch_row($request)) - $upgradeLogTable |= $row[0] == 'logTime'; -if ($request !== false) - mysql_free_result($request); - -if ($upgradeLogTable) -{ - $_GET['prep_lt'] = isset($_GET['prep_lt']) ? (int) $_GET['prep_lt'] : 0; - $step_progress['name'] = 'Preparing log table update'; - $step_progress['current'] = $_GET['prep_lt']; - $custom_warning = 'This step may take quite some time. During this time it may appear that nothing is happening while - the databases MySQL tables are expanded. Please be patient.'; - - // All these changes need to be made, they may take a while, so let's timeout neatly. - $log_additions = array( - array( - 'table' => 'log_topics', - 'type' => 'index', - 'method' => 'remove', - 'name' => 'ID_MEMBER', - 'target_columns' => array('ID_MEMBER'), - 'text' => 'DROP INDEX ID_MEMBER', - ), - array( - 'table' => 'log_topics', - 'type' => 'index', - 'method' => 'change', - 'name' => 'PRIMARY', - 'target_columns' => array('ID_MEMBER', 'ID_TOPIC'), - 'text' => ' - DROP PRIMARY KEY, - ADD PRIMARY KEY (ID_MEMBER, ID_TOPIC)', - ), - array( - 'table' => 'log_topics', - 'type' => 'index', - 'method' => 'add', - 'name' => 'logTime', - 'target_columns' => array('logTime'), - 'text' => 'ADD INDEX logTime (logTime)', - ), - array( - 'table' => 'log_boards', - 'type' => 'column', - 'method' => 'add', - 'name' => 'ID_MSG', - 'text' => 'ADD COLUMN ID_MSG mediumint(8) unsigned NOT NULL default \'0\'', - ), - array( - 'table' => 'log_mark_read', - 'type' => 'column', - 'method' => 'add', - 'name' => 'ID_MSG', - 'text' => 'ADD COLUMN ID_MSG mediumint(8) unsigned NOT NULL default \'0\'', - ), - array( - 'table' => 'log_topics', - 'type' => 'column', - 'method' => 'add', - 'name' => 'ID_MSG', - 'text' => 'ADD COLUMN ID_MSG mediumint(8) unsigned NOT NULL default \'0\'', - ), - array( - 'table' => 'messages', - 'type' => 'column', - 'method' => 'add', - 'name' => 'ID_MSG_MODIFIED', - 'text' => 'ADD COLUMN ID_MSG_MODIFIED mediumint(8) unsigned NOT NULL default \'0\' AFTER ID_MEMBER', - ), - array( - 'table' => 'boards', - 'type' => 'column', - 'method' => 'add', - 'name' => 'ID_MSG_UPDATED', - 'text' => 'ADD COLUMN ID_MSG_UPDATED mediumint(8) unsigned NOT NULL default \'0\' AFTER ID_LAST_MSG', - ), - array( - 'table' => 'boards', - 'type' => 'index', - 'method' => 'add', - 'name' => 'ID_MSG_UPDATED', - 'target_columns' => array('ID_MSG_UPDATED'), - 'text' => 'ADD INDEX ID_MSG_UPDATED (ID_MSG_UPDATED)', - ), - ); - $step_progress['total'] = count($log_additions); - - // Now we loop through the changes and work out where the hell we are. - foreach ($log_additions as $ind => $change) - { - // Already done it? - if ($_GET['prep_lt'] > $ind) - continue; - - // Make the index, with all the protection and all. - protected_alter($change, $substep); - - // Store this for the next table. - $_GET['prep_lt']++; - $step_progress['current'] = $_GET['prep_lt']; - } - - // Clean up. - unset($_GET['prep_lt']); -} ----} ----# - ----# Converting log tables (this might take some time!)... ----{ -$request = upgrade_query(" - SHOW COLUMNS - FROM {$db_prefix}log_topics"); -$upgradeLogTable = false; -while ($request && $row = mysql_fetch_row($request)) - $upgradeLogTable |= $row[0] == 'logTime'; -if ($request !== false) - mysql_free_result($request); - -if ($upgradeLogTable) -{ - $request = upgrade_query(" - SELECT MAX(ID_MSG) - FROM {$db_prefix}messages"); - list($maxMsg) = mysql_fetch_row($request); - mysql_free_result($request); - - if (empty($maxMsg)) - $maxMsg = 0; - - $_GET['m'] = isset($_GET['m']) ? (int) $_GET['m'] : 0; - $step_progress['name'] = 'Converting Log Tables'; - $step_progress['current'] = $_GET['m']; - $step_progress['total'] = $maxMsg; - $custom_warning = 'This step is converting all your log tables and may take quite some time on a large forum (Several hours for a forum with ~500,000 messages).'; - - // Only adjust the structure if this is the first message. - if ($_GET['m'] === 0) - { - // By default a message is modified when it was written. - upgrade_query(" - UPDATE {$db_prefix}messages - SET ID_MSG_MODIFIED = ID_MSG"); - - $request = upgrade_query(" - SELECT posterTime - FROM {$db_prefix}messages - WHERE ID_MSG = $maxMsg"); - list($maxPosterTime) = mysql_fetch_row($request); - mysql_free_result($request); - - if (empty($maxPosterTime)) - $maxPosterTime = 0; - - upgrade_query(" - UPDATE {$db_prefix}log_boards - SET ID_MSG = $maxMsg - WHERE logTime >= $maxPosterTime"); - upgrade_query(" - UPDATE {$db_prefix}log_mark_read - SET ID_MSG = $maxMsg - WHERE logTime >= $maxPosterTime"); - upgrade_query(" - UPDATE {$db_prefix}log_topics - SET ID_MSG = $maxMsg - WHERE logTime >= $maxPosterTime"); - upgrade_query(" - UPDATE {$db_prefix}messages - SET ID_MSG_MODIFIED = $maxMsg - WHERE modifiedTime >= $maxPosterTime"); - - // Timestamp 1 is where it all starts. - $lower_limit = 1; - } - else - { - // Determine the lower limit. - $request = upgrade_query(" - SELECT MAX(posterTime) + 1 - FROM {$db_prefix}messages - WHERE ID_MSG < $_GET[m]"); - list($lower_limit) = mysql_fetch_row($request); - mysql_free_result($request); - - if (empty($lower_limit)) - $lower_limit = 1; - - if (empty($maxPosterTime)) - $maxPosterTime = 1; - } - - while ($_GET['m'] <= $maxMsg) - { - $condition = ''; - $lowest_limit = $lower_limit; - $request = upgrade_query(" - SELECT MAX(ID_MSG) AS ID_MSG, posterTime - FROM {$db_prefix}messages - WHERE ID_MSG BETWEEN $_GET[m] AND " . ($_GET['m'] + 300) . " - GROUP BY posterTime - ORDER BY posterTime - LIMIT 300"); - while ($row = mysql_fetch_assoc($request)) - { - if ($condition === '') - $condition = "IF(logTime BETWEEN $lower_limit AND $row[posterTime], $row[ID_MSG], %else%)"; - else - $condition = strtr($condition, array('%else%' => "IF(logTime <= $row[posterTime], $row[ID_MSG], %else%)")); - - $lower_limit = $row['posterTime'] + 1; - } - mysql_free_result($request); - - if ($condition !== '') - { - $condition = strtr($condition, array('%else%' => '0')); - $highest_limit = $lower_limit; - - upgrade_query(" - UPDATE {$db_prefix}log_boards - SET ID_MSG = $condition - WHERE logTime BETWEEN $lowest_limit AND $highest_limit - AND ID_MSG = 0"); - upgrade_query(" - UPDATE {$db_prefix}log_mark_read - SET ID_MSG = $condition - WHERE logTime BETWEEN $lowest_limit AND $highest_limit - AND ID_MSG = 0"); - upgrade_query(" - UPDATE {$db_prefix}log_topics - SET ID_MSG = $condition - WHERE logTime BETWEEN $lowest_limit AND $highest_limit - AND ID_MSG = 0"); - upgrade_query(" - UPDATE {$db_prefix}messages - SET ID_MSG_MODIFIED = " . strtr($condition, array('logTime' => 'modifiedTime')) . " - WHERE modifiedTime BETWEEN $lowest_limit AND $highest_limit - AND modifiedTime > 0"); - } - - $_GET['m'] += 300; - nextSubstep($substep); - } - unset($_GET['m']); -} ----} ----# - ----# Updating last message IDs for boards. ----{ - -$request = upgrade_query(" - SHOW COLUMNS - FROM {$db_prefix}boards"); -$upgradeBoardsTable = false; -while ($request && $row = mysql_fetch_row($request)) - $upgradeBoardsTable |= $row[0] == 'lastUpdated'; -if ($request !== false) - mysql_free_result($request); - -if ($upgradeBoardsTable) -{ - $request = upgrade_query(" - SELECT MAX(ID_BOARD) - FROM {$db_prefix}boards"); - list ($maxBoard) = mysql_fetch_row($request); - mysql_free_result($request); - - $_GET['bdi'] = isset($_GET['bdi']) ? (int) $_GET['bdi'] : 0; - $step_progress['name'] = 'Updating Last Board ID'; - $step_progress['current'] = $_GET['bdi']; - $step_progress['total'] = $maxBoard; - - // OK, we need to get the last updated message. - $request = upgrade_query(" - SELECT ID_BOARD, lastUpdated - FROM {$db_prefix}boards"); - while ($row = mysql_fetch_assoc($request)) - { - // Done this? - if ($row['ID_BOARD'] < $_GET['bdi']) - continue; - - // Maybe we don't have any? - if ($row['lastUpdated'] == 0) - $ID_MSG = 0; - // Otherwise need to query it? - else - { - $request2 = upgrade_query(" - SELECT MIN(ID_MSG) - FROM {$db_prefix}messages - WHERE posterTime >= $row[lastUpdated]"); - list ($ID_MSG) = mysql_fetch_row($request2); - - if (empty($ID_MSG)) - $ID_MSG = 0; - } - - upgrade_query(" - UPDATE {$db_prefix}boards - SET ID_MSG_UPDATED = $ID_MSG - WHERE ID_BOARD = $row[ID_BOARD]"); - - $_GET['bdi']++; - $step_progress['current'] = $_GET['bdi']; - nextSubstep($substep); - } - unset($_GET['bdi']); -} ----} ----# - ----# Cleaning up old log indexes... ----{ -$request = upgrade_query(" - SHOW COLUMNS - FROM {$db_prefix}log_topics"); -$upgradeLogTable = false; -while ($request && $row = mysql_fetch_row($request)) - $upgradeLogTable |= $row[0] == 'logTime'; -if ($request !== false) - mysql_free_result($request); - -if ($upgradeLogTable) -{ - $_GET['prep_lt'] = isset($_GET['prep_lt']) ? (int) $_GET['prep_lt'] : 0; - $step_progress['name'] = 'Cleaning up old log table index\'s'; - $step_progress['current'] = $_GET['prep_lt']; - $custom_warning = 'This step may take quite some time. During this time it may appear that nothing is happening while - the databases MySQL tables are cleaned. Please be patient.'; - - // Here we remove all the unused indexes - $log_deletions = array( - array( - 'table' => 'boards', - 'type' => 'index', - 'method' => 'remove', - 'name' => 'lastUpdated', - 'target_columns' => array('lastUpdated'), - 'text' => 'DROP INDEX lastUpdated', - ), - array( - 'table' => 'messages', - 'type' => 'index', - 'method' => 'remove', - 'name' => 'posterTime', - 'target_columns' => array('posterTime'), - 'text' => 'DROP INDEX posterTime', - ), - array( - 'table' => 'messages', - 'type' => 'index', - 'method' => 'remove', - 'name' => 'modifiedTime', - 'target_columns' => array('modifiedTime'), - 'text' => 'DROP INDEX modifiedTime', - ), - array( - 'table' => 'log_topics', - 'type' => 'column', - 'method' => 'remove', - 'name' => 'logTime', - 'text' => 'DROP COLUMN logTime', - ), - array( - 'table' => 'log_boards', - 'type' => 'column', - 'method' => 'remove', - 'name' => 'logTime', - 'text' => 'DROP COLUMN logTime', - ), - array( - 'table' => 'log_mark_read', - 'type' => 'column', - 'method' => 'remove', - 'name' => 'logTime', - 'text' => 'DROP COLUMN logTime', - ), - array( - 'table' => 'boards', - 'type' => 'column', - 'method' => 'remove', - 'name' => 'lastUpdated', - 'text' => 'DROP COLUMN lastUpdated', - ), - ); - $step_progress['total'] = count($log_deletions); - - // Now we loop through the changes and work out where the hell we are. - foreach ($log_deletions as $ind => $change) - { - // Already done it? - if ($_GET['prep_lt'] > $ind) - continue; - - // Make the index, with all the protection and all. - protected_alter($change, $substep); - - // Store this for the next table. - $_GET['prep_lt']++; - $step_progress['current'] = $_GET['prep_lt']; - } - - // Clean up. - unset($_GET['prep_lt']); - $step_progress = array(); -} ----} ----# - -/******************************************************************************/ ---- Making SMF MySQL strict compatible... -/******************************************************************************/ - ----# Preparing messages table for strict upgrade -ALTER IGNORE TABLE {$db_prefix}messages -DROP INDEX ipIndex; ----# - ----# Adjusting text fields ----# ----{ -// Note we move on by one as there is no point ALTER'ing the same thing twice. -$_GET['strict_step'] = isset($_GET['strict_step']) ? (int) $_GET['strict_step'] + 1 : 0; -$step_progress['name'] = 'Adding MySQL strict compatibility'; -$step_progress['current'] = $_GET['strict_step']; - -// Take care with the body column from messages, just in case it's been enlarged by others. -$request = upgrade_query(" - SHOW COLUMNS - FROM {$db_prefix}messages - LIKE 'body'"); -$body_row = mysql_fetch_assoc($request); -mysql_free_result($request); - -$body_type = $body_row['Type']; - -$textfield_updates = array( - array( - 'table' => 'attachments', - 'column' => 'filename', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'ban_groups', - 'column' => 'reason', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'ban_items', - 'column' => 'hostname', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'ban_items', - 'column' => 'email_address', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'boards', - 'column' => 'name', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'boards', - 'column' => 'description', - 'type' => 'text', - 'null_allowed' => false, - ), - array( - 'table' => 'categories', - 'column' => 'name', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'log_actions', - 'column' => 'extra', - 'type' => 'text', - 'null_allowed' => false, - ), - array( - 'table' => 'log_banned', - 'column' => 'email', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'log_banned', - 'column' => 'email', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'log_errors', - 'column' => 'url', - 'type' => 'text', - 'null_allowed' => false, - ), - array( - 'table' => 'log_errors', - 'column' => 'message', - 'type' => 'text', - 'null_allowed' => false, - ), - array( - 'table' => 'log_online', - 'column' => 'url', - 'type' => 'text', - 'null_allowed' => false, - ), - array( - 'table' => 'membergroups', - 'column' => 'stars', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'members', - 'column' => 'lngfile', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'members', - 'column' => 'realName', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'members', - 'column' => 'buddy_list', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'members', - 'column' => 'pm_ignore_list', - 'type' => 'text', - 'null_allowed' => false, - ), - array( - 'table' => 'members', - 'column' => 'messageLabels', - 'type' => 'text', - 'null_allowed' => false, - ), - array( - 'table' => 'members', - 'column' => 'emailAddress', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'members', - 'column' => 'personalText', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'members', - 'column' => 'websiteTitle', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'members', - 'column' => 'websiteUrl', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'members', - 'column' => 'location', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'members', - 'column' => 'ICQ', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'members', - 'column' => 'MSN', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'members', - 'column' => 'signature', - 'type' => 'text', - 'null_allowed' => false, - ), - array( - 'table' => 'members', - 'column' => 'avatar', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'members', - 'column' => 'usertitle', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'members', - 'column' => 'memberIP', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'members', - 'column' => 'secretQuestion', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'members', - 'column' => 'additionalGroups', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'messages', - 'column' => 'subject', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'messages', - 'column' => 'posterName', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'messages', - 'column' => 'posterEmail', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'messages', - 'column' => 'posterIP', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'messages', - 'column' => 'modifiedName', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'messages', - 'column' => 'body', - 'type' => $body_type, - 'null_allowed' => false, - ), - array( - 'table' => 'personal_messages', - 'column' => 'body', - 'type' => 'text', - 'null_allowed' => false, - ), - array( - 'table' => 'package_servers', - 'column' => 'name', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'personal_messages', - 'column' => 'fromName', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'personal_messages', - 'column' => 'subject', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'personal_messages', - 'column' => 'body', - 'type' => 'text', - 'null_allowed' => false, - ), - array( - 'table' => 'polls', - 'column' => 'question', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'polls', - 'column' => 'posterName', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'poll_choices', - 'column' => 'label', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'settings', - 'column' => 'variable', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'settings', - 'column' => 'value', - 'type' => 'text', - 'null_allowed' => false, - ), - array( - 'table' => 'sessions', - 'column' => 'data', - 'type' => 'text', - 'null_allowed' => false, - ), - array( - 'table' => 'themes', - 'column' => 'variable', - 'type' => 'tinytext', - 'null_allowed' => false, - ), - array( - 'table' => 'themes', - 'column' => 'value', - 'type' => 'text', - 'null_allowed' => false, - ), -); -$step_progress['total'] = count($textfield_updates); - -foreach ($textfield_updates as $ind => $change) -{ - // Already done it? - if ($_GET['strict_step'] > $ind) - continue; - - // Make the index, with all the protection and all. - textfield_alter($change, $substep); - - // Store this for the next table. - $_GET['strict_step']++; - $step_progress['current'] = $_GET['strict_step']; -} - -$step_progress = array(); ----} ----# - ----# Replacing messages index. -ALTER TABLE {$db_prefix}messages -ADD INDEX ipIndex (posterIP(15), ID_TOPIC); ----# - ----# Adding log_topics index. ----{ -upgrade_query(" - ALTER TABLE {$db_prefix}log_topics - ADD INDEX ID_TOPIC (ID_TOPIC)", true); ----} ----# - -/******************************************************************************/ ---- Adding more room for the buddy list -/******************************************************************************/ - ----# Updating the members table ... -ALTER TABLE {$db_prefix}members -CHANGE COLUMN buddy_list buddy_list text NOT NULL; ----# - -/******************************************************************************/ ---- Change some column types to accomodate more messages. -/******************************************************************************/ - ----# Expanding message column size. ----{ -$_GET['msg_change'] = isset($_GET['msg_change']) ? (int) $_GET['msg_change'] : 0; -$step_progress['name'] = 'Expanding Message Capacity'; -$step_progress['current'] = $_GET['msg_change']; - -// The array holding all the changes. -$columnChanges = array( - array( - 'table' => 'boards', - 'type' => 'column', - 'method' => 'change', - 'name' => 'ID_LAST_MSG', - 'text' => 'CHANGE ID_LAST_MSG ID_LAST_MSG int(10) unsigned NOT NULL default \'0\'', - ), - array( - 'table' => 'boards', - 'type' => 'column', - 'method' => 'change', - 'name' => 'ID_MSG_UPDATED', - 'text' => 'CHANGE ID_MSG_UPDATED ID_MSG_UPDATED int(10) unsigned NOT NULL default \'0\'', - ), - array( - 'table' => 'log_boards', - 'type' => 'column', - 'method' => 'change', - 'name' => 'ID_MSG', - 'text' => 'CHANGE ID_MSG ID_MSG int(10) unsigned NOT NULL default \'0\'', - ), - array( - 'table' => 'log_mark_read', - 'type' => 'column', - 'method' => 'change', - 'name' => 'ID_MSG', - 'text' => 'CHANGE ID_MSG ID_MSG int(10) unsigned NOT NULL default \'0\'', - ), - array( - 'table' => 'log_topics', - 'type' => 'column', - 'method' => 'change', - 'name' => 'ID_MSG', - 'text' => 'CHANGE ID_MSG ID_MSG int(10) unsigned NOT NULL default \'0\'', - ), - array( - 'table' => 'messages', - 'type' => 'column', - 'method' => 'change', - 'name' => 'ID_MSG_MODIFIED', - 'text' => 'CHANGE ID_MSG_MODIFIED ID_MSG_MODIFIED int(10) unsigned NOT NULL default \'0\'', - ), -); - -if (!empty($modSettings['search_custom_index_config'])) - $columnChanges[] = array( - 'table' => 'log_search_words', - 'type' => 'column', - 'method' => 'change', - 'name' => 'ID_MSG', - 'text' => 'CHANGE ID_MSG ID_MSG int(10) unsigned NOT NULL default \'0\'', - ); - -$step_progress['total'] = count($columnChanges); - -// Now we do all the changes... -foreach ($columnChanges as $index => $change) -{ - // Already done it? - if ($_GET['msg_change'] > $ind) - continue; - - // Now change the column at last. - protected_alter($change, $substep); - - // Update where we are... - $_GET['msg_change']++; - $step_progress['current'] = $_GET['msg_change']; -} - -// Clean up. -unset($_GET['msg_change']); ----} ----# - -/******************************************************************************/ ---- Final clean up... -/******************************************************************************/ - ----# Sorting the boards... -ALTER TABLE {$db_prefix}categories -ORDER BY catOrder; - -ALTER TABLE {$db_prefix}boards -ORDER BY boardOrder; ----# - ----# Removing upgrade loop protection... -DELETE FROM {$db_prefix}settings -WHERE variable IN ('dont_repeat_smtp', 'dont_repeat_theme'); ----# \ No newline at end of file diff --git a/upgrade_2-0_mysql.sql b/upgrade_2-0_mysql.sql deleted file mode 100644 index de2ac4d..0000000 --- a/upgrade_2-0_mysql.sql +++ /dev/null @@ -1,3166 +0,0 @@ -/* ATTENTION: You don't need to run or use this file! The upgrade.php script does everything for you! */ - -/******************************************************************************/ ---- Changing column names. -/******************************************************************************/ - ----# Renaming table columns. ----{ -// The array holding all the changes. -$nameChanges = array( - 'admin_info_files' => array( - 'ID_FILE' => 'ID_FILE id_file tinyint(4) unsigned NOT NULL auto_increment', - ), - 'approval_queue' => array( - 'ID_MSG' => 'ID_MSG id_msg int(10) unsigned NOT NULL default \'0\'', - 'ID_ATTACH' => 'ID_ATTACH id_attach int(10) unsigned NOT NULL default \'0\'', - 'ID_EVENT' => 'ID_EVENT id_event smallint(5) unsigned NOT NULL default \'0\'', - 'attachmentType' => 'attachmentType attachment_type tinyint(3) unsigned NOT NULL default \'0\'', - ), - 'attachments' => array( - 'ID_ATTACH' => 'ID_ATTACH id_attach int(10) unsigned NOT NULL auto_increment', - 'ID_THUMB' => 'ID_THUMB id_thumb int(10) unsigned NOT NULL default \'0\'', - 'ID_MSG' => 'ID_MSG id_msg int(10) unsigned NOT NULL default \'0\'', - 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'', - 'attachmentType' => 'attachmentType attachment_type tinyint(3) unsigned NOT NULL default \'0\'', - ), - 'ban_groups' => array( - 'ID_BAN_GROUP' => 'ID_BAN_GROUP id_ban_group mediumint(8) unsigned NOT NULL auto_increment', - ), - 'ban_items' => array( - 'ID_BAN' => 'ID_BAN id_ban mediumint(8) unsigned NOT NULL auto_increment', - 'ID_BAN_GROUP' => 'ID_BAN_GROUP id_ban_group smallint(5) unsigned NOT NULL default \'0\'', - 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'', - ), - 'board_permissions' => array( - 'ID_GROUP' => 'ID_GROUP id_group smallint(5) NOT NULL default \'0\'', - 'ID_PROFILE' => 'ID_PROFILE id_profile smallint(5) NOT NULL default \'0\'', - 'addDeny' => 'addDeny add_deny tinyint(4) NOT NULL default \'1\'', - ), - 'boards' => array( - 'ID_BOARD' => 'ID_BOARD id_board smallint(5) unsigned NOT NULL auto_increment', - 'ID_CAT' => 'ID_CAT id_cat tinyint(4) unsigned NOT NULL default \'0\'', - 'childLevel' => 'childLevel child_level tinyint(4) unsigned NOT NULL default \'0\'', - 'ID_PARENT' => 'ID_PARENT id_parent smallint(5) unsigned NOT NULL default \'0\'', - 'boardOrder' => 'boardOrder board_order smallint(5) NOT NULL default \'0\'', - 'ID_LAST_MSG' => 'ID_LAST_MSG id_last_msg int(10) unsigned NOT NULL default \'0\'', - 'ID_MSG_UPDATED' => 'ID_MSG_UPDATED id_msg_updated int(10) unsigned NOT NULL default \'0\'', - 'memberGroups' => 'memberGroups member_groups varchar(255) NOT NULL default \'-1,0\'', - 'ID_PROFILE' => 'ID_PROFILE id_profile smallint(5) unsigned NOT NULL default \'1\'', - 'numTopics' => 'numTopics num_topics mediumint(8) unsigned NOT NULL default \'0\'', - 'numPosts' => 'numPosts num_posts mediumint(8) unsigned NOT NULL default \'0\'', - 'countPosts' => 'countPosts count_posts tinyint(4) NOT NULL default \'0\'', - 'ID_THEME' => 'ID_THEME id_theme tinyint(4) unsigned NOT NULL default \'0\'', - 'unapprovedPosts' => 'unapprovedPosts unapproved_posts smallint(5) NOT NULL default \'0\'', - 'unapprovedTopics' => 'unapprovedTopics unapproved_topics smallint(5) NOT NULL default \'0\'', - ), - 'calendar' => array( - 'ID_EVENT' => 'ID_EVENT id_event smallint(5) unsigned NOT NULL auto_increment', - 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'', - 'ID_BOARD' => 'ID_BOARD id_board smallint(5) unsigned NOT NULL default \'0\'', - 'ID_TOPIC' => 'ID_TOPIC id_topic mediumint(8) unsigned NOT NULL default \'0\'', - 'startDate' => 'startDate start_date date NOT NULL default \'0001-01-01\'', - 'endDate' => 'endDate end_date date NOT NULL default \'0001-01-01\'', - ), - 'calendar_holidays' => array( - 'ID_HOLIDAY' => 'ID_HOLIDAY id_holiday smallint(5) unsigned NOT NULL auto_increment', - 'eventDate' => 'eventDate event_date date NOT NULL default \'0001-01-01\'', - ), - 'categories' => array( - 'ID_CAT' => 'ID_CAT id_cat tinyint(4) unsigned NOT NULL auto_increment', - 'catOrder' => 'catOrder cat_order tinyint(4) NOT NULL default \'0\'', - 'canCollapse' => 'canCollapse can_collapse tinyint(1) NOT NULL default \'1\'', - ), - 'collapsed_categories' => array( - 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'', - 'ID_CAT' => 'ID_CAT id_cat tinyint(4) unsigned NOT NULL', - ), - 'custom_fields' => array( - 'ID_FIELD' => 'ID_FIELD id_field smallint(5) NOT NULL auto_increment', - 'colName' => 'colName col_name varchar(12) NOT NULL default \'\'', - 'fieldName' => 'fieldName field_name varchar(40) NOT NULL default \'\'', - 'fieldDesc' => 'fieldDesc field_desc varchar(255) NOT NULL default \'\'', - 'fieldType' => 'fieldType field_type varchar(8) NOT NULL default \'text\'', - 'fieldLength' => 'fieldLength field_length smallint(5) NOT NULL default \'255\'', - 'fieldOptions' => 'fieldOptions field_options text NOT NULL', - 'showReg' => 'showReg show_reg tinyint(3) NOT NULL default \'0\'', - 'showDisplay' => 'showDisplay show_display tinyint(3) NOT NULL default \'0\'', - 'showProfile' => 'showProfile show_profile varchar(20) NOT NULL default \'forumprofile\'', - 'defaultValue' => 'defaultValue default_value varchar(8) NOT NULL default \'0\'', - ), - 'group_moderators' => array( - 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'', - 'ID_GROUP' => 'ID_GROUP id_group smallint(5) unsigned NOT NULL default \'0\'', - ), - 'log_actions' => array( - 'ID_ACTION' => 'ID_ACTION id_action int(10) unsigned NOT NULL auto_increment', - 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'', - 'logTime' => 'logTime log_time int(10) unsigned NOT NULL default \'0\'', - 'ID_MSG' => 'ID_MSG id_msg int(10) unsigned NOT NULL default \'0\'', - 'ID_TOPIC' => 'ID_TOPIC id_topic mediumint(8) unsigned NOT NULL default \'0\'', - 'ID_BOARD' => 'ID_BOARD id_board smallint(5) unsigned NOT NULL default \'0\'', - ), - 'log_activity' => array( - 'mostOn' => 'mostOn most_on smallint(5) unsigned NOT NULL default \'0\'', - ), - 'log_banned' => array( - 'ID_BAN_LOG' => 'ID_BAN_LOG id_ban_log mediumint(8) unsigned NOT NULL auto_increment', - 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'', - 'logTime' => 'logTime log_time int(10) unsigned NOT NULL default \'0\'', - ), - 'log_boards' => array( - 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'', - 'ID_MSG' => 'ID_MSG id_msg int(10) unsigned NOT NULL default \'0\'', - 'ID_BOARD' => 'ID_BOARD id_board smallint(5) unsigned NOT NULL default \'0\'', - ), - 'log_digest' => array( - 'ID_TOPIC' => 'ID_TOPIC id_topic mediumint(8) unsigned NOT NULL default \'0\'', - 'ID_MSG' => 'ID_MSG id_msg int(10) unsigned NOT NULL default \'0\'', - ), - 'log_errors' => array( - 'ID_ERROR' => 'ID_ERROR id_error mediumint(8) unsigned NOT NULL auto_increment', - 'logTime' => 'logTime log_time int(10) unsigned NOT NULL default \'0\'', - 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'', - 'errorType' => 'errorType error_type char(15) NOT NULL default \'general\'', - ), - 'log_floodcontrol' => array( - 'logTime' => 'logTime log_time int(10) unsigned NOT NULL default \'0\'', - ), - 'log_group_requests' => array( - 'ID_REQUEST' => 'ID_REQUEST id_request mediumint(8) unsigned NOT NULL auto_increment', - 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'', - 'ID_GROUP' => 'ID_GROUP id_group smallint(5) unsigned NOT NULL default \'0\'', - ), - 'log_karma' => array( - 'ID_TARGET' => 'ID_TARGET id_target mediumint(8) unsigned NOT NULL default \'0\'', - 'ID_EXECUTOR' => 'ID_EXECUTOR id_executor mediumint(8) unsigned NOT NULL default \'0\'', - 'logTime' => 'logTime log_time int(10) unsigned NOT NULL default \'0\'', - ), - 'log_mark_read' => array( - 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'', - 'ID_MSG' => 'ID_MSG id_msg int(10) unsigned NOT NULL default \'0\'', - 'ID_BOARD' => 'ID_BOARD id_board smallint(5) unsigned NOT NULL default \'0\'', - ), - 'log_notify' => array( - 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'', - 'ID_TOPIC' => 'ID_TOPIC id_topic mediumint(8) unsigned NOT NULL default \'0\'', - 'ID_BOARD' => 'ID_BOARD id_board smallint(5) unsigned NOT NULL default \'0\'', - ), - 'log_packages' => array( - 'ID_INSTALL' => 'ID_INSTALL id_install int(10) NOT NULL auto_increment', - 'ID_MEMBER_INSTALLED' => 'ID_MEMBER_INSTALLED id_member_installed mediumint(8) NOT NULL default \'0\'', - 'ID_MEMBER_REMOVED' => 'ID_MEMBER_REMOVED id_member_removed mediumint(8) NOT NULL default \'0\'', - ), - 'log_polls' => array( - 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'', - 'ID_CHOICE' => 'ID_CHOICE id_choice tinyint(3) unsigned NOT NULL default \'0\'', - 'ID_POLL' => 'ID_POLL id_poll mediumint(8) unsigned NOT NULL default \'0\'', - ), - 'log_reported' => array( - 'ID_REPORT' => 'ID_REPORT id_report mediumint(8) unsigned NOT NULL auto_increment', - 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'', - 'ID_MSG' => 'ID_MSG id_msg int(10) unsigned NOT NULL default \'0\'', - 'ID_TOPIC' => 'ID_TOPIC id_topic mediumint(8) unsigned NOT NULL default \'0\'', - 'ID_BOARD' => 'ID_BOARD id_board smallint(5) unsigned NOT NULL default \'0\'', - ), - 'log_reported_comments' => array( - 'ID_COMMENT' => 'ID_COMMENT id_comment mediumint(8) unsigned NOT NULL auto_increment', - 'ID_REPORT' => 'ID_REPORT id_report mediumint(8) NOT NULL default \'0\'', - 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'', - ), - 'log_scheduled_tasks' => array( - 'ID_LOG' => 'ID_LOG id_log mediumint(8) NOT NULL auto_increment', - 'ID_TASK' => 'ID_TASK id_task smallint(5) NOT NULL default \'0\'', - 'timeRun' => 'timeRun time_run int(10) NOT NULL default \'0\'', - 'timeTaken' => 'timeTaken time_taken float NOT NULL default \'0\'', - ), - 'log_search_messages' => array( - 'ID_SEARCH' => 'ID_SEARCH id_search tinyint(3) unsigned NOT NULL default \'0\'', - 'ID_MSG' => 'ID_MSG id_msg int(10) unsigned NOT NULL default \'0\'', - ), - 'log_search_results' => array( - 'ID_TOPIC' => 'ID_TOPIC id_topic mediumint(8) unsigned NOT NULL default \'0\'', - 'ID_MSG' => 'ID_MSG id_msg int(10) unsigned NOT NULL default \'0\'', - 'ID_SEARCH' => 'ID_SEARCH id_search tinyint(3) unsigned NOT NULL default \'0\'', - ), - 'log_search_subjects' => array( - 'ID_TOPIC' => 'ID_TOPIC id_topic mediumint(8) unsigned NOT NULL default \'0\'', - ), - 'log_search_topics' => array( - 'ID_SEARCH' => 'ID_SEARCH id_search tinyint(3) unsigned NOT NULL default \'0\'', - 'ID_TOPIC' => 'ID_TOPIC id_topic mediumint(8) unsigned NOT NULL default \'0\'', - ), - 'log_subscribed' => array( - 'ID_SUBLOG' => 'ID_SUBLOG id_sublog int(10) unsigned NOT NULL auto_increment', - 'ID_SUBSCRIBE' => 'ID_SUBSCRIBE id_subscribe mediumint(8) unsigned NOT NULL default \'0\'', - 'OLD_ID_GROUP' => 'OLD_ID_GROUP old_id_group smallint(5) NOT NULL default \'0\'', - 'startTime' => 'startTime start_time int(10) NOT NULL default \'0\'', - 'endTime' => 'endTime end_time int(10) NOT NULL default \'0\'', - ), - 'log_topics' => array( - 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'', - 'ID_MSG' => 'ID_MSG id_msg int(10) unsigned NOT NULL default \'0\'', - 'ID_TOPIC' => 'ID_TOPIC id_topic mediumint(8) unsigned NOT NULL default \'0\'', - ), - 'mail_queue' => array( - 'ID_MAIL' => 'ID_MAIL id_mail int(10) unsigned NOT NULL auto_increment', - ), - 'members' => array( - 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL auto_increment', - 'memberName' => 'memberName member_name varchar(80) NOT NULL default \'\'', - 'dateRegistered' => 'dateRegistered date_registered int(10) unsigned NOT NULL default \'0\'', - 'ID_GROUP' => 'ID_GROUP id_group smallint(5) unsigned NOT NULL default \'0\'', - 'lastLogin' => 'lastLogin last_login int(10) unsigned NOT NULL default \'0\'', - 'realName' => 'realName real_name varchar(255) NOT NULL default \'\'', - 'instantMessages' => 'instantMessages instant_messages smallint(5) NOT NULL default \'0\'', - 'unreadMessages' => 'unreadMessages unread_messages smallint(5) NOT NULL default \'0\'', - 'messageLabels' => 'messageLabels message_labels text NOT NULL', - 'emailAddress' => 'emailAddress email_address varchar(255) NOT NULL default \'\'', - 'personalText' => 'personalText personal_text varchar(255) NOT NULL default \'\'', - 'websiteTitle' => 'websiteTitle website_title varchar(255) NOT NULL default \'\'', - 'websiteUrl' => 'websiteUrl website_url varchar(255) NOT NULL default \'\'', - 'ICQ' => 'ICQ icq varchar(255) NOT NULL default \'\'', - 'AIM' => 'AIM aim varchar(255) NOT NULL default \'\'', - 'YIM' => 'YIM yim varchar(32) NOT NULL default \'\'', - 'MSN' => 'MSN msn varchar(255) NOT NULL default \'\'', - 'hideEmail' => 'hideEmail hide_email tinyint(4) NOT NULL default \'0\'', - 'showOnline' => 'showOnline show_online tinyint(4) NOT NULL default \'1\'', - 'timeFormat' => 'timeFormat time_format varchar(80) NOT NULL default \'\'', - 'timeOffset' => 'timeOffset time_offset float NOT NULL default \'0\'', - 'karmaBad' => 'karmaBad karma_bad smallint(5) unsigned NOT NULL default \'0\'', - 'karmaGood' => 'karmaGood karma_good smallint(5) unsigned NOT NULL default \'0\'', - 'notifyAnnouncements' => 'notifyAnnouncements notify_announcements tinyint(4) NOT NULL default \'1\'', - 'notifyRegularity' => 'notifyRegularity notify_regularity tinyint(4) NOT NULL default \'1\'', - 'notifySendBody' => 'notifySendBody notify_send_body tinyint(4) NOT NULL default \'0\'', - 'notifyTypes' => 'notifyTypes notify_types tinyint(4) NOT NULL default \'2\'', - 'memberIP' => 'memberIP member_ip varchar(255) NOT NULL default \'\'', - 'secretQuestion' => 'secretQuestion secret_question varchar(255) NOT NULL default \'\'', - 'secretAnswer' => 'secretAnswer secret_answer varchar(64) NOT NULL default \'\'', - 'ID_THEME' => 'ID_THEME id_theme tinyint(4) unsigned NOT NULL default \'0\'', - 'ID_MSG_LAST_VISIT' => 'ID_MSG_LAST_VISIT id_msg_last_visit int(10) unsigned NOT NULL default \'0\'', - 'additionalGroups' => 'additionalGroups additional_groups varchar(255) NOT NULL default \'\'', - 'smileySet' => 'smileySet smiley_set varchar(48) NOT NULL default \'\'', - 'ID_POST_GROUP' => 'ID_POST_GROUP id_post_group smallint(5) unsigned NOT NULL default \'0\'', - 'totalTimeLoggedIn' => 'totalTimeLoggedIn total_time_logged_in int(10) unsigned NOT NULL default \'0\'', - 'passwordSalt' => 'passwordSalt password_salt varchar(255) NOT NULL default \'\'', - 'ignoreBoards' => 'ignoreBoards ignore_boards text NOT NULL', - 'memberIP2' => 'memberIP2 member_ip2 varchar(255) NOT NULL default \'\'', - ), - 'messages' => array( - 'ID_MSG' => 'ID_MSG id_msg int(10) unsigned NOT NULL auto_increment', - 'ID_TOPIC' => 'ID_TOPIC id_topic mediumint(8) unsigned NOT NULL default \'0\'', - 'ID_BOARD' => 'ID_BOARD id_board smallint(5) unsigned NOT NULL default \'0\'', - 'posterTime' => 'posterTime poster_time int(10) unsigned NOT NULL default \'0\'', - 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'', - 'ID_MSG_MODIFIED' => 'ID_MSG_MODIFIED id_msg_modified int(10) unsigned NOT NULL default \'0\'', - 'posterName' => 'posterName poster_name varchar(255) NOT NULL default \'\'', - 'posterEmail' => 'posterEmail poster_email varchar(255) NOT NULL default \'\'', - 'posterIP' => 'posterIP poster_ip varchar(255) NOT NULL default \'\'', - 'smileysEnabled' => 'smileysEnabled smileys_enabled tinyint(4) NOT NULL default \'1\'', - 'modifiedTime' => 'modifiedTime modified_time int(10) unsigned NOT NULL default \'0\'', - 'modifiedName' => 'modifiedName modified_name varchar(255) NOT NULL default \'\'', - ), - 'membergroups' => array( - 'ID_GROUP' => 'ID_GROUP id_group smallint(5) unsigned NOT NULL auto_increment', - 'ID_PARENT' => 'ID_PARENT id_parent smallint(5) NOT NULL default \'-2\'', - 'groupName' => 'groupName group_name varchar(80) NOT NULL default \'\'', - 'onlineColor' => 'onlineColor online_color varchar(20) NOT NULL default \'\'', - 'minPosts' => 'minPosts min_posts mediumint(9) NOT NULL default \'-1\'', - 'maxMessages' => 'maxMessages max_messages smallint(5) unsigned NOT NULL default \'0\'', - 'groupType' => 'groupType group_type tinyint(3) NOT NULL default \'0\'', - ), - 'message_icons' => array( - 'ID_ICON' => 'ID_ICON id_icon smallint(5) unsigned NOT NULL auto_increment', - 'iconOrder' => 'iconOrder icon_order smallint(5) unsigned NOT NULL default \'0\'', - 'ID_BOARD' => 'ID_BOARD id_board smallint(5) unsigned NOT NULL default \'0\'', - ), - 'moderators' => array( - 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'', - 'ID_BOARD' => 'ID_BOARD id_board smallint(5) unsigned NOT NULL default \'0\'', - ), - 'package_servers' => array( - 'ID_SERVER' => 'ID_SERVER id_server smallint(5) unsigned NOT NULL auto_increment', - ), - 'personal_messages' => array( - 'ID_PM' => 'ID_PM id_pm int(10) unsigned NOT NULL auto_increment', - 'ID_MEMBER_FROM' => 'ID_MEMBER_FROM id_member_from mediumint(8) unsigned NOT NULL default \'0\'', - 'deletedBySender' => 'deletedBySender deleted_by_sender tinyint(3) unsigned NOT NULL default \'0\'', - 'fromName' => 'fromName from_name varchar(255) NOT NULL default \'\'', - ), - 'permission_profiles' => array( - 'ID_PROFILE' => 'ID_PROFILE id_profile smallint(5) NOT NULL auto_increment', - ), - 'permissions' => array( - 'ID_GROUP' => 'ID_GROUP id_group smallint(5) NOT NULL default \'0\'', - 'addDeny' => 'addDeny add_deny tinyint(4) NOT NULL default \'1\'', - ), - 'pm_recipients' => array( - 'ID_PM' => 'ID_PM id_pm int(10) unsigned NOT NULL default \'0\'', - 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'', - ), - 'polls' => array( - 'ID_POLL' => 'ID_POLL id_poll mediumint(8) unsigned NOT NULL auto_increment', - 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) unsigned NOT NULL default \'0\'', - 'votingLocked' => 'votingLocked voting_locked tinyint(1) NOT NULL default \'0\'', - 'maxVotes' => 'maxVotes max_votes tinyint(3) unsigned NOT NULL default \'1\'', - 'expireTime' => 'expireTime expire_time int(10) unsigned NOT NULL default \'0\'', - 'hideResults' => 'hideResults hide_results tinyint(3) unsigned NOT NULL default \'0\'', - 'changeVote' => 'changeVote change_vote tinyint(3) unsigned NOT NULL default \'0\'', - 'posterName' => 'posterName poster_name varchar(255) NOT NULL default \'\'', - ), - 'poll_choices' => array( - 'ID_CHOICE' => 'ID_CHOICE id_choice tinyint(3) unsigned NOT NULL default \'0\'', - 'ID_POLL' => 'ID_POLL id_poll mediumint(8) unsigned NOT NULL default \'0\'', - ), - 'scheduled_tasks' => array( - 'ID_TASK' => 'ID_TASK id_task smallint(5) NOT NULL auto_increment', - 'nextTime' => 'nextTime next_time int(10) NOT NULL default \'0\'', - 'timeRegularity' => 'timeRegularity time_regularity smallint(5) NOT NULL default \'0\'', - 'timeOffset' => 'timeOffset time_offset int(10) NOT NULL default \'0\'', - 'timeUnit' => 'timeUnit time_unit varchar(1) NOT NULL default \'h\'', - ), - 'smileys' => array( - 'ID_SMILEY' => 'ID_SMILEY id_smiley smallint(5) unsigned NOT NULL auto_increment', - 'smileyRow' => 'smileyRow smiley_row tinyint(4) unsigned NOT NULL default \'0\'', - 'smileyOrder' => 'smileyOrder smiley_order smallint(5) unsigned NOT NULL default \'0\'', - ), - 'subscriptions' => array( - 'ID_SUBSCRIBE' => 'ID_SUBSCRIBE id_subscribe mediumint(8) unsigned NOT NULL auto_increment', - 'ID_GROUP' => 'ID_GROUP id_group smallint(5) NOT NULL default \'0\'', - 'addGroups' => 'addGroups add_groups varchar(40) NOT NULL default \'\'', - 'allowPartial' => 'allowPartial allow_partial tinyint(3) NOT NULL default \'0\'', - ), - 'themes' => array( - 'ID_MEMBER' => 'ID_MEMBER id_member mediumint(8) NOT NULL default \'0\'', - 'ID_THEME' => 'ID_THEME id_theme tinyint(4) unsigned NOT NULL default \'1\'', - ), - 'topics' => array( - 'ID_TOPIC' => 'ID_TOPIC id_topic mediumint(8) unsigned NOT NULL auto_increment', - 'isSticky' => 'isSticky is_sticky tinyint(4) NOT NULL default \'0\'', - 'ID_BOARD' => 'ID_BOARD id_board smallint(5) unsigned NOT NULL default \'0\'', - 'ID_FIRST_MSG' => 'ID_FIRST_MSG id_first_msg int(10) unsigned NOT NULL default \'0\'', - 'ID_LAST_MSG' => 'ID_LAST_MSG id_last_msg int(10) unsigned NOT NULL default \'0\'', - 'ID_MEMBER_STARTED' => 'ID_MEMBER_STARTED id_member_started mediumint(8) unsigned NOT NULL default \'0\'', - 'ID_MEMBER_UPDATED' => 'ID_MEMBER_UPDATED id_member_updated mediumint(8) unsigned NOT NULL default \'0\'', - 'ID_POLL' => 'ID_POLL id_poll mediumint(8) unsigned NOT NULL default \'0\'', - 'numReplies' => 'numReplies num_replies int(10) unsigned NOT NULL default \'0\'', - 'numViews' => 'numViews num_views int(10) unsigned NOT NULL default \'0\'', - 'unapprovedPosts' => 'unapprovedPosts unapproved_posts smallint(5) NOT NULL default \'0\'', - ), -); - -$_GET['ren_col'] = isset($_GET['ren_col']) ? (int) $_GET['ren_col'] : 0; -$step_progress['name'] = 'Renaming columns'; -$step_progress['current'] = $_GET['ren_col']; -$step_progress['total'] = count($nameChanges); - -$count = 0; -// Now do every table... -foreach ($nameChanges as $table_name => $table) -{ - // Already done this? - $count++; - if ($_GET['ren_col'] > $count) - continue; - $_GET['ren_col'] = $count; - - // Check the table exists! - $request = upgrade_query(" - SHOW TABLES - LIKE '{$db_prefix}$table_name'"); - if (mysql_num_rows($request) == 0) - { - mysql_free_result($request); - continue; - } - mysql_free_result($request); - - // Check each column! - $actualChanges = array(); - foreach ($table as $colname => $coldef) - { - $change = array( - 'table' => $table_name, - 'name' => $colname, - 'type' => 'column', - 'method' => 'change_remove', - 'text' => 'CHANGE ' . $coldef, - ); - - // Check if this change may need a special edit. - checkChange($change); - - if (protected_alter($change, $substep, true) == false) - $actualChanges[] = ' CHANGE COLUMN ' . $coldef; - } - - // Do the query - if it needs doing. - if (!empty($actualChanges)) - { - $change = array( - 'table' => $table_name, - 'name' => 'na', - 'type' => 'table', - 'method' => 'full_change', - 'text' => implode(', ', $actualChanges), - ); - - // Here we go - hold on! - protected_alter($change, $substep); - } - - // Update where we are! - $step_progress['current'] = $_GET['ren_col']; -} - -// All done! -unset($_GET['ren_col']); ----} ----# - ----# Converting "log_online". -DROP TABLE IF EXISTS {$db_prefix}log_online; -CREATE TABLE {$db_prefix}log_online ( - session varchar(32) NOT NULL default '', - log_time int(10) NOT NULL default '0', - id_member mediumint(8) unsigned NOT NULL default '0', - id_spider smallint(5) unsigned NOT NULL default '0', - ip int(10) unsigned NOT NULL default '0', - url text NOT NULL, - PRIMARY KEY (session), - KEY log_time (log_time), - KEY id_member (id_member) -) ENGINE=MyISAM{$db_collation}; ----# - -/******************************************************************************/ ---- Adding new board specific features. -/******************************************************************************/ - ----# Implementing board redirects. -ALTER TABLE {$db_prefix}boards -ADD COLUMN redirect varchar(255) NOT NULL default ''; ----# - -/******************************************************************************/ ---- Adding search engine tracking. -/******************************************************************************/ - ----# Creating spider table. -CREATE TABLE IF NOT EXISTS {$db_prefix}spiders ( - id_spider smallint(5) unsigned NOT NULL auto_increment, - spider_name varchar(255) NOT NULL default '', - user_agent varchar(255) NOT NULL default '', - ip_info varchar(255) NOT NULL default '', - PRIMARY KEY id_spider(id_spider) -) ENGINE=MyISAM{$db_collation}; - -INSERT IGNORE INTO {$db_prefix}spiders - (id_spider, spider_name, user_agent, ip_info) -VALUES - (1, 'Google', 'googlebot', ''), - (2, 'Yahoo!', 'slurp', ''), - (3, 'MSN', 'msnbot', ''), - (4, 'Google (Mobile)', 'Googlebot-Mobile', ''), - (5, 'Google (Image)', 'Googlebot-Image', ''), - (6, 'Google (AdSense)', 'Mediapartners-Google', ''), - (7, 'Google (Adwords)', 'AdsBot-Google', ''), - (8, 'Yahoo! (Mobile)', 'YahooSeeker/M1A1-R2D2', ''), - (9, 'Yahoo! (Image)', 'Yahoo-MMCrawler', ''), - (10, 'MSN (Mobile)', 'MSNBOT_Mobile', ''), - (11, 'MSN (Media)', 'msnbot-media', ''), - (12, 'Cuil', 'twiceler', ''), - (13, 'Ask', 'Teoma', ''), - (14, 'Baidu', 'Baiduspider', ''), - (15, 'Gigablast', 'Gigabot', ''), - (16, 'InternetArchive', 'ia_archiver-web.archive.org', ''), - (17, 'Alexa', 'ia_archiver', ''), - (18, 'Omgili', 'omgilibot', ''), - (19, 'EntireWeb', 'Speedy Spider', ''); ----# - ----# Removing a spider. ----{ - upgrade_query(" - DELETE FROM {$db_prefix}spiders - WHERE user_agent = 'yahoo' - AND spider_name = 'Yahoo! (Publisher)' - "); ----} ----# - ----# Creating spider hit tracking table. -CREATE TABLE IF NOT EXISTS {$db_prefix}log_spider_hits ( - id_hit int(10) unsigned NOT NULL auto_increment, - id_spider smallint(5) unsigned NOT NULL default '0', - log_time int(10) unsigned NOT NULL default '0', - url varchar(255) NOT NULL default '', - processed tinyint(3) unsigned NOT NULL default '0', - PRIMARY KEY (id_hit), - KEY id_spider(id_spider), - KEY log_time(log_time), - KEY processed (processed) -) ENGINE=MyISAM{$db_collation}; ----# - ----# Making some changes to spider hit table... -ALTER TABLE {$db_prefix}log_spider_hits -ADD COLUMN id_hit int(10) unsigned NOT NULL auto_increment, -ADD PRIMARY KEY (id_hit); ----# - ----# Creating spider statistic table. -CREATE TABLE IF NOT EXISTS {$db_prefix}log_spider_stats ( - id_spider smallint(5) unsigned NOT NULL default '0', - page_hits smallint(5) unsigned NOT NULL default '0', - last_seen int(10) unsigned NOT NULL default '0', - stat_date date NOT NULL default '0001-01-01', - PRIMARY KEY (stat_date, id_spider) -) ENGINE=MyISAM{$db_collation}; ----# - -/******************************************************************************/ ---- Adding new forum settings. -/******************************************************************************/ - ----# Resetting settings_updated. -REPLACE INTO {$db_prefix}settings - (variable, value) -VALUES - ('settings_updated', '0'), - ('last_mod_report_action', '0'), - ('search_floodcontrol_time', '5'), - ('next_task_time', UNIX_TIMESTAMP()); ----# - ----# Changing stats settings. ----{ -$request = upgrade_query(" - SELECT value - FROM {$db_prefix}themes - WHERE variable = 'show_sp1_info'"); -if (mysql_num_rows($request) != 0) -{ - upgrade_query(" - DELETE FROM {$db_prefix}themes - WHERE variable = 'show_stats_index'"); - - upgrade_query(" - UPDATE {$db_prefix}themes - SET variable = 'show_stats_index' - WHERE variable = 'show_sp1_info'"); -} -upgrade_query(" - DELETE FROM {$db_prefix}themes - WHERE variable = 'show_sp1_info'"); ----} ----# - ----# Enable cache if upgrading from 1.1 and lower. ----{ -if (isset($modSettings['smfVersion']) && $modSettings['smfVersion'] <= '2.0 Beta 1') -{ - $request = upgrade_query(" - SELECT value - FROM {$db_prefix}settings - WHERE variable = 'cache_enable'"); - list ($cache_enable) = $smcFunc['db_fetch_row']($request); - - // No cache before 1.1. - if ($smcFunc['db_num_rows']($request) == 0) - upgrade_query(" - INSERT INTO {$db_prefix}settings - (variable, value) - VALUES ('cache_enable', '1')"); - elseif (empty($cache_enable)) - upgrade_query(" - UPDATE {$db_prefix}settings - SET value = '1' - WHERE variable = 'cache_enable'"); -} ----} ----# - ----# Changing visual verification setting. ----{ -$request = upgrade_query(" - SELECT value - FROM {$db_prefix}settings - WHERE variable = 'disable_visual_verification'"); -if (mysql_num_rows($request) != 0) -{ - list ($oldValue) = mysql_fetch_row($request); - if ($oldValue != 0) - { - // We have changed the medium setting from SMF 1.1.2. - if ($oldValue == 4) - $oldValue = 5; - - upgrade_query(" - UPDATE {$db_prefix}settings - SET variable = 'visual_verification_type', value = $oldValue - WHERE variable = 'disable_visual_verification'"); - } -} -upgrade_query(" - DELETE FROM {$db_prefix}settings - WHERE variable = 'disable_visual_verification'"); ----} ----# - ----# Changing visual verification setting, again. ----{ -$request = upgrade_query(" - SELECT value - FROM {$db_prefix}settings - WHERE variable = 'reg_verification'"); -if (mysql_num_rows($request) == 0) -{ - // Upgrade visual verification again! - if (!empty($modSettings['visual_verification_type'])) - { - upgrade_query(" - UPDATE {$db_prefix}settings - SET value = value - 1 - WHERE variable = 'visual_verification_type'"); - $modSettings['visual_verification_type']--; - } - // Never set? - elseif (!isset($modSettings['visual_verification_type'])) - { - upgrade_query(" - INSERT INTO {$db_prefix}settings - (variable, value) - VALUES - ('visual_verification_type', '3')"); - $modSettings['visual_verification_type'] = 3; - } - - upgrade_query(" - INSERT INTO {$db_prefix}settings - (variable, value) - VALUES - ('reg_verification', '" . (!empty($modSettings['visual_verification_type']) ? 1 : 0) . "')"); -} ----} ----# - ----# Changing default personal text setting. -UPDATE {$db_prefix}settings -SET variable = 'default_personal_text' -WHERE variable = 'default_personalText'; - -DELETE FROM {$db_prefix}settings -WHERE variable = 'default_personalText'; ----# - ----# Removing allow hide email setting. -DELETE FROM {$db_prefix}settings -WHERE variable = 'allow_hideEmail' - OR variable = 'allow_hide_email'; ----# - ----# Ensuring stats index setting present... -INSERT IGNORE INTO {$db_prefix}themes - (id_theme, variable, value) -VALUES - (1, 'show_stats_index', '0'); ----# - ----# Ensuring forum width setting present... -INSERT IGNORE INTO {$db_prefix}themes - (id_theme, variable, value) -VALUES - (1, 'forum_width', '90%'); ----# - ----# Replacing old calendar settings... ----{ -// Only try it if one of the "new" settings doesn't yet exist. -if (!isset($modSettings['cal_showholidays']) || !isset($modSettings['cal_showbdays']) || !isset($modSettings['cal_showevents'])) -{ - // Default to just the calendar setting. - $modSettings['cal_showholidays'] = empty($modSettings['cal_showholidaysoncalendar']) ? 0 : 1; - $modSettings['cal_showbdays'] = empty($modSettings['cal_showbdaysoncalendar']) ? 0 : 1; - $modSettings['cal_showevents'] = empty($modSettings['cal_showeventsoncalendar']) ? 0 : 1; - - // Then take into account board index. - if (!empty($modSettings['cal_showholidaysonindex'])) - $modSettings['cal_showholidays'] = $modSettings['cal_showholidays'] === 1 ? 2 : 3; - if (!empty($modSettings['cal_showbdaysonindex'])) - $modSettings['cal_showbdays'] = $modSettings['cal_showbdays'] === 1 ? 2 : 3; - if (!empty($modSettings['cal_showeventsonindex'])) - $modSettings['cal_showevents'] = $modSettings['cal_showevents'] === 1 ? 2 : 3; - - // Actually save the settings. - upgrade_query(" - INSERT IGNORE INTO {$db_prefix}settings - (variable, value) - VALUES - ('cal_showholidays', $modSettings[cal_showholidays]), - ('cal_showbdays', $modSettings[cal_showbdays]), - ('cal_showevents', $modSettings[cal_showevents])"); -} - ----} ----# - ----# Fixing the calendar holidays if they were somehow wrong before... -UPDATE {$db_prefix}calendar_holidays -SET event_date = '2013-11-28' -WHERE event_date = '2013-11-21' - AND title = 'Thanksgiving'; - -UPDATE {$db_prefix}calendar_holidays -SET event_date = '2014-11-27' -WHERE event_date = '2014-11-20' - AND title = 'Thanksgiving'; - -UPDATE {$db_prefix}calendar_holidays -SET event_date = '2019-11-28' -WHERE event_date = '2019-11-21' - AND title = 'Thanksgiving'; - -UPDATE {$db_prefix}calendar_holidays -SET event_date = '2013-09-02' -WHERE event_date = '2013-09-09' - AND title = 'Labor Day'; - -UPDATE {$db_prefix}calendar_holidays -SET event_date = '2014-09-01' -WHERE event_date = '2014-09-08' - AND title = 'Labor Day'; - -UPDATE {$db_prefix}calendar_holidays -SET event_date = '2019-09-02' -WHERE event_date = '2019-09-09' - AND title = 'Labor Day'; ----# - ----# Deleting old calendar settings... - DELETE FROM {$db_prefix}settings - WHERE VARIABLE IN ('cal_showholidaysonindex', 'cal_showbdaysonindex', 'cal_showeventsonindex', - 'cal_showholidaysoncalendar', 'cal_showbdaysoncalendar', 'cal_showeventsoncalendar', - 'cal_holidaycolor', 'cal_bdaycolor', 'cal_eventcolor'); ----# - ----# Adjusting calendar maximum year... ----{ -if (!isset($modSettings['cal_maxyear']) || $modSettings['cal_maxyear'] == '2010') -{ - upgrade_query(" - REPLACE INTO {$db_prefix}settings - (variable, value) - VALUES - ('cal_maxyear', '2020')"); -} ----} ----# - ----# Adding advanced signature settings... ----{ -if (empty($modSettings['signature_settings'])) -{ - if (isset($modSettings['max_signatureLength'])) - $modSettings['signature_settings'] = '1,' . $modSettings['max_signatureLength'] . ',0,0,0,0,0,0:'; - else - $modSettings['signature_settings'] = '1,300,0,0,0,0,0,0:'; - - upgrade_query(" - INSERT IGNORE INTO {$db_prefix}settings - (variable, value) - VALUES - ('signature_settings', '$modSettings[signature_settings]')"); - - upgrade_query(" - DELETE FROM {$db_prefix}settings - WHERE variable = 'max_signatureLength'"); -} ----} ----# - ----# Updating spam protection settings. ----{ -if (empty($modSettings['pm_spam_settings'])) -{ - if (isset($modSettings['max_pm_recipients'])) - $modSettings['pm_spam_settings'] = $modSettings['max_pm_recipients'] . ',5,20'; - else - $modSettings['pm_spam_settings'] = '10,5,20'; -} -elseif (substr_count($modSettings['pm_spam_settings'], ',') == 1) -{ - $modSettings['pm_spam_settings'] .= ',20'; -} - -upgrade_query(" - INSERT IGNORE INTO {$db_prefix}settings - (variable, value) - VALUES - ('pm_spam_settings', '$modSettings[pm_spam_settings]')"); - -upgrade_query(" - DELETE FROM {$db_prefix}settings - WHERE variable = 'max_pm_recipients'"); ----} ----# - ----# Adjusting timezone settings... ----{ - if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set')) - { - $server_offset = mktime(0, 0, 0, 1, 1, 1970); - $timezone_id = 'Etc/GMT' . ($server_offset > 0 ? '+' : '') . ($server_offset / 3600); - if (date_default_timezone_set($timezone_id)) - upgrade_query(" - REPLACE INTO {$db_prefix}settings - (variable, value) - VALUES - ('default_timezone', '$timezone_id')"); - } ----} ----# - ----# Checking theme layers are correct for default themes. ----{ -$request = upgrade_query(" - SELECT id_theme, value, variable - FROM {$db_prefix}themes - WHERE variable = 'theme_layers' - OR variable = 'theme_dir'"); -$themeLayerChanges = array(); -while ($row = mysql_fetch_assoc($request)) -{ - $themeLayerChanges[$row['id_theme']][$row['variable']] = $row['value']; -} -mysql_free_result($request); - -foreach ($themeLayerChanges as $id_theme => $data) -{ - // Has to be a SMF provided theme and have custom layers defined. - if (!isset($data['theme_layers']) || !isset($data['theme_dir']) || !in_array(substr($data['theme_dir'], -7), array('default', 'babylon', 'classic'))) - continue; - - $layers = explode(',', $data['theme_layers']); - foreach ($layers as $k => $v) - if ($v == 'main') - { - $layers[$k] = 'html,body'; - upgrade_query(" - UPDATE {$db_prefix}themes - SET value = '" . implode(',', $layers) . "' - WHERE id_theme = $id_theme - AND variable = 'theme_layers'"); - break; - } -} ----} ----# - ----# Adding index to log_notify table... -ALTER TABLE {$db_prefix}log_notify -ADD INDEX id_topic (id_topic, id_member); ----# - -/******************************************************************************/ ---- Adding custom profile fields. -/******************************************************************************/ - ----# Creating "custom_fields" table... -CREATE TABLE IF NOT EXISTS {$db_prefix}custom_fields ( - id_field smallint(5) NOT NULL auto_increment, - col_name varchar(12) NOT NULL default '', - field_name varchar(40) NOT NULL default '', - field_desc varchar(255) NOT NULL default '', - field_type varchar(8) NOT NULL default 'text', - field_length smallint(5) NOT NULL default '255', - field_options text NOT NULL, - mask varchar(255) NOT NULL default '', - show_reg tinyint(3) NOT NULL default '0', - show_display tinyint(3) NOT NULL default '0', - show_profile varchar(20) NOT NULL default 'forumprofile', - private tinyint(3) NOT NULL default '0', - active tinyint(3) NOT NULL default '1', - bbc tinyint(3) NOT NULL default '0', - default_value varchar(255) NOT NULL default '', - PRIMARY KEY (id_field), - UNIQUE col_name (col_name) -) ENGINE=MyISAM{$db_collation}; ----# - ----# Adding search ability to custom fields. -ALTER TABLE {$db_prefix}custom_fields -ADD COLUMN can_search tinyint(3) NOT NULL default '0' AFTER bbc; ----# - ----# Fixing default value field length. -ALTER TABLE {$db_prefix}custom_fields -CHANGE COLUMN default_value default_value varchar(255) NOT NULL default ''; ----# - ----# Enhancing privacy settings for custom fields. ----{ -if (isset($modSettings['smfVersion']) && $modSettings['smfVersion'] <= '2.0 Beta 1') -{ -upgrade_query(" - UPDATE {$db_prefix}custom_fields - SET private = 2 - WHERE private = 1"); -} -if (isset($modSettings['smfVersion']) && $modSettings['smfVersion'] < '2.0 Beta 4') -{ -upgrade_query(" - UPDATE {$db_prefix}custom_fields - SET private = 3 - WHERE private = 2"); -} ----} ----# - ----# Checking display fields setup correctly.. ----{ -if (isset($modSettings['smfVersion']) && $modSettings['smfVersion'] <= '2.0 Beta 1' && isset($modSettings['displayFields']) && @unserialize($modSettings['displayFields']) == false) -{ -$request = upgrade_query(" - SELECT col_name, field_name, bbc - FROM {$db_prefix}custom_fields - WHERE show_display = 1 - AND active = 1 - AND private != 2"); -$fields = array(); -while ($row = mysql_fetch_assoc($request)) -{ - $fields[] = array( - 'c' => strtr($row['col_name'], array('|' => '', ';' => '')), - 'f' => strtr($row['field_name'], array('|' => '', ';' => '')), - 'b' => ($row['bbc'] ? '1' : '0') - ); -} -mysql_free_result($request); - -upgrade_query(" - UPDATE {$db_prefix}settings - SET value = '" . mysql_real_escape_string(serialize($fields)) . "' - WHERE variable = 'displayFields'"); -} ----} ----# - ----# Adding new custom fields columns. -ALTER TABLE {$db_prefix}custom_fields -ADD enclose text NOT NULL; - -ALTER TABLE {$db_prefix}custom_fields -ADD placement tinyint(3) NOT NULL default '0'; ----# - -/******************************************************************************/ ---- Adding email digest functionality. -/******************************************************************************/ - ----# Creating "log_digest" table... -CREATE TABLE IF NOT EXISTS {$db_prefix}log_digest ( - id_topic mediumint(8) unsigned NOT NULL default '0', - id_msg int(10) unsigned NOT NULL default '0', - note_type varchar(10) NOT NULL default 'post', - daily tinyint(3) unsigned NOT NULL default '0', - exclude mediumint(8) unsigned NOT NULL default '0' -) ENGINE=MyISAM{$db_collation}; ----# - ----# Adding digest option to "members" table... -ALTER TABLE {$db_prefix}members -CHANGE COLUMN notifyOnce notify_regularity tinyint(4) unsigned NOT NULL default '1'; ----# - -/******************************************************************************/ ---- Making changes to the package manager. -/******************************************************************************/ - ----# Creating "log_packages" table... -CREATE TABLE IF NOT EXISTS {$db_prefix}log_packages ( - id_install int(10) NOT NULL auto_increment, - filename varchar(255) NOT NULL default '', - package_id varchar(255) NOT NULL default '', - name varchar(255) NOT NULL default '', - version varchar(255) NOT NULL default '', - id_member_installed mediumint(8) NOT NULL default '0', - member_installed varchar(255) NOT NULL default '', - time_installed int(10) NOT NULL default '0', - id_member_removed mediumint(8) NOT NULL default '0', - member_removed varchar(255) NOT NULL default '', - time_removed int(10) NOT NULL default '0', - install_state tinyint(3) NOT NULL default '1', - failed_steps text NOT NULL, - themes_installed varchar(255) NOT NULL default '', - db_changes text NOT NULL, - PRIMARY KEY (id_install), - KEY filename (filename(15)) -) ENGINE=MyISAM{$db_collation}; ----# - ----# Adding extra "log_packages" columns... -ALTER TABLE {$db_prefix}log_packages -ADD db_changes text NOT NULL AFTER themes_installed; ----# - ----# Changing URL to SMF package server... -UPDATE {$db_prefix}package_servers -SET url = 'http://custom.simplemachines.org/packages/mods' -WHERE url = 'http://mods.simplemachines.org'; ----# - -/******************************************************************************/ ---- Creating mail queue functionality. -/******************************************************************************/ - ----# Creating "mail_queue" table... -CREATE TABLE IF NOT EXISTS {$db_prefix}mail_queue ( - id_mail int(10) unsigned NOT NULL auto_increment, - time_sent int(10) NOT NULL default '0', - recipient varchar(255) NOT NULL default '', - body text NOT NULL, - subject varchar(255) NOT NULL default '', - headers text NOT NULL, - send_html tinyint(3) NOT NULL default '0', - priority tinyint(3) NOT NULL default '1', - PRIMARY KEY (id_mail), - KEY time_sent (time_sent), - KEY mail_priority (priority, id_mail) -) ENGINE=MyISAM{$db_collation}; ----# - ----# Adding new mail queue settings... ----{ -if (!isset($modSettings['mail_next_send'])) -{ - upgrade_query(" - INSERT INTO {$db_prefix}settings - (variable, value) - VALUES - ('mail_next_send', '0'), - ('mail_recent', '0000000000|0')"); -} ----} ----# - ----# Change mail queue indexes... -ALTER TABLE {$db_prefix}mail_queue -DROP INDEX priority; - -ALTER TABLE {$db_prefix}mail_queue -ADD INDEX mail_priority (priority, id_mail); ----# - ----# Adding type to mail queue... -ALTER TABLE {$db_prefix}mail_queue -ADD private tinyint(1) NOT NULL default '0'; ----# - -/******************************************************************************/ ---- Creating moderation center tables. -/******************************************************************************/ - ----# Creating "log_reported" table... -CREATE TABLE IF NOT EXISTS {$db_prefix}log_reported ( - id_report mediumint(8) unsigned NOT NULL auto_increment, - id_msg int(10) unsigned NOT NULL default '0', - id_topic mediumint(8) unsigned NOT NULL default '0', - id_board smallint(5) unsigned NOT NULL default '0', - id_member mediumint(8) unsigned NOT NULL default '0', - membername varchar(255) NOT NULL default '', - subject varchar(255) NOT NULL default '', - body text NOT NULL, - time_started int(10) NOT NULL default '0', - time_updated int(10) NOT NULL default '0', - num_reports mediumint(6) NOT NULL default '0', - closed tinyint(3) NOT NULL default '0', - ignore_all tinyint(3) NOT NULL default '0', - PRIMARY KEY (id_report), - KEY id_member (id_member), - KEY id_topic (id_topic), - KEY closed (closed), - KEY time_started (time_started), - KEY id_msg (id_msg) -) ENGINE=MyISAM{$db_collation}; ----# - ----# Creating "log_reported_comments" table... -CREATE TABLE IF NOT EXISTS {$db_prefix}log_reported_comments ( - id_comment mediumint(8) unsigned NOT NULL auto_increment, - id_report mediumint(8) NOT NULL default '0', - id_member mediumint(8) NOT NULL, - membername varchar(255) NOT NULL default '', - comment varchar(255) NOT NULL default '', - time_sent int(10) NOT NULL, - PRIMARY KEY (id_comment), - KEY id_report (id_report), - KEY id_member (id_member), - KEY time_sent (time_sent) -) ENGINE=MyISAM{$db_collation}; ----# - ----# Adding moderator center permissions... ----{ -// Don't do this twice! -if (@$modSettings['smfVersion'] < '2.0') -{ - // Try find people who probably should see the moderation center. - $request = upgrade_query(" - SELECT id_group, add_deny, permission - FROM {$db_prefix}permissions - WHERE permission = 'calendar_edit_any'"); - $inserts = array(); - while ($row = mysql_fetch_assoc($request)) - { - $inserts[] = "($row[id_group], 'access_mod_center', $row[add_deny])"; - } - mysql_free_result($request); - - if (!empty($inserts)) - upgrade_query(" - INSERT IGNORE INTO {$db_prefix}permissions - (id_group, permission, add_deny) - VALUES - " . implode(',', $inserts)); -} ----} ----# - ----# Adding moderation center preferences... -ALTER TABLE {$db_prefix}members -ADD mod_prefs varchar(20) NOT NULL default ''; ----# - -/******************************************************************************/ ---- Adding user warnings. -/******************************************************************************/ - ----# Creating member notices table... -CREATE TABLE IF NOT EXISTS {$db_prefix}log_member_notices ( - id_notice mediumint(8) unsigned NOT NULL auto_increment, - subject varchar(255) NOT NULL default '', - body text NOT NULL, - PRIMARY KEY (id_notice) -) ENGINE=MyISAM{$db_collation}; ----# - ----# Creating comments table... -CREATE TABLE IF NOT EXISTS {$db_prefix}log_comments ( - id_comment mediumint(8) unsigned NOT NULL auto_increment, - id_member mediumint(8) unsigned NOT NULL default '0', - member_name varchar(80) NOT NULL default '', - comment_type varchar(8) NOT NULL default 'warning', - id_recipient mediumint(8) unsigned NOT NULL default '0', - recipient_name varchar(255) NOT NULL default '', - log_time int(10) NOT NULL default '0', - id_notice mediumint(8) unsigned NOT NULL default '0', - counter tinyint(3) NOT NULL default '0', - body text NOT NULL, - PRIMARY KEY (id_comment), - KEY id_recipient (id_recipient), - KEY log_time (log_time), - KEY comment_type (comment_type(8)) -) ENGINE=MyISAM{$db_collation}; ----# - ----# Adding user warning column... -ALTER TABLE {$db_prefix}members -ADD warning tinyint(4) NOT NULL default '0'; - -ALTER TABLE {$db_prefix}members -ADD INDEX warning (warning); ----# - ----# Ensuring warning settings are present... ----{ -// Only do this if not already done. -if (empty($modSettings['warning_settings'])) -{ - upgrade_query(" - INSERT IGNORE INTO {$db_prefix}settings - (variable, value) - VALUES - ('warning_settings', '1,20,0'), - ('warning_watch', '10'), - ('warning_moderate', '35'), - ('warning_mute', '60')"); -} ----} ----# - -/******************************************************************************/ ---- Enhancing membergroups. -/******************************************************************************/ - ----# Creating "log_group_requests" table... -CREATE TABLE IF NOT EXISTS {$db_prefix}log_group_requests ( - id_request mediumint(8) unsigned NOT NULL auto_increment, - id_member mediumint(8) unsigned NOT NULL default '0', - id_group smallint(5) unsigned NOT NULL default '0', - time_applied int(10) unsigned NOT NULL default '0', - reason text NOT NULL, - PRIMARY KEY (id_request), - UNIQUE id_member (id_member, id_group) -) ENGINE=MyISAM{$db_collation}; ----# - ----# Adding new membergroup table columns... -ALTER TABLE {$db_prefix}membergroups -ADD description text NOT NULL AFTER group_name; - -ALTER TABLE {$db_prefix}membergroups -ADD group_type tinyint(3) NOT NULL default '0'; - -ALTER TABLE {$db_prefix}membergroups -ADD hidden tinyint(3) NOT NULL default '0'; ----# - ----# Creating "group_moderators" table... -CREATE TABLE IF NOT EXISTS {$db_prefix}group_moderators ( - id_group smallint(5) unsigned NOT NULL default '0', - id_member mediumint(8) unsigned NOT NULL default '0', - PRIMARY KEY (id_group, id_member) -) ENGINE=MyISAM{$db_collation}; ----# - -/******************************************************************************/ ---- Updating attachment data... -/******************************************************************************/ - ----# Altering attachment table. -ALTER TABLE {$db_prefix}attachments -ADD COLUMN fileext varchar(8) NOT NULL default '', -ADD COLUMN mime_type varchar(20) NOT NULL default ''; - -ALTER TABLE {$db_prefix}attachments -ADD COLUMN id_folder tinyint(3) NOT NULL default '1'; ----# - ----# Adding file hash. -ALTER TABLE {$db_prefix}attachments -ADD COLUMN file_hash varchar(40) NOT NULL default ''; ----# - ----# Populate the attachment extension. -UPDATE {$db_prefix}attachments -SET fileext = LOWER(SUBSTRING(filename, 1 - (INSTR(REVERSE(filename), '.')))) -WHERE fileext = '' - AND INSTR(filename, '.') - AND attachment_type != 3; ----# - ----# Updating thumbnail attachments JPG. -UPDATE {$db_prefix}attachments -SET fileext = 'jpg' -WHERE attachment_type = 3 - AND fileext = '' - AND RIGHT(filename, 9) = 'JPG_thumb'; ----# - ----# Updating thumbnail attachments PNG. -UPDATE {$db_prefix}attachments -SET fileext = 'png' -WHERE attachment_type = 3 - AND fileext = '' - AND RIGHT(filename, 9) = 'PNG_thumb'; ----# - ----# Calculating attachment mime types. ----{ -// Don't ever bother doing this twice. -if (@$modSettings['smfVersion'] < '2.0' || @$modSettings['smfVersion'] === '2.0 a') -{ - $request = upgrade_query(" - SELECT MAX(id_attach) - FROM {$db_prefix}attachments"); - list ($step_progress['total']) = $smcFunc['db_fetch_row']($request); - $smcFunc['db_free_result']($request); - - $_GET['a'] = isset($_GET['a']) ? (int) $_GET['a'] : 0; - $step_progress['name'] = 'Calculating MIME Types'; - $step_progress['current'] = $_GET['a']; - - if (!function_exists('getAttachmentFilename')) - { - function getAttachmentFilename($filename, $attachment_id) - { - global $modSettings; - - $clean_name = strtr($filename, 'ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöøùúûüýÿ', 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy'); - $clean_name = strtr($clean_name, array('Þ' => 'TH', 'þ' => 'th', 'Ð' => 'DH', 'ð' => 'dh', 'ß' => 'ss', 'Œ' => 'OE', 'œ' => 'oe', 'Æ' => 'AE', 'æ' => 'ae', 'µ' => 'u')); - $clean_name = preg_replace(array('/\s/', '/[^\w_\.\-]/'), array('_', ''), $clean_name); - $enc_name = $attachment_id . '_' . strtr($clean_name, '.', '_') . md5($clean_name); - $clean_name = preg_replace('~\.[\.]+~', '.', $clean_name); - - if ($attachment_id == false) - return $clean_name; - - if (file_exists($modSettings['attachmentUploadDir'] . '/' . $enc_name)) - $filename = $modSettings['attachmentUploadDir'] . '/' . $enc_name; - else - $filename = $modSettings['attachmentUploadDir'] . '/' . $clean_name; - - return $filename; - } - } - - $ext_updates = array(); - - // What headers are valid results for getimagesize? - $validTypes = array( - 1 => 'gif', - 2 => 'jpeg', - 3 => 'png', - 5 => 'psd', - 6 => 'bmp', - 7 => 'tiff', - 8 => 'tiff', - 9 => 'jpeg', - 14 => 'iff', - ); - - $is_done = false; - while (!$is_done) - { - nextSubStep($substep); - - $request = upgrade_query(" - SELECT id_attach, filename, fileext - FROM {$db_prefix}attachments - WHERE fileext != '' - AND mime_type = '' - LIMIT $_GET[a], 100"); - // Finished? - if ($smcFunc['db_num_rows']($request) == 0) - $is_done = true; - while ($row = $smcFunc['db_fetch_assoc']($request)) - { - $filename = getAttachmentFilename($row['filename'], $row['id_attach']); - if (!file_exists($filename)) - continue; - - // Is it an image? - $size = @getimagesize($filename); - // Nothing valid? - if (empty($size) || empty($size[0])) - continue; - // Got the mime? - elseif (!empty($size['mime'])) - $mime = $size['mime']; - // Otherwise is it valid? - elseif (!isset($validTypes[$size[2]])) - continue; - else - $mime = 'image/' . $validTypes[$size[2]]; - - // Let's try keep updates to a minimum. - if (!isset($ext_updates[$row['fileext'] . $size['mime']])) - $ext_updates[$row['fileext'] . $size['mime']] = array( - 'fileext' => $row['fileext'], - 'mime' => $mime, - 'files' => array(), - ); - $ext_updates[$row['fileext'] . $size['mime']]['files'][] = $row['id_attach']; - } - $smcFunc['db_free_result']($request); - - // Do the updates? - foreach ($ext_updates as $key => $update) - { - upgrade_query(" - UPDATE {$db_prefix}attachments - SET mime_type = '$update[mime]' - WHERE id_attach IN (" . implode(',', $update['files']) . ")"); - - // Remove it. - unset($ext_updates[$key]); - } - - $_GET['a'] += 100; - $step_progress['current'] = $_GET['a']; - } - - unset($_GET['a']); -} ----} ----# - -/******************************************************************************/ ---- Adding Post Moderation. -/******************************************************************************/ - ----# Creating "approval_queue" table... -CREATE TABLE IF NOT EXISTS {$db_prefix}approval_queue ( - id_msg int(10) unsigned NOT NULL default '0', - id_attach int(10) unsigned NOT NULL default '0', - id_event smallint(5) unsigned NOT NULL default '0' -) ENGINE=MyISAM{$db_collation}; ----# - ----# Adding approved column to attachments table... -ALTER TABLE {$db_prefix}attachments -ADD approved tinyint(3) NOT NULL default '1'; ----# - ----# Adding approved column to messages table... -ALTER TABLE {$db_prefix}messages -ADD approved tinyint(3) NOT NULL default '1'; - -ALTER TABLE {$db_prefix}messages -ADD INDEX approved (approved); ----# - ----# Adding unapproved count column to topics table... -ALTER TABLE {$db_prefix}topics -ADD unapproved_posts smallint(5) NOT NULL default '0'; ----# - ----# Adding approved column to topics table... -ALTER TABLE {$db_prefix}topics -ADD approved tinyint(3) NOT NULL default '1', -ADD INDEX approved (approved); ----# - ----# Adding approved columns to boards table... -ALTER TABLE {$db_prefix}boards -ADD unapproved_posts smallint(5) NOT NULL default '0', -ADD unapproved_topics smallint(5) NOT NULL default '0'; ----# - ----# Adding post moderation permissions... ----{ -// We *cannot* do this twice! -if (@$modSettings['smfVersion'] < '2.0') -{ - // Anyone who can currently edit posts we assume can approve them... - $request = upgrade_query(" - SELECT id_group, id_board, add_deny, permission - FROM {$db_prefix}board_permissions - WHERE permission = 'modify_any'"); - $inserts = array(); - while ($row = mysql_fetch_assoc($request)) - { - $inserts[] = "($row[id_group], $row[id_board], 'approve_posts', $row[add_deny])"; - } - mysql_free_result($request); - - if (!empty($inserts)) - upgrade_query(" - INSERT IGNORE INTO {$db_prefix}board_permissions - (id_group, id_board, permission, add_deny) - VALUES - " . implode(',', $inserts)); -} ----} ----# - -/******************************************************************************/ ---- Upgrading the error log. -/******************************************************************************/ - ----# Adding columns to log_errors table... -ALTER TABLE {$db_prefix}log_errors -ADD error_type char(15) NOT NULL default 'general'; -ALTER TABLE {$db_prefix}log_errors -ADD file varchar(255) NOT NULL default '', -ADD line mediumint(8) unsigned NOT NULL default '0'; ----# - ----# Updating error log table... ----{ -$request = upgrade_query(" - SELECT COUNT(*) - FROM {$db_prefix}log_errors"); -list($totalActions) = mysql_fetch_row($request); -mysql_free_result($request); - -$_GET['m'] = !empty($_GET['m']) ? (int) $_GET['m'] : '0'; -$step_progress['total'] = $totalActions; -$step_progress['current'] = $_GET['m']; - -while ($_GET['m'] < $totalActions) -{ - nextSubStep($substep); - - $request = upgrade_query(" - SELECT id_error, message, file, line - FROM {$db_prefix}log_errors - LIMIT $_GET[m], 500"); - while($row = mysql_fetch_assoc($request)) - { - preg_match('~
(%1\$s: )?([\w\. \\\\/\-_:]+)
(%2\$s: )?([\d]+)~', $row['message'], $matches); - if (!empty($matches[2]) && !empty($matches[4]) && empty($row['file']) && empty($row['line'])) - { - $row['file'] = addslashes(str_replace('\\', '/', $matches[2])); - $row['line'] = (int) $matches[4]; - $row['message'] = addslashes(preg_replace('~
(%1\$s: )?([\w\. \\\\/\-_:]+)
(%2\$s: )?([\d]+)~', '', $row['message'])); - } - else - continue; - - upgrade_query(" - UPDATE {$db_prefix}log_errors - SET file = SUBSTRING('$row[file]', 1, 255), - line = $row[line], - message = SUBSTRING('$row[message]', 1, 65535) - WHERE id_error = $row[id_error] - LIMIT 1"); - } - - $_GET['m'] += 500; - $step_progress['current'] = $_GET['m']; -} -unset($_GET['m']); ----} ----# - -/******************************************************************************/ ---- Adding Scheduled Tasks Data. -/******************************************************************************/ - ----# Creating Scheduled Task Table... -CREATE TABLE IF NOT EXISTS {$db_prefix}scheduled_tasks ( - id_task smallint(5) NOT NULL auto_increment, - next_time int(10) NOT NULL default '0', - time_offset int(10) NOT NULL default '0', - time_regularity smallint(5) NOT NULL default '0', - time_unit varchar(1) NOT NULL default 'h', - disabled tinyint(3) NOT NULL default '0', - task varchar(24) NOT NULL default '', - PRIMARY KEY (id_task), - KEY next_time (next_time), - KEY disabled (disabled), - UNIQUE task (task) -) ENGINE=MyISAM{$db_collation}; ----# - ----# Populating Scheduled Task Table... -INSERT IGNORE INTO {$db_prefix}scheduled_tasks - (next_time, time_offset, time_regularity, time_unit, disabled, task) -VALUES - (0, 0, 2, 'h', 0, 'approval_notification'), - (0, 0, 7, 'd', 0, 'auto_optimize'), - (0, 60, 1, 'd', 0, 'daily_maintenance'), - (0, 0, 1, 'd', 0, 'daily_digest'), - (0, 0, 1, 'w', 0, 'weekly_digest'), - (0, 0, 1, 'd', 1, 'birthdayemails'), - (0, 120, 1, 'd', 0, 'paid_subscriptions'); ----# - ----# Adding the simple machines scheduled task. ----{ -// Randomise the time. -$randomTime = 82800 + rand(0, 86399); -upgrade_query(" - INSERT IGNORE INTO {$db_prefix}scheduled_tasks - (next_time, time_offset, time_regularity, time_unit, disabled, task) - VALUES - (0, {$randomTime}, 1, 'd', 0, 'fetchSMfiles')"); ----} ----# - ----# Deleting old scheduled task items... -DELETE FROM {$db_prefix}scheduled_tasks -WHERE task = 'clean_cache'; ----# - ----# Moving auto optimise settings to scheduled task... ----{ -if (!isset($modSettings['next_task_time']) && isset($modSettings['autoOptLastOpt'])) -{ - // Try move over the regularity... - if (isset($modSettings['autoOptDatabase'])) - { - $disabled = empty($modSettings['autoOptDatabase']) ? 1 : 0; - $regularity = $disabled ? 7 : $modSettings['autoOptDatabase']; - $next_time = $modSettings['autoOptLastOpt'] + 3600 * 24 * $modSettings['autoOptDatabase']; - - // Update the task accordingly. - upgrade_query(" - UPDATE {$db_prefix}scheduled_tasks - SET disabled = $disabled, time_regularity = $regularity, next_time = $next_time - WHERE task = 'auto_optimize'"); - } - - // Delete the old settings! - upgrade_query(" - DELETE FROM {$db_prefix}settings - WHERE VARIABLE IN ('autoOptLastOpt', 'autoOptDatabase')"); -} ----} ----# - ----# Creating Scheduled Task Log Table... -CREATE TABLE IF NOT EXISTS {$db_prefix}log_scheduled_tasks ( - id_log mediumint(8) NOT NULL auto_increment, - id_task smallint(5) NOT NULL default '0', - time_run int(10) NOT NULL default '0', - time_taken float NOT NULL default '0', - PRIMARY KEY (id_log) -) ENGINE=MyISAM{$db_collation}; ----# - ----# Adding new scheduled task setting... ----{ -if (!isset($modSettings['next_task_time'])) -{ - upgrade_query(" - INSERT INTO {$db_prefix}settings - (variable, value) - VALUES - ('next_task_time', '0')"); -} ----} ----# - ----# Setting the birthday email template if not set... ----{ -if (!isset($modSettings['birthday_email'])) -{ - upgrade_query(" - INSERT INTO {$db_prefix}settings - (variable, value) - VALUES - ('birthday_email', 'happy_birthday')"); -} ----} ----# - -/******************************************************************************/ ---- Adding permission profiles for boards. -/******************************************************************************/ - ----# Creating "permission_profiles" table... -CREATE TABLE IF NOT EXISTS {$db_prefix}permission_profiles ( - id_profile smallint(5) NOT NULL auto_increment, - profile_name varchar(255) NOT NULL default '', - PRIMARY KEY (id_profile) -) ENGINE=MyISAM{$db_collation}; ----# - ----# Adding profile columns to boards table... -ALTER TABLE {$db_prefix}boards -ADD id_profile smallint(5) unsigned NOT NULL default '1' AFTER member_groups; ----# - ----# Adding profile columns to board permission table... -ALTER TABLE {$db_prefix}board_permissions -ADD id_profile smallint(5) unsigned NOT NULL default '1' AFTER id_group; - -ALTER TABLE {$db_prefix}board_permissions -DROP PRIMARY KEY; - -ALTER TABLE {$db_prefix}board_permissions -ADD PRIMARY KEY (id_group, id_profile, permission); ----# - ----# Cleaning up some 2.0 Beta 1 permission profile bits... ----{ -$request = upgrade_query(" - SELECT id_profile - FROM {$db_prefix}permission_profiles - WHERE profile_name = ''"); -$profiles = array(); -while ($row = mysql_fetch_assoc($request)) - $profiles[] = $row['id_profile']; -mysql_free_result($request); - -if (!empty($profiles)) -{ - $request = upgrade_query(" - SELECT id_profile, name - FROM {$db_prefix}boards - WHERE id_profile IN (" . implode(',', $profiles) . ")"); - $done_ids = array(); - while ($row = mysql_fetch_assoc($request)) - { - if (isset($done_ids[$row['id_profile']])) - continue; - $done_ids[$row['id_profile']] = true; - - $row['name'] = mysql_real_escape_string($row['name']); - - upgrade_query(" - UPDATE {$db_prefix}permission_profiles - SET profile_name = '$row[name]' - WHERE id_profile = $row[id_profile]"); - } - mysql_free_result($request); -} ----} ----# - ----# Migrating old board profiles to profile system ----{ - -// Doing this twice would be awful! -$request = upgrade_query(" - SELECT COUNT(*) - FROM {$db_prefix}permission_profiles"); -list ($profileCount) = mysql_fetch_row($request); -mysql_free_result($request); - -if ($profileCount == 0) -{ - // Everything starts off invalid. - upgrade_query(" - UPDATE {$db_prefix}board_permissions - SET id_profile = 0"); - - // Insert a boat load of default profile permissions. - upgrade_query(" - INSERT INTO {$db_prefix}permission_profiles - (id_profile, profile_name) - VALUES - (1, 'default'), - (2, 'no_polls'), - (3, 'reply_only'), - (4, 'read_only')"); - - // Update the default permissions, this is easy! - upgrade_query(" - UPDATE {$db_prefix}board_permissions - SET id_profile = 1 - WHERE id_board = 0"); - - // Load all the other permissions - $request = upgrade_query(" - SELECT id_board, id_group, permission, add_deny - FROM {$db_prefix}board_permissions - WHERE id_profile = 0"); - $all_perms = array(); - while ($row = mysql_fetch_assoc($request)) - $all_perms[$row['id_board']][$row['id_group']][$row['permission']] = $row['add_deny']; - mysql_free_result($request); - - // Now we have the profile profiles for this installation. We now need to go through each board and work out what the permission profile should be! - $request = upgrade_query(" - SELECT id_board, name, permission_mode - FROM {$db_prefix}boards"); - $board_updates = array(); - while ($row = mysql_fetch_assoc($request)) - { - $row['name'] = addslashes($row['name']); - - // Is it a truely local permission board? If so this is a new profile! - if ($row['permission_mode'] == 1) - { - // I know we could cache this, but I think we need to be practical - this is slow but guaranteed to work. - upgrade_query(" - INSERT INTO {$db_prefix}permission_profiles - (profile_name) - VALUES - ('$row[name]')"); - $board_updates[mysql_insert_id()][] = $row['id_board']; - } - // Otherwise, dear god, this is an old school "simple" permission... - elseif ($row['permission_mode'] > 1 && $row['permission_mode'] < 5) - { - $board_updates[$row['permission_mode']][] = $row['id_board']; - } - // Otherwise this is easy. It becomes default. - else - $board_updates[1][] = $row['id_board']; - } - mysql_free_result($request); - - // Update the board tables. - foreach ($board_updates as $profile => $boards) - { - if (empty($boards)) - continue; - - $boards = implode(',', $boards); - - upgrade_query(" - UPDATE {$db_prefix}boards - SET id_profile = $profile - WHERE id_board IN ($boards)"); - - // If it's a custom profile then update this too. - if ($profile > 4) - upgrade_query(" - UPDATE {$db_prefix}board_permissions - SET id_profile = $profile - WHERE id_board IN ($boards) - AND id_profile = 0"); - } - - // Just in case we have any random permissions that didn't have boards. - upgrade_query(" - DELETE FROM {$db_prefix}board_permissions - WHERE id_profile = 0"); -} ----} ----# - ----# Removing old board permissions column... -ALTER TABLE {$db_prefix}board_permissions -DROP COLUMN id_board; ----# - ----# Check the predefined profiles all have the right permissions. ----{ -// What are all the permissions people can have. -$mod_permissions = array( - 'moderate_board', 'post_new', 'post_reply_own', 'post_reply_any', 'poll_post', 'poll_add_any', - 'poll_remove_any', 'poll_view', 'poll_vote', 'poll_lock_any', 'poll_edit_any', 'report_any', - 'lock_own', 'send_topic', 'mark_any_notify', 'mark_notify', 'delete_own', 'modify_own', 'make_sticky', - 'lock_any', 'remove_any', 'move_any', 'merge_any', 'split_any', 'delete_any', 'modify_any', 'approve_posts', - 'post_attachment', 'view_attachments', 'post_unapproved_replies_any', 'post_unapproved_replies_own', - 'post_unapproved_attachments', 'post_unapproved_topics', -); - -$no_poll_reg = array( - 'post_new', 'post_reply_own', 'post_reply_any', 'poll_view', 'poll_vote', 'report_any', - 'lock_own', 'send_topic', 'mark_any_notify', 'mark_notify', 'delete_own', 'modify_own', - 'post_attachment', 'view_attachments', 'remove_own', 'post_unapproved_replies_any', 'post_unapproved_replies_own', - 'post_unapproved_attachments', 'post_unapproved_topics', -); - -$reply_only_reg = array( - 'post_reply_own', 'post_reply_any', 'poll_view', 'poll_vote', 'report_any', - 'lock_own', 'send_topic', 'mark_any_notify', 'mark_notify', 'delete_own', 'modify_own', - 'post_attachment', 'view_attachments', 'remove_own', 'post_unapproved_replies_any', 'post_unapproved_replies_own', - 'post_unapproved_attachments', -); - -$read_only_reg = array( - 'poll_view', 'poll_vote', 'report_any', 'send_topic', 'mark_any_notify', 'mark_notify', 'view_attachments', -); - -// Clear all the current predefined profiles. -upgrade_query(" - DELETE FROM {$db_prefix}board_permissions - WHERE id_profile IN (2,3,4)"); - -// Get all the membergroups - cheating to use the fact id_group = 1 exists to get a group of 0. -$request = upgrade_query(" - SELECT IF(id_group = 1, 0, id_group) AS id_group - FROM {$db_prefix}membergroups - WHERE id_group != 0 - AND min_posts = -1"); -$inserts = array(); -while ($row = mysql_fetch_assoc($request)) -{ - if ($row['id_group'] == 2 || $row['id_group'] == 3) - { - foreach ($mod_permissions as $permission) - { - $inserts[] = "($row[id_group], 2, '$permission')"; - $inserts[] = "($row[id_group], 3, '$permission')"; - $inserts[] = "($row[id_group], 4, '$permission')"; - } - } - else - { - foreach ($no_poll_reg as $permission) - $inserts[] = "($row[id_group], 2, '$permission')"; - foreach ($reply_only_reg as $permission) - $inserts[] = "($row[id_group], 3, '$permission')"; - foreach ($read_only_reg as $permission) - $inserts[] = "($row[id_group], 4, '$permission')"; - } -} -mysql_free_result($request); - -upgrade_query(" - INSERT INTO {$db_prefix}board_permissions - (id_group, id_profile, permission) - VALUES (-1, 2, 'poll_view'), - (-1, 3, 'poll_view'), - (-1, 4, 'poll_view'), - " . implode(', ', $inserts)); - ----} ----# - ----# Adding inherited permissions... -ALTER TABLE {$db_prefix}membergroups -ADD id_parent smallint(5) NOT NULL default '-2'; ----# - ----# Make sure admins and moderators don't inherit... -UPDATE {$db_prefix}membergroups -SET id_parent = -2 -WHERE id_group = 1 - OR id_group = 3; ----# - ----# Deleting old permission settings... -DELETE FROM {$db_prefix}settings -WHERE VARIABLE IN ('permission_enable_by_board', 'autoOptDatabase'); ----# - ----# Removing old permission_mode column... -ALTER TABLE {$db_prefix}boards -DROP COLUMN permission_mode; ----# - -/******************************************************************************/ ---- Adding Some Additional Functionality. -/******************************************************************************/ - ----# Adding column to hold the boards being ignored ... -ALTER TABLE {$db_prefix}members -ADD ignore_boards text NOT NULL; ----# - ----# Purge flood control ... -DELETE FROM {$db_prefix}log_floodcontrol; ----# - ----# Adding advanced flood control ... -ALTER TABLE {$db_prefix}log_floodcontrol -ADD log_type varchar(8) NOT NULL default 'post'; ----# - ----# Sorting out flood control keys ... -ALTER TABLE {$db_prefix}log_floodcontrol -DROP PRIMARY KEY, -ADD PRIMARY KEY (ip(16), log_type(8)); ----# - ----# Adding guest voting ... -ALTER TABLE {$db_prefix}polls -ADD guest_vote tinyint(3) NOT NULL default '0'; - -DELETE FROM {$db_prefix}log_polls -WHERE id_member < 0; - -ALTER TABLE {$db_prefix}log_polls -DROP PRIMARY KEY; - -ALTER TABLE {$db_prefix}log_polls -ADD INDEX id_poll (id_poll, id_member, id_choice); ----# - ----# Implementing admin feature toggles. ----{ -if (!isset($modSettings['admin_features'])) -{ - // Work out what they used to have enabled. - $enabled_features = array('rg'); - if (!empty($modSettings['cal_enabled'])) - $enabled_features[] = 'cd'; - if (!empty($modSettings['karmaMode'])) - $enabled_features[] = 'k'; - if (!empty($modSettings['modlog_enabled'])) - $enabled_features[] = 'ml'; - if (!empty($modSettings['paid_enabled'])) - $enabled_features[] = 'ps'; - - $enabled_features = implode(',', $enabled_features); - - upgrade_query(" - INSERT INTO {$db_prefix}settings - (variable, value) - VALUES - ('admin_features', '$enabled_features')"); -} ----} ----# - ----# Adding advanced password brute force protection to "members" table... -ALTER TABLE {$db_prefix}members -ADD passwd_flood varchar(12) NOT NULL default ''; ----# - -/******************************************************************************/ ---- Adding some columns to moderation log -/******************************************************************************/ ----# Add the columns and the keys to log_actions ... -ALTER TABLE {$db_prefix}log_actions -ADD id_board smallint(5) unsigned NOT NULL default '0', -ADD id_topic mediumint(8) unsigned NOT NULL default '0', -ADD id_msg int(10) unsigned NOT NULL default '0', -ADD KEY id_board (id_board), -ADD KEY id_msg (id_msg); ----# - ----# Add the user log... -ALTER TABLE {$db_prefix}log_actions -ADD id_log tinyint(3) unsigned NOT NULL default '1', -ADD KEY id_log (id_log); ----# - ----# Update the information already in log_actions ----{ -$request = upgrade_query(" - SELECT COUNT(*) - FROM {$db_prefix}log_actions"); -list($totalActions) = mysql_fetch_row($request); -mysql_free_result($request); - -$_GET['m'] = !empty($_GET['m']) ? (int) $_GET['m'] : '0'; -$step_progress['total'] = $totalActions; -$step_progress['current'] = $_GET['m']; - -while ($_GET['m'] < $totalActions) -{ - nextSubStep($substep); - - $mrequest = upgrade_query(" - SELECT id_action, extra, id_board, id_topic, id_msg - FROM {$db_prefix}log_actions - LIMIT $_GET[m], 500"); - - while ($row = mysql_fetch_assoc($mrequest)) - { - if (!empty($row['id_board']) || !empty($row['id_topic']) || !empty($row['id_msg'])) - continue; - $row['extra'] = @unserialize($row['extra']); - // Corrupt? - $row['extra'] = is_array($row['extra']) ? $row['extra'] : array(); - if (!empty($row['extra']['board'])) - { - $board_id = (int) $row['extra']['board']; - unset($row['extra']['board']); - } - else - $board_id = '0'; - if (!empty($row['extra']['board_to']) && empty($board_id)) - { - $board_id = (int) $row['extra']['board_to']; - unset($row['extra']['board_to']); - } - - if (!empty($row['extra']['topic'])) - { - $topic_id = (int) $row['extra']['topic']; - unset($row['extra']['topic']); - if (empty($board_id)) - { - $trequest = upgrade_query(" - SELECT id_board - FROM {$db_prefix}topics - WHERE id_topic=$topic_id - LIMIT 1"); - if (mysql_num_rows($trequest)) - list($board_id) = mysql_fetch_row($trequest); - mysql_free_result($trequest); - } - } - else - $topic_id = '0'; - - if(!empty($row['extra']['message'])) - { - $msg_id = (int) $row['extra']['message']; - unset($row['extra']['message']); - if (empty($topic_id) || empty($board_id)) - { - $trequest = upgrade_query(" - SELECT id_board, id_topic - FROM {$db_prefix}messages - WHERE id_msg=$msg_id - LIMIT 1"); - if (mysql_num_rows($trequest)) - list($board_id, $topic_id) = mysql_fetch_row($trequest); - mysql_free_result($trequest); - } - } - else - $msg_id = '0'; - $row['extra'] = addslashes(serialize($row['extra'])); - upgrade_query("UPDATE {$db_prefix}log_actions SET id_board=$board_id, id_topic=$topic_id, id_msg=$msg_id, extra='$row[extra]' WHERE id_action=$row[id_action]"); - } - $_GET['m'] += 500; - $step_progress['current'] = $_GET['m']; -} -unset($_GET['m']); ----} ----# - -/******************************************************************************/ ---- Create a repository for the javascript files from Simple Machines... -/******************************************************************************/ - ----# Creating repository table ... -CREATE TABLE IF NOT EXISTS {$db_prefix}admin_info_files ( - id_file tinyint(4) unsigned NOT NULL auto_increment, - filename varchar(255) NOT NULL default '', - path varchar(255) NOT NULL default '', - parameters varchar(255) NOT NULL default '', - data text NOT NULL, - filetype varchar(255) NOT NULL default '', - PRIMARY KEY (id_file), - KEY filename (filename(30)) -) ENGINE=MyISAM{$db_collation}; ----# - ----# Add in the files to get from Simple Machines... -INSERT IGNORE INTO {$db_prefix}admin_info_files - (id_file, filename, path, parameters) -VALUES - (1, 'current-version.js', '/smf/', 'version=%3$s'), - (2, 'detailed-version.js', '/smf/', 'language=%1$s&version=%3$s'), - (3, 'latest-news.js', '/smf/', 'language=%1$s&format=%2$s'), - (4, 'latest-packages.js', '/smf/', 'language=%1$s&version=%3$s'), - (5, 'latest-smileys.js', '/smf/', 'language=%1$s&version=%3$s'), - (6, 'latest-support.js', '/smf/', 'language=%1$s&version=%3$s'), - (7, 'latest-themes.js', '/smf/', 'language=%1$s&version=%3$s'); ----# - ----# Ensure that the table has the filetype column -ALTER TABLE {$db_prefix}admin_info_files -ADD filetype varchar(255) NOT NULL default ''; ----# - ----# Set the filetype for the files -UPDATE {$db_prefix}admin_info_files -SET filetype='text/javascript' -WHERE id_file IN (1,2,3,4,5,6,7); ----# - ----# Ensure that the files from Simple Machines get updated -UPDATE {$db_prefix}scheduled_tasks -SET next_time = UNIX_TIMESTAMP() -WHERE id_task = 7 -LIMIT 1; ----# - -/******************************************************************************/ ---- Adding new personal messaging functionality. -/******************************************************************************/ - ----# Adding personal message rules table... -CREATE TABLE IF NOT EXISTS {$db_prefix}pm_rules ( - id_rule int(10) unsigned NOT NULL auto_increment, - id_member int(10) unsigned NOT NULL default '0', - rule_name varchar(60) NOT NULL, - criteria text NOT NULL, - actions text NOT NULL, - delete_pm tinyint(3) unsigned NOT NULL default '0', - is_or tinyint(3) unsigned NOT NULL default '0', - PRIMARY KEY (id_rule), - KEY id_member (id_member), - KEY delete_pm (delete_pm) -) ENGINE=MyISAM{$db_collation}; ----# - ----# Adding new message status columns... -ALTER TABLE {$db_prefix}members -ADD COLUMN new_pm tinyint(3) NOT NULL default '0'; - -ALTER TABLE {$db_prefix}members -ADD COLUMN pm_prefs mediumint(8) NOT NULL default '0'; - -ALTER TABLE {$db_prefix}pm_recipients -ADD COLUMN is_new tinyint(3) NOT NULL default '0'; ----# - ----# Set the new status to be correct.... ----{ -// Don't do this twice! -if (@$modSettings['smfVersion'] < '2.0') -{ - // Set all unread messages as new. - upgrade_query(" - UPDATE {$db_prefix}pm_recipients - SET is_new = 1 - WHERE is_read = 0"); - - // Also set members to have a new pm if they have any unread. - upgrade_query(" - UPDATE {$db_prefix}members - SET new_pm = 1 - WHERE unread_messages > 0"); -} ----} ----# - ----# Adding personal message tracking column... -ALTER TABLE {$db_prefix}personal_messages -ADD id_pm_head int(10) unsigned default '0' NOT NULL AFTER id_pm, -ADD INDEX id_pm_head (id_pm_head); ----# - ----# Adding personal message tracking column... -UPDATE {$db_prefix}personal_messages -SET id_pm_head = id_pm -WHERE id_pm_head = 0; ----# - -/******************************************************************************/ ---- Adding Open ID support. -/******************************************************************************/ - ----# Adding Open ID Assocation table... -CREATE TABLE IF NOT EXISTS {$db_prefix}openid_assoc ( - server_url text NOT NULL, - handle varchar(255) NOT NULL default '', - secret text NOT NULL, - issued int(10) NOT NULL default '0', - expires int(10) NOT NULL default '0', - assoc_type varchar(64) NOT NULL, - PRIMARY KEY (server_url(125), handle(125)), - KEY expires (expires) -) ENGINE=MyISAM{$db_collation}; ----# - ----# Adding column to hold Open ID URL... -ALTER TABLE {$db_prefix}members -ADD openid_uri text NOT NULL; ----# - -/******************************************************************************/ ---- Adding paid subscriptions. -/******************************************************************************/ - ----# Creating subscriptions table... -CREATE TABLE IF NOT EXISTS {$db_prefix}subscriptions( - id_subscribe mediumint(8) unsigned NOT NULL auto_increment, - name varchar(60) NOT NULL default '', - description varchar(255) NOT NULL default '', - cost text NOT NULL, - length varchar(6) NOT NULL default '', - id_group smallint(5) NOT NULL default '0', - add_groups varchar(40) NOT NULL default '', - active tinyint(3) NOT NULL default '1', - repeatable tinyint(3) NOT NULL default '0', - allow_partial tinyint(3) NOT NULL default '0', - reminder tinyint(3) NOT NULL default '0', - email_complete text NOT NULL, - PRIMARY KEY (id_subscribe), - KEY active (active) -) ENGINE=MyISAM{$db_collation}; ----# - ----# Creating log_subscribed table... -CREATE TABLE IF NOT EXISTS {$db_prefix}log_subscribed( - id_sublog int(10) unsigned NOT NULL auto_increment, - id_subscribe mediumint(8) unsigned NOT NULL default '0', - id_member int(10) NOT NULL default '0', - old_id_group smallint(5) NOT NULL default '0', - start_time int(10) NOT NULL default '0', - end_time int(10) NOT NULL default '0', - status tinyint(3) NOT NULL default '0', - payments_pending tinyint(3) NOT NULL default '0', - pending_details text NOT NULL, - reminder_sent tinyint(3) NOT NULL default '0', - vendor_ref varchar(255) NOT NULL default '', - PRIMARY KEY (id_sublog), - UNIQUE KEY id_subscribe (id_subscribe, id_member), - KEY end_time (end_time), - KEY reminder_sent (reminder_sent), - KEY payments_pending (payments_pending), - KEY id_member (id_member) -) ENGINE=MyISAM{$db_collation}; ----# - ----# Clean up any pre-2.0 mod settings. -UPDATE {$db_prefix}settings -SET variable = 'paid_currency_code' -WHERE variable = 'currency_code'; - -UPDATE {$db_prefix}settings -SET variable = 'paid_currency_symbol' -WHERE variable = 'currency_symbol'; - -DELETE FROM {$db_prefix}settings -WHERE variable = 'currency_code' - OR variable = 'currency_symbol'; ----# - ----# Clean up any pre-2.0 mod settings (part 2). ----{ -$request = upgrade_query(" - SHOW COLUMNS - FROM {$db_prefix}subscriptions"); -$new_cols = array('repeatable', 'reminder', 'email_complete', 'allow_partial'); -$new_cols = array_flip($new_cols); -while ($request && $row = mysql_fetch_row($request)) -{ - $row[0] = strtolower($row[0]); - if (isset($new_cols[$row[0]])) - unset($new_cols[$row[0]]); -} -if ($request) - mysql_free_result($request); - -if (isset($new_cols['repeatable'])) - upgrade_query(" - ALTER TABLE {$db_prefix}subscriptions - ADD COLUMN Repeatable tinyint(3) NOT NULL default '0'"); -if (isset($new_cols['reminder'])) - upgrade_query(" - ALTER TABLE {$db_prefix}subscriptions - ADD COLUMN reminder tinyint(3) NOT NULL default '0'"); -if (isset($new_cols['email_complete'])) - upgrade_query(" - ALTER TABLE {$db_prefix}subscriptions - ADD COLUMN email_complete text NOT NULL"); -if (isset($new_cols['allowpartial'])) - upgrade_query(" - ALTER TABLE {$db_prefix}subscriptions - ADD COLUMN allow_partial tinyint(3) NOT NULL default '0'"); - -$request = upgrade_query(" - SHOW COLUMNS - FROM {$db_prefix}log_subscribed"); -$new_cols = array('reminder_sent', 'vendor_ref', 'payments_pending', 'pending_details'); -$new_cols = array_flip($new_cols); -while ($request && $row = mysql_fetch_row($request)) -{ - if (isset($new_cols[$row[0]])) - unset($new_cols[$row[0]]); -} -if ($request) - mysql_free_result($request); - -if (isset($new_cols['reminder_sent'])) - upgrade_query(" - ALTER TABLE {$db_prefix}log_subscribed - ADD COLUMN reminder_sent tinyint(3) NOT NULL default '0'"); -if (isset($new_cols['vendor_ref'])) - upgrade_query(" - ALTER TABLE {$db_prefix}log_subscribed - ADD COLUMN vendor_ref varchar(255) NOT NULL default ''"); -if (isset($new_cols['payments_pending'])) - upgrade_query(" - ALTER TABLE {$db_prefix}log_subscribed - ADD COLUMN payments_pending tinyint(3) NOT NULL default '0'"); -if (isset($new_cols['pending_details'])) -{ - upgrade_query(" - UPDATE {$db_prefix}log_subscribed - SET status = 0 - WHERE status = 1"); - upgrade_query(" - UPDATE {$db_prefix}log_subscribed - SET status = 1 - WHERE status = 2"); - upgrade_query(" - ALTER TABLE {$db_prefix}log_subscribed - ADD COLUMN pending_details text NOT NULL"); -} ----} ----# - ----# Confirming paid subscription keys are in place ... -ALTER TABLE {$db_prefix}log_subscribed -ADD KEY reminder_sent (reminder_sent), -ADD KEY end_time (end_time), -ADD KEY payments_pending (payments_pending), -ADD KEY status (status); ----# - -/******************************************************************************/ ---- Adding weekly maintenance task. -/******************************************************************************/ - ----# Adding scheduled task... -INSERT IGNORE INTO {$db_prefix}scheduled_tasks (next_time, time_offset, time_regularity, time_unit, disabled, task) VALUES (0, 0, 1, 'w', 0, 'weekly_maintenance'); ----# - -/******************************************************************************/ ---- Adding log pruning. -/******************************************************************************/ - ----# Adding pruning option... -INSERT IGNORE INTO {$db_prefix}settings (variable, value) VALUES ('pruningOptions', '30,180,180,180,30,0'); ----# - -/******************************************************************************/ ---- Adding restore topic from recycle. -/******************************************************************************/ - ----# Adding restore from recycle feature... -ALTER TABLE {$db_prefix}topics -ADD COLUMN id_previous_board smallint(5) NOT NULL default '0', -ADD COLUMN id_previous_topic mediumint(8) NOT NULL default '0'; ----# - -/******************************************************************************/ ---- Providing more room for apf options. -/******************************************************************************/ - ----# Changing field_options column to a larger field type... -ALTER TABLE {$db_prefix}custom_fields -CHANGE field_options field_options text NOT NULL; ----# - -/******************************************************************************/ ---- Providing more room for ignoring boards. -/******************************************************************************/ - ----# Changing ignore_boards column to a larger field type... -ALTER TABLE {$db_prefix}members -CHANGE ignore_boards ignore_boards text NOT NULL; ----# - -/******************************************************************************/ ---- Allow for longer calendar event/holiday titles. -/******************************************************************************/ - ----# Changing event title column to a larger field type... -ALTER TABLE {$db_prefix}calendar -CHANGE title title varchar(255) NOT NULL default ''; ----# - ----# Changing holidays title column to a larger field type... -ALTER TABLE {$db_prefix}calendar_holidays -CHANGE title title varchar(255) NOT NULL default ''; ----# - -/******************************************************************************/ ---- Adding extra columns to polls. -/******************************************************************************/ - ----# Adding reset poll timestamp and guest voters counter... -ALTER TABLE {$db_prefix}polls -ADD COLUMN reset_poll int(10) unsigned NOT NULL default '0' AFTER guest_vote, -ADD COLUMN num_guest_voters int(10) unsigned NOT NULL default '0' AFTER guest_vote; ----# - ----# Fixing guest voter tallys on existing polls... ----{ -$request = upgrade_query(" - SELECT p.id_poll, count(lp.id_member) as guest_voters - FROM {$db_prefix}polls AS p - LEFT JOIN {$db_prefix}log_polls AS lp ON (lp.id_poll = p.id_poll AND lp.id_member = 0) - WHERE lp.id_member = 0 - AND p.num_guest_voters = 0 - GROUP BY p.id_poll"); - -while ($request && $row = $smcFunc['db_fetch_assoc']($request)) - upgrade_query(" - UPDATE {$db_prefix}polls - SET num_guest_voters = ". $row['guest_voters']. " - WHERE id_poll = " . $row['id_poll'] . " - AND num_guest_voters = 0"); ----} ----# - -/******************************************************************************/ ---- Changing all tinytext columns to varchar(255). -/******************************************************************************/ - ----# Changing all tinytext columns to varchar(255)... ----{ -// The array holding all the changes. -$nameChanges = array( - 'admin_info_files' => array( - 'filename' => 'filename filename varchar(255) NOT NULL default \'\'', - 'path' => 'path path varchar(255) NOT NULL default \'\'', - 'parameters' => 'parameters parameters varchar(255) NOT NULL default \'\'', - 'filetype' => 'filetype filetype varchar(255) NOT NULL default \'\'', - ), - 'attachments' => array( - 'filename' => 'filename filename varchar(255) NOT NULL default \'\'', - ), - 'ban_groups' => array( - 'reason' => 'reason reason varchar(255) NOT NULL default \'\'', - ), - 'ban_items' => array( - 'hostname' => 'hostname hostname varchar(255) NOT NULL default \'\'', - 'email_address' => 'email_address email_address varchar(255) NOT NULL default \'\'', - ), - 'boards' => array( - 'name' => 'name name varchar(255) NOT NULL default \'\'', - ), - 'categories' => array( - 'name' => 'name name varchar(255) NOT NULL default \'\'', - ), - 'custom_fields' => array( - 'field_desc' => 'field_desc field_desc varchar(255) NOT NULL default \'\'', - 'mask' => 'mask mask varchar(255) NOT NULL default \'\'', - 'default_value' => 'default_value default_value varchar(255) NOT NULL default \'\'', - ), - 'log_banned' => array( - 'email' => 'email email varchar(255) NOT NULL default \'\'', - ), - 'log_comments' => array( - 'recipient_name' => 'recipient_name recipient_name varchar(255) NOT NULL default \'\'', - ), - 'log_errors' => array( - 'file' => 'file file varchar(255) NOT NULL default \'\'', - ), - 'log_member_notices' => array( - 'subject' => 'subject subject varchar(255) NOT NULL default \'\'', - ), - 'log_packages' => array( - 'filename' => 'filename filename varchar(255) NOT NULL default \'\'', - 'package_id' => 'package_id package_id varchar(255) NOT NULL default \'\'', - 'name' => 'name name varchar(255) NOT NULL default \'\'', - 'version' => 'version version varchar(255) NOT NULL default \'\'', - 'member_installed' => 'member_installed member_installed varchar(255) NOT NULL default \'\'', - 'member_removed' => 'member_removed member_removed varchar(255) NOT NULL default \'\'', - 'themes_installed' => 'themes_installed themes_installed varchar(255) NOT NULL default \'\'', - ), - 'log_reported' => array( - 'membername' => 'membername membername varchar(255) NOT NULL default \'\'', - 'subject' => 'subject subject varchar(255) NOT NULL default \'\'', - ), - 'log_reported_comments' => array( - 'membername' => 'membername membername varchar(255) NOT NULL default \'\'', - 'comment' => 'comment comment varchar(255) NOT NULL default \'\'', - ), - 'log_spider_hits' => array( - 'url' => 'url url varchar(255) NOT NULL default \'\'', - ), - 'log_subscribed' => array( - 'vendor_ref' => 'vendor_ref vendor_ref varchar(255) NOT NULL default \'\'', - ), - 'mail_queue' => array( - 'recipient' => 'recipient recipient varchar(255) NOT NULL default \'\'', - 'subject' => 'subject subject varchar(255) NOT NULL default \'\'', - ), - 'membergroups' => array( - 'stars' => 'stars stars varchar(255) NOT NULL default \'\'', - ), - 'members' => array( - 'lngfile' => 'lngfile lngfile varchar(255) NOT NULL default \'\'', - 'real_name' => 'real_name real_name varchar(255) NOT NULL default \'\'', - 'pm_ignore_list' => 'pm_ignore_list pm_ignore_list varchar(255) NOT NULL default \'\'', - 'email_address' => 'email_address email_address varchar(255) NOT NULL default \'\'', - 'personal_text' => 'personal_text personal_text varchar(255) NOT NULL default \'\'', - 'website_title' => 'website_title website_title varchar(255) NOT NULL default \'\'', - 'website_url' => 'website_url website_url varchar(255) NOT NULL default \'\'', - 'location' => 'location location varchar(255) NOT NULL default \'\'', - 'icq' => 'icq icq varchar(255) NOT NULL default \'\'', - 'aim' => 'aim aim varchar(255) NOT NULL default \'\'', - 'msn' => 'msn msn varchar(255) NOT NULL default \'\'', - 'avatar' => 'avatar avatar varchar(255) NOT NULL default \'\'', - 'usertitle' => 'usertitle usertitle varchar(255) NOT NULL default \'\'', - 'member_ip' => 'member_ip member_ip varchar(255) NOT NULL default \'\'', - 'member_ip2' => 'member_ip2 member_ip2 varchar(255) NOT NULL default \'\'', - 'secret_question' => 'secret_question secret_question varchar(255) NOT NULL default \'\'', - 'additional_groups' => 'additional_groups additional_groups varchar(255) NOT NULL default \'\'', - ), - 'messages' => array( - 'subject' => 'subject subject varchar(255) NOT NULL default \'\'', - 'poster_name' => 'poster_name poster_name varchar(255) NOT NULL default \'\'', - 'poster_email' => 'poster_email poster_email varchar(255) NOT NULL default \'\'', - 'poster_ip' => 'poster_ip poster_ip varchar(255) NOT NULL default \'\'', - 'modified_name' => 'modified_name modified_name varchar(255) NOT NULL default \'\'', - ), - 'openid_assoc' => array( - 'handle' => 'handle handle varchar(255) NOT NULL default \'\'', - ), - 'package_servers' => array( - 'name' => 'name name varchar(255) NOT NULL default \'\'', - 'url' => 'url url varchar(255) NOT NULL default \'\'', - ), - 'permission_profiles' => array( - 'profile_name' => 'profile_name profile_name varchar(255) NOT NULL default \'\'', - ), - 'personal_messages' => array( - 'from_name' => 'from_name from_name varchar(255) NOT NULL default \'\'', - 'subject' => 'subject subject varchar(255) NOT NULL default \'\'', - ), - 'polls' => array( - 'question' => 'question question varchar(255) NOT NULL default \'\'', - 'poster_name' => 'poster_name poster_name varchar(255) NOT NULL default \'\'', - ), - 'poll_choices' => array( - 'label' => 'label label varchar(255) NOT NULL default \'\'', - ), - 'settings' => array( - 'variable' => 'variable variable varchar(255) NOT NULL default \'\'', - ), - 'spiders' => array( - 'spider_name' => 'spider_name spider_name varchar(255) NOT NULL default \'\'', - 'user_agent' => 'user_agent user_agent varchar(255) NOT NULL default \'\'', - 'ip_info' => 'ip_info ip_info varchar(255) NOT NULL default \'\'', - ), - 'subscriptions' => array( - 'description' => 'description description varchar(255) NOT NULL default \'\'', - ), - 'themes' => array( - 'variable' => 'variable variable varchar(255) NOT NULL default \'\'', - ), -); - -$_GET['ren_col'] = isset($_GET['ren_col']) ? (int) $_GET['ren_col'] : 0; -$step_progress['name'] = 'Changing tinytext columns to varchar(255)'; -$step_progress['current'] = $_GET['ren_col']; -$step_progress['total'] = count($nameChanges); - -$count = 0; -// Now do every table... -foreach ($nameChanges as $table_name => $table) -{ - // Already done this? - $count++; - if ($_GET['ren_col'] > $count) - continue; - $_GET['ren_col'] = $count; - - // Check the table exists! - $request = upgrade_query(" - SHOW TABLES - LIKE '{$db_prefix}$table_name'"); - if (mysql_num_rows($request) == 0) - { - mysql_free_result($request); - continue; - } - mysql_free_result($request); - - // Converting is intensive, so make damn sure that we need to do it. - $request = upgrade_query(" - SHOW FIELDS - FROM `{$db_prefix}$table_name`"); - $tinytextColumns = array(); - while($row = mysql_fetch_assoc($request)) - { - // Tinytext detected so store column name. - if ($row['Type'] == 'tinytext') - $tinytextColumns[$row['Field']] = $row['Field']; - } - mysql_free_result($request); - - // Check each column! - $actualChanges = array(); - foreach ($table as $colname => $coldef) - { - // Column was not detected as tinytext so skip it - // Either it was already converted or was changed eg text (so do not break it) - if (!isset($tinytextColumns[$colname])) - continue; - - $change = array( - 'table' => $table_name, - 'name' => $colname, - 'type' => 'column', - 'method' => 'change_remove', - 'text' => 'CHANGE ' . $coldef, - ); - if (protected_alter($change, $substep, true) == false) - $actualChanges[] = ' CHANGE COLUMN ' . $coldef; - } - - // Do the query - if it needs doing. - if (!empty($actualChanges)) - { - $change = array( - 'table' => $table_name, - 'name' => 'na', - 'type' => 'table', - 'method' => 'full_change', - 'text' => implode(', ', $actualChanges), - ); - - // Here we go - hold on! - protected_alter($change, $substep); - } - - // Update where we are! - $step_progress['current'] = $_GET['ren_col']; -} - -// All done! -unset($_GET['ren_col']); ----} ----# - -/******************************************************************************/ ---- Adding new personal message setting. -/******************************************************************************/ - ----# Adding column that stores the PM receiving setting... -ALTER TABLE {$db_prefix}members -ADD COLUMN pm_receive_from tinyint(4) unsigned NOT NULL default '1'; ----# - ----# Enable the buddy and ignore lists if we have not done so thus far... ----{ - -// Don't do this if we've done this already. -if (empty($modSettings['dont_repeat_buddylists'])) -{ - // Make sure the pm_receive_from column has the right default value - early adoptors might have a '0' set here. - upgrade_query(" - ALTER TABLE {$db_prefix}members - CHANGE pm_receive_from pm_receive_from tinyint(3) unsigned NOT NULL default '1'"); - - // Update previous ignore lists if they're set to ignore all. - upgrade_query(" - UPDATE {$db_prefix}members - SET pm_receive_from = 3, pm_ignore_list = '' - WHERE pm_ignore_list = '*'"); - - // Ignore posts made by ignored users by default. - upgrade_query(" - REPLACE INTO {$db_prefix}themes - (id_member, id_theme, variable, value) - VALUES - (-1, 1, 'posts_apply_ignore_list', '1')"); - - // Enable buddy and ignore lists, and make sure not to skip this step next time we run this. - upgrade_query(" - REPLACE INTO {$db_prefix}settings - (variable, value) - VALUES - ('enable_buddylist', '1'), - ('dont_repeat_buddylists', '1')"); -} - -// And yet, and yet... We might have a small hiccup here... -if (!empty($modSettings['dont_repeat_buddylists']) && !isset($modSettings['enable_buddylist'])) -{ - // Correct RC3 adopters setting here... - if (isset($modSettings['enable_buddylists'])) - { - upgrade_query(" - REPLACE INTO {$db_prefix}settings - (variable, value) - VALUES - ('enable_buddylist', '" . $modSettings['enable_buddylists'] . "')"); - } - else - { - // This should never happen :) - upgrade_query(" - REPLACE INTO {$db_prefix}settings - (variable, value) - VALUES - ('enable_buddylist', '1')"); - } -} - ----} ----# - -/******************************************************************************/ ---- Adding settings for attachments and avatars. -/******************************************************************************/ - ----# Add new security settings for attachments and avatars... ----{ - -// Don't do this if we've done this already. -if (!isset($modSettings['attachment_image_reencode'])) -{ - // Enable image re-encoding by default. - upgrade_query(" - REPLACE INTO {$db_prefix}settings - (variable, value) - VALUES - ('attachment_image_reencode', '1')"); -} -if (!isset($modSettings['attachment_image_paranoid'])) -{ - // Disable draconic checks by default. - upgrade_query(" - REPLACE INTO {$db_prefix}settings - (variable, value) - VALUES - ('attachment_image_paranoid', '0')"); -} -if (!isset($modSettings['avatar_reencode'])) -{ - // Enable image re-encoding by default. - upgrade_query(" - REPLACE INTO {$db_prefix}settings - (variable, value) - VALUES - ('avatar_reencode', '1')"); -} -if (!isset($modSettings['avatar_paranoid'])) -{ - // Disable draconic checks by default. - upgrade_query(" - REPLACE INTO {$db_prefix}settings - (variable, value) - VALUES - ('avatar_paranoid', '0')"); -} - ----} ----# - ----# Add other attachment settings... ----{ -if (!isset($modSettings['attachment_thumb_png'])) -{ - // Make image attachment thumbnail as PNG by default. - upgrade_query(" - REPLACE INTO {$db_prefix}settings - (variable, value) - VALUES - ('attachment_thumb_png', '1')"); -} - ----} ----# - -/******************************************************************************/ ---- Installing new default theme... -/******************************************************************************/ - ----# Installing theme settings... ----{ -// This is Grudge's secret "I'm not a developer" theme install code - keep this quiet ;) - -// Firstly, I'm going out of my way to not do this twice! -if ((!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '2.0 RC5' || $modSettings['smfVersion'] === '2.0 a') && empty($modSettings['dont_repeat_theme_core'])) -{ - // Check it's not already here, just in case. - $theme_request = upgrade_query(" - SELECT id_theme - FROM {$db_prefix}themes - WHERE variable = 'theme_dir' - AND value LIKE '%core'"); - // Only do the upgrade if it doesn't find the theme already. - if (mysql_num_rows($theme_request) == 0) - { - // Try to get some settings from the current default theme. - $request = upgrade_query(" - SELECT t1.value AS theme_dir, t2.value AS theme_url, t3.value AS images_url - FROM ({$db_prefix}themes AS t1, {$db_prefix}themes AS t2, {$db_prefix}themes AS t3) - WHERE t1.id_theme = 1 - AND t1.id_member = 0 - AND t1.variable = 'theme_dir' - AND t2.id_theme = 1 - AND t2.id_member = 0 - AND t2.variable = 'theme_url' - AND t3.id_theme = 1 - AND t3.id_member = 0 - AND t3.variable = 'images_url' - LIMIT 1"); - if (mysql_num_rows($request) != 0) - { - $curve = mysql_fetch_assoc($request); - - if (substr_count($curve['theme_dir'], 'default') === 1) - $core['theme_dir'] = strtr($curve['theme_dir'], array('default' => 'core')); - if (substr_count($curve['theme_url'], 'default') === 1) - $core['theme_url'] = strtr($curve['theme_url'], array('default' => 'core')); - if (substr_count($curve['images_url'], 'default') === 1) - $core['images_url'] = strtr($curve['images_url'], array('default' => 'core')); - } - mysql_free_result($request); - - if (!isset($core['theme_dir'])) - $core['theme_dir'] = addslashes($GLOBALS['boarddir']) . '/Themes/core'; - if (!isset($core['theme_url'])) - $core['theme_url'] = $GLOBALS['boardurl'] . '/Themes/core'; - if (!isset($core['images_url'])) - $core['images_url'] = $GLOBALS['boardurl'] . '/Themes/core/images'; - - // Get an available id_theme first... - $request = upgrade_query(" - SELECT MAX(id_theme) + 1 - FROM {$db_prefix}themes"); - list ($id_core_theme) = mysql_fetch_row($request); - mysql_free_result($request); - - // Insert the core theme into the tables. - upgrade_query(" - INSERT INTO {$db_prefix}themes - (id_member, id_theme, variable, value) - VALUES - (0, $id_core_theme, 'name', 'Core Theme'), - (0, $id_core_theme, 'theme_url', '$core[theme_url]'), - (0, $id_core_theme, 'images_url', '$core[images_url]'), - (0, $id_core_theme, 'theme_dir', '$core[theme_dir]')"); - - // Update the name of the default theme in the database. - upgrade_query(" - UPDATE {$db_prefix}themes - SET value = 'SMF Default Theme - Curve' - WHERE id_theme = 1 - AND variable = 'name'"); - - // If known themes aren't set, let's just pick all themes available. - if (empty($modSettings['knownThemes'])) - { - $request = upgrade_query(" - SELECT DISTINCT id_theme - FROM {$db_prefix}themes"); - $themes = array(); - while ($row = mysql_fetch_assoc($request)) - $themes[] = $row['id_theme']; - $modSettings['knownThemes'] = implode(',', $themes); - upgrade_query(" - UPDATE {$db_prefix}settings - SET value = '$modSettings[knownThemes]' - WHERE variable = 'knownThemes'"); - } - - // Known themes. - $allThemes = explode(',', $modSettings['knownThemes']); - $allThemes[] = $id_core_theme; - $newSettings = array(); - $newSettings[] = "('knownThemes', '" . implode(',', $allThemes) . "')"; - - upgrade_query(" - REPLACE INTO {$db_prefix}settings - (variable, value) - VALUES - " . implode(', ', $newSettings)); - - // The other themes used to use core as their base theme. - if (isset($core['theme_dir']) && isset($core['theme_url'])) - { - $coreBasedThemes = array_diff($allThemes, array(1)); - - // Exclude the themes that already have a base_theme_dir. - $request = upgrade_query(" - SELECT DISTINCT id_theme - FROM {$db_prefix}themes - WHERE variable = 'base_theme_dir'"); - while ($row = mysql_fetch_assoc($request)) - $coreBasedThemes = array_diff($coreBasedThemes, array($row['id_theme'])); - mysql_free_result($request); - - // Only base themes if there are templates that need a fall-back. - $insertRows = array(); - $request = upgrade_query(" - SELECT id_theme, value AS theme_dir - FROM {$db_prefix}themes - WHERE id_theme IN (" . implode(', ', $coreBasedThemes) . ") - AND id_member = 0 - AND variable = 'theme_dir'"); - while ($row = mysql_fetch_assoc($request)) - { - if (!file_exists($row['theme_dir'] . '/BoardIndex.template.php') || !file_exists($row['theme_dir'] . '/Display.template.php') || !file_exists($row['theme_dir'] . '/index.template.php') || !file_exists($row['theme_dir'] . '/MessageIndex.template.php') || !file_exists($row['theme_dir'] . '/Settings.template.php')) - { - $insertRows[] = "(0, $row[id_theme], 'base_theme_dir', '" . addslashes($core['theme_dir']) . "')"; - $insertRows[] = "(0, $row[id_theme], 'base_theme_url', '" . addslashes($core['theme_url']) . "')"; - } - } - mysql_free_result($request); - - if (!empty($insertRows)) - upgrade_query(" - INSERT IGNORE INTO {$db_prefix}themes - (id_member, id_theme, variable, value) - VALUES - " . implode(', - ', $insertRows)); - } - } - mysql_free_result($theme_request); - - // This ain't running twice either. - upgrade_query(" - REPLACE INTO {$db_prefix}settings - (variable, value) - VALUES - ('dont_repeat_theme_core', '1')"); -} - ----} ----# - -/******************************************************************************/ ---- Installing new smileys sets... -/******************************************************************************/ - ----# Installing new smiley sets... ----{ -// Don't do this twice! -if (empty($modSettings['installed_new_smiley_sets_20'])) -{ - // First, the entries. - upgrade_query(" - UPDATE {$db_prefix}settings - SET value = CONCAT(value, ',aaron,akyhne') - WHERE variable = 'smiley_sets_known'"); - - // Second, the names. - upgrade_query(" - UPDATE {$db_prefix}settings - SET value = CONCAT(value, '\nAaron\nAkyhne') - WHERE variable = 'smiley_sets_names'"); - - // This ain't running twice either. - upgrade_query(" - REPLACE INTO {$db_prefix}settings - (variable, value) - VALUES - ('installed_new_smiley_sets_20', '1')"); -} ----} ----# - -/******************************************************************************/ ---- Adding new indexes to the topics table. -/******************************************************************************/ - ----# Adding index member_started... -ALTER TABLE {$db_prefix}topics -ADD INDEX member_started (id_member_started, id_board); ----# - ----# Adding index last_message_sticky... -ALTER TABLE {$db_prefix}topics -ADD INDEX last_message_sticky (id_board, is_sticky, id_last_msg); ----# - ----# Adding index board_news... -ALTER TABLE {$db_prefix}topics -ADD INDEX board_news (id_board, id_first_msg); ----# - -/******************************************************************************/ ---- Adding new indexes to members table. -/******************************************************************************/ - ----# Adding index on total_time_logged_in... -ALTER TABLE {$db_prefix}members -ADD INDEX total_time_logged_in (total_time_logged_in); ----# - ----# Adding index on id_theme... -ALTER TABLE {$db_prefix}members -ADD INDEX id_theme (id_theme); ----# - ----# Dropping index on real_name(30) ... ----{ -// Detect existing index with limited length -$request = upgrade_query(" - SHOW INDEXES - FROM {$db_prefix}members" -); - -// Drop the existing index before we recreate it. -while ($row = mysql_fetch_assoc($request)) -{ - if ($row['Key_name'] === 'real_name' && $row['Sub_part'] == 30) - { - upgrade_query(" - ALTER TABLE {$db_prefix}members - DROP INDEX real_name" - ); - break; - } -} - -mysql_free_result($request); ----} ----# - ----# Adding index on real_name... -ALTER TABLE {$db_prefix}members -ADD INDEX real_name (real_name); ----# - ----# Dropping index member_name(30)... ----{ -// Detect existing index with limited length -$request = upgrade_query(" - SHOW INDEXES - FROM {$db_prefix}members" -); - -// Drop the existing index before we recreate it. -while ($row = mysql_fetch_assoc($request)) -{ - if ($row['Key_name'] === 'member_name' && $row['Sub_part'] == 30) - { - upgrade_query(" - ALTER TABLE {$db_prefix}members - DROP INDEX member_name" - ); - break; - } -} - -mysql_free_result($request); - ----} ----# - ----# Adding index on member_name... -ALTER TABLE {$db_prefix}members -ADD INDEX member_name (member_name); ----# - -/******************************************************************************/ ---- Adding new indexes to messages table. -/******************************************************************************/ - ----# Adding index id_member_msg... -ALTER TABLE {$db_prefix}messages -ADD INDEX id_member_msg (id_member, approved, id_msg); ----# - ----# Adding index current_topic... -ALTER TABLE {$db_prefix}messages -ADD INDEX current_topic (id_topic, id_msg, id_member, approved); ----# - ----# Adding index related_ip... -ALTER TABLE {$db_prefix}messages -ADD INDEX related_ip (id_member, poster_ip, id_msg); ----# - -/******************************************************************************/ ---- Adding new indexes to attachments table. -/******************************************************************************/ - ----# Adding index on attachment_type... -ALTER TABLE {$db_prefix}attachments -ADD INDEX attachment_type (attachment_type); ----# - -/******************************************************************************/ ---- Dropping unnecessary indexes... -/******************************************************************************/ - ----# Removing index on hits... -ALTER TABLE {$db_prefix}log_activity -DROP INDEX hits; ----# - -/******************************************************************************/ ---- Adding extra columns to reported post comments -/******************************************************************************/ - ----# Adding email address and member ip columns... -ALTER TABLE {$db_prefix}log_reported_comments -ADD COLUMN member_ip varchar(255) NOT NULL default '' AFTER membername, -ADD COLUMN email_address varchar(255) NOT NULL default '' AFTER membername; ----# - -/******************************************************************************/ ---- Adjusting group types. -/******************************************************************************/ - ----# Fixing the group types. ----{ -// Get the admin group type. -$request = upgrade_query(" - SELECT group_type - FROM {$db_prefix}membergroups - WHERE id_group = 1 - LIMIT 1"); -list ($admin_group_type) = mysql_fetch_row($request); -mysql_free_result($request); - -// Not protected means we haven't updated yet! -if ($admin_group_type != 1) -{ - // Increase by one. - upgrade_query(" - UPDATE {$db_prefix}membergroups - SET group_type = group_type + 1 - WHERE group_type > 0"); -} ----} ----# - ----# Changing the group type for Administrator group. -UPDATE {$db_prefix}membergroups -SET group_type = 1 -WHERE id_group = 1; ----# - -/******************************************************************************/ ---- Final clean up... -/******************************************************************************/ - ----# Sorting the boards... -ALTER TABLE {$db_prefix}categories -ORDER BY cat_order; - -ALTER TABLE {$db_prefix}boards -ORDER BY board_order; ----#