6 * @copyright (c) 2006 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 define('UPDATES_TO_VERSION', '3.0.10');
13 // Enter any version to update from to test updates. The version within the db will not be updated.
14 define('DEBUG_FROM_VERSION', false);
16 // Which oldest version does this updater support?
17 define('OLDEST_FROM_VERSION', '3.0.0');
19 // Return if we "just include it" to find out for which version the database update is responsible for
20 if (defined('IN_PHPBB') && defined('IN_INSTALL'))
22 $updates_to_version = UPDATES_TO_VERSION;
23 $debug_from_version = DEBUG_FROM_VERSION;
24 $oldest_from_version = OLDEST_FROM_VERSION;
31 define('IN_PHPBB', true);
32 define('IN_INSTALL', true);
34 $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../';
35 $phpEx = substr(strrchr(__FILE__, '.'), 1);
37 if (!function_exists('phpbb_require_updated'))
39 function phpbb_require_updated($path, $optional = false)
41 global $phpbb_root_path;
43 $new_path = $phpbb_root_path . 'install/update/new/' . $path;
44 $old_path = $phpbb_root_path . $path;
46 if (file_exists($new_path))
50 else if (!$optional || file_exists($old_path))
57 phpbb_require_updated('includes/startup.' . $phpEx);
59 $updates_to_version = UPDATES_TO_VERSION;
60 $debug_from_version = DEBUG_FROM_VERSION;
61 $oldest_from_version = OLDEST_FROM_VERSION;
63 error_reporting(E_ALL);
67 // Include essential scripts
68 include($phpbb_root_path . 'config.' . $phpEx);
70 if (!defined('PHPBB_INSTALLED') || empty($dbms) || empty($acm_type))
72 die("Please read: <a href='../docs/INSTALL.html'>INSTALL.html</a> before attempting to update.");
76 if (!empty($load_extensions) && function_exists('dl'))
78 $load_extensions = explode(',', $load_extensions);
80 foreach ($load_extensions as $extension)
82 @dl(trim($extension));
87 require($phpbb_root_path . 'includes/acm/acm_' . $acm_type . '.' . $phpEx);
88 require($phpbb_root_path . 'includes/cache.' . $phpEx);
89 require($phpbb_root_path . 'includes/template.' . $phpEx);
90 require($phpbb_root_path . 'includes/session.' . $phpEx);
91 require($phpbb_root_path . 'includes/auth.' . $phpEx);
93 require($phpbb_root_path . 'includes/functions.' . $phpEx);
95 phpbb_require_updated('includes/functions_content.' . $phpEx, true);
97 require($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
98 require($phpbb_root_path . 'includes/constants.' . $phpEx);
99 require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
100 require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
102 phpbb_require_updated('includes/db/db_tools.' . $phpEx);
104 // new table constants are separately defined here in case the updater is run
105 // before the files are updated
106 if (!defined('LOGIN_ATTEMPT_TABLE'))
108 define('LOGIN_ATTEMPT_TABLE', $table_prefix . 'login_attempts');
112 $cache = new cache();
115 // Add own hook handler, if present. :o
116 if (file_exists($phpbb_root_path . 'includes/hooks/index.' . $phpEx))
118 require($phpbb_root_path . 'includes/hooks/index.' . $phpEx);
119 $phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('template', 'display')));
121 foreach ($cache->obtain_hooks() as $hook)
123 @include($phpbb_root_path . 'includes/hooks/' . $hook . '.' . $phpEx);
132 $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false);
134 // We do not need this any longer, unset for safety purposes
137 $user->ip = (!empty($_SERVER['REMOTE_ADDR'])) ? htmlspecialchars($_SERVER['REMOTE_ADDR']) : '';
138 $user->ip = (stripos($user->ip, '::ffff:') === 0) ? substr($user->ip, 7) : $user->ip;
140 $sql = "SELECT config_value
141 FROM " . CONFIG_TABLE . "
142 WHERE config_name = 'default_lang'";
143 $result = $db->sql_query($sql);
144 $row = $db->sql_fetchrow($result);
145 $db->sql_freeresult($result);
147 $language = basename(request_var('language', ''));
151 $language = $row['config_value'];
154 if (!file_exists($phpbb_root_path . 'language/' . $language))
156 die('No language found!');
159 // And finally, load the relevant language files
160 include($phpbb_root_path . 'language/' . $language . '/common.' . $phpEx);
161 include($phpbb_root_path . 'language/' . $language . '/acp/common.' . $phpEx);
162 include($phpbb_root_path . 'language/' . $language . '/install.' . $phpEx);
164 // Set PHP error handler to ours
165 //set_error_handler('msg_handler');
167 // Define some variables for the database update
168 $inline_update = (request_var('type', 0)) ? true : false;
170 // To let set_config() calls succeed, we need to make the config array available globally
174 FROM ' . CONFIG_TABLE;
175 $result = $db->sql_query($sql);
177 while ($row = $db->sql_fetchrow($result))
179 $config[$row['config_name']] = $row['config_value'];
181 $db->sql_freeresult($result);
183 // phpbb_db_tools will be taken from new files (under install/update/new)
184 // if possible, falling back to the board's copy.
185 $db_tools = new phpbb_db_tools($db, true);
187 $database_update_info = database_update_info();
189 $error_ary = array();
192 header('Content-type: text/html; charset=UTF-8');
195 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
196 <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']; ?>">
199 <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
200 <meta http-equiv="content-language" content="<?php echo $lang['USER_LANG']; ?>" />
201 <meta http-equiv="content-style-type" content="text/css" />
202 <meta http-equiv="imagetoolbar" content="no" />
204 <title><?php echo $lang['UPDATING_TO_LATEST_STABLE']; ?></title>
206 <link href="../adm/style/admin.css" rel="stylesheet" type="text/css" media="screen" />
212 <div id="page-header"> </div>
217 <span class="corners-top"><span></span></span>
219 <div id="main" class="install-body">
221 <h1><?php echo $lang['UPDATING_TO_LATEST_STABLE']; ?></h1>
225 <p><?php echo $lang['DATABASE_TYPE']; ?> :: <strong><?php echo $db->sql_layer; ?></strong><br />
228 if ($debug_from_version !== false)
230 $config['version'] = $debug_from_version;
233 echo $lang['PREVIOUS_VERSION'] . ' :: <strong>' . $config['version'] . '</strong><br />';
234 echo $lang['UPDATED_VERSION'] . ' :: <strong>' . $updates_to_version . '</strong></p>';
236 $current_version = str_replace('rc', 'RC', strtolower($config['version']));
237 $latest_version = str_replace('rc', 'RC', strtolower($updates_to_version));
238 $orig_version = $config['version'];
241 if (empty($config['dbms_version']))
243 set_config('dbms_version', $db->sql_server_info(true));
246 // Firebird update from Firebird 2.0 to 2.1+ required?
247 if ($db->sql_layer == 'firebird')
249 // We do not trust any PHP5 function enabled, we will simply test for a function new in 2.1
250 $db->sql_return_on_error(true);
252 $sql = 'SELECT 1 FROM RDB$DATABASE
253 WHERE BIN_AND(10, 1) = 0';
254 $result = $db->sql_query($sql);
256 if (!$result || $db->sql_error_triggered)
259 echo '<h1>' . $lang['ERROR'] . '</h1><br />';
261 echo '<p>' . $lang['FIREBIRD_DBMS_UPDATE_REQUIRED'] . '</p>';
269 $db->sql_freeresult($result);
270 $db->sql_return_on_error(false);
273 // MySQL update from MySQL 3.x/4.x to > 4.1.x required?
274 if ($db->sql_layer == 'mysql' || $db->sql_layer == 'mysql4' || $db->sql_layer == 'mysqli')
276 // Verify by fetching column... if the column type matches the new type we update dbms_version...
277 $sql = "SHOW COLUMNS FROM " . CONFIG_TABLE;
278 $result = $db->sql_query($sql);
281 while ($row = $db->sql_fetchrow($result))
283 $field = strtolower($row['Field']);
285 if ($field == 'config_value')
287 $column_type = strtolower($row['Type']);
291 $db->sql_freeresult($result);
293 // If column type is blob, but mysql version says we are on > 4.1.3, then the schema needs an update
294 if (strpos($column_type, 'blob') !== false && version_compare($db->sql_server_info(true), '4.1.3', '>='))
297 echo '<h1>' . $lang['ERROR'] . '</h1><br />';
299 echo '<p>' . sprintf($lang['MYSQL_SCHEMA_UPDATE_REQUIRED'], $config['dbms_version'], $db->sql_server_info(true)) . '</p>';
308 // Now check if the user wants to update from a version we no longer support updates from
309 if (version_compare($current_version, $oldest_from_version, '<'))
311 echo '<br /><br /><h1>' . $lang['ERROR'] . '</h1><br />';
312 echo '<p>' . sprintf($lang['DB_UPDATE_NOT_SUPPORTED'], $oldest_from_version, $current_version) . '</p>';
319 // If the latest version and the current version are 'unequal', we will update the version_update_from, else we do not update anything.
322 if ($current_version !== $latest_version)
324 set_config('version_update_from', $orig_version);
329 // If not called from the update script, we will actually remove the traces
330 $db->sql_query('DELETE FROM ' . CONFIG_TABLE . " WHERE config_name = 'version_update_from'");
337 <h1><?php echo $lang['UPDATE_DATABASE_SCHEMA']; ?></h1>
340 <p><?php echo $lang['PROGRESS']; ?> :: <strong>
346 // We go through the schema changes from the lowest to the highest version
347 // We try to also include versions 'in-between'...
349 $versions = array_keys($database_update_info);
350 for ($i = 0; $i < sizeof($versions); $i++)
352 $version = $versions[$i];
353 $schema_changes = $database_update_info[$version];
355 $next_version = (isset($versions[$i + 1])) ? $versions[$i + 1] : $updates_to_version;
357 // 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
358 if (version_compare($version, $current_version, '<') && version_compare($current_version, $next_version, '>='))
363 if (!sizeof($schema_changes))
370 // We run one index after the other... to be consistent with schema changes...
371 foreach ($schema_changes as $key => $changes)
373 $statements = $db_tools->perform_schema_changes(array($key => $changes));
375 foreach ($statements as $sql)
377 _sql($sql, $errored, $error_ary);
382 _write_result($no_updates, $errored, $error_ary);
385 $error_ary = array();
386 $errored = $no_updates = false;
391 <h1><?php echo $lang['UPDATING_DATA']; ?></h1>
393 <p><?php echo $lang['PROGRESS']; ?> :: <strong>
400 $versions = array_keys($database_update_info);
403 for ($i = 0; $i < sizeof($versions); $i++)
405 $version = $versions[$i];
406 $next_version = (isset($versions[$i + 1])) ? $versions[$i + 1] : $updates_to_version;
408 // 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
409 if (version_compare($version, $current_version, '<') && version_compare($current_version, $next_version, '>='))
414 change_database_data($no_updates, $version);
417 _write_result($no_updates, $errored, $error_ary);
419 $error_ary = array();
420 $errored = $no_updates = false;
425 <h1><?php echo $lang['UPDATE_VERSION_OPTIMIZE']; ?></h1>
427 <p><?php echo $lang['PROGRESS']; ?> :: <strong>
433 if ($debug_from_version === false)
435 // update the version
436 $sql = "UPDATE " . CONFIG_TABLE . "
437 SET config_value = '$updates_to_version'
438 WHERE config_name = 'version'";
439 _sql($sql, $errored, $error_ary);
443 $sql = 'UPDATE ' . USERS_TABLE . "
444 SET user_permissions = '',
446 _sql($sql, $errored, $error_ary);
448 // Update the dbms version if everything is ok...
449 set_config('dbms_version', $db->sql_server_info(true));
451 /* Optimize/vacuum analyze the tables where appropriate
452 // this should be done for each version in future along with
453 // the version number update
454 switch ($db->sql_layer)
459 $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';
460 _sql($sql, $errored, $error_ary);
464 _sql("VACUUM ANALYZE", $errored, $error_ary);
469 _write_result($no_updates, $errored, $error_ary);
474 <h1><?php echo $lang['UPDATE_COMPLETED']; ?></h1>
484 <p style="color:red"><?php echo $lang['UPDATE_FILES_NOTICE']; ?></p>
486 <p><?php echo $lang['COMPLETE_LOGIN_TO_BOARD']; ?></p>
494 <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>
496 <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>
501 // Add database update to log
502 add_log('admin', 'LOG_UPDATE_DATABASE', $orig_version, $updates_to_version);
504 // Now we purge the session table as well as all cache files
509 garbage_collection();
511 if (function_exists('exit_handler'))
519 function _print_footer()
524 <span class="corners-bottom"><span></span></span>
529 <div id="page-footer">
530 Powered by <a href="http://www.phpbb.com/">phpBB</a>® Forum Software © phpBB Group
540 * Function for triggering an sql statement
542 function _sql($sql, &$errored, &$error_ary, $echo_dot = true)
546 if (defined('DEBUG_EXTRA'))
548 echo "<br />\n{$sql}\n<br />";
551 $db->sql_return_on_error(true);
553 if ($sql === 'begin')
555 $result = $db->sql_transaction('begin');
557 else if ($sql === 'commit')
559 $result = $db->sql_transaction('commit');
563 $result = $db->sql_query($sql);
564 if ($db->sql_error_triggered)
567 $error_ary['sql'][] = $db->sql_error_sql;
568 $error_ary['error_code'][] = $db->sql_error_returned;
572 $db->sql_return_on_error(false);
583 function _write_result($no_updates, $errored, $error_ary)
589 echo ' ' . $lang['NO_UPDATES_REQUIRED'] . '</strong></p>';
593 echo ' <span class="success">' . $lang['DONE'] . '</span></strong><br />' . $lang['RESULT'] . ' :: ';
597 echo ' <strong>' . $lang['SOME_QUERIES_FAILED'] . '</strong> <ul>';
599 for ($i = 0; $i < sizeof($error_ary['sql']); $i++)
601 echo '<li>' . $lang['ERROR'] . ' :: <strong>' . htmlspecialchars($error_ary['error_code'][$i]['message']) . '</strong><br />';
602 echo $lang['SQL'] . ' :: <strong>' . htmlspecialchars($error_ary['sql'][$i]) . '</strong><br /><br /></li>';
605 echo '</ul> <br /><br />' . $lang['SQL_FAILURE_EXPLAIN'] . '</p>';
609 echo '<strong>' . $lang['NO_ERRORS'] . '</strong></p>';
614 function _add_modules($modules_to_install)
616 global $phpbb_root_path, $phpEx, $db;
618 include_once($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx);
620 $_module = new acp_modules();
622 foreach ($modules_to_install as $module_mode => $module_data)
624 $_module->module_class = $module_data['class'];
626 // Determine parent id first
627 $sql = 'SELECT module_id
628 FROM ' . MODULES_TABLE . "
629 WHERE module_class = '" . $db->sql_escape($module_data['class']) . "'
630 AND module_langname = '" . $db->sql_escape($module_data['cat']) . "'
632 AND module_basename = ''";
633 $result = $db->sql_query($sql);
635 // There may be more than one categories with the same name
636 $categories = array();
637 while ($row = $db->sql_fetchrow($result))
639 $categories[] = (int) $row['module_id'];
641 $db->sql_freeresult($result);
643 if (!sizeof($categories))
648 // Add the module to all categories found
649 foreach ($categories as $parent_id)
651 // Check if the module already exists
653 FROM ' . MODULES_TABLE . "
654 WHERE module_basename = '" . $db->sql_escape($module_data['base']) . "'
655 AND module_class = '" . $db->sql_escape($module_data['class']) . "'
656 AND module_langname = '" . $db->sql_escape($module_data['title']) . "'
657 AND module_mode = '" . $db->sql_escape($module_mode) . "'
658 AND module_auth = '" . $db->sql_escape($module_data['auth']) . "'
659 AND parent_id = {$parent_id}";
660 $result = $db->sql_query($sql);
661 $row = $db->sql_fetchrow($result);
662 $db->sql_freeresult($result);
664 // If it exists, we simply continue with the next category
670 // Build the module sql row
672 'module_basename' => $module_data['base'],
673 'module_enabled' => (isset($module_data['enabled'])) ? (int) $module_data['enabled'] : 1,
674 'module_display' => (isset($module_data['display'])) ? (int) $module_data['display'] : 1,
675 'parent_id' => $parent_id,
676 'module_class' => $module_data['class'],
677 'module_langname' => $module_data['title'],
678 'module_mode' => $module_mode,
679 'module_auth' => $module_data['auth'],
682 $_module->update_module_data($module_row, true);
684 // Ok, do we need to re-order the module, move it up or down?
685 if (!isset($module_data['after']))
690 $after_mode = $module_data['after'][0];
691 $after_langname = $module_data['after'][1];
693 // First of all, get the module id for the module this one has to be placed after
694 $sql = 'SELECT left_id
695 FROM ' . MODULES_TABLE . "
696 WHERE module_class = '" . $db->sql_escape($module_data['class']) . "'
697 AND module_basename = '" . $db->sql_escape($module_data['base']) . "'
698 AND module_langname = '" . $db->sql_escape($after_langname) . "'
699 AND module_mode = '" . $db->sql_escape($after_mode) . "'
700 AND parent_id = '{$parent_id}'";
701 $result = $db->sql_query($sql);
702 $first_left_id = (int) $db->sql_fetchfield('left_id');
703 $db->sql_freeresult($result);
710 // Ok, count the number of modules between $after_mode and the added module
711 $sql = 'SELECT COUNT(module_id) as num_modules
712 FROM ' . MODULES_TABLE . "
713 WHERE module_class = '" . $db->sql_escape($module_data['class']) . "'
714 AND parent_id = {$parent_id}
715 AND left_id BETWEEN {$first_left_id} AND {$module_row['left_id']}";
716 $result = $db->sql_query($sql);
717 $steps = (int) $db->sql_fetchfield('num_modules');
718 $db->sql_freeresult($result);
720 // We need to substract 2
728 // Ok, move module up $num_modules times. ;)
729 $_module->move_module_by($module_row, 'move_up', $steps);
733 $_module->remove_cache_file();
736 /****************************************************************************
737 * ADD YOUR DATABASE SCHEMA CHANGES HERE *
738 *****************************************************************************/
739 function database_update_info()
742 // Changes from 3.0.0 to the next version
744 // Add the following columns
745 'add_columns' => array(
746 FORUMS_TABLE => array(
747 'display_subforum_list' => array('BOOL', 1),
749 SESSIONS_TABLE => array(
750 'session_forum_id' => array('UINT', 0),
753 'drop_keys' => array(
754 GROUPS_TABLE => array('group_legend'),
756 'add_index' => array(
757 SESSIONS_TABLE => array(
758 'session_forum_id' => array('session_forum_id'),
760 GROUPS_TABLE => array(
761 'group_legend_name' => array('group_legend', 'group_name'),
765 // No changes from 3.0.1-RC1 to 3.0.1
766 '3.0.1-RC1' => array(),
767 // No changes from 3.0.1 to 3.0.2-RC1
769 // Changes from 3.0.2-RC1 to 3.0.2-RC2
770 '3.0.2-RC1' => array(
771 'change_columns' => array(
772 DRAFTS_TABLE => array(
773 'draft_subject' => array('STEXT_UNI', ''),
775 FORUMS_TABLE => array(
776 'forum_last_post_subject' => array('STEXT_UNI', ''),
778 POSTS_TABLE => array(
779 'post_subject' => array('STEXT_UNI', '', 'true_sort'),
781 PRIVMSGS_TABLE => array(
782 'message_subject' => array('STEXT_UNI', ''),
784 TOPICS_TABLE => array(
785 'topic_title' => array('STEXT_UNI', '', 'true_sort'),
786 'topic_last_post_subject' => array('STEXT_UNI', ''),
789 'drop_keys' => array(
790 SESSIONS_TABLE => array('session_forum_id'),
792 'add_index' => array(
793 SESSIONS_TABLE => array(
794 'session_fid' => array('session_forum_id'),
798 // No changes from 3.0.2-RC2 to 3.0.2
799 '3.0.2-RC2' => array(),
801 // Changes from 3.0.2 to 3.0.3-RC1
803 // Add the following columns
804 'add_columns' => array(
805 STYLES_TEMPLATE_TABLE => array(
806 'template_inherits_id' => array('UINT:4', 0),
807 'template_inherit_path' => array('VCHAR', ''),
809 GROUPS_TABLE => array(
810 'group_max_recipients' => array('UINT', 0),
815 // No changes from 3.0.3-RC1 to 3.0.3
816 '3.0.3-RC1' => array(),
818 // Changes from 3.0.3 to 3.0.4-RC1
820 'add_columns' => array(
821 PROFILE_FIELDS_TABLE => array(
822 'field_show_profile' => array('BOOL', 0),
825 'change_columns' => array(
826 STYLES_TABLE => array(
827 'style_id' => array('UINT', NULL, 'auto_increment'),
828 'template_id' => array('UINT', 0),
829 'theme_id' => array('UINT', 0),
830 'imageset_id' => array('UINT', 0),
832 STYLES_IMAGESET_TABLE => array(
833 'imageset_id' => array('UINT', NULL, 'auto_increment'),
835 STYLES_IMAGESET_DATA_TABLE => array(
836 'image_id' => array('UINT', NULL, 'auto_increment'),
837 'imageset_id' => array('UINT', 0),
839 STYLES_THEME_TABLE => array(
840 'theme_id' => array('UINT', NULL, 'auto_increment'),
842 STYLES_TEMPLATE_TABLE => array(
843 'template_id' => array('UINT', NULL, 'auto_increment'),
845 STYLES_TEMPLATE_DATA_TABLE => array(
846 'template_id' => array('UINT', 0),
848 FORUMS_TABLE => array(
849 'forum_style' => array('UINT', 0),
851 USERS_TABLE => array(
852 'user_style' => array('UINT', 0),
857 // Changes from 3.0.4-RC1 to 3.0.4
858 '3.0.4-RC1' => array(),
860 // Changes from 3.0.4 to 3.0.5-RC1
862 'change_columns' => array(
863 FORUMS_TABLE => array(
864 'forum_style' => array('UINT', 0),
869 // No changes from 3.0.5-RC1 to 3.0.5
870 '3.0.5-RC1' => array(),
872 // Changes from 3.0.5 to 3.0.6-RC1
874 'add_columns' => array(
875 CONFIRM_TABLE => array(
876 'attempts' => array('UINT', 0),
878 USERS_TABLE => array(
879 'user_new' => array('BOOL', 1),
880 'user_reminded' => array('TINT:4', 0),
881 'user_reminded_time'=> array('TIMESTAMP', 0),
883 GROUPS_TABLE => array(
884 'group_skip_auth' => array('BOOL', 0, 'after' => 'group_founder_manage'),
886 PRIVMSGS_TABLE => array(
887 'message_reported' => array('BOOL', 0),
889 REPORTS_TABLE => array(
890 'pm_id' => array('UINT', 0),
892 PROFILE_FIELDS_TABLE => array(
893 'field_show_on_vt' => array('BOOL', 0),
895 FORUMS_TABLE => array(
896 'forum_options' => array('UINT:20', 0),
899 'change_columns' => array(
900 USERS_TABLE => array(
901 'user_options' => array('UINT:11', 230271),
904 'add_index' => array(
905 REPORTS_TABLE => array(
906 'post_id' => array('post_id'),
907 'pm_id' => array('pm_id'),
909 POSTS_TABLE => array(
910 'post_username' => array('post_username:255'),
915 // No changes from 3.0.6-RC1 to 3.0.6-RC2
916 '3.0.6-RC1' => array(),
917 // No changes from 3.0.6-RC2 to 3.0.6-RC3
918 '3.0.6-RC2' => array(),
919 // No changes from 3.0.6-RC3 to 3.0.6-RC4
920 '3.0.6-RC3' => array(),
921 // No changes from 3.0.6-RC4 to 3.0.6
922 '3.0.6-RC4' => array(),
924 // Changes from 3.0.6 to 3.0.7-RC1
926 'drop_keys' => array(
927 LOG_TABLE => array('log_time'),
929 'add_index' => array(
930 TOPICS_TRACK_TABLE => array(
931 'topic_id' => array('topic_id'),
936 // No changes from 3.0.7-RC1 to 3.0.7-RC2
937 '3.0.7-RC1' => array(),
938 // No changes from 3.0.7-RC2 to 3.0.7
939 '3.0.7-RC2' => array(),
940 // No changes from 3.0.7 to 3.0.7-PL1
942 // No changes from 3.0.7-PL1 to 3.0.8-RC1
943 '3.0.7-PL1' => array(),
944 // No changes from 3.0.8-RC1 to 3.0.8
945 '3.0.8-RC1' => array(),
946 // Changes from 3.0.8 to 3.0.9-RC1
948 'add_tables' => array(
949 LOGIN_ATTEMPT_TABLE => array(
951 // this column was removed from the database updater
952 // after 3.0.9-RC3 was released. It might still exist
953 // in 3.0.9-RCX installations and has to be dropped in
954 // 3.0.11 after the db_tools class is capable of properly
955 // removing a primary key.
956 // 'attempt_id' => array('UINT', NULL, 'auto_increment'),
957 'attempt_ip' => array('VCHAR:40', ''),
958 'attempt_browser' => array('VCHAR:150', ''),
959 'attempt_forwarded_for' => array('VCHAR:255', ''),
960 'attempt_time' => array('TIMESTAMP', 0),
961 'user_id' => array('UINT', 0),
962 'username' => array('VCHAR_UNI:255', 0),
963 'username_clean' => array('VCHAR_CI', 0),
965 //'PRIMARY_KEY' => 'attempt_id',
967 'att_ip' => array('INDEX', array('attempt_ip', 'attempt_time')),
968 'att_for' => array('INDEX', array('attempt_forwarded_for', 'attempt_time')),
969 'att_time' => array('INDEX', array('attempt_time')),
970 'user_id' => array('INDEX', 'user_id'),
974 'change_columns' => array(
975 BBCODES_TABLE => array(
976 'bbcode_id' => array('USINT', 0),
980 // No changes from 3.0.9-RC1 to 3.0.9-RC2
981 '3.0.9-RC1' => array(),
982 // No changes from 3.0.9-RC2 to 3.0.9-RC3
983 '3.0.9-RC2' => array(),
984 // No changes from 3.0.9-RC3 to 3.0.9-RC4
985 '3.0.9-RC3' => array(),
986 // No changes from 3.0.9-RC4 to 3.0.9
987 '3.0.9-RC4' => array(),
988 // No changes from 3.0.9 to 3.0.10-RC1
990 // No changes from 3.0.10-RC1 to 3.0.10-RC2
991 '3.0.10-RC1' => array(),
992 // No changes from 3.0.10-RC2 to 3.0.10-RC3
993 '3.0.10-RC2' => array(),
994 // No changes from 3.0.10-RC3 to 3.0.10
995 '3.0.10-RC3' => array(),
997 /** @todo DROP LOGIN_ATTEMPT_TABLE.attempt_id in 3.0.11-RC1 */
1001 /****************************************************************************
1002 * ADD YOUR DATABASE DATA CHANGES HERE *
1003 * REMEMBER: You NEED to enter a schema array above and a data array here, *
1004 * even if both or one of them are empty. *
1005 *****************************************************************************/
1006 function change_database_data(&$no_updates, $version)
1008 global $db, $errored, $error_ary, $config, $phpbb_root_path, $phpEx;
1014 $sql = 'UPDATE ' . TOPICS_TABLE . "
1015 SET topic_last_view_time = topic_last_post_time
1016 WHERE topic_last_view_time = 0";
1017 _sql($sql, $errored, $error_ary);
1019 // Update smiley sizes
1020 $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');
1022 foreach ($smileys as $smiley)
1024 if (file_exists($phpbb_root_path . 'images/smilies/' . $smiley))
1026 list($width, $height) = getimagesize($phpbb_root_path . 'images/smilies/' . $smiley);
1028 $sql = 'UPDATE ' . SMILIES_TABLE . '
1029 SET smiley_width = ' . $width . ', smiley_height = ' . $height . "
1030 WHERE smiley_url = '" . $db->sql_escape($smiley) . "'";
1032 _sql($sql, $errored, $error_ary);
1036 $no_updates = false;
1039 // No changes from 3.0.1-RC1 to 3.0.1
1043 // changes from 3.0.1 to 3.0.2-RC1
1046 set_config('referer_validation', '1');
1047 set_config('check_attachment_content', '1');
1048 set_config('mime_triggers', 'body|head|html|img|plaintext|a href|pre|script|table|title');
1050 $no_updates = false;
1053 // No changes from 3.0.2-RC1 to 3.0.2-RC2
1057 // No changes from 3.0.2-RC2 to 3.0.2
1061 // Changes from 3.0.2 to 3.0.3-RC1
1063 set_config('enable_queue_trigger', '0');
1064 set_config('queue_trigger_posts', '3');
1066 set_config('pm_max_recipients', '0');
1068 // Set maximum number of recipients for the registered users, bots, guests group
1069 $sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_max_recipients = 5
1070 WHERE ' . $db->sql_in_set('group_name', array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA', 'BOTS'));
1071 _sql($sql, $errored, $error_ary);
1073 // Not prefilling yet
1074 set_config('dbms_version', '');
1076 // Add new permission u_masspm_group and duplicate settings from u_masspm
1077 include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
1078 $auth_admin = new auth_admin();
1080 // Only add the new permission if it does not already exist
1081 if (empty($auth_admin->acl_options['id']['u_masspm_group']))
1083 $auth_admin->acl_add_option(array('global' => array('u_masspm_group')));
1085 // Now the tricky part, filling the permission
1086 $old_id = $auth_admin->acl_options['id']['u_masspm'];
1087 $new_id = $auth_admin->acl_options['id']['u_masspm_group'];
1089 $tables = array(ACL_GROUPS_TABLE, ACL_ROLES_DATA_TABLE, ACL_USERS_TABLE);
1091 foreach ($tables as $table)
1095 WHERE auth_option_id = ' . $old_id;
1096 $result = _sql($sql, $errored, $error_ary);
1099 while ($row = $db->sql_fetchrow($result))
1101 $row['auth_option_id'] = $new_id;
1104 $db->sql_freeresult($result);
1106 if (sizeof($sql_ary))
1108 $db->sql_multi_insert($table, $sql_ary);
1112 // Remove any old permission entries
1113 $auth_admin->acl_clear_prefetch();
1117 * Do not resync post counts here. An admin may do this later from the ACP
1119 $step = ($config['num_posts']) ? (max((int) ($config['num_posts'] / 5), 20000)) : 20000;
1121 $sql = 'UPDATE ' . USERS_TABLE . ' SET user_posts = 0';
1122 _sql($sql, $errored, $error_ary);
1126 $sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
1127 FROM ' . POSTS_TABLE . '
1128 WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . '
1129 AND post_postcount = 1 AND post_approved = 1
1130 GROUP BY poster_id';
1131 $result = _sql($sql, $errored, $error_ary);
1133 if ($row = $db->sql_fetchrow($result))
1137 $sql = 'UPDATE ' . USERS_TABLE . " SET user_posts = user_posts + {$row['num_posts']} WHERE user_id = {$row['poster_id']}";
1138 _sql($sql, $errored, $error_ary);
1140 while ($row = $db->sql_fetchrow($result));
1148 $db->sql_freeresult($result);
1153 $sql = 'UPDATE ' . MODULES_TABLE . '
1154 SET module_auth = \'acl_a_email && cfg_email_enable\'
1155 WHERE module_class = \'acp\'
1156 AND module_basename = \'email\'';
1157 _sql($sql, $errored, $error_ary);
1159 $no_updates = false;
1162 // Changes from 3.0.3-RC1 to 3.0.3
1164 if ($db->sql_layer == 'oracle')
1166 // log_operation is CLOB - but we can change this later
1167 $sql = 'UPDATE ' . LOG_TABLE . "
1168 SET log_operation = 'LOG_DELETE_TOPIC'
1169 WHERE log_operation LIKE 'LOG_TOPIC_DELETED'";
1170 _sql($sql, $errored, $error_ary);
1174 $sql = 'UPDATE ' . LOG_TABLE . "
1175 SET log_operation = 'LOG_DELETE_TOPIC'
1176 WHERE log_operation = 'LOG_TOPIC_DELETED'";
1177 _sql($sql, $errored, $error_ary);
1180 $no_updates = false;
1183 // Changes from 3.0.3 to 3.0.4-RC1
1185 // Update the Custom Profile Fields based on previous settings to the new format
1186 $sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide
1187 FROM ' . PROFILE_FIELDS_TABLE;
1188 $result = _sql($sql, $errored, $error_ary);
1190 while ($row = $db->sql_fetchrow($result))
1193 'field_required' => 0,
1194 'field_show_on_reg' => 0,
1196 'field_show_profile'=> 0,
1199 if ($row['field_required'])
1201 $sql_ary['field_required'] = $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1;
1203 else if ($row['field_show_on_reg'])
1205 $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1;
1207 else if ($row['field_hide'])
1209 // 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
1210 $sql_ary['field_hide'] = 1;
1214 // equivelant to "none", which is the "Display in user control panel" option
1215 $sql_ary['field_show_profile'] = 1;
1218 _sql('UPDATE ' . PROFILE_FIELDS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary);
1220 $no_updates = false;
1224 // Changes from 3.0.4-RC1 to 3.0.4
1228 // Changes from 3.0.4 to 3.0.5-RC1
1231 // Captcha config variables
1232 set_config('captcha_gd_wave', 0);
1233 set_config('captcha_gd_3d_noise', 1);
1234 set_config('captcha_gd_fonts', 1);
1235 set_config('confirm_refresh', 1);
1237 // Maximum number of keywords
1238 set_config('max_num_search_keywords', 10);
1240 // Remove static config var and put it back as dynamic variable
1241 $sql = 'UPDATE ' . CONFIG_TABLE . "
1243 WHERE config_name = 'search_indexing_state'";
1244 _sql($sql, $errored, $error_ary);
1246 // Hash old MD5 passwords
1247 $sql = 'SELECT user_id, user_password
1248 FROM ' . USERS_TABLE . '
1249 WHERE user_pass_convert = 1';
1250 $result = _sql($sql, $errored, $error_ary);
1252 while ($row = $db->sql_fetchrow($result))
1254 if (strlen($row['user_password']) == 32)
1257 'user_password' => phpbb_hash($row['user_password']),
1260 _sql('UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $row['user_id'], $errored, $error_ary);
1263 $db->sql_freeresult($result);
1266 $sql = 'UPDATE ' . BOTS_TABLE . "
1267 SET bot_agent = 'ichiro/'
1268 WHERE bot_agent = 'ichiro/2'";
1269 _sql($sql, $errored, $error_ary);
1272 // Before we are able to add a unique key to auth_option, we need to remove duplicate entries
1274 // We get duplicate entries first
1275 $sql = 'SELECT auth_option
1276 FROM ' . ACL_OPTIONS_TABLE . '
1277 GROUP BY auth_option
1278 HAVING COUNT(*) >= 2';
1279 $result = $db->sql_query($sql);
1281 $auth_options = array();
1282 while ($row = $db->sql_fetchrow($result))
1284 $auth_options[] = $row['auth_option'];
1286 $db->sql_freeresult($result);
1288 // Remove specific auth options
1289 if (!empty($auth_options))
1291 foreach ($auth_options as $option)
1293 // Select auth_option_ids... the largest id will be preserved
1294 $sql = 'SELECT auth_option_id
1295 FROM ' . ACL_OPTIONS_TABLE . "
1296 WHERE auth_option = '" . $db->sql_escape($option) . "'
1297 ORDER BY auth_option_id DESC";
1298 // sql_query_limit not possible here, due to bug in postgresql layer
1299 $result = $db->sql_query($sql);
1301 // Skip first row, this is our original auth option we want to preserve
1302 $row = $db->sql_fetchrow($result);
1304 while ($row = $db->sql_fetchrow($result))
1306 // Ok, remove this auth option...
1307 _sql('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary);
1308 _sql('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary);
1309 _sql('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary);
1310 _sql('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary);
1312 $db->sql_freeresult($result);
1316 // Now make auth_option UNIQUE, by dropping the old index and adding a UNIQUE one.
1318 'drop_keys' => array(
1319 ACL_OPTIONS_TABLE => array('auth_option'),
1325 $statements = $db_tools->perform_schema_changes($changes);
1327 foreach ($statements as $sql)
1329 _sql($sql, $errored, $error_ary);
1333 'add_unique_index' => array(
1334 ACL_OPTIONS_TABLE => array(
1335 'auth_option' => array('auth_option'),
1340 $statements = $db_tools->perform_schema_changes($changes);
1342 foreach ($statements as $sql)
1344 _sql($sql, $errored, $error_ary);
1347 $no_updates = false;
1351 // No changes from 3.0.5-RC1 to 3.0.5
1355 // Changes from 3.0.5 to 3.0.6-RC1
1357 // Let's see if the GD Captcha can be enabled... we simply look for what *is* enabled...
1358 if (!empty($config['captcha_gd']) && !isset($config['captcha_plugin']))
1360 set_config('captcha_plugin', 'phpbb_captcha_gd');
1362 else if (!isset($config['captcha_plugin']))
1364 set_config('captcha_plugin', 'phpbb_captcha_nogd');
1367 // Entries for the Feed Feature
1368 set_config('feed_enable', '0');
1369 set_config('feed_limit', '10');
1371 set_config('feed_overall_forums', '1');
1372 set_config('feed_overall_forums_limit', '15');
1374 set_config('feed_overall_topics', '0');
1375 set_config('feed_overall_topics_limit', '15');
1377 set_config('feed_forum', '1');
1378 set_config('feed_topic', '1');
1379 set_config('feed_item_statistics', '1');
1381 // Entries for smiley pagination
1382 set_config('smilies_per_page', '50');
1384 // Entry for reporting PMs
1385 set_config('allow_pm_report', '1');
1388 $modules_to_install = array(
1392 'title' => 'ACP_FEED_SETTINGS',
1393 'auth' => 'acl_a_board',
1394 'cat' => 'ACP_BOARD_CONFIGURATION',
1395 'after' => array('signature', 'ACP_SIGNATURE_SETTINGS')
1397 'warnings' => array(
1400 'title' => 'ACP_USER_WARNINGS',
1401 'auth' => 'acl_a_user',
1403 'cat' => 'ACP_CAT_USERS',
1404 'after' => array('feedback', 'ACP_USER_FEEDBACK')
1406 'send_statistics' => array(
1407 'base' => 'send_statistics',
1409 'title' => 'ACP_SEND_STATISTICS',
1410 'auth' => 'acl_a_server',
1411 'cat' => 'ACP_SERVER_CONFIGURATION'
1413 'setting_forum_copy' => array(
1414 'base' => 'permissions',
1416 'title' => 'ACP_FORUM_PERMISSIONS_COPY',
1417 'auth' => 'acl_a_fauth && acl_a_authusers && acl_a_authgroups && acl_a_mauth',
1418 'cat' => 'ACP_FORUM_BASED_PERMISSIONS',
1419 'after' => array('setting_forum_local', 'ACP_FORUM_PERMISSIONS')
1421 'pm_reports' => array(
1422 'base' => 'pm_reports',
1424 'title' => 'MCP_PM_REPORTS_OPEN',
1425 'auth' => 'aclf_m_report',
1426 'cat' => 'MCP_REPORTS'
1428 'pm_reports_closed' => array(
1429 'base' => 'pm_reports',
1431 'title' => 'MCP_PM_REPORTS_CLOSED',
1432 'auth' => 'aclf_m_report',
1433 'cat' => 'MCP_REPORTS'
1435 'pm_report_details' => array(
1436 'base' => 'pm_reports',
1438 'title' => 'MCP_PM_REPORT_DETAILS',
1439 'auth' => 'aclf_m_report',
1440 'cat' => 'MCP_REPORTS'
1444 _add_modules($modules_to_install);
1446 // Add newly_registered group... but check if it already exists (we always supported running the updater on any schema)
1447 $sql = 'SELECT group_id
1448 FROM ' . GROUPS_TABLE . "
1449 WHERE group_name = 'NEWLY_REGISTERED'";
1450 $result = $db->sql_query($sql);
1451 $group_id = (int) $db->sql_fetchfield('group_id');
1452 $db->sql_freeresult($result);
1456 $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)";
1457 _sql($sql, $errored, $error_ary);
1459 $group_id = $db->sql_nextid();
1462 // Insert new user role... at the end of the chain
1463 $sql = 'SELECT role_id
1464 FROM ' . ACL_ROLES_TABLE . "
1465 WHERE role_name = 'ROLE_USER_NEW_MEMBER'
1466 AND role_type = 'u_'";
1467 $result = $db->sql_query($sql);
1468 $u_role = (int) $db->sql_fetchfield('role_id');
1469 $db->sql_freeresult($result);
1473 $sql = 'SELECT MAX(role_order) as max_order_id
1474 FROM ' . ACL_ROLES_TABLE . "
1475 WHERE role_type = 'u_'";
1476 $result = $db->sql_query($sql);
1477 $next_order_id = (int) $db->sql_fetchfield('max_order_id');
1478 $db->sql_freeresult($result);
1482 $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)";
1483 _sql($sql, $errored, $error_ary);
1484 $u_role = $db->sql_nextid();
1488 // Now add the correct data to the roles...
1489 // The standard role says that new users are not able to send a PM, Mass PM, are not able to PM groups
1490 $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')";
1491 _sql($sql, $errored, $error_ary);
1493 // Add user role to group
1494 $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)";
1495 _sql($sql, $errored, $error_ary);
1499 // Insert new forum role
1500 $sql = 'SELECT role_id
1501 FROM ' . ACL_ROLES_TABLE . "
1502 WHERE role_name = 'ROLE_FORUM_NEW_MEMBER'
1503 AND role_type = 'f_'";
1504 $result = $db->sql_query($sql);
1505 $f_role = (int) $db->sql_fetchfield('role_id');
1506 $db->sql_freeresult($result);
1510 $sql = 'SELECT MAX(role_order) as max_order_id
1511 FROM ' . ACL_ROLES_TABLE . "
1512 WHERE role_type = 'f_'";
1513 $result = $db->sql_query($sql);
1514 $next_order_id = (int) $db->sql_fetchfield('max_order_id');
1515 $db->sql_freeresult($result);
1519 $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)";
1520 _sql($sql, $errored, $error_ary);
1521 $f_role = $db->sql_nextid();
1525 $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')";
1526 _sql($sql, $errored, $error_ary);
1530 // 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)
1532 FROM ' . USERS_TABLE . '
1533 WHERE user_new = 0';
1534 $result = $db->sql_query_limit($sql, 1);
1535 $row = $db->sql_fetchrow($result);
1536 $db->sql_freeresult($result);
1540 $sql = 'UPDATE ' . USERS_TABLE . ' SET user_new = 0';
1541 _sql($sql, $errored, $error_ary);
1544 // Newly registered users limit
1545 if (!isset($config['new_member_post_limit']))
1547 set_config('new_member_post_limit', (!empty($config['enable_queue_trigger'])) ? $config['queue_trigger_posts'] : 0);
1550 if (!isset($config['new_member_group_default']))
1552 set_config('new_member_group_default', 0);
1555 // 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...
1556 // Check if the role is already assigned...
1557 $sql = 'SELECT forum_id
1558 FROM ' . ACL_GROUPS_TABLE . '
1559 WHERE group_id = ' . $group_id . '
1560 AND auth_role_id = ' . $f_role;
1561 $result = $db->sql_query($sql);
1562 $is_options = (int) $db->sql_fetchfield('forum_id');
1563 $db->sql_freeresult($result);
1565 // Not assigned at all... :/
1568 // Get postable forums
1569 $sql = 'SELECT forum_id
1570 FROM ' . FORUMS_TABLE . '
1571 WHERE forum_type != ' . FORUM_LINK;
1572 $result = $db->sql_query($sql);
1574 while ($row = $db->sql_fetchrow($result))
1576 _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);
1578 $db->sql_freeresult($result);
1581 // Clear permissions...
1582 include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
1583 $auth_admin = new auth_admin();
1584 $auth_admin->acl_clear_prefetch();
1586 if (!isset($config['allow_avatar']))
1588 if ($config['allow_avatar_upload'] || $config['allow_avatar_local'] || $config['allow_avatar_remote'])
1590 set_config('allow_avatar', '1');
1594 set_config('allow_avatar', '0');
1598 if (!isset($config['allow_avatar_remote_upload']))
1600 if ($config['allow_avatar_remote'] && $config['allow_avatar_upload'])
1602 set_config('allow_avatar_remote_upload', '1');
1606 set_config('allow_avatar_remote_upload', '0');
1610 // Minimum number of characters
1611 if (!isset($config['min_post_chars']))
1613 set_config('min_post_chars', '1');
1616 if (!isset($config['allow_quick_reply']))
1618 set_config('allow_quick_reply', '1');
1621 // Set every members user_options column to enable
1622 // bbcode, smilies and URLs for signatures by default
1623 $sql = 'SELECT user_options
1624 FROM ' . USERS_TABLE . '
1625 WHERE user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')';
1626 $result = $db->sql_query_limit($sql, 1);
1627 $user_option = (int) $db->sql_fetchfield('user_options');
1628 $db->sql_freeresult($result);
1630 // Check if we already updated the database by checking bit 15 which we used to store the sig_bbcode option
1631 if (!($user_option & 1 << 15))
1633 // 229376 is the added value to enable all three signature options
1634 $sql = 'UPDATE ' . USERS_TABLE . ' SET user_options = user_options + 229376';
1635 _sql($sql, $errored, $error_ary);
1638 if (!isset($config['delete_time']))
1640 set_config('delete_time', $config['edit_time']);
1643 $no_updates = false;
1646 // No changes from 3.0.6-RC1 to 3.0.6-RC2
1650 // Changes from 3.0.6-RC2 to 3.0.6-RC3
1653 // Update the Custom Profile Fields based on previous settings to the new format
1654 $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . '
1655 SET field_show_on_vt = 1
1656 WHERE field_hide = 0
1657 AND (field_required = 1 OR field_show_on_reg = 1 OR field_show_profile = 1)';
1658 _sql($sql, $errored, $error_ary);
1659 $no_updates = false;
1663 // No changes from 3.0.6-RC3 to 3.0.6-RC4
1667 // No changes from 3.0.6-RC4 to 3.0.6
1671 // Changes from 3.0.6 to 3.0.7-RC1
1675 set_config('feed_overall', '1');
1676 set_config('feed_http_auth', '0');
1677 set_config('feed_limit_post', (string) (isset($config['feed_limit']) ? (int) $config['feed_limit'] : 15));
1678 set_config('feed_limit_topic', (string) (isset($config['feed_overall_topics_limit']) ? (int) $config['feed_overall_topics_limit'] : 10));
1679 set_config('feed_topics_new', (!empty($config['feed_overall_topics']) ? '1' : '0'));
1680 set_config('feed_topics_active', (!empty($config['feed_overall_topics']) ? '1' : '0'));
1682 // Delete all text-templates from the template_data
1683 $sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . '
1684 WHERE template_filename ' . $db->sql_like_expression($db->any_char . '.txt');
1685 _sql($sql, $errored, $error_ary);
1687 $no_updates = false;
1690 // Changes from 3.0.7-RC1 to 3.0.7-RC2
1693 $sql = 'SELECT user_id, user_email, user_email_hash
1694 FROM ' . USERS_TABLE . '
1695 WHERE user_type <> ' . USER_IGNORE . "
1696 AND user_email <> ''";
1697 $result = $db->sql_query($sql);
1700 while ($row = $db->sql_fetchrow($result))
1702 // Snapshot of the phpbb_email_hash() function
1703 // We cannot call it directly because the auto updater updates the DB first. :/
1704 $user_email_hash = sprintf('%u', crc32(strtolower($row['user_email']))) . strlen($row['user_email']);
1706 if ($user_email_hash != $row['user_email_hash'])
1709 'user_email_hash' => $user_email_hash,
1712 $sql = 'UPDATE ' . USERS_TABLE . '
1713 SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
1714 WHERE user_id = ' . (int) $row['user_id'];
1715 _sql($sql, $errored, $error_ary, ($i % 100 == 0));
1720 $db->sql_freeresult($result);
1722 $no_updates = false;
1726 // No changes from 3.0.7-RC2 to 3.0.7
1730 // No changes from 3.0.7 to 3.0.7-PL1
1734 // Changes from 3.0.7-PL1 to 3.0.8-RC1
1736 // Update file extension group names to use language strings.
1737 $sql = 'SELECT lang_dir
1738 FROM ' . LANG_TABLE;
1739 $result = $db->sql_query($sql);
1741 $extension_groups_updated = array();
1742 while ($lang_dir = $db->sql_fetchfield('lang_dir'))
1744 $lang_dir = basename($lang_dir);
1746 // The language strings we need are either in language/.../acp/attachments.php
1747 // in the update package if we're updating to 3.0.8-RC1 or later,
1748 // or they are in language/.../install.php when we're updating from 3.0.7-PL1 or earlier.
1749 // On an already updated board, they can also already be in language/.../acp/attachments.php
1750 // in the board root.
1751 $lang_files = array(
1752 "{$phpbb_root_path}install/update/new/language/$lang_dir/acp/attachments.$phpEx",
1753 "{$phpbb_root_path}language/$lang_dir/install.$phpEx",
1754 "{$phpbb_root_path}language/$lang_dir/acp/attachments.$phpEx",
1757 foreach ($lang_files as $lang_file)
1759 if (!file_exists($lang_file))
1765 include($lang_file);
1767 foreach($lang as $lang_key => $lang_val)
1769 if (isset($extension_groups_updated[$lang_key]) || strpos($lang_key, 'EXT_GROUP_') !== 0)
1775 'group_name' => substr($lang_key, 10), // Strip off 'EXT_GROUP_'
1778 $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . '
1779 SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
1780 WHERE group_name = '" . $db->sql_escape($lang_val) . "'";
1781 _sql($sql, $errored, $error_ary);
1783 $extension_groups_updated[$lang_key] = true;
1787 $db->sql_freeresult($result);
1790 $modules_to_install = array(
1794 'title' => 'ACP_POST_SETTINGS',
1795 'auth' => 'acl_a_board',
1796 'cat' => 'ACP_MESSAGES',
1797 'after' => array('message', 'ACP_MESSAGE_SETTINGS')
1801 _add_modules($modules_to_install);
1804 $sql = 'UPDATE ' . MODULES_TABLE . '
1805 SET module_auth = \'cfg_allow_avatar && (cfg_allow_avatar_local || cfg_allow_avatar_remote || cfg_allow_avatar_upload || cfg_allow_avatar_remote_upload)\'
1806 WHERE module_class = \'ucp\'
1807 AND module_basename = \'profile\'
1808 AND module_mode = \'avatar\'';
1809 _sql($sql, $errored, $error_ary);
1812 $bot_name = 'Bing [Bot]';
1813 $bot_name_clean = utf8_clean_string($bot_name);
1815 $sql = 'SELECT user_id
1816 FROM ' . USERS_TABLE . "
1817 WHERE username_clean = '" . $db->sql_escape($bot_name_clean) . "'";
1818 $result = $db->sql_query($sql);
1819 $bing_already_added = (bool) $db->sql_fetchfield('user_id');
1820 $db->sql_freeresult($result);
1822 if (!$bing_already_added)
1824 $bot_agent = 'bingbot/';
1826 $sql = 'SELECT group_id, group_colour
1827 FROM ' . GROUPS_TABLE . "
1828 WHERE group_name = 'BOTS'";
1829 $result = $db->sql_query($sql);
1830 $group_row = $db->sql_fetchrow($result);
1831 $db->sql_freeresult($result);
1835 // default fallback, should never get here
1836 $group_row['group_id'] = 6;
1837 $group_row['group_colour'] = '9E8DA7';
1840 if (!function_exists('user_add'))
1842 include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
1846 'user_type' => USER_IGNORE,
1847 'group_id' => $group_row['group_id'],
1848 'username' => $bot_name,
1849 'user_regdate' => time(),
1850 'user_password' => '',
1851 'user_colour' => $group_row['group_colour'],
1853 'user_lang' => $config['default_lang'],
1854 'user_style' => $config['default_style'],
1855 'user_timezone' => 0,
1856 'user_dateformat' => $config['default_dateformat'],
1857 'user_allow_massemail' => 0,
1860 $user_id = user_add($user_row);
1862 $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
1864 'bot_name' => (string) $bot_name,
1865 'user_id' => (int) $user_id,
1866 'bot_agent' => (string) $bot_agent,
1867 'bot_ip' => (string) $bot_ip,
1870 _sql($sql, $errored, $error_ary);
1872 // end Bing Bot addition
1874 // Delete shadow topics pointing to not existing topics
1877 // Set of affected forums we have to resync
1878 $sync_forum_ids = array();
1883 'SELECT' => 't1.topic_id, t1.forum_id',
1885 TOPICS_TABLE => 't1',
1887 'LEFT_JOIN' => array(
1889 'FROM' => array(TOPICS_TABLE => 't2'),
1890 'ON' => 't1.topic_moved_id = t2.topic_id',
1893 'WHERE' => 't1.topic_moved_id <> 0
1894 AND t2.topic_id IS NULL',
1896 $sql = $db->sql_build_query('SELECT', $sql_array);
1897 $result = $db->sql_query_limit($sql, $batch_size);
1899 $topic_ids = array();
1900 while ($row = $db->sql_fetchrow($result))
1902 $topic_ids[] = (int) $row['topic_id'];
1904 $sync_forum_ids[(int) $row['forum_id']] = (int) $row['forum_id'];
1906 $db->sql_freeresult($result);
1908 if (!empty($topic_ids))
1910 $sql = 'DELETE FROM ' . TOPICS_TABLE . '
1911 WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
1912 $db->sql_query($sql);
1915 while (sizeof($topic_ids) == $batch_size);
1917 // Sync the forums we have deleted shadow topics from.
1918 sync('forum', 'forum_id', $sync_forum_ids, true, true);
1920 // Unread posts search load switch
1921 set_config('load_unreads_search', '1');
1923 // Reduce queue interval to 60 seconds, email package size to 20
1924 if ($config['queue_interval'] == 600)
1926 set_config('queue_interval', '60');
1929 if ($config['email_package_size'] == 50)
1931 set_config('email_package_size', '20');
1934 $no_updates = false;
1937 // No changes from 3.0.8-RC1 to 3.0.8
1941 // Changes from 3.0.8 to 3.0.9-RC1
1943 set_config('ip_login_limit_max', '50');
1944 set_config('ip_login_limit_time', '21600');
1945 set_config('ip_login_limit_use_forwarded', '0');
1947 // Update file extension group names to use language strings, again.
1948 $sql = 'SELECT group_id, group_name
1949 FROM ' . EXTENSION_GROUPS_TABLE . '
1950 WHERE group_name ' . $db->sql_like_expression('EXT_GROUP_' . $db->any_char);
1951 $result = $db->sql_query($sql);
1953 while ($row = $db->sql_fetchrow($result))
1956 'group_name' => substr($row['group_name'], 10), // Strip off 'EXT_GROUP_'
1959 $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . '
1960 SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
1961 WHERE group_id = ' . $row['group_id'];
1962 _sql($sql, $errored, $error_ary);
1964 $db->sql_freeresult($result);
1966 global $db_tools, $table_prefix;
1968 // Recover from potentially broken Q&A CAPTCHA table on firebird
1969 // Q&A CAPTCHA was uninstallable, so it's safe to remove these
1970 // without data loss
1971 if ($db_tools->sql_layer == 'firebird')
1974 $table_prefix . 'captcha_questions',
1975 $table_prefix . 'captcha_answers',
1976 $table_prefix . 'qa_confirm',
1978 foreach ($tables as $table)
1980 if ($db_tools->sql_table_exists($table))
1982 $db_tools->sql_table_drop($table);
1987 $no_updates = false;
1990 // No changes from 3.0.9-RC1 to 3.0.9-RC2
1994 // No changes from 3.0.9-RC2 to 3.0.9-RC3
1998 // No changes from 3.0.9-RC3 to 3.0.9-RC4
2002 // No changes from 3.0.9-RC4 to 3.0.9
2006 // Changes from 3.0.9 to 3.0.10-RC1
2008 if (!isset($config['email_max_chunk_size']))
2010 set_config('email_max_chunk_size', '50');
2013 $no_updates = false;
2016 // No changes from 3.0.10-RC1 to 3.0.10-RC2
2020 // No changes from 3.0.10-RC2 to 3.0.10-RC3
2024 // No changes from 3.0.10-RC3 to 3.0.10