1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/install/database_update.php Wed Mar 07 16:41:10 2012 +0400
1.3 @@ -0,0 +1,2030 @@
1.4 +<?php
1.5 +/**
1.6 +*
1.7 +* @package install
1.8 +* @version $Id$
1.9 +* @copyright (c) 2006 phpBB Group
1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
1.11 +*
1.12 +*/
1.13 +
1.14 +define('UPDATES_TO_VERSION', '3.0.10');
1.15 +
1.16 +// Enter any version to update from to test updates. The version within the db will not be updated.
1.17 +define('DEBUG_FROM_VERSION', false);
1.18 +
1.19 +// Which oldest version does this updater support?
1.20 +define('OLDEST_FROM_VERSION', '3.0.0');
1.21 +
1.22 +// Return if we "just include it" to find out for which version the database update is responsible for
1.23 +if (defined('IN_PHPBB') && defined('IN_INSTALL'))
1.24 +{
1.25 + $updates_to_version = UPDATES_TO_VERSION;
1.26 + $debug_from_version = DEBUG_FROM_VERSION;
1.27 + $oldest_from_version = OLDEST_FROM_VERSION;
1.28 +
1.29 + return;
1.30 +}
1.31 +
1.32 +/**
1.33 +*/
1.34 +define('IN_PHPBB', true);
1.35 +define('IN_INSTALL', true);
1.36 +
1.37 +$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../';
1.38 +$phpEx = substr(strrchr(__FILE__, '.'), 1);
1.39 +
1.40 +if (!function_exists('phpbb_require_updated'))
1.41 +{
1.42 + function phpbb_require_updated($path, $optional = false)
1.43 + {
1.44 + global $phpbb_root_path;
1.45 +
1.46 + $new_path = $phpbb_root_path . 'install/update/new/' . $path;
1.47 + $old_path = $phpbb_root_path . $path;
1.48 +
1.49 + if (file_exists($new_path))
1.50 + {
1.51 + require($new_path);
1.52 + }
1.53 + else if (!$optional || file_exists($old_path))
1.54 + {
1.55 + require($old_path);
1.56 + }
1.57 + }
1.58 +}
1.59 +
1.60 +phpbb_require_updated('includes/startup.' . $phpEx);
1.61 +
1.62 +$updates_to_version = UPDATES_TO_VERSION;
1.63 +$debug_from_version = DEBUG_FROM_VERSION;
1.64 +$oldest_from_version = OLDEST_FROM_VERSION;
1.65 +
1.66 +error_reporting(E_ALL);
1.67 +
1.68 +@set_time_limit(0);
1.69 +
1.70 +// Include essential scripts
1.71 +include($phpbb_root_path . 'config.' . $phpEx);
1.72 +
1.73 +if (!defined('PHPBB_INSTALLED') || empty($dbms) || empty($acm_type))
1.74 +{
1.75 + die("Please read: <a href='../docs/INSTALL.html'>INSTALL.html</a> before attempting to update.");
1.76 +}
1.77 +
1.78 +// Load Extensions
1.79 +if (!empty($load_extensions) && function_exists('dl'))
1.80 +{
1.81 + $load_extensions = explode(',', $load_extensions);
1.82 +
1.83 + foreach ($load_extensions as $extension)
1.84 + {
1.85 + @dl(trim($extension));
1.86 + }
1.87 +}
1.88 +
1.89 +// Include files
1.90 +require($phpbb_root_path . 'includes/acm/acm_' . $acm_type . '.' . $phpEx);
1.91 +require($phpbb_root_path . 'includes/cache.' . $phpEx);
1.92 +require($phpbb_root_path . 'includes/template.' . $phpEx);
1.93 +require($phpbb_root_path . 'includes/session.' . $phpEx);
1.94 +require($phpbb_root_path . 'includes/auth.' . $phpEx);
1.95 +
1.96 +require($phpbb_root_path . 'includes/functions.' . $phpEx);
1.97 +
1.98 +phpbb_require_updated('includes/functions_content.' . $phpEx, true);
1.99 +
1.100 +require($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
1.101 +require($phpbb_root_path . 'includes/constants.' . $phpEx);
1.102 +require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
1.103 +require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
1.104 +
1.105 +phpbb_require_updated('includes/db/db_tools.' . $phpEx);
1.106 +
1.107 +// new table constants are separately defined here in case the updater is run
1.108 +// before the files are updated
1.109 +if (!defined('LOGIN_ATTEMPT_TABLE'))
1.110 +{
1.111 + define('LOGIN_ATTEMPT_TABLE', $table_prefix . 'login_attempts');
1.112 +}
1.113 +
1.114 +$user = new user();
1.115 +$cache = new cache();
1.116 +$db = new $sql_db();
1.117 +
1.118 +// Add own hook handler, if present. :o
1.119 +if (file_exists($phpbb_root_path . 'includes/hooks/index.' . $phpEx))
1.120 +{
1.121 + require($phpbb_root_path . 'includes/hooks/index.' . $phpEx);
1.122 + $phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('template', 'display')));
1.123 +
1.124 + foreach ($cache->obtain_hooks() as $hook)
1.125 + {
1.126 + @include($phpbb_root_path . 'includes/hooks/' . $hook . '.' . $phpEx);
1.127 + }
1.128 +}
1.129 +else
1.130 +{
1.131 + $phpbb_hook = false;
1.132 +}
1.133 +
1.134 +// Connect to DB
1.135 +$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false);
1.136 +
1.137 +// We do not need this any longer, unset for safety purposes
1.138 +unset($dbpasswd);
1.139 +
1.140 +$user->ip = (!empty($_SERVER['REMOTE_ADDR'])) ? htmlspecialchars($_SERVER['REMOTE_ADDR']) : '';
1.141 +$user->ip = (stripos($user->ip, '::ffff:') === 0) ? substr($user->ip, 7) : $user->ip;
1.142 +
1.143 +$sql = "SELECT config_value
1.144 + FROM " . CONFIG_TABLE . "
1.145 + WHERE config_name = 'default_lang'";
1.146 +$result = $db->sql_query($sql);
1.147 +$row = $db->sql_fetchrow($result);
1.148 +$db->sql_freeresult($result);
1.149 +
1.150 +$language = basename(request_var('language', ''));
1.151 +
1.152 +if (!$language)
1.153 +{
1.154 + $language = $row['config_value'];
1.155 +}
1.156 +
1.157 +if (!file_exists($phpbb_root_path . 'language/' . $language))
1.158 +{
1.159 + die('No language found!');
1.160 +}
1.161 +
1.162 +// And finally, load the relevant language files
1.163 +include($phpbb_root_path . 'language/' . $language . '/common.' . $phpEx);
1.164 +include($phpbb_root_path . 'language/' . $language . '/acp/common.' . $phpEx);
1.165 +include($phpbb_root_path . 'language/' . $language . '/install.' . $phpEx);
1.166 +
1.167 +// Set PHP error handler to ours
1.168 +//set_error_handler('msg_handler');
1.169 +
1.170 +// Define some variables for the database update
1.171 +$inline_update = (request_var('type', 0)) ? true : false;
1.172 +
1.173 +// To let set_config() calls succeed, we need to make the config array available globally
1.174 +$config = array();
1.175 +
1.176 +$sql = 'SELECT *
1.177 + FROM ' . CONFIG_TABLE;
1.178 +$result = $db->sql_query($sql);
1.179 +
1.180 +while ($row = $db->sql_fetchrow($result))
1.181 +{
1.182 + $config[$row['config_name']] = $row['config_value'];
1.183 +}
1.184 +$db->sql_freeresult($result);
1.185 +
1.186 +// phpbb_db_tools will be taken from new files (under install/update/new)
1.187 +// if possible, falling back to the board's copy.
1.188 +$db_tools = new phpbb_db_tools($db, true);
1.189 +
1.190 +$database_update_info = database_update_info();
1.191 +
1.192 +$error_ary = array();
1.193 +$errored = false;
1.194 +
1.195 +header('Content-type: text/html; charset=UTF-8');
1.196 +
1.197 +?>
1.198 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1.199 +<html xmlns="http://www.w3.org/1999/xhtml" dir="<?php echo $lang['DIRECTION']; ?>" lang="<?php echo $lang['USER_LANG']; ?>" xml:lang="<?php echo $lang['USER_LANG']; ?>">
1.200 +<head>
1.201 +
1.202 +<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
1.203 +<meta http-equiv="content-language" content="<?php echo $lang['USER_LANG']; ?>" />
1.204 +<meta http-equiv="content-style-type" content="text/css" />
1.205 +<meta http-equiv="imagetoolbar" content="no" />
1.206 +
1.207 +<title><?php echo $lang['UPDATING_TO_LATEST_STABLE']; ?></title>
1.208 +
1.209 +<link href="../adm/style/admin.css" rel="stylesheet" type="text/css" media="screen" />
1.210 +
1.211 +</head>
1.212 +
1.213 +<body>
1.214 +<div id="wrap">
1.215 + <div id="page-header"> </div>
1.216 +
1.217 + <div id="page-body">
1.218 + <div id="acp">
1.219 + <div class="panel">
1.220 + <span class="corners-top"><span></span></span>
1.221 + <div id="content">
1.222 + <div id="main" class="install-body">
1.223 +
1.224 + <h1><?php echo $lang['UPDATING_TO_LATEST_STABLE']; ?></h1>
1.225 +
1.226 + <br />
1.227 +
1.228 + <p><?php echo $lang['DATABASE_TYPE']; ?> :: <strong><?php echo $db->sql_layer; ?></strong><br />
1.229 +<?php
1.230 +
1.231 +if ($debug_from_version !== false)
1.232 +{
1.233 + $config['version'] = $debug_from_version;
1.234 +}
1.235 +
1.236 +echo $lang['PREVIOUS_VERSION'] . ' :: <strong>' . $config['version'] . '</strong><br />';
1.237 +echo $lang['UPDATED_VERSION'] . ' :: <strong>' . $updates_to_version . '</strong></p>';
1.238 +
1.239 +$current_version = str_replace('rc', 'RC', strtolower($config['version']));
1.240 +$latest_version = str_replace('rc', 'RC', strtolower($updates_to_version));
1.241 +$orig_version = $config['version'];
1.242 +
1.243 +// Fill DB version
1.244 +if (empty($config['dbms_version']))
1.245 +{
1.246 + set_config('dbms_version', $db->sql_server_info(true));
1.247 +}
1.248 +
1.249 +// Firebird update from Firebird 2.0 to 2.1+ required?
1.250 +if ($db->sql_layer == 'firebird')
1.251 +{
1.252 + // We do not trust any PHP5 function enabled, we will simply test for a function new in 2.1
1.253 + $db->sql_return_on_error(true);
1.254 +
1.255 + $sql = 'SELECT 1 FROM RDB$DATABASE
1.256 + WHERE BIN_AND(10, 1) = 0';
1.257 + $result = $db->sql_query($sql);
1.258 +
1.259 + if (!$result || $db->sql_error_triggered)
1.260 + {
1.261 + echo '<br /><br />';
1.262 + echo '<h1>' . $lang['ERROR'] . '</h1><br />';
1.263 +
1.264 + echo '<p>' . $lang['FIREBIRD_DBMS_UPDATE_REQUIRED'] . '</p>';
1.265 +
1.266 + _print_footer();
1.267 +
1.268 + exit_handler();
1.269 + exit;
1.270 + }
1.271 +
1.272 + $db->sql_freeresult($result);
1.273 + $db->sql_return_on_error(false);
1.274 +}
1.275 +
1.276 +// MySQL update from MySQL 3.x/4.x to > 4.1.x required?
1.277 +if ($db->sql_layer == 'mysql' || $db->sql_layer == 'mysql4' || $db->sql_layer == 'mysqli')
1.278 +{
1.279 + // Verify by fetching column... if the column type matches the new type we update dbms_version...
1.280 + $sql = "SHOW COLUMNS FROM " . CONFIG_TABLE;
1.281 + $result = $db->sql_query($sql);
1.282 +
1.283 + $column_type = '';
1.284 + while ($row = $db->sql_fetchrow($result))
1.285 + {
1.286 + $field = strtolower($row['Field']);
1.287 +
1.288 + if ($field == 'config_value')
1.289 + {
1.290 + $column_type = strtolower($row['Type']);
1.291 + break;
1.292 + }
1.293 + }
1.294 + $db->sql_freeresult($result);
1.295 +
1.296 + // If column type is blob, but mysql version says we are on > 4.1.3, then the schema needs an update
1.297 + if (strpos($column_type, 'blob') !== false && version_compare($db->sql_server_info(true), '4.1.3', '>='))
1.298 + {
1.299 + echo '<br /><br />';
1.300 + echo '<h1>' . $lang['ERROR'] . '</h1><br />';
1.301 +
1.302 + echo '<p>' . sprintf($lang['MYSQL_SCHEMA_UPDATE_REQUIRED'], $config['dbms_version'], $db->sql_server_info(true)) . '</p>';
1.303 +
1.304 + _print_footer();
1.305 +
1.306 + exit_handler();
1.307 + exit;
1.308 + }
1.309 +}
1.310 +
1.311 +// Now check if the user wants to update from a version we no longer support updates from
1.312 +if (version_compare($current_version, $oldest_from_version, '<'))
1.313 +{
1.314 + echo '<br /><br /><h1>' . $lang['ERROR'] . '</h1><br />';
1.315 + echo '<p>' . sprintf($lang['DB_UPDATE_NOT_SUPPORTED'], $oldest_from_version, $current_version) . '</p>';
1.316 +
1.317 + _print_footer();
1.318 + exit_handler();
1.319 + exit;
1.320 +}
1.321 +
1.322 +// If the latest version and the current version are 'unequal', we will update the version_update_from, else we do not update anything.
1.323 +if ($inline_update)
1.324 +{
1.325 + if ($current_version !== $latest_version)
1.326 + {
1.327 + set_config('version_update_from', $orig_version);
1.328 + }
1.329 +}
1.330 +else
1.331 +{
1.332 + // If not called from the update script, we will actually remove the traces
1.333 + $db->sql_query('DELETE FROM ' . CONFIG_TABLE . " WHERE config_name = 'version_update_from'");
1.334 +}
1.335 +
1.336 +// Schema updates
1.337 +?>
1.338 + <br /><br />
1.339 +
1.340 + <h1><?php echo $lang['UPDATE_DATABASE_SCHEMA']; ?></h1>
1.341 +
1.342 + <br />
1.343 + <p><?php echo $lang['PROGRESS']; ?> :: <strong>
1.344 +
1.345 +<?php
1.346 +
1.347 +flush();
1.348 +
1.349 +// We go through the schema changes from the lowest to the highest version
1.350 +// We try to also include versions 'in-between'...
1.351 +$no_updates = true;
1.352 +$versions = array_keys($database_update_info);
1.353 +for ($i = 0; $i < sizeof($versions); $i++)
1.354 +{
1.355 + $version = $versions[$i];
1.356 + $schema_changes = $database_update_info[$version];
1.357 +
1.358 + $next_version = (isset($versions[$i + 1])) ? $versions[$i + 1] : $updates_to_version;
1.359 +
1.360 + // If the installed version to be updated to is < than the current version, and if the current version is >= as the version to be updated to next, we will skip the process
1.361 + if (version_compare($version, $current_version, '<') && version_compare($current_version, $next_version, '>='))
1.362 + {
1.363 + continue;
1.364 + }
1.365 +
1.366 + if (!sizeof($schema_changes))
1.367 + {
1.368 + continue;
1.369 + }
1.370 +
1.371 + $no_updates = false;
1.372 +
1.373 + // We run one index after the other... to be consistent with schema changes...
1.374 + foreach ($schema_changes as $key => $changes)
1.375 + {
1.376 + $statements = $db_tools->perform_schema_changes(array($key => $changes));
1.377 +
1.378 + foreach ($statements as $sql)
1.379 + {
1.380 + _sql($sql, $errored, $error_ary);
1.381 + }
1.382 + }
1.383 +}
1.384 +
1.385 +_write_result($no_updates, $errored, $error_ary);
1.386 +
1.387 +// Data updates
1.388 +$error_ary = array();
1.389 +$errored = $no_updates = false;
1.390 +
1.391 +?>
1.392 +
1.393 +<br /><br />
1.394 +<h1><?php echo $lang['UPDATING_DATA']; ?></h1>
1.395 +<br />
1.396 +<p><?php echo $lang['PROGRESS']; ?> :: <strong>
1.397 +
1.398 +<?php
1.399 +
1.400 +flush();
1.401 +
1.402 +$no_updates = true;
1.403 +$versions = array_keys($database_update_info);
1.404 +
1.405 +// some code magic
1.406 +for ($i = 0; $i < sizeof($versions); $i++)
1.407 +{
1.408 + $version = $versions[$i];
1.409 + $next_version = (isset($versions[$i + 1])) ? $versions[$i + 1] : $updates_to_version;
1.410 +
1.411 + // If the installed version to be updated to is < than the current version, and if the current version is >= as the version to be updated to next, we will skip the process
1.412 + if (version_compare($version, $current_version, '<') && version_compare($current_version, $next_version, '>='))
1.413 + {
1.414 + continue;
1.415 + }
1.416 +
1.417 + change_database_data($no_updates, $version);
1.418 +}
1.419 +
1.420 +_write_result($no_updates, $errored, $error_ary);
1.421 +
1.422 +$error_ary = array();
1.423 +$errored = $no_updates = false;
1.424 +
1.425 +?>
1.426 +
1.427 +<br /><br />
1.428 +<h1><?php echo $lang['UPDATE_VERSION_OPTIMIZE']; ?></h1>
1.429 +<br />
1.430 +<p><?php echo $lang['PROGRESS']; ?> :: <strong>
1.431 +
1.432 +<?php
1.433 +
1.434 +flush();
1.435 +
1.436 +if ($debug_from_version === false)
1.437 +{
1.438 + // update the version
1.439 + $sql = "UPDATE " . CONFIG_TABLE . "
1.440 + SET config_value = '$updates_to_version'
1.441 + WHERE config_name = 'version'";
1.442 + _sql($sql, $errored, $error_ary);
1.443 +}
1.444 +
1.445 +// Reset permissions
1.446 +$sql = 'UPDATE ' . USERS_TABLE . "
1.447 + SET user_permissions = '',
1.448 + user_perm_from = 0";
1.449 +_sql($sql, $errored, $error_ary);
1.450 +
1.451 +// Update the dbms version if everything is ok...
1.452 +set_config('dbms_version', $db->sql_server_info(true));
1.453 +
1.454 +/* Optimize/vacuum analyze the tables where appropriate
1.455 +// this should be done for each version in future along with
1.456 +// the version number update
1.457 +switch ($db->sql_layer)
1.458 +{
1.459 + case 'mysql':
1.460 + case 'mysqli':
1.461 + case 'mysql4':
1.462 + $sql = 'OPTIMIZE TABLE ' . $table_prefix . 'auth_access, ' . $table_prefix . 'banlist, ' . $table_prefix . 'categories, ' . $table_prefix . 'config, ' . $table_prefix . 'disallow, ' . $table_prefix . 'forum_prune, ' . $table_prefix . 'forums, ' . $table_prefix . 'groups, ' . $table_prefix . 'posts, ' . $table_prefix . 'posts_text, ' . $table_prefix . 'privmsgs, ' . $table_prefix . 'privmsgs_text, ' . $table_prefix . 'ranks, ' . $table_prefix . 'search_results, ' . $table_prefix . 'search_wordlist, ' . $table_prefix . 'search_wordmatch, ' . $table_prefix . 'sessions_keys' . $table_prefix . 'smilies, ' . $table_prefix . 'themes, ' . $table_prefix . 'themes_name, ' . $table_prefix . 'topics, ' . $table_prefix . 'topics_watch, ' . $table_prefix . 'user_group, ' . $table_prefix . 'users, ' . $table_prefix . 'vote_desc, ' . $table_prefix . 'vote_results, ' . $table_prefix . 'vote_voters, ' . $table_prefix . 'words';
1.463 + _sql($sql, $errored, $error_ary);
1.464 + break;
1.465 +
1.466 + case 'postgresql':
1.467 + _sql("VACUUM ANALYZE", $errored, $error_ary);
1.468 + break;
1.469 +}
1.470 +*/
1.471 +
1.472 +_write_result($no_updates, $errored, $error_ary);
1.473 +
1.474 +?>
1.475 +
1.476 +<br />
1.477 +<h1><?php echo $lang['UPDATE_COMPLETED']; ?></h1>
1.478 +
1.479 +<br />
1.480 +
1.481 +<?php
1.482 +
1.483 +if (!$inline_update)
1.484 +{
1.485 +?>
1.486 +
1.487 + <p style="color:red"><?php echo $lang['UPDATE_FILES_NOTICE']; ?></p>
1.488 +
1.489 + <p><?php echo $lang['COMPLETE_LOGIN_TO_BOARD']; ?></p>
1.490 +
1.491 +<?php
1.492 +}
1.493 +else
1.494 +{
1.495 +?>
1.496 +
1.497 + <p><?php echo ((isset($lang['INLINE_UPDATE_SUCCESSFUL'])) ? $lang['INLINE_UPDATE_SUCCESSFUL'] : 'The database update was successful. Now you need to continue the update process.'); ?></p>
1.498 +
1.499 + <p><a href="<?php echo append_sid("{$phpbb_root_path}install/index.{$phpEx}", "mode=update&sub=file_check&language=$language"); ?>" class="button1"><?php echo (isset($lang['CONTINUE_UPDATE_NOW'])) ? $lang['CONTINUE_UPDATE_NOW'] : 'Continue the update process now'; ?></a></p>
1.500 +
1.501 +<?php
1.502 +}
1.503 +
1.504 +// Add database update to log
1.505 +add_log('admin', 'LOG_UPDATE_DATABASE', $orig_version, $updates_to_version);
1.506 +
1.507 +// Now we purge the session table as well as all cache files
1.508 +$cache->purge();
1.509 +
1.510 +_print_footer();
1.511 +
1.512 +garbage_collection();
1.513 +
1.514 +if (function_exists('exit_handler'))
1.515 +{
1.516 + exit_handler();
1.517 +}
1.518 +
1.519 +/**
1.520 +* Print out footer
1.521 +*/
1.522 +function _print_footer()
1.523 +{
1.524 + echo <<<EOF
1.525 + </div>
1.526 + </div>
1.527 + <span class="corners-bottom"><span></span></span>
1.528 + </div>
1.529 + </div>
1.530 + </div>
1.531 +
1.532 + <div id="page-footer">
1.533 + Powered by <a href="http://www.phpbb.com/">phpBB</a>® Forum Software © phpBB Group
1.534 + </div>
1.535 +</div>
1.536 +
1.537 +</body>
1.538 +</html>
1.539 +EOF;
1.540 +}
1.541 +
1.542 +/**
1.543 +* Function for triggering an sql statement
1.544 +*/
1.545 +function _sql($sql, &$errored, &$error_ary, $echo_dot = true)
1.546 +{
1.547 + global $db;
1.548 +
1.549 + if (defined('DEBUG_EXTRA'))
1.550 + {
1.551 + echo "<br />\n{$sql}\n<br />";
1.552 + }
1.553 +
1.554 + $db->sql_return_on_error(true);
1.555 +
1.556 + if ($sql === 'begin')
1.557 + {
1.558 + $result = $db->sql_transaction('begin');
1.559 + }
1.560 + else if ($sql === 'commit')
1.561 + {
1.562 + $result = $db->sql_transaction('commit');
1.563 + }
1.564 + else
1.565 + {
1.566 + $result = $db->sql_query($sql);
1.567 + if ($db->sql_error_triggered)
1.568 + {
1.569 + $errored = true;
1.570 + $error_ary['sql'][] = $db->sql_error_sql;
1.571 + $error_ary['error_code'][] = $db->sql_error_returned;
1.572 + }
1.573 + }
1.574 +
1.575 + $db->sql_return_on_error(false);
1.576 +
1.577 + if ($echo_dot)
1.578 + {
1.579 + echo ". \n";
1.580 + flush();
1.581 + }
1.582 +
1.583 + return $result;
1.584 +}
1.585 +
1.586 +function _write_result($no_updates, $errored, $error_ary)
1.587 +{
1.588 + global $lang;
1.589 +
1.590 + if ($no_updates)
1.591 + {
1.592 + echo ' ' . $lang['NO_UPDATES_REQUIRED'] . '</strong></p>';
1.593 + }
1.594 + else
1.595 + {
1.596 + echo ' <span class="success">' . $lang['DONE'] . '</span></strong><br />' . $lang['RESULT'] . ' :: ';
1.597 +
1.598 + if ($errored)
1.599 + {
1.600 + echo ' <strong>' . $lang['SOME_QUERIES_FAILED'] . '</strong> <ul>';
1.601 +
1.602 + for ($i = 0; $i < sizeof($error_ary['sql']); $i++)
1.603 + {
1.604 + echo '<li>' . $lang['ERROR'] . ' :: <strong>' . htmlspecialchars($error_ary['error_code'][$i]['message']) . '</strong><br />';
1.605 + echo $lang['SQL'] . ' :: <strong>' . htmlspecialchars($error_ary['sql'][$i]) . '</strong><br /><br /></li>';
1.606 + }
1.607 +
1.608 + echo '</ul> <br /><br />' . $lang['SQL_FAILURE_EXPLAIN'] . '</p>';
1.609 + }
1.610 + else
1.611 + {
1.612 + echo '<strong>' . $lang['NO_ERRORS'] . '</strong></p>';
1.613 + }
1.614 + }
1.615 +}
1.616 +
1.617 +function _add_modules($modules_to_install)
1.618 +{
1.619 + global $phpbb_root_path, $phpEx, $db;
1.620 +
1.621 + include_once($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx);
1.622 +
1.623 + $_module = new acp_modules();
1.624 +
1.625 + foreach ($modules_to_install as $module_mode => $module_data)
1.626 + {
1.627 + $_module->module_class = $module_data['class'];
1.628 +
1.629 + // Determine parent id first
1.630 + $sql = 'SELECT module_id
1.631 + FROM ' . MODULES_TABLE . "
1.632 + WHERE module_class = '" . $db->sql_escape($module_data['class']) . "'
1.633 + AND module_langname = '" . $db->sql_escape($module_data['cat']) . "'
1.634 + AND module_mode = ''
1.635 + AND module_basename = ''";
1.636 + $result = $db->sql_query($sql);
1.637 +
1.638 + // There may be more than one categories with the same name
1.639 + $categories = array();
1.640 + while ($row = $db->sql_fetchrow($result))
1.641 + {
1.642 + $categories[] = (int) $row['module_id'];
1.643 + }
1.644 + $db->sql_freeresult($result);
1.645 +
1.646 + if (!sizeof($categories))
1.647 + {
1.648 + continue;
1.649 + }
1.650 +
1.651 + // Add the module to all categories found
1.652 + foreach ($categories as $parent_id)
1.653 + {
1.654 + // Check if the module already exists
1.655 + $sql = 'SELECT *
1.656 + FROM ' . MODULES_TABLE . "
1.657 + WHERE module_basename = '" . $db->sql_escape($module_data['base']) . "'
1.658 + AND module_class = '" . $db->sql_escape($module_data['class']) . "'
1.659 + AND module_langname = '" . $db->sql_escape($module_data['title']) . "'
1.660 + AND module_mode = '" . $db->sql_escape($module_mode) . "'
1.661 + AND module_auth = '" . $db->sql_escape($module_data['auth']) . "'
1.662 + AND parent_id = {$parent_id}";
1.663 + $result = $db->sql_query($sql);
1.664 + $row = $db->sql_fetchrow($result);
1.665 + $db->sql_freeresult($result);
1.666 +
1.667 + // If it exists, we simply continue with the next category
1.668 + if ($row)
1.669 + {
1.670 + continue;
1.671 + }
1.672 +
1.673 + // Build the module sql row
1.674 + $module_row = array(
1.675 + 'module_basename' => $module_data['base'],
1.676 + 'module_enabled' => (isset($module_data['enabled'])) ? (int) $module_data['enabled'] : 1,
1.677 + 'module_display' => (isset($module_data['display'])) ? (int) $module_data['display'] : 1,
1.678 + 'parent_id' => $parent_id,
1.679 + 'module_class' => $module_data['class'],
1.680 + 'module_langname' => $module_data['title'],
1.681 + 'module_mode' => $module_mode,
1.682 + 'module_auth' => $module_data['auth'],
1.683 + );
1.684 +
1.685 + $_module->update_module_data($module_row, true);
1.686 +
1.687 + // Ok, do we need to re-order the module, move it up or down?
1.688 + if (!isset($module_data['after']))
1.689 + {
1.690 + continue;
1.691 + }
1.692 +
1.693 + $after_mode = $module_data['after'][0];
1.694 + $after_langname = $module_data['after'][1];
1.695 +
1.696 + // First of all, get the module id for the module this one has to be placed after
1.697 + $sql = 'SELECT left_id
1.698 + FROM ' . MODULES_TABLE . "
1.699 + WHERE module_class = '" . $db->sql_escape($module_data['class']) . "'
1.700 + AND module_basename = '" . $db->sql_escape($module_data['base']) . "'
1.701 + AND module_langname = '" . $db->sql_escape($after_langname) . "'
1.702 + AND module_mode = '" . $db->sql_escape($after_mode) . "'
1.703 + AND parent_id = '{$parent_id}'";
1.704 + $result = $db->sql_query($sql);
1.705 + $first_left_id = (int) $db->sql_fetchfield('left_id');
1.706 + $db->sql_freeresult($result);
1.707 +
1.708 + if (!$first_left_id)
1.709 + {
1.710 + continue;
1.711 + }
1.712 +
1.713 + // Ok, count the number of modules between $after_mode and the added module
1.714 + $sql = 'SELECT COUNT(module_id) as num_modules
1.715 + FROM ' . MODULES_TABLE . "
1.716 + WHERE module_class = '" . $db->sql_escape($module_data['class']) . "'
1.717 + AND parent_id = {$parent_id}
1.718 + AND left_id BETWEEN {$first_left_id} AND {$module_row['left_id']}";
1.719 + $result = $db->sql_query($sql);
1.720 + $steps = (int) $db->sql_fetchfield('num_modules');
1.721 + $db->sql_freeresult($result);
1.722 +
1.723 + // We need to substract 2
1.724 + $steps -= 2;
1.725 +
1.726 + if ($steps <= 0)
1.727 + {
1.728 + continue;
1.729 + }
1.730 +
1.731 + // Ok, move module up $num_modules times. ;)
1.732 + $_module->move_module_by($module_row, 'move_up', $steps);
1.733 + }
1.734 + }
1.735 +
1.736 + $_module->remove_cache_file();
1.737 +}
1.738 +
1.739 +/****************************************************************************
1.740 +* ADD YOUR DATABASE SCHEMA CHANGES HERE *
1.741 +*****************************************************************************/
1.742 +function database_update_info()
1.743 +{
1.744 + return array(
1.745 + // Changes from 3.0.0 to the next version
1.746 + '3.0.0' => array(
1.747 + // Add the following columns
1.748 + 'add_columns' => array(
1.749 + FORUMS_TABLE => array(
1.750 + 'display_subforum_list' => array('BOOL', 1),
1.751 + ),
1.752 + SESSIONS_TABLE => array(
1.753 + 'session_forum_id' => array('UINT', 0),
1.754 + ),
1.755 + ),
1.756 + 'drop_keys' => array(
1.757 + GROUPS_TABLE => array('group_legend'),
1.758 + ),
1.759 + 'add_index' => array(
1.760 + SESSIONS_TABLE => array(
1.761 + 'session_forum_id' => array('session_forum_id'),
1.762 + ),
1.763 + GROUPS_TABLE => array(
1.764 + 'group_legend_name' => array('group_legend', 'group_name'),
1.765 + ),
1.766 + ),
1.767 + ),
1.768 + // No changes from 3.0.1-RC1 to 3.0.1
1.769 + '3.0.1-RC1' => array(),
1.770 + // No changes from 3.0.1 to 3.0.2-RC1
1.771 + '3.0.1' => array(),
1.772 + // Changes from 3.0.2-RC1 to 3.0.2-RC2
1.773 + '3.0.2-RC1' => array(
1.774 + 'change_columns' => array(
1.775 + DRAFTS_TABLE => array(
1.776 + 'draft_subject' => array('STEXT_UNI', ''),
1.777 + ),
1.778 + FORUMS_TABLE => array(
1.779 + 'forum_last_post_subject' => array('STEXT_UNI', ''),
1.780 + ),
1.781 + POSTS_TABLE => array(
1.782 + 'post_subject' => array('STEXT_UNI', '', 'true_sort'),
1.783 + ),
1.784 + PRIVMSGS_TABLE => array(
1.785 + 'message_subject' => array('STEXT_UNI', ''),
1.786 + ),
1.787 + TOPICS_TABLE => array(
1.788 + 'topic_title' => array('STEXT_UNI', '', 'true_sort'),
1.789 + 'topic_last_post_subject' => array('STEXT_UNI', ''),
1.790 + ),
1.791 + ),
1.792 + 'drop_keys' => array(
1.793 + SESSIONS_TABLE => array('session_forum_id'),
1.794 + ),
1.795 + 'add_index' => array(
1.796 + SESSIONS_TABLE => array(
1.797 + 'session_fid' => array('session_forum_id'),
1.798 + ),
1.799 + ),
1.800 + ),
1.801 + // No changes from 3.0.2-RC2 to 3.0.2
1.802 + '3.0.2-RC2' => array(),
1.803 +
1.804 + // Changes from 3.0.2 to 3.0.3-RC1
1.805 + '3.0.2' => array(
1.806 + // Add the following columns
1.807 + 'add_columns' => array(
1.808 + STYLES_TEMPLATE_TABLE => array(
1.809 + 'template_inherits_id' => array('UINT:4', 0),
1.810 + 'template_inherit_path' => array('VCHAR', ''),
1.811 + ),
1.812 + GROUPS_TABLE => array(
1.813 + 'group_max_recipients' => array('UINT', 0),
1.814 + ),
1.815 + ),
1.816 + ),
1.817 +
1.818 + // No changes from 3.0.3-RC1 to 3.0.3
1.819 + '3.0.3-RC1' => array(),
1.820 +
1.821 + // Changes from 3.0.3 to 3.0.4-RC1
1.822 + '3.0.3' => array(
1.823 + 'add_columns' => array(
1.824 + PROFILE_FIELDS_TABLE => array(
1.825 + 'field_show_profile' => array('BOOL', 0),
1.826 + ),
1.827 + ),
1.828 + 'change_columns' => array(
1.829 + STYLES_TABLE => array(
1.830 + 'style_id' => array('UINT', NULL, 'auto_increment'),
1.831 + 'template_id' => array('UINT', 0),
1.832 + 'theme_id' => array('UINT', 0),
1.833 + 'imageset_id' => array('UINT', 0),
1.834 + ),
1.835 + STYLES_IMAGESET_TABLE => array(
1.836 + 'imageset_id' => array('UINT', NULL, 'auto_increment'),
1.837 + ),
1.838 + STYLES_IMAGESET_DATA_TABLE => array(
1.839 + 'image_id' => array('UINT', NULL, 'auto_increment'),
1.840 + 'imageset_id' => array('UINT', 0),
1.841 + ),
1.842 + STYLES_THEME_TABLE => array(
1.843 + 'theme_id' => array('UINT', NULL, 'auto_increment'),
1.844 + ),
1.845 + STYLES_TEMPLATE_TABLE => array(
1.846 + 'template_id' => array('UINT', NULL, 'auto_increment'),
1.847 + ),
1.848 + STYLES_TEMPLATE_DATA_TABLE => array(
1.849 + 'template_id' => array('UINT', 0),
1.850 + ),
1.851 + FORUMS_TABLE => array(
1.852 + 'forum_style' => array('UINT', 0),
1.853 + ),
1.854 + USERS_TABLE => array(
1.855 + 'user_style' => array('UINT', 0),
1.856 + ),
1.857 + ),
1.858 + ),
1.859 +
1.860 + // Changes from 3.0.4-RC1 to 3.0.4
1.861 + '3.0.4-RC1' => array(),
1.862 +
1.863 + // Changes from 3.0.4 to 3.0.5-RC1
1.864 + '3.0.4' => array(
1.865 + 'change_columns' => array(
1.866 + FORUMS_TABLE => array(
1.867 + 'forum_style' => array('UINT', 0),
1.868 + ),
1.869 + ),
1.870 + ),
1.871 +
1.872 + // No changes from 3.0.5-RC1 to 3.0.5
1.873 + '3.0.5-RC1' => array(),
1.874 +
1.875 + // Changes from 3.0.5 to 3.0.6-RC1
1.876 + '3.0.5' => array(
1.877 + 'add_columns' => array(
1.878 + CONFIRM_TABLE => array(
1.879 + 'attempts' => array('UINT', 0),
1.880 + ),
1.881 + USERS_TABLE => array(
1.882 + 'user_new' => array('BOOL', 1),
1.883 + 'user_reminded' => array('TINT:4', 0),
1.884 + 'user_reminded_time'=> array('TIMESTAMP', 0),
1.885 + ),
1.886 + GROUPS_TABLE => array(
1.887 + 'group_skip_auth' => array('BOOL', 0, 'after' => 'group_founder_manage'),
1.888 + ),
1.889 + PRIVMSGS_TABLE => array(
1.890 + 'message_reported' => array('BOOL', 0),
1.891 + ),
1.892 + REPORTS_TABLE => array(
1.893 + 'pm_id' => array('UINT', 0),
1.894 + ),
1.895 + PROFILE_FIELDS_TABLE => array(
1.896 + 'field_show_on_vt' => array('BOOL', 0),
1.897 + ),
1.898 + FORUMS_TABLE => array(
1.899 + 'forum_options' => array('UINT:20', 0),
1.900 + ),
1.901 + ),
1.902 + 'change_columns' => array(
1.903 + USERS_TABLE => array(
1.904 + 'user_options' => array('UINT:11', 230271),
1.905 + ),
1.906 + ),
1.907 + 'add_index' => array(
1.908 + REPORTS_TABLE => array(
1.909 + 'post_id' => array('post_id'),
1.910 + 'pm_id' => array('pm_id'),
1.911 + ),
1.912 + POSTS_TABLE => array(
1.913 + 'post_username' => array('post_username:255'),
1.914 + ),
1.915 + ),
1.916 + ),
1.917 +
1.918 + // No changes from 3.0.6-RC1 to 3.0.6-RC2
1.919 + '3.0.6-RC1' => array(),
1.920 + // No changes from 3.0.6-RC2 to 3.0.6-RC3
1.921 + '3.0.6-RC2' => array(),
1.922 + // No changes from 3.0.6-RC3 to 3.0.6-RC4
1.923 + '3.0.6-RC3' => array(),
1.924 + // No changes from 3.0.6-RC4 to 3.0.6
1.925 + '3.0.6-RC4' => array(),
1.926 +
1.927 + // Changes from 3.0.6 to 3.0.7-RC1
1.928 + '3.0.6' => array(
1.929 + 'drop_keys' => array(
1.930 + LOG_TABLE => array('log_time'),
1.931 + ),
1.932 + 'add_index' => array(
1.933 + TOPICS_TRACK_TABLE => array(
1.934 + 'topic_id' => array('topic_id'),
1.935 + ),
1.936 + ),
1.937 + ),
1.938 +
1.939 + // No changes from 3.0.7-RC1 to 3.0.7-RC2
1.940 + '3.0.7-RC1' => array(),
1.941 + // No changes from 3.0.7-RC2 to 3.0.7
1.942 + '3.0.7-RC2' => array(),
1.943 + // No changes from 3.0.7 to 3.0.7-PL1
1.944 + '3.0.7' => array(),
1.945 + // No changes from 3.0.7-PL1 to 3.0.8-RC1
1.946 + '3.0.7-PL1' => array(),
1.947 + // No changes from 3.0.8-RC1 to 3.0.8
1.948 + '3.0.8-RC1' => array(),
1.949 + // Changes from 3.0.8 to 3.0.9-RC1
1.950 + '3.0.8' => array(
1.951 + 'add_tables' => array(
1.952 + LOGIN_ATTEMPT_TABLE => array(
1.953 + 'COLUMNS' => array(
1.954 + // this column was removed from the database updater
1.955 + // after 3.0.9-RC3 was released. It might still exist
1.956 + // in 3.0.9-RCX installations and has to be dropped in
1.957 + // 3.0.11 after the db_tools class is capable of properly
1.958 + // removing a primary key.
1.959 + // 'attempt_id' => array('UINT', NULL, 'auto_increment'),
1.960 + 'attempt_ip' => array('VCHAR:40', ''),
1.961 + 'attempt_browser' => array('VCHAR:150', ''),
1.962 + 'attempt_forwarded_for' => array('VCHAR:255', ''),
1.963 + 'attempt_time' => array('TIMESTAMP', 0),
1.964 + 'user_id' => array('UINT', 0),
1.965 + 'username' => array('VCHAR_UNI:255', 0),
1.966 + 'username_clean' => array('VCHAR_CI', 0),
1.967 + ),
1.968 + //'PRIMARY_KEY' => 'attempt_id',
1.969 + 'KEYS' => array(
1.970 + 'att_ip' => array('INDEX', array('attempt_ip', 'attempt_time')),
1.971 + 'att_for' => array('INDEX', array('attempt_forwarded_for', 'attempt_time')),
1.972 + 'att_time' => array('INDEX', array('attempt_time')),
1.973 + 'user_id' => array('INDEX', 'user_id'),
1.974 + ),
1.975 + ),
1.976 + ),
1.977 + 'change_columns' => array(
1.978 + BBCODES_TABLE => array(
1.979 + 'bbcode_id' => array('USINT', 0),
1.980 + ),
1.981 + ),
1.982 + ),
1.983 + // No changes from 3.0.9-RC1 to 3.0.9-RC2
1.984 + '3.0.9-RC1' => array(),
1.985 + // No changes from 3.0.9-RC2 to 3.0.9-RC3
1.986 + '3.0.9-RC2' => array(),
1.987 + // No changes from 3.0.9-RC3 to 3.0.9-RC4
1.988 + '3.0.9-RC3' => array(),
1.989 + // No changes from 3.0.9-RC4 to 3.0.9
1.990 + '3.0.9-RC4' => array(),
1.991 + // No changes from 3.0.9 to 3.0.10-RC1
1.992 + '3.0.9' => array(),
1.993 + // No changes from 3.0.10-RC1 to 3.0.10-RC2
1.994 + '3.0.10-RC1' => array(),
1.995 + // No changes from 3.0.10-RC2 to 3.0.10-RC3
1.996 + '3.0.10-RC2' => array(),
1.997 + // No changes from 3.0.10-RC3 to 3.0.10
1.998 + '3.0.10-RC3' => array(),
1.999 +
1.1000 + /** @todo DROP LOGIN_ATTEMPT_TABLE.attempt_id in 3.0.11-RC1 */
1.1001 + );
1.1002 +}
1.1003 +
1.1004 +/****************************************************************************
1.1005 +* ADD YOUR DATABASE DATA CHANGES HERE *
1.1006 +* REMEMBER: You NEED to enter a schema array above and a data array here, *
1.1007 +* even if both or one of them are empty. *
1.1008 +*****************************************************************************/
1.1009 +function change_database_data(&$no_updates, $version)
1.1010 +{
1.1011 + global $db, $errored, $error_ary, $config, $phpbb_root_path, $phpEx;
1.1012 +
1.1013 + switch ($version)
1.1014 + {
1.1015 + case '3.0.0':
1.1016 +
1.1017 + $sql = 'UPDATE ' . TOPICS_TABLE . "
1.1018 + SET topic_last_view_time = topic_last_post_time
1.1019 + WHERE topic_last_view_time = 0";
1.1020 + _sql($sql, $errored, $error_ary);
1.1021 +
1.1022 + // Update smiley sizes
1.1023 + $smileys = array('icon_e_surprised.gif', 'icon_eek.gif', 'icon_cool.gif', 'icon_lol.gif', 'icon_mad.gif', 'icon_razz.gif', 'icon_redface.gif', 'icon_cry.gif', 'icon_evil.gif', 'icon_twisted.gif', 'icon_rolleyes.gif', 'icon_exclaim.gif', 'icon_question.gif', 'icon_idea.gif', 'icon_arrow.gif', 'icon_neutral.gif', 'icon_mrgreen.gif', 'icon_e_ugeek.gif');
1.1024 +
1.1025 + foreach ($smileys as $smiley)
1.1026 + {
1.1027 + if (file_exists($phpbb_root_path . 'images/smilies/' . $smiley))
1.1028 + {
1.1029 + list($width, $height) = getimagesize($phpbb_root_path . 'images/smilies/' . $smiley);
1.1030 +
1.1031 + $sql = 'UPDATE ' . SMILIES_TABLE . '
1.1032 + SET smiley_width = ' . $width . ', smiley_height = ' . $height . "
1.1033 + WHERE smiley_url = '" . $db->sql_escape($smiley) . "'";
1.1034 +
1.1035 + _sql($sql, $errored, $error_ary);
1.1036 + }
1.1037 + }
1.1038 +
1.1039 + $no_updates = false;
1.1040 + break;
1.1041 +
1.1042 + // No changes from 3.0.1-RC1 to 3.0.1
1.1043 + case '3.0.1-RC1':
1.1044 + break;
1.1045 +
1.1046 + // changes from 3.0.1 to 3.0.2-RC1
1.1047 + case '3.0.1':
1.1048 +
1.1049 + set_config('referer_validation', '1');
1.1050 + set_config('check_attachment_content', '1');
1.1051 + set_config('mime_triggers', 'body|head|html|img|plaintext|a href|pre|script|table|title');
1.1052 +
1.1053 + $no_updates = false;
1.1054 + break;
1.1055 +
1.1056 + // No changes from 3.0.2-RC1 to 3.0.2-RC2
1.1057 + case '3.0.2-RC1':
1.1058 + break;
1.1059 +
1.1060 + // No changes from 3.0.2-RC2 to 3.0.2
1.1061 + case '3.0.2-RC2':
1.1062 + break;
1.1063 +
1.1064 + // Changes from 3.0.2 to 3.0.3-RC1
1.1065 + case '3.0.2':
1.1066 + set_config('enable_queue_trigger', '0');
1.1067 + set_config('queue_trigger_posts', '3');
1.1068 +
1.1069 + set_config('pm_max_recipients', '0');
1.1070 +
1.1071 + // Set maximum number of recipients for the registered users, bots, guests group
1.1072 + $sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_max_recipients = 5
1.1073 + WHERE ' . $db->sql_in_set('group_name', array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA', 'BOTS'));
1.1074 + _sql($sql, $errored, $error_ary);
1.1075 +
1.1076 + // Not prefilling yet
1.1077 + set_config('dbms_version', '');
1.1078 +
1.1079 + // Add new permission u_masspm_group and duplicate settings from u_masspm
1.1080 + include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
1.1081 + $auth_admin = new auth_admin();
1.1082 +
1.1083 + // Only add the new permission if it does not already exist
1.1084 + if (empty($auth_admin->acl_options['id']['u_masspm_group']))
1.1085 + {
1.1086 + $auth_admin->acl_add_option(array('global' => array('u_masspm_group')));
1.1087 +
1.1088 + // Now the tricky part, filling the permission
1.1089 + $old_id = $auth_admin->acl_options['id']['u_masspm'];
1.1090 + $new_id = $auth_admin->acl_options['id']['u_masspm_group'];
1.1091 +
1.1092 + $tables = array(ACL_GROUPS_TABLE, ACL_ROLES_DATA_TABLE, ACL_USERS_TABLE);
1.1093 +
1.1094 + foreach ($tables as $table)
1.1095 + {
1.1096 + $sql = 'SELECT *
1.1097 + FROM ' . $table . '
1.1098 + WHERE auth_option_id = ' . $old_id;
1.1099 + $result = _sql($sql, $errored, $error_ary);
1.1100 +
1.1101 + $sql_ary = array();
1.1102 + while ($row = $db->sql_fetchrow($result))
1.1103 + {
1.1104 + $row['auth_option_id'] = $new_id;
1.1105 + $sql_ary[] = $row;
1.1106 + }
1.1107 + $db->sql_freeresult($result);
1.1108 +
1.1109 + if (sizeof($sql_ary))
1.1110 + {
1.1111 + $db->sql_multi_insert($table, $sql_ary);
1.1112 + }
1.1113 + }
1.1114 +
1.1115 + // Remove any old permission entries
1.1116 + $auth_admin->acl_clear_prefetch();
1.1117 + }
1.1118 +
1.1119 + /**
1.1120 + * Do not resync post counts here. An admin may do this later from the ACP
1.1121 + $start = 0;
1.1122 + $step = ($config['num_posts']) ? (max((int) ($config['num_posts'] / 5), 20000)) : 20000;
1.1123 +
1.1124 + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_posts = 0';
1.1125 + _sql($sql, $errored, $error_ary);
1.1126 +
1.1127 + do
1.1128 + {
1.1129 + $sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
1.1130 + FROM ' . POSTS_TABLE . '
1.1131 + WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . '
1.1132 + AND post_postcount = 1 AND post_approved = 1
1.1133 + GROUP BY poster_id';
1.1134 + $result = _sql($sql, $errored, $error_ary);
1.1135 +
1.1136 + if ($row = $db->sql_fetchrow($result))
1.1137 + {
1.1138 + do
1.1139 + {
1.1140 + $sql = 'UPDATE ' . USERS_TABLE . " SET user_posts = user_posts + {$row['num_posts']} WHERE user_id = {$row['poster_id']}";
1.1141 + _sql($sql, $errored, $error_ary);
1.1142 + }
1.1143 + while ($row = $db->sql_fetchrow($result));
1.1144 +
1.1145 + $start += $step;
1.1146 + }
1.1147 + else
1.1148 + {
1.1149 + $start = 0;
1.1150 + }
1.1151 + $db->sql_freeresult($result);
1.1152 + }
1.1153 + while ($start);
1.1154 + */
1.1155 +
1.1156 + $sql = 'UPDATE ' . MODULES_TABLE . '
1.1157 + SET module_auth = \'acl_a_email && cfg_email_enable\'
1.1158 + WHERE module_class = \'acp\'
1.1159 + AND module_basename = \'email\'';
1.1160 + _sql($sql, $errored, $error_ary);
1.1161 +
1.1162 + $no_updates = false;
1.1163 + break;
1.1164 +
1.1165 + // Changes from 3.0.3-RC1 to 3.0.3
1.1166 + case '3.0.3-RC1':
1.1167 + if ($db->sql_layer == 'oracle')
1.1168 + {
1.1169 + // log_operation is CLOB - but we can change this later
1.1170 + $sql = 'UPDATE ' . LOG_TABLE . "
1.1171 + SET log_operation = 'LOG_DELETE_TOPIC'
1.1172 + WHERE log_operation LIKE 'LOG_TOPIC_DELETED'";
1.1173 + _sql($sql, $errored, $error_ary);
1.1174 + }
1.1175 + else
1.1176 + {
1.1177 + $sql = 'UPDATE ' . LOG_TABLE . "
1.1178 + SET log_operation = 'LOG_DELETE_TOPIC'
1.1179 + WHERE log_operation = 'LOG_TOPIC_DELETED'";
1.1180 + _sql($sql, $errored, $error_ary);
1.1181 + }
1.1182 +
1.1183 + $no_updates = false;
1.1184 + break;
1.1185 +
1.1186 + // Changes from 3.0.3 to 3.0.4-RC1
1.1187 + case '3.0.3':
1.1188 + // Update the Custom Profile Fields based on previous settings to the new format
1.1189 + $sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide
1.1190 + FROM ' . PROFILE_FIELDS_TABLE;
1.1191 + $result = _sql($sql, $errored, $error_ary);
1.1192 +
1.1193 + while ($row = $db->sql_fetchrow($result))
1.1194 + {
1.1195 + $sql_ary = array(
1.1196 + 'field_required' => 0,
1.1197 + 'field_show_on_reg' => 0,
1.1198 + 'field_hide' => 0,
1.1199 + 'field_show_profile'=> 0,
1.1200 + );
1.1201 +
1.1202 + if ($row['field_required'])
1.1203 + {
1.1204 + $sql_ary['field_required'] = $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1;
1.1205 + }
1.1206 + else if ($row['field_show_on_reg'])
1.1207 + {
1.1208 + $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1;
1.1209 + }
1.1210 + else if ($row['field_hide'])
1.1211 + {
1.1212 + // Only administrators and moderators can see this CPF, if the view is enabled, they can see it, otherwise just admins in the acp_users module
1.1213 + $sql_ary['field_hide'] = 1;
1.1214 + }
1.1215 + else
1.1216 + {
1.1217 + // equivelant to "none", which is the "Display in user control panel" option
1.1218 + $sql_ary['field_show_profile'] = 1;
1.1219 + }
1.1220 +
1.1221 + _sql('UPDATE ' . PROFILE_FIELDS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary);
1.1222 + }
1.1223 + $no_updates = false;
1.1224 +
1.1225 + break;
1.1226 +
1.1227 + // Changes from 3.0.4-RC1 to 3.0.4
1.1228 + case '3.0.4-RC1':
1.1229 + break;
1.1230 +
1.1231 + // Changes from 3.0.4 to 3.0.5-RC1
1.1232 + case '3.0.4':
1.1233 +
1.1234 + // Captcha config variables
1.1235 + set_config('captcha_gd_wave', 0);
1.1236 + set_config('captcha_gd_3d_noise', 1);
1.1237 + set_config('captcha_gd_fonts', 1);
1.1238 + set_config('confirm_refresh', 1);
1.1239 +
1.1240 + // Maximum number of keywords
1.1241 + set_config('max_num_search_keywords', 10);
1.1242 +
1.1243 + // Remove static config var and put it back as dynamic variable
1.1244 + $sql = 'UPDATE ' . CONFIG_TABLE . "
1.1245 + SET is_dynamic = 1
1.1246 + WHERE config_name = 'search_indexing_state'";
1.1247 + _sql($sql, $errored, $error_ary);
1.1248 +
1.1249 + // Hash old MD5 passwords
1.1250 + $sql = 'SELECT user_id, user_password
1.1251 + FROM ' . USERS_TABLE . '
1.1252 + WHERE user_pass_convert = 1';
1.1253 + $result = _sql($sql, $errored, $error_ary);
1.1254 +
1.1255 + while ($row = $db->sql_fetchrow($result))
1.1256 + {
1.1257 + if (strlen($row['user_password']) == 32)
1.1258 + {
1.1259 + $sql_ary = array(
1.1260 + 'user_password' => phpbb_hash($row['user_password']),
1.1261 + );
1.1262 +
1.1263 + _sql('UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $row['user_id'], $errored, $error_ary);
1.1264 + }
1.1265 + }
1.1266 + $db->sql_freeresult($result);
1.1267 +
1.1268 + // Adjust bot entry
1.1269 + $sql = 'UPDATE ' . BOTS_TABLE . "
1.1270 + SET bot_agent = 'ichiro/'
1.1271 + WHERE bot_agent = 'ichiro/2'";
1.1272 + _sql($sql, $errored, $error_ary);
1.1273 +
1.1274 +
1.1275 + // Before we are able to add a unique key to auth_option, we need to remove duplicate entries
1.1276 +
1.1277 + // We get duplicate entries first
1.1278 + $sql = 'SELECT auth_option
1.1279 + FROM ' . ACL_OPTIONS_TABLE . '
1.1280 + GROUP BY auth_option
1.1281 + HAVING COUNT(*) >= 2';
1.1282 + $result = $db->sql_query($sql);
1.1283 +
1.1284 + $auth_options = array();
1.1285 + while ($row = $db->sql_fetchrow($result))
1.1286 + {
1.1287 + $auth_options[] = $row['auth_option'];
1.1288 + }
1.1289 + $db->sql_freeresult($result);
1.1290 +
1.1291 + // Remove specific auth options
1.1292 + if (!empty($auth_options))
1.1293 + {
1.1294 + foreach ($auth_options as $option)
1.1295 + {
1.1296 + // Select auth_option_ids... the largest id will be preserved
1.1297 + $sql = 'SELECT auth_option_id
1.1298 + FROM ' . ACL_OPTIONS_TABLE . "
1.1299 + WHERE auth_option = '" . $db->sql_escape($option) . "'
1.1300 + ORDER BY auth_option_id DESC";
1.1301 + // sql_query_limit not possible here, due to bug in postgresql layer
1.1302 + $result = $db->sql_query($sql);
1.1303 +
1.1304 + // Skip first row, this is our original auth option we want to preserve
1.1305 + $row = $db->sql_fetchrow($result);
1.1306 +
1.1307 + while ($row = $db->sql_fetchrow($result))
1.1308 + {
1.1309 + // Ok, remove this auth option...
1.1310 + _sql('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary);
1.1311 + _sql('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary);
1.1312 + _sql('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary);
1.1313 + _sql('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary);
1.1314 + }
1.1315 + $db->sql_freeresult($result);
1.1316 + }
1.1317 + }
1.1318 +
1.1319 + // Now make auth_option UNIQUE, by dropping the old index and adding a UNIQUE one.
1.1320 + $changes = array(
1.1321 + 'drop_keys' => array(
1.1322 + ACL_OPTIONS_TABLE => array('auth_option'),
1.1323 + ),
1.1324 + );
1.1325 +
1.1326 + global $db_tools;
1.1327 +
1.1328 + $statements = $db_tools->perform_schema_changes($changes);
1.1329 +
1.1330 + foreach ($statements as $sql)
1.1331 + {
1.1332 + _sql($sql, $errored, $error_ary);
1.1333 + }
1.1334 +
1.1335 + $changes = array(
1.1336 + 'add_unique_index' => array(
1.1337 + ACL_OPTIONS_TABLE => array(
1.1338 + 'auth_option' => array('auth_option'),
1.1339 + ),
1.1340 + ),
1.1341 + );
1.1342 +
1.1343 + $statements = $db_tools->perform_schema_changes($changes);
1.1344 +
1.1345 + foreach ($statements as $sql)
1.1346 + {
1.1347 + _sql($sql, $errored, $error_ary);
1.1348 + }
1.1349 +
1.1350 + $no_updates = false;
1.1351 +
1.1352 + break;
1.1353 +
1.1354 + // No changes from 3.0.5-RC1 to 3.0.5
1.1355 + case '3.0.5-RC1':
1.1356 + break;
1.1357 +
1.1358 + // Changes from 3.0.5 to 3.0.6-RC1
1.1359 + case '3.0.5':
1.1360 + // Let's see if the GD Captcha can be enabled... we simply look for what *is* enabled...
1.1361 + if (!empty($config['captcha_gd']) && !isset($config['captcha_plugin']))
1.1362 + {
1.1363 + set_config('captcha_plugin', 'phpbb_captcha_gd');
1.1364 + }
1.1365 + else if (!isset($config['captcha_plugin']))
1.1366 + {
1.1367 + set_config('captcha_plugin', 'phpbb_captcha_nogd');
1.1368 + }
1.1369 +
1.1370 + // Entries for the Feed Feature
1.1371 + set_config('feed_enable', '0');
1.1372 + set_config('feed_limit', '10');
1.1373 +
1.1374 + set_config('feed_overall_forums', '1');
1.1375 + set_config('feed_overall_forums_limit', '15');
1.1376 +
1.1377 + set_config('feed_overall_topics', '0');
1.1378 + set_config('feed_overall_topics_limit', '15');
1.1379 +
1.1380 + set_config('feed_forum', '1');
1.1381 + set_config('feed_topic', '1');
1.1382 + set_config('feed_item_statistics', '1');
1.1383 +
1.1384 + // Entries for smiley pagination
1.1385 + set_config('smilies_per_page', '50');
1.1386 +
1.1387 + // Entry for reporting PMs
1.1388 + set_config('allow_pm_report', '1');
1.1389 +
1.1390 + // Install modules
1.1391 + $modules_to_install = array(
1.1392 + 'feed' => array(
1.1393 + 'base' => 'board',
1.1394 + 'class' => 'acp',
1.1395 + 'title' => 'ACP_FEED_SETTINGS',
1.1396 + 'auth' => 'acl_a_board',
1.1397 + 'cat' => 'ACP_BOARD_CONFIGURATION',
1.1398 + 'after' => array('signature', 'ACP_SIGNATURE_SETTINGS')
1.1399 + ),
1.1400 + 'warnings' => array(
1.1401 + 'base' => 'users',
1.1402 + 'class' => 'acp',
1.1403 + 'title' => 'ACP_USER_WARNINGS',
1.1404 + 'auth' => 'acl_a_user',
1.1405 + 'display' => 0,
1.1406 + 'cat' => 'ACP_CAT_USERS',
1.1407 + 'after' => array('feedback', 'ACP_USER_FEEDBACK')
1.1408 + ),
1.1409 + 'send_statistics' => array(
1.1410 + 'base' => 'send_statistics',
1.1411 + 'class' => 'acp',
1.1412 + 'title' => 'ACP_SEND_STATISTICS',
1.1413 + 'auth' => 'acl_a_server',
1.1414 + 'cat' => 'ACP_SERVER_CONFIGURATION'
1.1415 + ),
1.1416 + 'setting_forum_copy' => array(
1.1417 + 'base' => 'permissions',
1.1418 + 'class' => 'acp',
1.1419 + 'title' => 'ACP_FORUM_PERMISSIONS_COPY',
1.1420 + 'auth' => 'acl_a_fauth && acl_a_authusers && acl_a_authgroups && acl_a_mauth',
1.1421 + 'cat' => 'ACP_FORUM_BASED_PERMISSIONS',
1.1422 + 'after' => array('setting_forum_local', 'ACP_FORUM_PERMISSIONS')
1.1423 + ),
1.1424 + 'pm_reports' => array(
1.1425 + 'base' => 'pm_reports',
1.1426 + 'class' => 'mcp',
1.1427 + 'title' => 'MCP_PM_REPORTS_OPEN',
1.1428 + 'auth' => 'aclf_m_report',
1.1429 + 'cat' => 'MCP_REPORTS'
1.1430 + ),
1.1431 + 'pm_reports_closed' => array(
1.1432 + 'base' => 'pm_reports',
1.1433 + 'class' => 'mcp',
1.1434 + 'title' => 'MCP_PM_REPORTS_CLOSED',
1.1435 + 'auth' => 'aclf_m_report',
1.1436 + 'cat' => 'MCP_REPORTS'
1.1437 + ),
1.1438 + 'pm_report_details' => array(
1.1439 + 'base' => 'pm_reports',
1.1440 + 'class' => 'mcp',
1.1441 + 'title' => 'MCP_PM_REPORT_DETAILS',
1.1442 + 'auth' => 'aclf_m_report',
1.1443 + 'cat' => 'MCP_REPORTS'
1.1444 + ),
1.1445 + );
1.1446 +
1.1447 + _add_modules($modules_to_install);
1.1448 +
1.1449 + // Add newly_registered group... but check if it already exists (we always supported running the updater on any schema)
1.1450 + $sql = 'SELECT group_id
1.1451 + FROM ' . GROUPS_TABLE . "
1.1452 + WHERE group_name = 'NEWLY_REGISTERED'";
1.1453 + $result = $db->sql_query($sql);
1.1454 + $group_id = (int) $db->sql_fetchfield('group_id');
1.1455 + $db->sql_freeresult($result);
1.1456 +
1.1457 + if (!$group_id)
1.1458 + {
1.1459 + $sql = 'INSERT INTO ' . GROUPS_TABLE . " (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('NEWLY_REGISTERED', 3, 0, '', 0, '', '', '', 5)";
1.1460 + _sql($sql, $errored, $error_ary);
1.1461 +
1.1462 + $group_id = $db->sql_nextid();
1.1463 + }
1.1464 +
1.1465 + // Insert new user role... at the end of the chain
1.1466 + $sql = 'SELECT role_id
1.1467 + FROM ' . ACL_ROLES_TABLE . "
1.1468 + WHERE role_name = 'ROLE_USER_NEW_MEMBER'
1.1469 + AND role_type = 'u_'";
1.1470 + $result = $db->sql_query($sql);
1.1471 + $u_role = (int) $db->sql_fetchfield('role_id');
1.1472 + $db->sql_freeresult($result);
1.1473 +
1.1474 + if (!$u_role)
1.1475 + {
1.1476 + $sql = 'SELECT MAX(role_order) as max_order_id
1.1477 + FROM ' . ACL_ROLES_TABLE . "
1.1478 + WHERE role_type = 'u_'";
1.1479 + $result = $db->sql_query($sql);
1.1480 + $next_order_id = (int) $db->sql_fetchfield('max_order_id');
1.1481 + $db->sql_freeresult($result);
1.1482 +
1.1483 + $next_order_id++;
1.1484 +
1.1485 + $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_USER_NEW_MEMBER', 'ROLE_DESCRIPTION_USER_NEW_MEMBER', 'u_', $next_order_id)";
1.1486 + _sql($sql, $errored, $error_ary);
1.1487 + $u_role = $db->sql_nextid();
1.1488 +
1.1489 + if (!$errored)
1.1490 + {
1.1491 + // Now add the correct data to the roles...
1.1492 + // The standard role says that new users are not able to send a PM, Mass PM, are not able to PM groups
1.1493 + $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $u_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'u_%' AND auth_option IN ('u_sendpm', 'u_masspm', 'u_masspm_group')";
1.1494 + _sql($sql, $errored, $error_ary);
1.1495 +
1.1496 + // Add user role to group
1.1497 + $sql = 'INSERT INTO ' . ACL_GROUPS_TABLE . " (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES ($group_id, 0, 0, $u_role, 0)";
1.1498 + _sql($sql, $errored, $error_ary);
1.1499 + }
1.1500 + }
1.1501 +
1.1502 + // Insert new forum role
1.1503 + $sql = 'SELECT role_id
1.1504 + FROM ' . ACL_ROLES_TABLE . "
1.1505 + WHERE role_name = 'ROLE_FORUM_NEW_MEMBER'
1.1506 + AND role_type = 'f_'";
1.1507 + $result = $db->sql_query($sql);
1.1508 + $f_role = (int) $db->sql_fetchfield('role_id');
1.1509 + $db->sql_freeresult($result);
1.1510 +
1.1511 + if (!$f_role)
1.1512 + {
1.1513 + $sql = 'SELECT MAX(role_order) as max_order_id
1.1514 + FROM ' . ACL_ROLES_TABLE . "
1.1515 + WHERE role_type = 'f_'";
1.1516 + $result = $db->sql_query($sql);
1.1517 + $next_order_id = (int) $db->sql_fetchfield('max_order_id');
1.1518 + $db->sql_freeresult($result);
1.1519 +
1.1520 + $next_order_id++;
1.1521 +
1.1522 + $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_FORUM_NEW_MEMBER', 'ROLE_DESCRIPTION_FORUM_NEW_MEMBER', 'f_', $next_order_id)";
1.1523 + _sql($sql, $errored, $error_ary);
1.1524 + $f_role = $db->sql_nextid();
1.1525 +
1.1526 + if (!$errored)
1.1527 + {
1.1528 + $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $f_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'f_%' AND auth_option IN ('f_noapprove')";
1.1529 + _sql($sql, $errored, $error_ary);
1.1530 + }
1.1531 + }
1.1532 +
1.1533 + // Set every members user_new column to 0 (old users) only if there is no one yet (this makes sure we do not execute this more than once)
1.1534 + $sql = 'SELECT 1
1.1535 + FROM ' . USERS_TABLE . '
1.1536 + WHERE user_new = 0';
1.1537 + $result = $db->sql_query_limit($sql, 1);
1.1538 + $row = $db->sql_fetchrow($result);
1.1539 + $db->sql_freeresult($result);
1.1540 +
1.1541 + if (!$row)
1.1542 + {
1.1543 + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_new = 0';
1.1544 + _sql($sql, $errored, $error_ary);
1.1545 + }
1.1546 +
1.1547 + // Newly registered users limit
1.1548 + if (!isset($config['new_member_post_limit']))
1.1549 + {
1.1550 + set_config('new_member_post_limit', (!empty($config['enable_queue_trigger'])) ? $config['queue_trigger_posts'] : 0);
1.1551 + }
1.1552 +
1.1553 + if (!isset($config['new_member_group_default']))
1.1554 + {
1.1555 + set_config('new_member_group_default', 0);
1.1556 + }
1.1557 +
1.1558 + // To mimick the old "feature" we will assign the forum role to every forum, regardless of the setting (this makes sure there are no "this does not work!!!! YUO!!!" posts...
1.1559 + // Check if the role is already assigned...
1.1560 + $sql = 'SELECT forum_id
1.1561 + FROM ' . ACL_GROUPS_TABLE . '
1.1562 + WHERE group_id = ' . $group_id . '
1.1563 + AND auth_role_id = ' . $f_role;
1.1564 + $result = $db->sql_query($sql);
1.1565 + $is_options = (int) $db->sql_fetchfield('forum_id');
1.1566 + $db->sql_freeresult($result);
1.1567 +
1.1568 + // Not assigned at all... :/
1.1569 + if (!$is_options)
1.1570 + {
1.1571 + // Get postable forums
1.1572 + $sql = 'SELECT forum_id
1.1573 + FROM ' . FORUMS_TABLE . '
1.1574 + WHERE forum_type != ' . FORUM_LINK;
1.1575 + $result = $db->sql_query($sql);
1.1576 +
1.1577 + while ($row = $db->sql_fetchrow($result))
1.1578 + {
1.1579 + _sql('INSERT INTO ' . ACL_GROUPS_TABLE . ' (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (' . $group_id . ', ' . (int) $row['forum_id'] . ', 0, ' . $f_role . ', 0)', $errored, $error_ary);
1.1580 + }
1.1581 + $db->sql_freeresult($result);
1.1582 + }
1.1583 +
1.1584 + // Clear permissions...
1.1585 + include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
1.1586 + $auth_admin = new auth_admin();
1.1587 + $auth_admin->acl_clear_prefetch();
1.1588 +
1.1589 + if (!isset($config['allow_avatar']))
1.1590 + {
1.1591 + if ($config['allow_avatar_upload'] || $config['allow_avatar_local'] || $config['allow_avatar_remote'])
1.1592 + {
1.1593 + set_config('allow_avatar', '1');
1.1594 + }
1.1595 + else
1.1596 + {
1.1597 + set_config('allow_avatar', '0');
1.1598 + }
1.1599 + }
1.1600 +
1.1601 + if (!isset($config['allow_avatar_remote_upload']))
1.1602 + {
1.1603 + if ($config['allow_avatar_remote'] && $config['allow_avatar_upload'])
1.1604 + {
1.1605 + set_config('allow_avatar_remote_upload', '1');
1.1606 + }
1.1607 + else
1.1608 + {
1.1609 + set_config('allow_avatar_remote_upload', '0');
1.1610 + }
1.1611 + }
1.1612 +
1.1613 + // Minimum number of characters
1.1614 + if (!isset($config['min_post_chars']))
1.1615 + {
1.1616 + set_config('min_post_chars', '1');
1.1617 + }
1.1618 +
1.1619 + if (!isset($config['allow_quick_reply']))
1.1620 + {
1.1621 + set_config('allow_quick_reply', '1');
1.1622 + }
1.1623 +
1.1624 + // Set every members user_options column to enable
1.1625 + // bbcode, smilies and URLs for signatures by default
1.1626 + $sql = 'SELECT user_options
1.1627 + FROM ' . USERS_TABLE . '
1.1628 + WHERE user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')';
1.1629 + $result = $db->sql_query_limit($sql, 1);
1.1630 + $user_option = (int) $db->sql_fetchfield('user_options');
1.1631 + $db->sql_freeresult($result);
1.1632 +
1.1633 + // Check if we already updated the database by checking bit 15 which we used to store the sig_bbcode option
1.1634 + if (!($user_option & 1 << 15))
1.1635 + {
1.1636 + // 229376 is the added value to enable all three signature options
1.1637 + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_options = user_options + 229376';
1.1638 + _sql($sql, $errored, $error_ary);
1.1639 + }
1.1640 +
1.1641 + if (!isset($config['delete_time']))
1.1642 + {
1.1643 + set_config('delete_time', $config['edit_time']);
1.1644 + }
1.1645 +
1.1646 + $no_updates = false;
1.1647 + break;
1.1648 +
1.1649 + // No changes from 3.0.6-RC1 to 3.0.6-RC2
1.1650 + case '3.0.6-RC1':
1.1651 + break;
1.1652 +
1.1653 + // Changes from 3.0.6-RC2 to 3.0.6-RC3
1.1654 + case '3.0.6-RC2':
1.1655 +
1.1656 + // Update the Custom Profile Fields based on previous settings to the new format
1.1657 + $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . '
1.1658 + SET field_show_on_vt = 1
1.1659 + WHERE field_hide = 0
1.1660 + AND (field_required = 1 OR field_show_on_reg = 1 OR field_show_profile = 1)';
1.1661 + _sql($sql, $errored, $error_ary);
1.1662 + $no_updates = false;
1.1663 +
1.1664 + break;
1.1665 +
1.1666 + // No changes from 3.0.6-RC3 to 3.0.6-RC4
1.1667 + case '3.0.6-RC3':
1.1668 + break;
1.1669 +
1.1670 + // No changes from 3.0.6-RC4 to 3.0.6
1.1671 + case '3.0.6-RC4':
1.1672 + break;
1.1673 +
1.1674 + // Changes from 3.0.6 to 3.0.7-RC1
1.1675 + case '3.0.6':
1.1676 +
1.1677 + // ATOM Feeds
1.1678 + set_config('feed_overall', '1');
1.1679 + set_config('feed_http_auth', '0');
1.1680 + set_config('feed_limit_post', (string) (isset($config['feed_limit']) ? (int) $config['feed_limit'] : 15));
1.1681 + set_config('feed_limit_topic', (string) (isset($config['feed_overall_topics_limit']) ? (int) $config['feed_overall_topics_limit'] : 10));
1.1682 + set_config('feed_topics_new', (!empty($config['feed_overall_topics']) ? '1' : '0'));
1.1683 + set_config('feed_topics_active', (!empty($config['feed_overall_topics']) ? '1' : '0'));
1.1684 +
1.1685 + // Delete all text-templates from the template_data
1.1686 + $sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . '
1.1687 + WHERE template_filename ' . $db->sql_like_expression($db->any_char . '.txt');
1.1688 + _sql($sql, $errored, $error_ary);
1.1689 +
1.1690 + $no_updates = false;
1.1691 + break;
1.1692 +
1.1693 + // Changes from 3.0.7-RC1 to 3.0.7-RC2
1.1694 + case '3.0.7-RC1':
1.1695 +
1.1696 + $sql = 'SELECT user_id, user_email, user_email_hash
1.1697 + FROM ' . USERS_TABLE . '
1.1698 + WHERE user_type <> ' . USER_IGNORE . "
1.1699 + AND user_email <> ''";
1.1700 + $result = $db->sql_query($sql);
1.1701 +
1.1702 + $i = 0;
1.1703 + while ($row = $db->sql_fetchrow($result))
1.1704 + {
1.1705 + // Snapshot of the phpbb_email_hash() function
1.1706 + // We cannot call it directly because the auto updater updates the DB first. :/
1.1707 + $user_email_hash = sprintf('%u', crc32(strtolower($row['user_email']))) . strlen($row['user_email']);
1.1708 +
1.1709 + if ($user_email_hash != $row['user_email_hash'])
1.1710 + {
1.1711 + $sql_ary = array(
1.1712 + 'user_email_hash' => $user_email_hash,
1.1713 + );
1.1714 +
1.1715 + $sql = 'UPDATE ' . USERS_TABLE . '
1.1716 + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
1.1717 + WHERE user_id = ' . (int) $row['user_id'];
1.1718 + _sql($sql, $errored, $error_ary, ($i % 100 == 0));
1.1719 +
1.1720 + ++$i;
1.1721 + }
1.1722 + }
1.1723 + $db->sql_freeresult($result);
1.1724 +
1.1725 + $no_updates = false;
1.1726 +
1.1727 + break;
1.1728 +
1.1729 + // No changes from 3.0.7-RC2 to 3.0.7
1.1730 + case '3.0.7-RC2':
1.1731 + break;
1.1732 +
1.1733 + // No changes from 3.0.7 to 3.0.7-PL1
1.1734 + case '3.0.7':
1.1735 + break;
1.1736 +
1.1737 + // Changes from 3.0.7-PL1 to 3.0.8-RC1
1.1738 + case '3.0.7-PL1':
1.1739 + // Update file extension group names to use language strings.
1.1740 + $sql = 'SELECT lang_dir
1.1741 + FROM ' . LANG_TABLE;
1.1742 + $result = $db->sql_query($sql);
1.1743 +
1.1744 + $extension_groups_updated = array();
1.1745 + while ($lang_dir = $db->sql_fetchfield('lang_dir'))
1.1746 + {
1.1747 + $lang_dir = basename($lang_dir);
1.1748 +
1.1749 + // The language strings we need are either in language/.../acp/attachments.php
1.1750 + // in the update package if we're updating to 3.0.8-RC1 or later,
1.1751 + // or they are in language/.../install.php when we're updating from 3.0.7-PL1 or earlier.
1.1752 + // On an already updated board, they can also already be in language/.../acp/attachments.php
1.1753 + // in the board root.
1.1754 + $lang_files = array(
1.1755 + "{$phpbb_root_path}install/update/new/language/$lang_dir/acp/attachments.$phpEx",
1.1756 + "{$phpbb_root_path}language/$lang_dir/install.$phpEx",
1.1757 + "{$phpbb_root_path}language/$lang_dir/acp/attachments.$phpEx",
1.1758 + );
1.1759 +
1.1760 + foreach ($lang_files as $lang_file)
1.1761 + {
1.1762 + if (!file_exists($lang_file))
1.1763 + {
1.1764 + continue;
1.1765 + }
1.1766 +
1.1767 + $lang = array();
1.1768 + include($lang_file);
1.1769 +
1.1770 + foreach($lang as $lang_key => $lang_val)
1.1771 + {
1.1772 + if (isset($extension_groups_updated[$lang_key]) || strpos($lang_key, 'EXT_GROUP_') !== 0)
1.1773 + {
1.1774 + continue;
1.1775 + }
1.1776 +
1.1777 + $sql_ary = array(
1.1778 + 'group_name' => substr($lang_key, 10), // Strip off 'EXT_GROUP_'
1.1779 + );
1.1780 +
1.1781 + $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . '
1.1782 + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
1.1783 + WHERE group_name = '" . $db->sql_escape($lang_val) . "'";
1.1784 + _sql($sql, $errored, $error_ary);
1.1785 +
1.1786 + $extension_groups_updated[$lang_key] = true;
1.1787 + }
1.1788 + }
1.1789 + }
1.1790 + $db->sql_freeresult($result);
1.1791 +
1.1792 + // Install modules
1.1793 + $modules_to_install = array(
1.1794 + 'post' => array(
1.1795 + 'base' => 'board',
1.1796 + 'class' => 'acp',
1.1797 + 'title' => 'ACP_POST_SETTINGS',
1.1798 + 'auth' => 'acl_a_board',
1.1799 + 'cat' => 'ACP_MESSAGES',
1.1800 + 'after' => array('message', 'ACP_MESSAGE_SETTINGS')
1.1801 + ),
1.1802 + );
1.1803 +
1.1804 + _add_modules($modules_to_install);
1.1805 +
1.1806 + // update
1.1807 + $sql = 'UPDATE ' . MODULES_TABLE . '
1.1808 + SET module_auth = \'cfg_allow_avatar && (cfg_allow_avatar_local || cfg_allow_avatar_remote || cfg_allow_avatar_upload || cfg_allow_avatar_remote_upload)\'
1.1809 + WHERE module_class = \'ucp\'
1.1810 + AND module_basename = \'profile\'
1.1811 + AND module_mode = \'avatar\'';
1.1812 + _sql($sql, $errored, $error_ary);
1.1813 +
1.1814 + // add Bing Bot
1.1815 + $bot_name = 'Bing [Bot]';
1.1816 + $bot_name_clean = utf8_clean_string($bot_name);
1.1817 +
1.1818 + $sql = 'SELECT user_id
1.1819 + FROM ' . USERS_TABLE . "
1.1820 + WHERE username_clean = '" . $db->sql_escape($bot_name_clean) . "'";
1.1821 + $result = $db->sql_query($sql);
1.1822 + $bing_already_added = (bool) $db->sql_fetchfield('user_id');
1.1823 + $db->sql_freeresult($result);
1.1824 +
1.1825 + if (!$bing_already_added)
1.1826 + {
1.1827 + $bot_agent = 'bingbot/';
1.1828 + $bot_ip = '';
1.1829 + $sql = 'SELECT group_id, group_colour
1.1830 + FROM ' . GROUPS_TABLE . "
1.1831 + WHERE group_name = 'BOTS'";
1.1832 + $result = $db->sql_query($sql);
1.1833 + $group_row = $db->sql_fetchrow($result);
1.1834 + $db->sql_freeresult($result);
1.1835 +
1.1836 + if (!$group_row)
1.1837 + {
1.1838 + // default fallback, should never get here
1.1839 + $group_row['group_id'] = 6;
1.1840 + $group_row['group_colour'] = '9E8DA7';
1.1841 + }
1.1842 +
1.1843 + if (!function_exists('user_add'))
1.1844 + {
1.1845 + include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
1.1846 + }
1.1847 +
1.1848 + $user_row = array(
1.1849 + 'user_type' => USER_IGNORE,
1.1850 + 'group_id' => $group_row['group_id'],
1.1851 + 'username' => $bot_name,
1.1852 + 'user_regdate' => time(),
1.1853 + 'user_password' => '',
1.1854 + 'user_colour' => $group_row['group_colour'],
1.1855 + 'user_email' => '',
1.1856 + 'user_lang' => $config['default_lang'],
1.1857 + 'user_style' => $config['default_style'],
1.1858 + 'user_timezone' => 0,
1.1859 + 'user_dateformat' => $config['default_dateformat'],
1.1860 + 'user_allow_massemail' => 0,
1.1861 + );
1.1862 +
1.1863 + $user_id = user_add($user_row);
1.1864 +
1.1865 + $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
1.1866 + 'bot_active' => 1,
1.1867 + 'bot_name' => (string) $bot_name,
1.1868 + 'user_id' => (int) $user_id,
1.1869 + 'bot_agent' => (string) $bot_agent,
1.1870 + 'bot_ip' => (string) $bot_ip,
1.1871 + ));
1.1872 +
1.1873 + _sql($sql, $errored, $error_ary);
1.1874 + }
1.1875 + // end Bing Bot addition
1.1876 +
1.1877 + // Delete shadow topics pointing to not existing topics
1.1878 + $batch_size = 500;
1.1879 +
1.1880 + // Set of affected forums we have to resync
1.1881 + $sync_forum_ids = array();
1.1882 +
1.1883 + do
1.1884 + {
1.1885 + $sql_array = array(
1.1886 + 'SELECT' => 't1.topic_id, t1.forum_id',
1.1887 + 'FROM' => array(
1.1888 + TOPICS_TABLE => 't1',
1.1889 + ),
1.1890 + 'LEFT_JOIN' => array(
1.1891 + array(
1.1892 + 'FROM' => array(TOPICS_TABLE => 't2'),
1.1893 + 'ON' => 't1.topic_moved_id = t2.topic_id',
1.1894 + ),
1.1895 + ),
1.1896 + 'WHERE' => 't1.topic_moved_id <> 0
1.1897 + AND t2.topic_id IS NULL',
1.1898 + );
1.1899 + $sql = $db->sql_build_query('SELECT', $sql_array);
1.1900 + $result = $db->sql_query_limit($sql, $batch_size);
1.1901 +
1.1902 + $topic_ids = array();
1.1903 + while ($row = $db->sql_fetchrow($result))
1.1904 + {
1.1905 + $topic_ids[] = (int) $row['topic_id'];
1.1906 +
1.1907 + $sync_forum_ids[(int) $row['forum_id']] = (int) $row['forum_id'];
1.1908 + }
1.1909 + $db->sql_freeresult($result);
1.1910 +
1.1911 + if (!empty($topic_ids))
1.1912 + {
1.1913 + $sql = 'DELETE FROM ' . TOPICS_TABLE . '
1.1914 + WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
1.1915 + $db->sql_query($sql);
1.1916 + }
1.1917 + }
1.1918 + while (sizeof($topic_ids) == $batch_size);
1.1919 +
1.1920 + // Sync the forums we have deleted shadow topics from.
1.1921 + sync('forum', 'forum_id', $sync_forum_ids, true, true);
1.1922 +
1.1923 + // Unread posts search load switch
1.1924 + set_config('load_unreads_search', '1');
1.1925 +
1.1926 + // Reduce queue interval to 60 seconds, email package size to 20
1.1927 + if ($config['queue_interval'] == 600)
1.1928 + {
1.1929 + set_config('queue_interval', '60');
1.1930 + }
1.1931 +
1.1932 + if ($config['email_package_size'] == 50)
1.1933 + {
1.1934 + set_config('email_package_size', '20');
1.1935 + }
1.1936 +
1.1937 + $no_updates = false;
1.1938 + break;
1.1939 +
1.1940 + // No changes from 3.0.8-RC1 to 3.0.8
1.1941 + case '3.0.8-RC1':
1.1942 + break;
1.1943 +
1.1944 + // Changes from 3.0.8 to 3.0.9-RC1
1.1945 + case '3.0.8':
1.1946 + set_config('ip_login_limit_max', '50');
1.1947 + set_config('ip_login_limit_time', '21600');
1.1948 + set_config('ip_login_limit_use_forwarded', '0');
1.1949 +
1.1950 + // Update file extension group names to use language strings, again.
1.1951 + $sql = 'SELECT group_id, group_name
1.1952 + FROM ' . EXTENSION_GROUPS_TABLE . '
1.1953 + WHERE group_name ' . $db->sql_like_expression('EXT_GROUP_' . $db->any_char);
1.1954 + $result = $db->sql_query($sql);
1.1955 +
1.1956 + while ($row = $db->sql_fetchrow($result))
1.1957 + {
1.1958 + $sql_ary = array(
1.1959 + 'group_name' => substr($row['group_name'], 10), // Strip off 'EXT_GROUP_'
1.1960 + );
1.1961 +
1.1962 + $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . '
1.1963 + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
1.1964 + WHERE group_id = ' . $row['group_id'];
1.1965 + _sql($sql, $errored, $error_ary);
1.1966 + }
1.1967 + $db->sql_freeresult($result);
1.1968 +
1.1969 + global $db_tools, $table_prefix;
1.1970 +
1.1971 + // Recover from potentially broken Q&A CAPTCHA table on firebird
1.1972 + // Q&A CAPTCHA was uninstallable, so it's safe to remove these
1.1973 + // without data loss
1.1974 + if ($db_tools->sql_layer == 'firebird')
1.1975 + {
1.1976 + $tables = array(
1.1977 + $table_prefix . 'captcha_questions',
1.1978 + $table_prefix . 'captcha_answers',
1.1979 + $table_prefix . 'qa_confirm',
1.1980 + );
1.1981 + foreach ($tables as $table)
1.1982 + {
1.1983 + if ($db_tools->sql_table_exists($table))
1.1984 + {
1.1985 + $db_tools->sql_table_drop($table);
1.1986 + }
1.1987 + }
1.1988 + }
1.1989 +
1.1990 + $no_updates = false;
1.1991 + break;
1.1992 +
1.1993 + // No changes from 3.0.9-RC1 to 3.0.9-RC2
1.1994 + case '3.0.9-RC1':
1.1995 + break;
1.1996 +
1.1997 + // No changes from 3.0.9-RC2 to 3.0.9-RC3
1.1998 + case '3.0.9-RC2':
1.1999 + break;
1.2000 +
1.2001 + // No changes from 3.0.9-RC3 to 3.0.9-RC4
1.2002 + case '3.0.9-RC3':
1.2003 + break;
1.2004 +
1.2005 + // No changes from 3.0.9-RC4 to 3.0.9
1.2006 + case '3.0.9-RC4':
1.2007 + break;
1.2008 +
1.2009 + // Changes from 3.0.9 to 3.0.10-RC1
1.2010 + case '3.0.9':
1.2011 + if (!isset($config['email_max_chunk_size']))
1.2012 + {
1.2013 + set_config('email_max_chunk_size', '50');
1.2014 + }
1.2015 +
1.2016 + $no_updates = false;
1.2017 + break;
1.2018 +
1.2019 + // No changes from 3.0.10-RC1 to 3.0.10-RC2
1.2020 + case '3.0.10-RC1':
1.2021 + break;
1.2022 +
1.2023 + // No changes from 3.0.10-RC2 to 3.0.10-RC3
1.2024 + case '3.0.10-RC2':
1.2025 + break;
1.2026 +
1.2027 + // No changes from 3.0.10-RC3 to 3.0.10
1.2028 + case '3.0.10-RC3':
1.2029 + break;
1.2030 + }
1.2031 +}
1.2032 +
1.2033 +?>