/db_update.php
PHP | 2506 lines | 1703 code | 504 blank | 299 comment | 307 complexity | 77c17742443f40dac5b7fa190fab8fe1 MD5 | raw file
Possible License(s): GPL-2.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * @copyright Copyright (C) 2011-2012 Yoory Nagumanov
- * @copyright Copyright (C) 2008-2012 FluxBB
- * @copyright based on code by Rickard Andersson copyright (C) 2002-2008 PunBB
- * @license http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
- */
- // The FluxBB version this script updates to
- define('UPDATE_TO', '1.4.5');
- define('UPDATE_TO_PE', '0.1-alpha4');
- define('UPDATE_TO_DB_REVISION', 11);
- define('UPDATE_TO_PE_DB_REVISION', 18);
- define('UPDATE_TO_SI_REVISION', 2);
- define('UPDATE_TO_PARSER_REVISION', 2);
- define('MIN_PHP_VERSION', '5.3.0');
- define('MIN_MYSQL_VERSION', '4.1.2');
- define('MIN_PGSQL_VERSION', '7.0.0');
- define('PUN_SEARCH_MIN_WORD', 3);
- define('PUN_SEARCH_MAX_WORD', 20);
- // Enable DEBUG mode by removing // from the following line
- //define('PUN_DEBUG', 1);
- // Show the Exception stack trace on error page.
- // Works only in DEBUG mode (needs PUN_DEBUG to be defined too)
- // DO NOT enable this in a production environment! (Leakage of sensitive information may occur!)
- //define('SHOW_EXCEPTION_STACK_TRACE', 1);
- // This displays all executed queries in the page footer.
- // DO NOT enable this in a production environment! (Leakage of sensitive information may occur!)
- //define('PUN_SHOW_QUERIES', 1);
- // The MySQL connection character set that was used for FluxBB 1.2 - in 99% of cases this should be detected automatically,
- // but can be overridden using the below constant if required.
- //define('FORUM_DEFAULT_CHARSET', 'latin1');
- // The number of items to process per page view (lower this if the update script times out during UTF-8 conversion)
- define('PER_PAGE', 300);
- // Don't set to UTF-8 until after we've found out what the default character set is
- define('FORUM_NO_SET_NAMES', 1);
- // Make sure we are running at least MIN_PHP_VERSION
- if (!function_exists('version_compare') || version_compare(PHP_VERSION, MIN_PHP_VERSION, '<'))
- exit('You are running PHP version '.PHP_VERSION.'. FluxBB '.UPDATE_TO.' requires at least PHP '.MIN_PHP_VERSION.' to run properly. You must upgrade your PHP installation before you can continue.');
- define('PUN_ROOT', dirname(__FILE__).'/');
- require PUN_ROOT . 'protected/pebase.php';
- /* На данный момент, PUN_ROOT и Pe::get('root') содержат абсолютно идентичные значения. Заменять PUN_ROOT на Pe::get('root') в тексте скрипта нет смысла по соображениям эффективности. Аналогичная ситуация у FORUM_CACHE_DIR и Pe::get('forum_cache_dir'). Однако некоторые подмены вида Pe::set('var', $var) ниже в скрипте необходимы для правильной работы функций, находящихся в подключаемых скриптах. */
- if (file_exists(PUN_ROOT . 'protected/config/main.php'))
- Pe::config(include(PUN_ROOT . 'protected/config/main.php'));
- else
- throw new PeException('Application is not configured');
- /* TODO: попрежнему далеко от совершенства. Даже если база данных обновится корректно, нужно как-то сообщить пользователям, что еще нужно конфиг переместить и изменить его формат :(
- C PE на PE должно обновляться нормально. И с FluxBB на FluxBB.PE должно нормально обвновлять структуру базы данных (но не config.php!). Если, конечно, где-то не запрятан глюк.
- */
- // Attempt to load the configuration file config.php (FluxBB)
- if (file_exists(PUN_ROOT.'config.php'))
- {
- include PUN_ROOT.'config.php';
- // If we have the 1.3-legacy constant defined, define the proper 1.4 constant so we don't get an incorrect "need to install" message
- if (defined('FORUM'))
- define('PUN', FORUM);
- // If PUN isn't defined, config.php is missing or corrupt
- if (!defined('PUN'))
- {
- header('Location: install.php');
- exit;
- }
- Pe::config(array(
- 'db_type' => $db_type,
- 'db_host' => $db_host,
- 'db_name' => $db_name,
- 'db_username' => $db_username,
- 'db_password' => $db_password,
- 'db_prefix' => $db_prefix,
- 'p_connect' => $p_connect,
- 'cookie_name' => $cookie_name,
- 'cookie_domain' => $cookie_domain,
- 'cookie_path' => $cookie_path,
- 'cookie_secure' => $cookie_secure,
- 'cookie_seed' => $cookie_seed,
- ));
- }
- // Attempt to load the configuration file config.php (PunBB PE)
- else if (file_exists(PUN_ROOT.'include/config.php'))
- {
- include PUN_ROOT.'include/config.php';
- // If we have the 1.3-legacy constant defined, define the proper 1.4 constant so we don't get an incorrect "need to install" message
- if (defined('FORUM'))
- define('PUN', FORUM);
- // If PUN isn't defined, config.php is missing or corrupt
- if (!defined('PUN'))
- {
- header('Location: install.php');
- exit;
- }
- Pe::config(array(
- 'db_type' => $db_type,
- 'db_host' => $db_host,
- 'db_name' => $db_name,
- 'db_username' => $db_username,
- 'db_password' => $db_password,
- 'db_prefix' => $db_prefix,
- 'p_connect' => $p_connect,
- 'cookie_name' => $cookie_name,
- 'cookie_domain' => $cookie_domain,
- 'cookie_path' => $cookie_path,
- 'cookie_secure' => $cookie_secure,
- 'cookie_seed' => $cookie_seed,
- ));
- }
- // Check to see whether FluxBB PE is already installed
- else if (file_exists(PUN_ROOT.'protected/config/config.php'))
- {
- $cfg = require(PUN_ROOT.'protected/config/config.php');
- Pe::config($cfg);
- extract($cfg);
- unset($cfg);
- }
- else
- {
- header('Location: install.php');
- exit;
- }
- /* TODO: подумать, есть ли смысл завести отдельный конфиг для db_update.php (как для install.php)?
- * Сейчас склоняюсь, что нет, но тем не менее отдельный файл с некоторыми дефайнами отсюда можно сделать.
- *
- * С другой стороны хотелось бы исключить лишние зависимости, если они есть.
- * Насколько я вижу из кода, db_update.php старается как можно меньше использовать
- * возможности движка, которым нужна база данных.
- */
- // Enable debug mode
- if (!defined('PUN_DEBUG'))
- define('PUN_DEBUG', 1);
- // Load the functions script
- require PUN_ROOT.'include/functions.php';
- // Load UTF-8 functions
- require PUN_ROOT.'include/utf8/utf8.php';
- // Strip out "bad" UTF-8 characters
- forum_remove_bad_characters();
- // Reverse the effect of register_globals
- forum_unregister_globals();
- // Turn on full PHP error reporting
- error_reporting(E_ALL);
- // Force POSIX locale (to prevent functions such as strtolower() from messing up UTF-8 strings)
- setlocale(LC_CTYPE, 'C');
- // Turn off magic_quotes_runtime
- if (get_magic_quotes_runtime())
- set_magic_quotes_runtime(0);
- // Strip slashes from GET/POST/COOKIE (if magic_quotes_gpc is enabled)
- if (get_magic_quotes_gpc())
- {
- function stripslashes_array($array)
- {
- return is_array($array) ? array_map('stripslashes_array', $array) : stripslashes($array);
- }
- $_GET = stripslashes_array($_GET);
- $_POST = stripslashes_array($_POST);
- $_COOKIE = stripslashes_array($_COOKIE);
- $_REQUEST = stripslashes_array($_REQUEST);
- }
- // If a cookie name is not specified in config.php, we use the default (forum_cookie)
- if (empty($cookie_name))
- $cookie_name = 'pun_cookie';
- // If the cache directory is not specified, we use the default setting
- if (!defined('FORUM_CACHE_DIR'))
- define('FORUM_CACHE_DIR', PUN_ROOT.'cache/');
- // Turn off PHP time limit
- @set_time_limit(0);
- // Define a few commonly used constants
- define('PUN_UNVERIFIED', 0);
- define('PUN_ADMIN', 1);
- define('PUN_MOD', 2);
- define('PUN_GUEST', 3);
- define('PUN_MEMBER', 4);
- // Load DB abstraction layer and try to connect
- /* @var $db \pe\dblayer\DBLayer */
- $db = Pe::get('db');
- // Check what the default character set is - since 1.2 didn't specify any we will use whatever the default was (usually latin1)
- $old_connection_charset = defined('FORUM_DEFAULT_CHARSET') ? FORUM_DEFAULT_CHARSET : $db->get_names();
- // Set the connection to UTF-8 now
- $db->set_names('utf8');
- // Get the forum config
- $result = $db->query('SELECT * FROM '.$db->prefix.'config');
- while ($cur_config_item = $db->fetch_row($result))
- $pun_config[$cur_config_item[0]] = $cur_config_item[1];
- // Временное решение:
- Pe::set('pun_config', $pun_config); // Чтобы не обрабатывался вызов к CacheLoader (и может быть CacheGenerator)
- // Load language file
- $default_lang = $pun_config['o_default_lang'];
- if (!file_exists(PUN_ROOT.'lang/'.$default_lang.'/update.php'))
- $default_lang = 'English';
- $lang_update = require PUN_ROOT.'lang/'.$default_lang.'/update.php';
- // Set the $pun_user to satisfy the dependences
- Pe::set('pun_user', array('lang' => $default_lang));
- // Check current version
- $cur_version = $pun_config['o_cur_version'];
- if (version_compare($cur_version, '1.2', '<'))
- throw new PeException(sprintf($lang_update['Version mismatch error'], $db_name));
- // Do some DB type specific checks
- $mysql = false;
- switch ($db_type)
- {
- case 'mysql':
- case 'mysqli':
- case 'mysql_innodb':
- case 'mysqli_innodb':
- $mysql_info = $db->get_version();
- if (version_compare($mysql_info['version'], MIN_MYSQL_VERSION, '<'))
- throw new PeDbException(sprintf($lang_update['You are running error'], 'MySQL', $mysql_info['version'], UPDATE_TO, MIN_MYSQL_VERSION));
- $mysql = true;
- break;
- case 'pgsql':
- $pgsql_info = $db->get_version();
- if (version_compare($pgsql_info['version'], MIN_PGSQL_VERSION, '<'))
- throw new PeDbException(sprintf($lang_update['You are running error'], 'PostgreSQL', $pgsql_info['version'], UPDATE_TO, MIN_PGSQL_VERSION));
- break;
- }
- // Check the database, search index and parser revision and the current version
- if (isset($pun_config['o_database_revision']) && $pun_config['o_database_revision'] >= UPDATE_TO_DB_REVISION &&
- isset($pun_config['o_pe_database_revision']) && $pun_config['o_pe_database_revision'] >= UPDATE_TO_PE_DB_REVISION&&
- isset($pun_config['o_searchindex_revision']) && $pun_config['o_searchindex_revision'] >= UPDATE_TO_SI_REVISION &&
- isset($pun_config['o_parser_revision']) && $pun_config['o_parser_revision'] >= UPDATE_TO_PARSER_REVISION &&
- version_compare($pun_config['o_cur_version'], UPDATE_TO, '>=') &&
- version_compare($pun_config['o_cur_pe_version'], UPDATE_TO_PE, '>='))
- throw new PeException($lang_update['No update error']);
- $default_style = $pun_config['o_default_style'];
- if (!file_exists(PUN_ROOT.'style/'.$default_style.'.css'))
- $default_style = 'Air';
- // Start a session, used to queue up errors if duplicate users occur when converting from FluxBB v1.2.
- session_start();
- //
- // Determines whether $str is UTF-8 encoded or not
- //
- function seems_utf8($str)
- {
- $str_len = strlen($str);
- for ($i = 0; $i < $str_len; ++$i)
- {
- if (ord($str[$i]) < 0x80) continue; # 0bbbbbbb
- else if ((ord($str[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb
- else if ((ord($str[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb
- else if ((ord($str[$i]) & 0xF8) == 0xF0) $n=3; # 11110bbb
- else if ((ord($str[$i]) & 0xFC) == 0xF8) $n=4; # 111110bb
- else if ((ord($str[$i]) & 0xFE) == 0xFC) $n=5; # 1111110b
- else return false; # Does not match any model
- for ($j = 0; $j < $n; ++$j) # n bytes matching 10bbbbbb follow ?
- {
- if ((++$i == strlen($str)) || ((ord($str[$i]) & 0xC0) != 0x80))
- return false;
- }
- }
- return true;
- }
- //
- // Translates the number from a HTML numeric entity into an UTF-8 character
- //
- function dcr2utf8($src)
- {
- $dest = '';
- if ($src < 0)
- return false;
- else if ($src <= 0x007f)
- $dest .= chr($src);
- else if ($src <= 0x07ff)
- {
- $dest .= chr(0xc0 | ($src >> 6));
- $dest .= chr(0x80 | ($src & 0x003f));
- }
- else if ($src == 0xFEFF)
- {
- // nop -- zap the BOM
- }
- else if ($src >= 0xD800 && $src <= 0xDFFF)
- {
- // found a surrogate
- return false;
- }
- else if ($src <= 0xffff)
- {
- $dest .= chr(0xe0 | ($src >> 12));
- $dest .= chr(0x80 | (($src >> 6) & 0x003f));
- $dest .= chr(0x80 | ($src & 0x003f));
- }
- else if ($src <= 0x10ffff)
- {
- $dest .= chr(0xf0 | ($src >> 18));
- $dest .= chr(0x80 | (($src >> 12) & 0x3f));
- $dest .= chr(0x80 | (($src >> 6) & 0x3f));
- $dest .= chr(0x80 | ($src & 0x3f));
- }
- else
- {
- // out of range
- return false;
- }
- return $dest;
- }
- //
- // Attempts to convert $str from $old_charset to UTF-8. Also converts HTML entities (including numeric entities) to UTF-8 characters
- //
- function convert_to_utf8(&$str, $old_charset)
- {
- if ($str === null || $str == '')
- return false;
- $save = $str;
- // Replace literal entities (for non-UTF-8 compliant html_entity_encode)
- if (version_compare(PHP_VERSION, '5.0.0', '<') && $old_charset == 'ISO-8859-1' || $old_charset == 'ISO-8859-15')
- $str = html_entity_decode($str, ENT_QUOTES, $old_charset);
- if ($old_charset != 'UTF-8' && !seems_utf8($str))
- {
- if (function_exists('iconv'))
- $str = iconv($old_charset == 'ISO-8859-1' ? 'WINDOWS-1252' : 'ISO-8859-1', 'UTF-8', $str);
- else if (function_exists('mb_convert_encoding'))
- $str = mb_convert_encoding($str, 'UTF-8', $old_charset == 'ISO-8859-1' ? 'WINDOWS-1252' : 'ISO-8859-1');
- else if ($old_charset == 'ISO-8859-1')
- $str = utf8_encode($str);
- }
- // Replace literal entities (for UTF-8 compliant html_entity_encode)
- if (version_compare(PHP_VERSION, '5.0.0', '>='))
- $str = html_entity_decode($str, ENT_QUOTES, 'UTF-8');
- // Replace numeric entities
- $str = preg_replace_callback('/&#([0-9]+);/', 'utf8_callback_1', $str);
- $str = preg_replace_callback('/&#x([a-f0-9]+);/i', 'utf8_callback_2', $str);
- // Remove "bad" characters
- $str = remove_bad_characters($str);
- return ($save != $str);
- }
- function utf8_callback_1($matches)
- {
- return dcr2utf8($matches[1]);
- }
- function utf8_callback_2($matches)
- {
- return dcr2utf8(hexdec($matches[1]));
- }
- //
- // Alter a table to be utf8. MySQL only
- // Function based on update_convert_table_utf8() from the Drupal project (http://drupal.org/)
- //
- function alter_table_utf8($table)
- {
- global $mysql, $db;
- static $types;
- if (!$mysql)
- return;
- if (!isset($types))
- {
- $types = array(
- 'char' => 'binary',
- 'varchar' => 'varbinary',
- 'tinytext' => 'tinyblob',
- 'mediumtext' => 'mediumblob',
- 'text' => 'blob',
- 'longtext' => 'longblob'
- );
- }
- // Set table default charset to utf8
- $db->query('ALTER TABLE '.$table.' CHARACTER SET utf8');
- // Find out which columns need converting and build SQL statements
- $result = $db->query('SHOW FULL COLUMNS FROM '.$table);
- while ($cur_column = $db->fetch_assoc($result))
- {
- if ($cur_column['Collation'] === null)
- continue;
- list($type) = explode('(', $cur_column['Type']);
- if (isset($types[$type]) && strpos($cur_column['Collation'], 'utf8') === false)
- {
- $allow_null = ($cur_column['Null'] == 'YES');
- $collate = (substr($cur_column['Collation'], -3) == 'bin') ? 'utf8_bin' : 'utf8_general_ci';
- $db->alter_field($table, $cur_column['Field'], preg_replace('/'.$type.'/i', $types[$type], $cur_column['Type']), $allow_null, $cur_column['Default'], null, true);
- $db->alter_field($table, $cur_column['Field'], $cur_column['Type'].' CHARACTER SET utf8 COLLATE '.$collate, $allow_null, $cur_column['Default'], null, true);
- }
- }
- }
- //
- // Safely converts text type columns into utf8
- // If finished returns true, otherwise returns $end_at
- //
- function convert_table_utf8($table, $callback, $old_charset, $key = null, $start_at = null, $error_callback = null)
- {
- global $mysql, $db, $old_connection_charset;
- $finished = true;
- $end_at = 0;
- if ($mysql)
- {
- // Only set up the tables if we are doing this in 1 go, or its the first go
- if ($start_at === null || $start_at == 0)
- {
- // Drop any temp table that exists, in-case it's left over from a failed update
- $db->drop_table($table.'_utf8', true);
- // Copy the table
- $db->query('CREATE TABLE '.$table.'_utf8 LIKE '.$table);
- // Set table default charset to utf8
- alter_table_utf8($table.'_utf8');
- }
- // Change to the old character set so MySQL doesn't attempt to perform conversion on the data from the old table
- $db->set_names($old_connection_charset);
- // Move & Convert everything
- $result = $db->query('SELECT * FROM '.$table.($start_at === null ? '' : ' WHERE '.$key.'>'.$start_at).' ORDER BY '.$key.' ASC'.($start_at === null ? '' : ' LIMIT '.PER_PAGE), false);
- // Change back to utf8 mode so we can insert it into the new table
- $db->set_names('utf8');
- while ($cur_item = $db->fetch_assoc($result))
- {
- $cur_item = call_user_func($callback, $cur_item, $old_charset);
- $temp = array();
- foreach ($cur_item as $idx => $value)
- $temp[$idx] = $value === null ? 'NULL' : '\''.$db->escape($value).'\'';
- try
- {
- $db->query('INSERT INTO '.$table.'_utf8('.implode(',', array_keys($temp)).') VALUES ('.implode(',', array_values($temp)).')');
- }
- catch (PeDbException $ex)
- {
- if ($error_callback === null)
- throw $ex;
- else
- call_user_func($error_callback, $cur_item);
- }
- $end_at = $cur_item[$key];
- }
- // If we aren't doing this all in 1 go and $end_at has a value (i.e. we have processed at least 1 row), figure out if we have more to do or not
- if ($start_at !== null && $end_at > 0)
- {
- $result = $db->query('SELECT 1 FROM '.$table.' WHERE '.$key.'>'.$end_at.' ORDER BY '.$key.' ASC LIMIT 1');
- $finished = $db->num_rows($result) == 0;
- }
- // Only swap the tables if we are doing this in 1 go, or its the last go
- if ($finished)
- {
- // Delete old table
- $db->drop_table($table, true);
- // Rename table
- $db->query('ALTER TABLE '.$table.'_utf8 RENAME '.$table);
- return true;
- }
- return $end_at;
- }
- else
- {
- // Convert everything
- $result = $db->query('SELECT * FROM '.$table.($start_at === null ? '' : ' WHERE '.$key.'>'.$start_at).' ORDER BY '.$key.' ASC'.($start_at === null ? '' : ' LIMIT '.PER_PAGE));
- while ($cur_item = $db->fetch_assoc($result))
- {
- $cur_item = call_user_func($callback, $cur_item, $old_charset);
- $temp = array();
- foreach ($cur_item as $idx => $value)
- $temp[] = $idx.'='.($value === null ? 'NULL' : '\''.$db->escape($value).'\'');
- if (!empty($temp))
- $db->query('UPDATE '.$table.' SET '.implode(', ', $temp).' WHERE '.$key.'=\''.$db->escape($cur_item[$key]).'\'');
- $end_at = $cur_item[$key];
- }
- if ($start_at !== null && $end_at > 0)
- {
- $result = $db->query('SELECT 1 FROM '.$table.' WHERE '.$key.'>'.$end_at.' ORDER BY '.$key.' ASC LIMIT 1');
- if ($db->num_rows($result) == 0)
- return true;
- return $end_at;
- }
- return true;
- }
- }
- header('Content-type: text/html; charset=utf-8');
- // Empty all output buffers and stop buffering
- while (@ob_end_clean());
- $stage = isset($_REQUEST['stage']) ? $_REQUEST['stage'] : '';
- $old_charset = isset($_REQUEST['req_old_charset']) ? str_replace('ISO8859', 'ISO-8859', strtoupper($_REQUEST['req_old_charset'])) : 'ISO-8859-1';
- $start_at = isset($_REQUEST['start_at']) ? intval($_REQUEST['start_at']) : 0;
- $query_str = '';
- // Show form
- if (empty($stage))
- {
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title><?php echo $lang_update['Update'] ?></title>
- <link rel="stylesheet" type="text/css" href="style/<?php echo $default_style ?>.css" />
- </head>
- <body onload="document.getElementById('install').req_db_type.focus();document.getElementById('install').start.disabled=false;">
- <div id="pundb_update" class="pun">
- <div class="top-box"><div><!-- Top Corners --></div></div>
- <div class="punwrap">
- <div id="brdheader" class="block">
- <div class="box">
- <div id="brdtitle" class="inbox">
- <h1><span><?php echo $lang_update['Update'] ?></span></h1>
- <div id="brddesc"><p><?php echo $lang_update['Update message'] ?></p><p><strong><?php echo $lang_update['Note']; ?></strong> <?php echo $lang_update['Members message']; ?></p></div>
- </div>
- </div>
- </div>
- <div id="brdmain">
- <div class="blockform">
- <h2><span><?php echo $lang_update['Update'] ?></span></h2>
- <div class="box">
- <form method="post" action="db_update.php">
- <input type="hidden" name="stage" value="start" />
- <div class="inform">
- <fieldset>
- <legend><?php echo $lang_update['Administrator only'] ?></legend>
- <div class="infldset">
- <p><?php echo $lang_update['Database password info'] ?></p>
- <p><strong><?php echo $lang_update['Note']; ?></strong> <?php echo $lang_update['Database password note'] ?></p>
- <label class="required"><strong><?php echo $lang_update['Database password'] ?> <span><?php echo $lang_update['Required'] ?></span></strong><br /><input type="password" id="req_db_pass" name="req_db_pass" /><br /></label>
- </div>
- </fieldset>
- </div>
- <div class="inform">
- <div class="forminfo">
- <p><?php echo $lang_update['Intro 1'] ?></p>
- <p><?php echo $lang_update['Intro 2'] ?></p>
- <?php
- if (strpos($cur_version, '1.2') === 0)
- {
- if (!function_exists('iconv') && !function_exists('mb_convert_encoding'))
- {
- ?>
- <p><?php echo $lang_update['No charset conversion'] ?></p>
- <?php
- }
- ?>
- </div>
- </div>
- <div class="inform">
- <div class="forminfo">
- <p><?php echo $lang_update['Enable conversion'] ?></p>
- <p><?php echo $lang_update['Current character set'] ?></p>
- </div>
- <fieldset>
- <legend><?php echo $lang_update['Charset conversion'] ?></legend>
- <div class="infldset">
- <div class="rbox">
- <label><input type="checkbox" name="convert_charset" value="1" checked="checked" /><?php echo $lang_update['Enable conversion label'] ?><br /></label>
- </div>
- <label>
- <strong><?php echo $lang_update['Current character set label'] ?></strong><br /><?php echo $lang_update['Current character set info'] ?><br />
- <input type="text" name="req_old_charset" size="12" maxlength="20" value="<?php echo $old_charset ?>" /><br />
- </label>
- </div>
- </fieldset>
- <?php
- }
- else
- echo "\t\t\t\t".'</div>'."\n";
- ?>
- </div>
- <p class="buttons"><input type="submit" name="start" value="<?php echo $lang_update['Start update'] ?>" /></p>
- </form>
- </div>
- </div>
- </div>
- </div>
- <div class="end-box"><div><!-- Bottom Corners --></div></div>
- </div>
- </body>
- </html>
- <?php
- $db->end_transaction();
- $db->close();
- exit;
- }
- // Read the lock file
- $lock = file_exists(FORUM_CACHE_DIR.'db_update.lock') ? trim(file_get_contents(FORUM_CACHE_DIR.'db_update.lock')) : false;
- $lock_error = false;
- // Generate or fetch the UID - this confirms we have a valid admin
- if (isset($_POST['req_db_pass']))
- {
- $req_db_pass = strtolower(trim($_POST['req_db_pass']));
- switch ($db_type)
- {
- // For SQLite we compare against the database file name, since the password is left blank
- case 'sqlite':
- if ($req_db_pass != strtolower($db_name))
- throw new PeAccessException(sprintf($lang_update['Invalid file error'], 'config.php'));
- break;
- // For everything else, check the password matches
- default:
- if ($req_db_pass != strtolower($db_password))
- throw new PeAccessException(sprintf($lang_update['Invalid password error'], 'config.php'));
- break;
- }
- // Generate a unique id to identify this session, only if this is a valid session
- $uid = pun_hash($req_db_pass.'|'.uniqid(rand(), true));
- if ($lock) // We already have a lock file
- $lock_error = true;
- else // Create the lock file
- {
- $fh = @fopen(FORUM_CACHE_DIR.'db_update.lock', 'wb');
- if (!$fh)
- throw new PeAccessException(sprintf($lang_update['Unable to lock error'], 'cache'));
- fwrite($fh, $uid);
- fclose($fh);
- }
- }
- else if (isset($_GET['uid']))
- {
- $uid = trim($_GET['uid']);
- if (!$lock || $lock != $uid) // The lock doesn't exist or doesn't match the given UID
- $lock_error = true;
- }
- else
- throw new PeAccessException($lang_update['No password error']);
- // If there is an error with the lock file
- if ($lock_error)
- throw new PeAccessException(sprintf($lang_update['Script runs error'], FORUM_CACHE_DIR.'db_update.lock'));
- switch ($stage)
- {
- // Start by updating the database structure
- case 'start':
- $query_str = '?stage=preparse_posts';
- // If we don't need to update the database, skip this stage
- if (isset($pun_config['o_database_revision']) && $pun_config['o_database_revision'] >= UPDATE_TO_DB_REVISION && isset($pun_config['o_pe_database_revision']) && $pun_config['o_pe_database_revision'] >= UPDATE_TO_PE_DB_REVISION)
- break;
- // Make all email fields VARCHAR(80)
- $db->alter_field('bans', 'email', 'VARCHAR(80)', true);
- $db->alter_field('posts', 'poster_email', 'VARCHAR(80)', true);
- $db->alter_field('users', 'email', 'VARCHAR(80)', false, '');
- $db->alter_field('users', 'jabber', 'VARCHAR(80)', true);
- $db->alter_field('users', 'msn', 'VARCHAR(80)', true);
- $db->alter_field('users', 'activate_string', 'VARCHAR(80)', true);
- // Make all IP fields VARCHAR(39) to support IPv6
- $db->alter_field('posts', 'poster_ip', 'VARCHAR(39)', true);
- $db->alter_field('users', 'registration_ip', 'VARCHAR(39)', false, '0.0.0.0');
- // Make the message field MEDIUMTEXT to allow proper conversion of 65535 character posts to UTF-8
- $db->alter_field('posts', 'message', 'MEDIUMTEXT', true);
- // Add the kind field to the forums table
- $db->add_field('forums', 'kind', 'TINYINT(1)', false, Pe::get('pun_kind_forum'), 'cat_id');
- // Limited support for PunBB Power Edition
- if ($db->field_exists('categories', 'kind'))
- {
- $result = $db->query('SELECT id, kind FROM '.$db->prefix.'categories');
- while ($cur_cat = $db->fetch_assoc($result))
- $db->query('UPDATE '.$db->prefix.'forums SET kind='.$cur_cat['kind'].' WHERE cat_id='.$cur_cat['id']);
- $db->drop_field('categories', 'kind');
- }
- // Add the DST option to the users table
- $db->add_field('users', 'dst', 'TINYINT(1)', false, 0, 'timezone');
- // Add the last_post field to the online table
- $db->add_field('online', 'last_post', 'INT(10) UNSIGNED', true, null, null);
- // Add the last_search field to the online table
- $db->add_field('online', 'last_search', 'INT(10) UNSIGNED', true, null, null);
- // Add the last_search column to the users table
- $db->add_field('users', 'last_search', 'INT(10) UNSIGNED', true, null, 'last_post');
- // Add the file_bonus column to the users table
- $db->add_field('users', 'file_bonus', 'INT(10)', false, 0);
- // Add the num_files column to the users table
- $db->add_field('users', 'num_files', 'INT(10)', false, 0);
- // Add the total_files column to the users table
- $db->add_field('users', 'total_files', 'INT(10)', false, 0);
- // Add the last_mark_read column to the users table
- $db->add_field('users', 'last_mark_read', 'INT(10)', false, 0);
- // Add the g_file_download column to the groups table
- $db->add_field('groups', 'g_file_download', 'TINYINT(1)', false, 1);
- // Add the g_file_upload column to the groups table
- $db->add_field('groups', 'g_file_upload', 'TINYINT(1)', false, 0);
- // Add the g_file_private column to the groups table
- $db->add_field('groups', 'g_file_private', 'TINYINT(1)', false, 0);
- // Add the g_file_limit column to the groups table
- $db->add_field('groups', 'g_file_limit', 'INT(10)', false, 0);
- // Add the g_file_limit_mode column to the groups table
- $db->add_field('groups', 'g_file_limit_mode', 'TINYINT(1)', false, 1);
- // Add the g_file_bonus_mode column to the groups table
- $db->add_field('groups', 'g_file_bonus_mode', 'TINYINT(1)', false, 0);
- // Update unchangeable File Upload settings for Administrator group
- $db->query('UPDATE '.$db->prefix.'groups SET g_file_download=1, g_file_upload=1, g_file_private=1, g_file_limit=999, g_file_limit_mode=0 WHERE g_id=1');
- // Add the g_see_hidden_text column to the groups table
- $db->add_field('groups', 'g_see_hidden_text', 'TINYINT(1)', false, 0);
- // Make admin able to see hidden text
- $db->query('UPDATE '.$db->prefix.'groups SET g_see_hidden_text=1 WHERE g_id=1');
- // Add the cat_desc column to the categories table
- $db->add_field('categories', 'cat_desc', 'TEXT', false, '');
- // Add the cat_enabled column to the categories table
- $db->add_field('categories', 'cat_enabled', 'TINYINT(1)', false, 1);
- // Drop use_avatar column from users table
- $db->drop_field('users', 'use_avatar');
- // Drop save_pass column from users table
- $db->drop_field('users', 'save_pass');
- // Drop g_edit_subjects_interval column from groups table
- $db->drop_field('groups', 'g_edit_subjects_interval');
- // Add PE version
- if (!array_key_exists('o_cur_pe_version', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_cur_pe_version\', \'0\')');
- // Add database revision number
- if (!array_key_exists('o_database_revision', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_database_revision\', \'0\')');
- // Add PE database revision number
- if (!array_key_exists('o_pe_database_revision', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_pe_database_revision\', \'0\')');
- // Add search index revision number
- if (!array_key_exists('o_searchindex_revision', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_searchindex_revision\', \'0\')');
- // Add parser revision number
- if (!array_key_exists('o_parser_revision', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_parser_revision\', \'0\')');
- // Add default email setting option
- if (!array_key_exists('o_default_email_setting', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_default_email_setting\', \'1\')');
- // Make sure we have o_additional_navlinks (was added in 1.2.1)
- if (!array_key_exists('o_additional_navlinks', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_additional_navlinks\', \'\')');
- // Insert new config option o_topic_views
- if (!array_key_exists('o_topic_views', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_topic_views\', \'1\')');
- // Insert new config option o_signatures
- if (!array_key_exists('o_signatures', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_signatures\', \'1\')');
- // Insert new config option o_smtp_ssl
- if (!array_key_exists('o_smtp_ssl', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_smtp_ssl\', \'0\')');
- // Insert new config option o_default_dst
- if (!array_key_exists('o_default_dst', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_default_dst\', \'0\')');
- // Insert new config option o_quote_depth
- if (!array_key_exists('o_quote_depth', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_quote_depth\', \'3\')');
- // Insert new config option o_feed_type
- if (!array_key_exists('o_feed_type', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_feed_type\', \'2\')');
- // Insert new config option o_feed_ttl
- if (!array_key_exists('o_feed_ttl', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_feed_ttl\', \'0\')');
- // Insert new config option file_upload_path
- if (!array_key_exists('file_upload_path', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'file_upload_path\', \'upload/\')');
- // Insert new config option file_current_subpath
- if (!array_key_exists('file_current_subpath', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'file_current_subpath\', \'\')');
- // Insert new config option file_max_subpath_files
- if (!array_key_exists('file_max_subpath_files', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'file_max_subpath_files\', \'10000\')');
- // Insert new config option file_friendly_url
- if (!array_key_exists('file_friendly_url', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'file_friendly_url\', \'0\')');
- // Insert new config option file_thumb_path
- if (!array_key_exists('file_thumb_path', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'file_thumb_path\', \'img/thumb/\')');
- // Insert new config option file_preview_path
- if (!array_key_exists('file_preview_path', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'file_preview_path\', \'img/preview/\')');
- // Insert new config option file_allowed_ext
- if (!array_key_exists('file_allowed_ext', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'file_allowed_ext\', \'gif,png,jpg,jpeg,zip,rar\')');
- // Insert new config option file_image_ext
- if (!array_key_exists('file_image_ext', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'file_image_ext\', \'gif,png,jpg,jpeg\')');
- // Insert new config option file_max_size
- if (!array_key_exists('file_max_size', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'file_max_size\', \'2097152\')');
- // Insert new config option file_max_dimension
- if (!array_key_exists('file_max_dimension', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'file_max_dimension\', \'3000\')');
- // Insert new config option file_preview_dimension
- if (!array_key_exists('file_preview_dimension', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'file_preview_dimension\', \'500\')');
- // Insert new config option file_thumb_dimension
- if (!array_key_exists('file_thumb_dimension', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'file_thumb_dimension\', \'100\')');
- // Insert new config option pe_enabled_kinds
- if (!array_key_exists('pe_enabled_kinds', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'pe_enabled_kinds\', \''.$db->escape(serialize(array(Pe::get('pun_kind_forum')))).'\')');
- // Insert new config option pe_navigation_type
- if (!array_key_exists('pe_navigation_type', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'pe_navigation_type\', \'1\')');
- // Insert new config option pe_default_kind
- if (!array_key_exists('pe_default_kind', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'pe_default_kind\', \''.Pe::get('pun_kind_forum').'\')');
- // Insert new config option o_topics_track_timeout
- if (!array_key_exists('o_topics_track_timeout', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_topics_track_timeout\', \'15\')');
- // Insert new config option o_new_topics_timeout
- if (!array_key_exists('o_new_topics_timeout', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_new_topics_timeout\', \'5\')');
- // Insert new config option pe_default_category
- if (!array_key_exists('pe_default_category', $pun_config))
- {
- // Fetch the first real category ID form the DB or use 0 if none.
- $result = $db->query('SELECT id FROM '.$db->prefix.'categories ORDER BY id ASC LIMIT 1');
- $def_cat = $db->num_rows($result) ? $db->result($result) : 0;
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'pe_default_category\', \''.$def_cat.'\')');
- }
- // Insert new config option pe_default_index
- if (!array_key_exists('pe_default_index', $pun_config))
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'pe_default_index\', \'0\')');
- // Insert config option o_base_url which was removed in 1.3
- if (!array_key_exists('o_base_url', $pun_config))
- {
- // If it isn't in $pun_config['o_base_url'] it should be in $base_url, but just in-case it isn't we can make a guess at it
- if (!isset($base_url))
- {
- // Make an educated guess regarding base_url
- $base_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://'; // protocol
- $base_url .= preg_replace('/:(80|443)$/', '', $_SERVER['HTTP_HOST']); // host[:port]
- $base_url .= str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME'])); // path
- }
- if (substr($base_url, -1) == '/')
- $base_url = substr($base_url, 0, -1);
- $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_base_url\', \''.$db->escape($base_url).'\')');
- }
- if (strpos($cur_version, '1.2') === 0)
- {
- // Groups are almost the same as 1.2:
- // unverified: 32000 -> 0
- $db->query('UPDATE '.$db->prefix.'users SET group_id = 0 WHERE group_id = 32000');
- }
- else if (strpos($cur_version, '1.3') === 0)
- {
- // Groups have changed quite a lot from 1.3:
- // unverified: 0 -> 0
- // admin: 1 -> 1
- // mod: ? -> 2
- // guest: 2 -> 3
- // member: ? -> 4
- $result = $db->query('SELECT MAX(g_id) + 1 FROM '.$db->prefix.'groups');
- $temp_id = $db->result($result);
- $result = $db->query('SELECT g_id FROM '.$db->prefix.'groups WHERE g_moderator = 1 AND g_id > 1 LIMIT 1');
- if ($db->num_rows($result))
- $mod_gid = $db->result($result);
- else
- {
- $db->query('INSERT INTO '.$db->prefix.'groups (g_title, g_user_title, g_moderator, g_mod_edit_users, g_mod_rename_users, g_mod_change_passwords, g_mod_ban_users, g_read_board, g_view_users, g_post_replies, g_post_topics, g_edit_posts, g_delete_posts, g_delete_topics, g_set_title, g_search, g_search_users, g_send_email, g_post_flood, g_search_flood, g_email_flood) VALUES('."'Moderators', 'Moderator', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0)");
- $mod_gid = $db->insert_id();
- }
- $member_gid = $pun_config['o_default_user_group'];
- // move the mod group to a temp place
- $db->query('UPDATE '.$db->prefix.'groups SET g_id = '.$temp_id.' WHERE g_id = '.$mod_gid);
- $db->query('UPDATE '.$db->prefix.'users SET group_id = '.$temp_id.' WHERE group_id = '.$mod_gid);
- $db->query('UPDATE '.$db->prefix.'forum_perms SET group_id = '.$temp_id.' WHERE group_id = '.$mod_gid);
- if ($member_gid == $mod_gid) $member_gid = $temp_id;
- // move whoever is in 3 to a spare slot
- $db->query('UPDATE '.$db->prefix.'groups SET g_id = '.$mod_gid.' WHERE g_id = 3');
- $db->query('UPDATE '.$db->prefix.'users SET group_id = '.$mod_gid.' WHERE group_id = 3');
- $db->query('UPDATE '.$db->prefix.'forum_perms SET group_id = '.$mod_gid.' WHERE group_id = 3');
- if ($member_gid == 3) $member_gid = $mod_gid;
- // move guest to 3
- $db->query('UPDATE '.$db->prefix.'groups SET g_id = 3 WHERE g_id = 2');
- $db->query('UPDATE '.$db->prefix.'users SET group_id = 3 WHERE group_id = 2');
- $db->query('UPDATE '.$db->prefix.'forum_perms SET group_id = 3 WHERE group_id = 2');
- if ($member_gid == 2) $member_gid = 3;
- // move mod group in temp place to 2
- $db->query('UPDATE '.$db->prefix.'groups SET g_id = 2 WHERE g_id = '.$temp_id);
- $db->query('UPDATE '.$db->prefix.'users SET group_id = 2 WHERE group_id = '.$temp_id);
- $db->query('UPDATE '.$db->prefix.'forum_perms SET group_id = 2 WHERE group_id = '.$temp_id);
- if ($member_gid == $temp_id) $member_gid = 2;
- // Only move stuff around if it isn't already in the right place
- if ($member_gid != $mod_gid || $member_gid != 4)
- {
- // move members to temp place
- $db->query('UPDATE '.$db->prefix.'groups SET g_id = '.$temp_id.' WHERE g_id = '.$member_gid);
- $db->query('UPDATE '.$db->prefix.'users SET group_id = '.$temp_id.' WHERE group_id = '.$member_gid);
- $db->query('UPDATE '.$db->prefix.'forum_perms SET group_id = '.$temp_id.' WHERE group_id = '.$member_gid);
- // move whoever is in 4 to members place
- $db->query('UPDATE '.$db->prefix.'groups SET g_id = '.$member_gid.' WHERE g_id = 4');
- $db->query('UPDATE '.$db->prefix.'users SET group_id = '.$member_gid.' WHERE group_id = 4');
- $db->query('UPDATE '.$db->prefix.'forum_perms SET group_id = '.$member_gid.' WHERE group_id = 4');
- // move members in temp place to 4
- $db->query('UPDATE '.$db->prefix.'groups SET g_id = 4 WHERE g_id = '.$temp_id);
- $db->query('UPDATE '.$db->prefix.'users SET group_id = 4 WHERE group_id = '.$temp_id);
- $db->query('UPDATE '.$db->prefix.'forum_perms SET group_id = 4 WHERE group_id = '.$temp_id);
- }
- $db->query('UPDATE '.$db->prefix.'config SET conf_value=\''.$member_gid.'\' WHERE conf_name=\'o_default_user_group\'');
- }
- // Server time zone is now simply the default time zone
- if (!array_key_exists('o_default_timezone', $pun_config))
- $db->query('UPDATE '.$db->prefix.'config SET conf_name = \'o_default_timezone\' WHERE conf_name = \'o_server_timezone\'');
- // Increase visit timeout to 30 minutes (only if it hasn't been changed from the default)
- if (!array_key_exists('o_database_revision', $pun_config) && $pun_config['o_timeout_visit'] == '600')
- $db->query('UPDATE '.$db->prefix.'config SET conf_value = \'1800\' WHERE conf_name = \'o_timeout_visit\'');
- // Remove obsolete g_post_polls permission from groups table
- $db->drop_field('groups', 'g_post_polls');
- // Make room for multiple moderator groups
- if (!$db->field_exists('groups', 'g_moderator'))
- {
- // Add g_moderator column to groups table
- $db->add_field('groups', 'g_moderator', 'TINYINT(1)', false, 0, 'g_user_title');
- // Give the moderator group moderator privileges
- $db->query('UPDATE '.$db->prefix.'groups SET g_moderator = 1 WHERE g_id = 2');
- }
- // Replace obsolete p_mod_edit_users config setting with new per-group permission
- if (array_key_exists('p_mod_edit_users', $pun_config))
- {
- $db->query('DELETE FROM '.$db->prefix.'config WHERE conf_name = \'p_mod_edit_users\'');
- $db->add_field('groups', 'g_mod_edit_users', 'TINYINT(1)', false, 0, 'g_moderator');
- $db->query('UPDATE '.$db->prefix.'groups SET g_mod_edit_users = '.$pun_config['p_mod_edit_users'].' WHERE g_moderator = 1');
- }
- // Replace obsolete p_mod_rename_users config setting with new per-group permission
- if (array_key_exists('p_mod_rename_users', $pun_config))
- {
- $db->query('DELETE FROM '.$db->prefix.'config WHERE conf_name = \'p_mod_rename_users\'');
- $db->add_field('groups', 'g_mod_rename_users', 'TINYINT(1)', false, 0, 'g_mod_edit_users');
- $db->query('UPDATE '.$db->prefix.'groups SET g_mod_rename_users = '.$pun_config['p_mod_rename_users'].' WHERE g_moderator = 1');
- }
- // Replace obsolete p_mod_change_passwords config setting with new per-group permission
- if (array_key_exists('p_mod_change_passwords', $pun_config))
- {
- $db->query('DELETE FROM '.$db->prefix.'config WHERE conf_name = \'p_mod_change_passwords\'');
- $db->add_field('groups', 'g_mod_change_passwords', 'TINYINT(1)', false, 0, 'g_mod_rename_users');
- $db->query('UPDATE '.$db->prefix.'groups SET g_mod_change_passwords = '.$pun_config['p_mod_change_passwords'].' WHERE g_moderator = 1');
- }
- // Replace obsolete p_mod_ban_users config setting with new per-group permission
- if (array_key_exists('p_mod_ban_users', $pun_config))
- {
- $db->query('DELETE FROM '.$db->prefix.'config WHERE conf_name = \'p_mod_ban_users\'');
- $db->add_field('groups', 'g_mod_ban_users', 'TINYINT(1)', false, 0, 'g_mod_change_passwords');
- $db->query('UPDATE '.$db->prefix.'groups SET g_mod_ban_users = '.$pun_config['p_mod_ban_users'].' WHERE g_moderator = 1');
- }
- // We need to add a unique index to avoid users having multiple rows in the online table
- if (!$db->index_exists('online', 'user_id_ident_idx'))
- {
- $db->truncate_table('online');
- if ($mysql)
- $db->add_index('online', 'user_id_ident_idx', array('user_id', 'ident(25)'), true);
- else
- $db->add_index('online', 'user_id_ident_idx', array('user_id', 'ident'), true);
- }
- // Remove the redundant user_id_idx on the online table
- $db->drop_index('online', 'user_id_idx');
- // Add an index to ident on the online table
- if ($mysql)
- $db->add_index('online', 'ident_idx', array('ident(25)'));
- else
- $db->add_index('online', 'ident_idx', array('ident'));
- // Add an index to logged in the online table
- $db->add_index('online', 'logged_idx', array('logged'));
- // Add an index to last_post in the topics table
- $db->add_index('topics', 'last_post_idx', array('last_post'));
- // Add an index to username on the bans table
- if ($mysql)
- $db->add_index('bans', 'username_idx', array('username(25)'));
- else
- $db->add_index('bans', 'username_idx', array('username'));
- // Change the username_idx on users to a unique index of max size 25
- $db->drop_index('users', 'username_idx');
- $field = $mysql ? 'username(25)' : 'username';
- // Attempt to add a unique index. If the user doesn't use a transactional database this can fail due to multiple matching usernames in the
- // users table. This is bad, but just giving up if it happens is even worse! If it fails just add a regular non-unique index.
- if (!$db->add_index('users', 'username_idx', array($field), true))
- $db->add_index('users', 'username_idx', array($field));
- // Add g_view_users field to groups table
- $db->add_field('groups', 'g_view_users', 'TINYINT(1)', false, 1, 'g_read_board');
- // Add the last_email_sent column to the users table and the g_send_email and
- // g_email_flood columns to the groups table
- $db->add_field('users', 'last_email_sent', 'INT(10) UNSIGNED', true, null, 'last_search');
- $db->add_field('groups', 'g_send_email', 'TINYINT(1)', false, 1, 'g_search_users');
- $db->add_field('groups', 'g_email_flood', 'SMALLINT(6)', false, 60, 'g_search_flood');
- // Set non-default g_send_email and g_flood_email values properly
- $db->query('UPDATE '.$db->prefix.'groups SET g_send_email = 0 WHERE g_id = 3');
- $db->query('UPDATE '.$db->prefix.'groups SET g_email_flood = 0 WHERE g_id IN (1,2,3)');
- // Add the auto notify/subscription option to the users table
- $db->add_field('users', 'auto_notify', 'TINYINT(1)', false, 1, 'notify_with_post');
- // Change the auto_notify field default value to '1' (in FluxBB 1.4 it is '0' by default)
- $db->alter_field('users', 'auto_notify', 'TINYINT(1)', false, 1);
- // Add the first_post_id column to the topics table
- if (!$db->field_exists('topics', 'first_post_id'))
- {
- $db->add_field('topics', 'first_post_id', 'INT(10) UNSIGNED', false, 0, 'posted');
- $db->add_index('topics', 'first_post_id_idx', array('first_post_id'));
- // Now that we've added the column and indexed it, we need to give it correct data
- $result = $db->query('SELECT MIN(id) AS first_post, topic_id FROM '.$db->prefix.'posts GROUP BY topic_id');
- while ($cur_post = $db->fetch_assoc($result))
- $db->query('UPDATE '.$db->prefix.'topics SET first_post_id = '.$cur_post['first_post'].' WHERE id = '.$cur_post['topic_id']);
- }
- // Move any users with the old unverified status to their new group
- $db->query('UPDATE '.$db->prefix.'users SET group_id=0 WHERE group_id=32000');
- // Add the ban_creator column to the bans table
- $db->add_field('bans', 'ban_creator', 'INT(10) UNSIGNED', false, 0);
- // Add the time/date format settings to the user table
- $db->add_field('users', 'time_format', 'TINYINT(1)', false, 0, 'dst');
- $db->add_field('users', 'date_format', 'TINYINT(1)', false, 0, 'dst');
- // Change the search_data field to mediumtext
- $db->alter_field('search_cache', 'search_data', 'MEDIUMTEXT', true);
- // Incase we had the fulltext search extension installed (1.3-legacy), remove it
- $db->drop_index('topics', 'subject_idx');
- $db->drop_index('posts', 'message_idx');
- // Incase we had the fulltext search mod installed (1.2), remove it
- $db->drop_index('topics', 'subject_fulltext_search');
- $db->drop_index('posts', 'message_fulltext_search');
- // If the search_cache table has been dropped by the fulltext search extension, recreate it
- if (!$db->table_exists('search_cache'))
- {
- $schema = array(
- 'FIELDS' => array(
- 'id' => array(
- 'datatype' => 'INT(10) UNSIGNED',
- 'allow_null' => false,
- 'default' => '0'
- ),
- 'ident' => array(
- 'datatype' => 'VARCHAR(200)',
- 'allow_null' => false,
- 'default' => '\'\''
- ),
- 'search_data' => array(
- 'datatype' => 'MEDIUMTEXT',
- 'allow_null' => true
- )
- ),
- 'PRIMARY KEY' => array('id'),
- 'INDEXES' => array(
- 'ident_idx' => array('ident')
- )
- );
- if ($db_type == 'mysql' || $db_type == 'mysqli' || $db_type == 'mysql_innodb' || $db_type == 'mysqli_innodb')
- $schema['INDEXES']['ident_idx'] = array('ident(8)');
- $db->create_table('search_cache', $schema);
- }
- // If the search_matches table has been dropped by the fulltext search extension, recreate it
- if (!$db->table_exists('search_matches'))
- {
- $schema = array(
- 'FIELDS' => array(
- 'post_id' => array(
- 'datatype' => 'INT(10) UNSIGNED',
- 'allow_null' => false,
- 'default' => '0'
- ),
- 'word_id' => array(
- 'datatype' => 'INT(10) UNSIGNED',
- 'allow_null' => false,
- 'default' => '0'
- ),
- 'subject_match' => array(
- 'datatype' => 'TINYINT(1)',
- 'allow_null' => false,
- 'default' => '0'
- )
- ),
- 'INDEXES' => array(
- 'word_id_idx' => array('word_id'),
- …
Large files files are truncated, but you can click here to view the full file