aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/install/database_update.php
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/install/database_update.php')
-rw-r--r--phpBB/install/database_update.php1040
1 files changed, 970 insertions, 70 deletions
diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php
index 6097341ace..4a61d189a3 100644
--- a/phpBB/install/database_update.php
+++ b/phpBB/install/database_update.php
@@ -2,13 +2,16 @@
/**
*
* @package install
-* @version $Id$
* @copyright (c) 2006 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
-define('UPDATES_TO_VERSION', '3.0.11-dev');
+use Symfony\Component\Config\FileLocator;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
+
+define('UPDATES_TO_VERSION', '3.1.0-dev');
// Enter any version to update from to test updates. The version within the db will not be updated.
define('DEBUG_FROM_VERSION', false);
@@ -60,8 +63,6 @@ $updates_to_version = UPDATES_TO_VERSION;
$debug_from_version = DEBUG_FROM_VERSION;
$oldest_from_version = OLDEST_FROM_VERSION;
-error_reporting(E_ALL);
-
@set_time_limit(0);
// Include essential scripts
@@ -72,31 +73,20 @@ if (!defined('PHPBB_INSTALLED') || empty($dbms) || empty($acm_type))
die("Please read: <a href='../docs/INSTALL.html'>INSTALL.html</a> before attempting to update.");
}
-// Load Extensions
-if (!empty($load_extensions) && function_exists('dl'))
-{
- $load_extensions = explode(',', $load_extensions);
-
- foreach ($load_extensions as $extension)
- {
- @dl(trim($extension));
- }
-}
+// In case $phpbb_adm_relative_path is not set (in case of an update), use the default.
+$phpbb_adm_relative_path = (isset($phpbb_adm_relative_path)) ? $phpbb_adm_relative_path : 'adm/';
+$phpbb_admin_path = (defined('PHPBB_ADMIN_PATH')) ? PHPBB_ADMIN_PATH : $phpbb_root_path . $phpbb_adm_relative_path;
// Include files
-require($phpbb_root_path . 'includes/acm/acm_' . $acm_type . '.' . $phpEx);
-require($phpbb_root_path . 'includes/cache.' . $phpEx);
-require($phpbb_root_path . 'includes/template.' . $phpEx);
-require($phpbb_root_path . 'includes/session.' . $phpEx);
-require($phpbb_root_path . 'includes/auth.' . $phpEx);
+require($phpbb_root_path . 'includes/class_loader.' . $phpEx);
require($phpbb_root_path . 'includes/functions.' . $phpEx);
+require($phpbb_root_path . 'includes/functions_container.' . $phpEx);
phpbb_require_updated('includes/functions_content.' . $phpEx, true);
require($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
require($phpbb_root_path . 'includes/constants.' . $phpEx);
-require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
phpbb_require_updated('includes/db/db_tools.' . $phpEx);
@@ -107,10 +97,35 @@ if (!defined('LOGIN_ATTEMPT_TABLE'))
{
define('LOGIN_ATTEMPT_TABLE', $table_prefix . 'login_attempts');
}
+if (!defined('EXT_TABLE'))
+{
+ define('EXT_TABLE', $table_prefix . 'ext');
+}
+
+// Setup class loader first
+$phpbb_class_loader = new phpbb_class_loader('phpbb_', "{$phpbb_root_path}includes/", ".$phpEx");
+$phpbb_class_loader->register();
+$phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', "{$phpbb_root_path}ext/", ".$phpEx");
+$phpbb_class_loader_ext->register();
+
+// Set up container
+$phpbb_container = phpbb_create_default_container($phpbb_root_path, $phpEx);
+
+$phpbb_class_loader->set_cache($phpbb_container->get('cache.driver'));
+$phpbb_class_loader_ext->set_cache($phpbb_container->get('cache.driver'));
+
+// set up caching
+$cache = $phpbb_container->get('cache');
+
+// Instantiate some basic classes
+$phpbb_dispatcher = $phpbb_container->get('dispatcher');
+$request = $phpbb_container->get('request');
+$user = $phpbb_container->get('user');
+$auth = $phpbb_container->get('auth');
+$db = $phpbb_container->get('dbal.conn');
-$user = new user();
-$cache = new cache();
-$db = new $sql_db();
+// make sure request_var uses this request instance
+request_var('', 0, false, false, $request); // "dependency injection" for a function
// Add own hook handler, if present. :o
if (file_exists($phpbb_root_path . 'includes/hooks/index.' . $phpEx))
@@ -118,7 +133,8 @@ if (file_exists($phpbb_root_path . 'includes/hooks/index.' . $phpEx))
require($phpbb_root_path . 'includes/hooks/index.' . $phpEx);
$phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('template', 'display')));
- foreach ($cache->obtain_hooks() as $hook)
+ $phpbb_hook_finder = $phpbb_container->get('hook_finder');
+ foreach ($phpbb_hook_finder->find() as $hook)
{
@include($phpbb_root_path . 'includes/hooks/' . $hook . '.' . $phpEx);
}
@@ -134,8 +150,11 @@ $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false);
// We do not need this any longer, unset for safety purposes
unset($dbpasswd);
-$user->ip = (!empty($_SERVER['REMOTE_ADDR'])) ? htmlspecialchars($_SERVER['REMOTE_ADDR']) : '';
-$user->ip = (stripos($user->ip, '::ffff:') === 0) ? substr($user->ip, 7) : $user->ip;
+$user->ip = '';
+if ($request->server('REMOTE_ADDR'))
+{
+ $user->ip = (function_exists('phpbb_ip_normalise')) ? phpbb_ip_normalise($request->server('REMOTE_ADDR')) : $request->server('REMOTE_ADDR');
+}
$sql = "SELECT config_value
FROM " . CONFIG_TABLE . "
@@ -168,17 +187,15 @@ include($phpbb_root_path . 'language/' . $language . '/install.' . $phpEx);
$inline_update = (request_var('type', 0)) ? true : false;
// To let set_config() calls succeed, we need to make the config array available globally
-$config = array();
-
-$sql = 'SELECT *
- FROM ' . CONFIG_TABLE;
-$result = $db->sql_query($sql);
+$config = new phpbb_config_db($db, $phpbb_container->get('cache.driver'), CONFIG_TABLE);
+set_config(null, null, null, $config);
+set_config_count(null, null, null, $config);
-while ($row = $db->sql_fetchrow($result))
+// Update asset_version
+if (isset($config['assets_version']))
{
- $config[$row['config_name']] = $row['config_value'];
+ set_config('assets_version', $config['assets_version'] + 1);
}
-$db->sql_freeresult($result);
// phpbb_db_tools will be taken from new files (under install/update/new)
// if possible, falling back to the board's copy.
@@ -189,21 +206,76 @@ $database_update_info = database_update_info();
$error_ary = array();
$errored = false;
+$sql = 'SELECT topic_id
+ FROM ' . TOPICS_TABLE . '
+ WHERE forum_id = 0
+ AND topic_type = ' . POST_GLOBAL;
+$result = $db->sql_query_limit($sql, 1);
+$has_global = (int) $db->sql_fetchfield('topic_id');
+$db->sql_freeresult($result);
+$ga_forum_id = request_var('ga_forum_id', 0);
+
+if ($has_global && !$ga_forum_id)
+{
+ ?>
+ <!DOCTYPE html>
+ <html dir="<?php echo $lang['DIRECTION']; ?>" lang="<?php echo $lang['USER_LANG']; ?>">
+ <head>
+ <meta charset="utf-8">
+
+ <title><?php echo $lang['UPDATING_TO_LATEST_STABLE']; ?></title>
+
+ <link href="<?php echo htmlspecialchars($phpbb_admin_path); ?>style/admin.css" rel="stylesheet" type="text/css" media="screen" />
+
+ </head>
+
+ <body>
+ <div id="wrap">
+ <div id="page-header">&nbsp;</div>
+
+ <div id="page-body">
+ <div id="acp">
+ <div class="panel">
+ <span class="corners-top"><span></span></span>
+ <div id="content">
+ <div id="main" class="install-body">
+
+ <h1><?php echo $lang['UPDATING_TO_LATEST_STABLE']; ?></h1>
+
+ <br />
+
+ <form action="" method="post" id="select_ga_forum_id">
+ <?php
+ if (isset($lang['SELECT_FORUM_GA']))
+ {
+ // Language string is available:
+ echo $lang['SELECT_FORUM_GA'];
+ }
+ else
+ {
+ echo 'In phpBB 3.1 the global announcements are linked to forums. Select a forum for your current global announcements (can be moved later):';
+ }
+ ?>
+ <select id="ga_forum_id" name="ga_forum_id"><?php echo make_forum_select(false, false, true, true) ?></select>
+
+ <input type="submit" name="post" value="<?php echo $lang['SUBMIT']; ?>" class="button1" />
+ </form>
+ <?php
+ _print_footer();
+ exit_handler();
+}
+
header('Content-type: text/html; charset=UTF-8');
?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" dir="<?php echo $lang['DIRECTION']; ?>" lang="<?php echo $lang['USER_LANG']; ?>" xml:lang="<?php echo $lang['USER_LANG']; ?>">
+<!DOCTYPE html>
+<html dir="<?php echo $lang['DIRECTION']; ?>" lang="<?php echo $lang['USER_LANG']; ?>">
<head>
-
-<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
-<meta http-equiv="content-language" content="<?php echo $lang['USER_LANG']; ?>" />
-<meta http-equiv="content-style-type" content="text/css" />
-<meta http-equiv="imagetoolbar" content="no" />
+<meta charset="utf-8">
<title><?php echo $lang['UPDATING_TO_LATEST_STABLE']; ?></title>
-<link href="../adm/style/admin.css" rel="stylesheet" type="text/css" media="screen" />
+<link href="<?php echo htmlspecialchars($phpbb_admin_path); ?>style/admin.css" rel="stylesheet" type="text/css" media="screen" />
</head>
@@ -502,7 +574,7 @@ else
add_log('admin', 'LOG_UPDATE_DATABASE', $orig_version, $updates_to_version);
// Now we purge the session table as well as all cache files
-$cache->purge();
+$phpbb_container->get('cache.driver')->purge();
_print_footer();
@@ -527,7 +599,7 @@ function _print_footer()
</div>
<div id="page-footer">
- Powered by <a href="http://www.phpbb.com/">phpBB</a>&reg; Forum Software &copy; phpBB Group
+ Powered by <a href="https://www.phpbb.com/">phpBB</a>&reg; Forum Software &copy; phpBB Group
</div>
</div>
@@ -543,7 +615,7 @@ function _sql($sql, &$errored, &$error_ary, $echo_dot = true)
{
global $db;
- if (defined('DEBUG_EXTRA'))
+ if (defined('DEBUG'))
{
echo "<br />\n{$sql}\n<br />";
}
@@ -613,7 +685,13 @@ function _write_result($no_updates, $errored, $error_ary)
function _add_modules($modules_to_install)
{
- global $phpbb_root_path, $phpEx, $db;
+ global $phpbb_root_path, $phpEx, $db, $phpbb_extension_manager, $config;
+
+ // modules require an extension manager
+ if (empty($phpbb_extension_manager))
+ {
+ $phpbb_extension_manager = new phpbb_extension_manager($db, $config, EXT_TABLE, $phpbb_root_path, ".$phpEx");
+ }
include_once($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx);
@@ -733,6 +811,70 @@ function _add_modules($modules_to_install)
$_module->remove_cache_file();
}
+/**
+* Add a new permission, optionally copy permission setting from another
+*
+* @param auth_admin $auth_admin auth_admin object
+* @param phpbb_db_driver $db Database object
+* @param string $permission_name Name of the permission to add
+* @param bool $is_global True is global, false is local
+* @param string $copy_from Optional permission name from which to copy
+* @return bool true on success, false on failure
+*/
+function _add_permission(auth_admin $auth_admin, phpbb_db_driver $db, $permission_name, $is_global = true, $copy_from = '')
+{
+ // Only add a permission that don't already exist
+ if (!empty($auth_admin->acl_options['id'][$permission_name]))
+ {
+ return true;
+ }
+
+ $permission_scope = $is_global ? 'global' : 'local';
+
+ $result = $auth_admin->acl_add_option(array(
+ $permission_scope => array($permission_name),
+ ));
+
+ if (!$result)
+ {
+ return $result;
+ }
+
+ // The permission has been added, now we can copy it if needed
+ if ($copy_from && isset($auth_admin->acl_options['id'][$copy_from]))
+ {
+ $old_id = $auth_admin->acl_options['id'][$copy_from];
+ $new_id = $auth_admin->acl_options['id'][$permission_name];
+
+ $tables = array(ACL_GROUPS_TABLE, ACL_ROLES_DATA_TABLE, ACL_USERS_TABLE);
+
+ foreach ($tables as $table)
+ {
+ $sql = 'SELECT *
+ FROM ' . $table . '
+ WHERE auth_option_id = ' . $old_id;
+ $result = _sql($sql, $errored, $error_ary);
+
+ $sql_ary = array();
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $row['auth_option_id'] = $new_id;
+ $sql_ary[] = $row;
+ }
+ $db->sql_freeresult($result);
+
+ if (sizeof($sql_ary))
+ {
+ $db->sql_multi_insert($table, $sql_ary);
+ }
+ }
+
+ $auth_admin->acl_clear_prefetch();
+ }
+
+ return true;
+}
+
/****************************************************************************
* ADD YOUR DATABASE SCHEMA CHANGES HERE *
*****************************************************************************/
@@ -951,7 +1093,7 @@ function database_update_info()
// this column was removed from the database updater
// after 3.0.9-RC3 was released. It might still exist
// in 3.0.9-RCX installations and has to be dropped in
- // 3.0.11 after the db_tools class is capable of properly
+ // 3.0.12 after the db_tools class is capable of properly
// removing a primary key.
// 'attempt_id' => array('UINT', NULL, 'auto_increment'),
'attempt_ip' => array('VCHAR:40', ''),
@@ -995,8 +1137,71 @@ function database_update_info()
'3.0.10-RC3' => array(),
// No changes from 3.0.10 to 3.0.11-RC1
'3.0.10' => array(),
+ // Changes from 3.0.11-RC1 to 3.0.11-RC2
+ '3.0.11-RC1' => array(
+ 'add_columns' => array(
+ PROFILE_FIELDS_TABLE => array(
+ 'field_show_novalue' => array('BOOL', 0),
+ ),
+ ),
+ ),
+ // No changes from 3.0.11-RC2 to 3.0.11
+ '3.0.11-RC2' => array(),
+ // No changes from 3.0.11 to 3.0.12-RC1
+ '3.0.11' => array(),
- /** @todo DROP LOGIN_ATTEMPT_TABLE.attempt_id in 3.0.11-RC1 */
+ /** @todo DROP LOGIN_ATTEMPT_TABLE.attempt_id in 3.0.12-RC1 */
+
+ // Changes from 3.1.0-dev to 3.1.0-A1
+ '3.1.0-dev' => array(
+ 'add_tables' => array(
+ EXT_TABLE => array(
+ 'COLUMNS' => array(
+ 'ext_name' => array('VCHAR', ''),
+ 'ext_active' => array('BOOL', 0),
+ 'ext_state' => array('TEXT', ''),
+ ),
+ 'KEYS' => array(
+ 'ext_name' => array('UNIQUE', 'ext_name'),
+ ),
+ ),
+ ),
+ 'add_columns' => array(
+ GROUPS_TABLE => array(
+ 'group_teampage' => array('UINT', 0, 'after' => 'group_legend'),
+ ),
+ PROFILE_FIELDS_TABLE => array(
+ 'field_show_on_pm' => array('BOOL', 0),
+ ),
+ STYLES_TABLE => array(
+ 'style_path' => array('VCHAR:100', ''),
+ 'bbcode_bitfield' => array('VCHAR:255', 'kNg='),
+ 'style_parent_id' => array('UINT:4', 0),
+ 'style_parent_tree' => array('TEXT', ''),
+ ),
+ REPORTS_TABLE => array(
+ 'reported_post_text' => array('MTEXT_UNI', ''),
+ 'reported_post_uid' => array('VCHAR:8', ''),
+ 'reported_post_bitfield' => array('VCHAR:255', ''),
+ 'reported_post_enable_bbcode' => array('BOOL', 1),
+ 'reported_post_enable_smilies' => array('BOOL', 1),
+ 'reported_post_enable_magic_url' => array('BOOL', 1),
+ ),
+ ),
+ 'change_columns' => array(
+ GROUPS_TABLE => array(
+ 'group_legend' => array('UINT', 0),
+ ),
+ USERS_TABLE => array(
+ 'user_timezone' => array('VCHAR:100', ''),
+ ),
+ ),
+ 'drop_columns' => array(
+ USERS_TABLE => array(
+ 'user_msnm',
+ ),
+ ),
+ ),
);
}
@@ -1007,7 +1212,9 @@ function database_update_info()
*****************************************************************************/
function change_database_data(&$no_updates, $version)
{
- global $db, $errored, $error_ary, $config, $phpbb_root_path, $phpEx;
+ global $db, $db_tools, $errored, $error_ary, $config, $table_prefix, $phpbb_root_path, $phpEx;
+
+ $update_helpers = new phpbb_update_helpers();
switch ($version)
{
@@ -1322,8 +1529,6 @@ function change_database_data(&$no_updates, $version)
),
);
- global $db_tools;
-
$statements = $db_tools->perform_schema_changes($changes);
foreach ($statements as $sql)
@@ -1854,7 +2059,7 @@ function change_database_data(&$no_updates, $version)
'user_email' => '',
'user_lang' => $config['default_lang'],
'user_style' => $config['default_style'],
- 'user_timezone' => 0,
+ 'user_timezone' => 'UTC',
'user_dateformat' => $config['default_dateformat'],
'user_allow_massemail' => 0,
);
@@ -1965,26 +2170,41 @@ function change_database_data(&$no_updates, $version)
}
$db->sql_freeresult($result);
- global $db_tools, $table_prefix;
-
- // Recover from potentially broken Q&A CAPTCHA table on firebird
- // Q&A CAPTCHA was uninstallable, so it's safe to remove these
- // without data loss
+ /*
+ * Due to a bug, vanilla phpbb could not create captcha tables
+ * in 3.0.8 on firebird. It was possible for board administrators
+ * to adjust the code to work. If code was manually adjusted by
+ * board administrators, index names would not be the same as
+ * what 3.0.9 and newer expect. This code fragment drops captcha
+ * tables, destroying all entered Q&A captcha configuration, such
+ * that when Q&A is configured next the respective tables will be
+ * created with correct index names.
+ *
+ * If you wish to preserve your Q&A captcha configuration, you can
+ * manually rename indexes to the currently expected name:
+ * phpbb_captcha_questions_lang_iso => phpbb_captcha_questions_lang
+ * phpbb_captcha_answers_question_id => phpbb_captcha_answers_qid
+ *
+ * Again, this needs to be done only if a board was manually modified
+ * to fix broken captcha code.
+ *
if ($db_tools->sql_layer == 'firebird')
{
- $tables = array(
- $table_prefix . 'captcha_questions',
- $table_prefix . 'captcha_answers',
- $table_prefix . 'qa_confirm',
+ $changes = array(
+ 'drop_tables' => array(
+ $table_prefix . 'captcha_questions',
+ $table_prefix . 'captcha_answers',
+ $table_prefix . 'qa_confirm',
+ ),
);
- foreach ($tables as $table)
+ $statements = $db_tools->perform_schema_changes($changes);
+
+ foreach ($statements as $sql)
{
- if ($db_tools->sql_table_exists($table))
- {
- $db_tools->sql_table_drop($table);
- }
+ _sql($sql, $errored, $error_ary);
}
}
+ */
$no_updates = false;
break;
@@ -2026,7 +2246,7 @@ function change_database_data(&$no_updates, $version)
// No changes from 3.0.10-RC3 to 3.0.10
case '3.0.10-RC3':
break;
-
+
// Changes from 3.0.10 to 3.0.11-RC1
case '3.0.10':
// Updates users having current style a deactivated one
@@ -2050,9 +2270,689 @@ function change_database_data(&$no_updates, $version)
_sql($sql, $errored, $error_ary);
}
+ // Delete orphan private messages
+ $batch_size = 500;
+
+ $sql_array = array(
+ 'SELECT' => 'p.msg_id',
+ 'FROM' => array(
+ PRIVMSGS_TABLE => 'p',
+ ),
+ 'LEFT_JOIN' => array(
+ array(
+ 'FROM' => array(PRIVMSGS_TO_TABLE => 't'),
+ 'ON' => 'p.msg_id = t.msg_id',
+ ),
+ ),
+ 'WHERE' => 't.user_id IS NULL',
+ );
+ $sql = $db->sql_build_query('SELECT', $sql_array);
+
+ do
+ {
+ $result = $db->sql_query_limit($sql, $batch_size);
+
+ $delete_pms = array();
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $delete_pms[] = (int) $row['msg_id'];
+ }
+ $db->sql_freeresult($result);
+
+ if (!empty($delete_pms))
+ {
+ $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . '
+ WHERE ' . $db->sql_in_set('msg_id', $delete_pms);
+ _sql($sql, $errored, $error_ary);
+ }
+ }
+ while (sizeof($delete_pms) == $batch_size);
+
+ $no_updates = false;
+ break;
+
+ // No changes from 3.0.11-RC1 to 3.0.11-RC2
+ case '3.0.11-RC1':
+ break;
+
+ // No changes from 3.0.11-RC2 to 3.0.11
+ case '3.0.11-RC2':
+ break;
+
+ // Changes from 3.0.11 to 3.0.12-RC1
+ case '3.0.11':
+ $sql = 'UPDATE ' . MODULES_TABLE . '
+ SET module_auth = \'acl_u_sig\'
+ WHERE module_class = \'ucp\'
+ AND module_basename = \'profile\'
+ AND module_mode = \'signature\'';
+ _sql($sql, $errored, $error_ary);
+
+ // Update bots
+ if (!function_exists('user_delete'))
+ {
+ include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
+ }
+
+ $bots_updates = array(
+ // Bot Deletions
+ 'NG-Search [Bot]' => false,
+ 'Nutch/CVS [Bot]' => false,
+ 'OmniExplorer [Bot]' => false,
+ 'Seekport [Bot]' => false,
+ 'Synoo [Bot]' => false,
+ 'WiseNut [Bot]' => false,
+
+ // Bot Updates
+ // Bot name to bot user agent map
+ 'Baidu [Spider]' => 'Baiduspider',
+ 'Exabot [Bot]' => 'Exabot',
+ 'Voyager [Bot]' => 'voyager/',
+ 'W3C [Validator]' => 'W3C_Validator',
+ );
+
+ foreach ($bots_updates as $bot_name => $bot_agent)
+ {
+ $sql = 'SELECT user_id
+ FROM ' . USERS_TABLE . '
+ WHERE user_type = ' . USER_IGNORE . "
+ AND username_clean = '" . $db->sql_escape(utf8_clean_string($bot_name)) . "'";
+ $result = $db->sql_query($sql);
+ $bot_user_id = (int) $db->sql_fetchfield('user_id');
+ $db->sql_freeresult($result);
+
+ if ($bot_user_id)
+ {
+ if ($bot_agent === false)
+ {
+ $sql = 'DELETE FROM ' . BOTS_TABLE . "
+ WHERE user_id = $bot_user_id";
+ _sql($sql, $errored, $error_ary);
+
+ user_delete('remove', $bot_user_id);
+ }
+ else
+ {
+ $sql = 'UPDATE ' . BOTS_TABLE . "
+ SET bot_agent = '" . $db->sql_escape($bot_agent) . "'
+ WHERE user_id = $bot_user_id";
+ _sql($sql, $errored, $error_ary);
+ }
+ }
+ }
+
+ // Disable receiving pms for bots
+ $sql = 'SELECT user_id
+ FROM ' . BOTS_TABLE;
+ $result = $db->sql_query($sql);
+
+ $bot_user_ids = array();
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $bot_user_ids[] = (int) $row['user_id'];
+ }
+ $db->sql_freeresult($result);
+
+ if (!empty($bot_user_ids))
+ {
+ $sql = 'UPDATE ' . USERS_TABLE . '
+ SET user_allow_pm = 0
+ WHERE ' . $db->sql_in_set('user_id', $bot_user_ids);
+ _sql($sql, $errored, $error_ary);
+ }
+
+ $no_updates = false;
+ break;
+
+ // Changes from 3.1.0-dev to 3.1.0-A1
+ case '3.1.0-dev':
+
+ // rename all module basenames to full classname
+ $sql = 'SELECT module_id, module_basename, module_class
+ FROM ' . MODULES_TABLE;
+ $result = $db->sql_query($sql);
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $module_id = (int) $row['module_id'];
+ unset($row['module_id']);
+
+ if (!empty($row['module_basename']) && !empty($row['module_class']))
+ {
+ // all the class names start with class name or with phpbb_ for auto loading
+ if (strpos($row['module_basename'], $row['module_class'] . '_') !== 0 &&
+ strpos($row['module_basename'], 'phpbb_') !== 0)
+ {
+ $row['module_basename'] = $row['module_class'] . '_' . $row['module_basename'];
+
+ $sql_update = $db->sql_build_array('UPDATE', $row);
+
+ $sql = 'UPDATE ' . MODULES_TABLE . '
+ SET ' . $sql_update . '
+ WHERE module_id = ' . $module_id;
+ _sql($sql, $errored, $error_ary);
+ }
+ }
+ }
+
+ $db->sql_freeresult($result);
+
+ if (substr($config['search_type'], 0, 6) !== 'phpbb_')
+ {
+ // try to guess the new auto loaded search class name
+ // works for native and mysql fulltext
+ set_config('search_type', 'phpbb_search_' . $config['search_type']);
+ }
+
+ if (!isset($config['fulltext_postgres_ts_name']))
+ {
+ set_config('fulltext_postgres_ts_name', 'simple');
+ }
+
+ if (!isset($config['fulltext_postgres_min_word_len']))
+ {
+ set_config('fulltext_postgres_min_word_len', 4);
+ }
+
+ if (!isset($config['fulltext_postgres_max_word_len']))
+ {
+ set_config('fulltext_postgres_max_word_len', 254);
+ }
+
+ if (!isset($config['fulltext_sphinx_stopwords']))
+ {
+ set_config('fulltext_sphinx_stopwords', 0);
+ }
+
+ if (!isset($config['fulltext_sphinx_indexer_mem_limit']))
+ {
+ set_config('fulltext_sphinx_indexer_mem_limit', 512);
+ }
+
+ if (!isset($config['load_jquery_cdn']))
+ {
+ set_config('load_jquery_cdn', 0);
+ set_config('load_jquery_url', '//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js');
+ }
+
+ if (!isset($config['use_system_cron']))
+ {
+ set_config('use_system_cron', 0);
+ }
+
+ $sql = 'SELECT group_teampage
+ FROM ' . GROUPS_TABLE . '
+ WHERE group_teampage > 0';
+ $result = $db->sql_query_limit($sql, 1);
+ $added_groups_teampage = (bool) $db->sql_fetchfield('group_teampage');
+ $db->sql_freeresult($result);
+
+ if (!$added_groups_teampage)
+ {
+ $sql = 'UPDATE ' . GROUPS_TABLE . '
+ SET group_teampage = 1
+ WHERE group_type = ' . GROUP_SPECIAL . "
+ AND group_name = 'ADMINISTRATORS'";
+ _sql($sql, $errored, $error_ary);
+
+ $sql = 'UPDATE ' . GROUPS_TABLE . '
+ SET group_teampage = 2
+ WHERE group_type = ' . GROUP_SPECIAL . "
+ AND group_name = 'GLOBAL_MODERATORS'";
+ _sql($sql, $errored, $error_ary);
+ }
+
+ if (!isset($config['legend_sort_groupname']))
+ {
+ set_config('legend_sort_groupname', '0');
+ set_config('teampage_forums', '1');
+ }
+
+ $sql = 'SELECT group_legend
+ FROM ' . GROUPS_TABLE . '
+ WHERE group_teampage > 1';
+ $result = $db->sql_query_limit($sql, 1);
+ $updated_group_legend = (bool) $db->sql_fetchfield('group_teampage');
+ $db->sql_freeresult($result);
+
+ if (!$updated_group_legend)
+ {
+ $sql = 'SELECT group_id
+ FROM ' . GROUPS_TABLE . '
+ WHERE group_legend = 1
+ ORDER BY group_name ASC';
+ $result = $db->sql_query($sql);
+
+ $next_legend = 1;
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $sql = 'UPDATE ' . GROUPS_TABLE . '
+ SET group_legend = ' . $next_legend . '
+ WHERE group_id = ' . (int) $row['group_id'];
+ _sql($sql, $errored, $error_ary);
+
+ $next_legend++;
+ }
+ $db->sql_freeresult($result);
+ unset($next_legend);
+ }
+
+ // Rename styles module to Customise
+ $sql = 'UPDATE ' . MODULES_TABLE . "
+ SET module_langname = 'ACP_CAT_CUSTOMISE'
+ WHERE module_langname = 'ACP_CAT_STYLES'";
+ _sql($sql, $errored, $error_ary);
+
+ // Install modules
+ $modules_to_install = array(
+ 'position' => array(
+ 'base' => 'acp_groups',
+ 'class' => 'acp',
+ 'title' => 'ACP_GROUPS_POSITION',
+ 'auth' => 'acl_a_group',
+ 'cat' => 'ACP_GROUPS',
+ ),
+ 'manage' => array(
+ 'base' => 'acp_attachments',
+ 'class' => 'acp',
+ 'title' => 'ACP_MANAGE_ATTACHMENTS',
+ 'auth' => 'acl_a_attach',
+ 'cat' => 'ACP_ATTACHMENTS',
+ ),
+ 'install' => array(
+ 'base' => 'acp_styles',
+ 'class' => 'acp',
+ 'title' => 'ACP_STYLES_INSTALL',
+ 'auth' => 'acl_a_styles',
+ 'cat' => 'ACP_STYLE_MANAGEMENT',
+ ),
+ 'cache' => array(
+ 'base' => 'acp_styles',
+ 'class' => 'acp',
+ 'title' => 'ACP_STYLES_CACHE',
+ 'auth' => 'acl_a_styles',
+ 'cat' => 'ACP_STYLE_MANAGEMENT',
+ ),
+ 'autologin_keys' => array(
+ 'base' => 'ucp_profile',
+ 'class' => 'ucp',
+ 'title' => 'UCP_PROFILE_AUTOLOGIN_KEYS',
+ 'auth' => '',
+ 'cat' => 'UCP_PROFILE',
+ ),
+ // To add a category, the mode and basename must be empty
+ // The mode is taken from the array key
+ '' => array(
+ 'base' => '',
+ 'class' => 'acp',
+ 'title' => 'ACP_EXTENSION_MANAGEMENT',
+ 'auth' => 'acl_a_extensions',
+ 'cat' => 'ACP_CAT_CUSTOMISE',
+ ),
+ 'extensions' => array(
+ 'base' => 'acp_extensions',
+ 'class' => 'acp',
+ 'title' => 'ACP_EXTENSIONS',
+ 'auth' => 'acl_a_extensions',
+ 'cat' => 'ACP_EXTENSION_MANAGEMENT',
+ ),
+ );
+
+ _add_modules($modules_to_install);
+
+ // We need a separate array for the new language sub heading
+ // because it requires another empty key
+ $modules_to_install = array(
+ '' => array(
+ 'base' => '',
+ 'class' => 'acp',
+ 'title' => 'ACP_LANGUAGE',
+ 'auth' => 'acl_a_language',
+ 'cat' => 'ACP_CAT_CUSTOMISE',
+ ),
+ );
+
+ _add_modules($modules_to_install);
+
+ // Move language management to new location in the Customise tab
+ // First get language module id
+ $sql = 'SELECT module_id FROM ' . MODULES_TABLE . "
+ WHERE module_basename = 'acp_language'";
+ $result = $db->sql_query($sql);
+ $language_module_id = $db->sql_fetchfield('module_id');
+ $db->sql_freeresult($result);
+ // Next get language management module id of the one just created
+ $sql = 'SELECT module_id FROM ' . MODULES_TABLE . "
+ WHERE module_langname = 'ACP_LANGUAGE'";
+ $result = $db->sql_query($sql);
+ $language_management_module_id = $db->sql_fetchfield('module_id');
+ $db->sql_freeresult($result);
+
+ if (!class_exists('acp_modules'))
+ {
+ include($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx);
+ }
+ // acp_modules calls adm_back_link, which is undefined at this point
+ if (!function_exists('adm_back_link'))
+ {
+ include($phpbb_root_path . 'includes/functions_acp.' . $phpEx);
+ }
+ $module_manager = new acp_modules();
+ $module_manager->module_class = 'acp';
+ $module_manager->move_module($language_module_id, $language_management_module_id);
+
+ $sql = 'DELETE FROM ' . MODULES_TABLE . "
+ WHERE (module_basename = 'styles' OR module_basename = 'acp_styles') AND (module_mode = 'imageset' OR module_mode = 'theme' OR module_mode = 'template')";
+ _sql($sql, $errored, $error_ary);
+
+ // Localise Global Announcements
+ $sql = 'SELECT topic_id, topic_approved, (topic_replies + 1) AS topic_posts, topic_last_post_id, topic_last_post_subject, topic_last_post_time, topic_last_poster_id, topic_last_poster_name, topic_last_poster_colour
+ FROM ' . TOPICS_TABLE . '
+ WHERE forum_id = 0
+ AND topic_type = ' . POST_GLOBAL;
+ $result = $db->sql_query($sql);
+
+ $global_announcements = $update_lastpost_data = array();
+ $update_lastpost_data['forum_last_post_time'] = 0;
+ $update_forum_data = array(
+ 'forum_posts' => 0,
+ 'forum_topics' => 0,
+ 'forum_topics_real' => 0,
+ );
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $global_announcements[] = (int) $row['topic_id'];
+
+ $update_forum_data['forum_posts'] += (int) $row['topic_posts'];
+ $update_forum_data['forum_topics_real']++;
+ if ($row['topic_approved'])
+ {
+ $update_forum_data['forum_topics']++;
+ }
+
+ if ($update_lastpost_data['forum_last_post_time'] < $row['topic_last_post_time'])
+ {
+ $update_lastpost_data = array(
+ 'forum_last_post_id' => (int) $row['topic_last_post_id'],
+ 'forum_last_post_subject' => $row['topic_last_post_subject'],
+ 'forum_last_post_time' => (int) $row['topic_last_post_time'],
+ 'forum_last_poster_id' => (int) $row['topic_last_poster_id'],
+ 'forum_last_poster_name' => $row['topic_last_poster_name'],
+ 'forum_last_poster_colour' => $row['topic_last_poster_colour'],
+ );
+ }
+ }
+ $db->sql_freeresult($result);
+
+ if (!empty($global_announcements))
+ {
+ // Update the post/topic-count for the forum and the last-post if needed
+ $ga_forum_id = request_var('ga_forum_id', 0);
+
+ $sql = 'SELECT forum_last_post_time
+ FROM ' . FORUMS_TABLE . '
+ WHERE forum_id = ' . $ga_forum_id;
+ $result = $db->sql_query($sql);
+ $lastpost = (int) $db->sql_fetchfield('forum_last_post_time');
+ $db->sql_freeresult($result);
+
+ $sql_update = 'forum_posts = forum_posts + ' . $update_forum_data['forum_posts'] . ', ';
+ $sql_update .= 'forum_topics_real = forum_topics_real + ' . $update_forum_data['forum_topics_real'] . ', ';
+ $sql_update .= 'forum_topics = forum_topics + ' . $update_forum_data['forum_topics'];
+ if ($lastpost < $update_lastpost_data['forum_last_post_time'])
+ {
+ $sql_update .= ', ' . $db->sql_build_array('UPDATE', $update_lastpost_data);
+ }
+
+ $sql = 'UPDATE ' . FORUMS_TABLE . '
+ SET ' . $sql_update . '
+ WHERE forum_id = ' . $ga_forum_id;
+ _sql($sql, $errored, $error_ary);
+
+ // Update some forum_ids
+ $table_ary = array(TOPICS_TABLE, POSTS_TABLE, LOG_TABLE, DRAFTS_TABLE, TOPICS_TRACK_TABLE);
+ foreach ($table_ary as $table)
+ {
+ $sql = "UPDATE $table
+ SET forum_id = $ga_forum_id
+ WHERE " . $db->sql_in_set('topic_id', $global_announcements);
+ _sql($sql, $errored, $error_ary);
+ }
+ unset($table_ary);
+ }
+
+ // Allow custom profile fields in pm templates
+ if (!isset($config['load_cpf_pm']))
+ {
+ set_config('load_cpf_pm', '0');
+ }
+
+ if (!isset($config['teampage_memberships']))
+ {
+ set_config('teampage_memberships', '1');
+ }
+
+ // Check if styles table was already updated
+ if ($db_tools->sql_table_exists(STYLES_THEME_TABLE))
+ {
+ // Get list of valid 3.1 styles
+ $available_styles = array('prosilver');
+
+ $iterator = new DirectoryIterator($phpbb_root_path . 'styles');
+ $skip_dirs = array('.', '..', 'prosilver');
+ foreach ($iterator as $fileinfo)
+ {
+ if ($fileinfo->isDir() && !in_array($fileinfo->getFilename(), $skip_dirs) && file_exists($fileinfo->getPathname() . '/style.cfg'))
+ {
+ $style_cfg = parse_cfg_file($fileinfo->getPathname() . '/style.cfg');
+ if (isset($style_cfg['phpbb_version']) && version_compare($style_cfg['phpbb_version'], '3.1.0-dev', '>='))
+ {
+ // 3.1 style
+ $available_styles[] = $fileinfo->getFilename();
+ }
+ }
+ }
+
+ // Get all installed styles
+ if ($db_tools->sql_table_exists(STYLES_IMAGESET_TABLE))
+ {
+ $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id, i.imageset_path
+ FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c, ' . STYLES_IMAGESET_TABLE . " i
+ WHERE t.template_id = s.template_id
+ AND c.theme_id = s.theme_id
+ AND i.imageset_id = s.imageset_id";
+ }
+ else
+ {
+ $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id
+ FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . " c
+ WHERE t.template_id = s.template_id
+ AND c.theme_id = s.theme_id";
+ }
+ $result = $db->sql_query($sql);
+
+ $styles = array();
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $styles[] = $row;
+ }
+ $db->sql_freeresult($result);
+
+ // Decide which styles to keep, all others will be deleted
+ $valid_styles = array();
+ foreach ($styles as $style_row)
+ {
+ if (
+ // Delete styles with parent style (not supported yet)
+ $style_row['template_inherits_id'] == 0 &&
+ // Check if components match
+ $style_row['template_path'] == $style_row['theme_path'] && (!isset($style_row['imageset_path']) || $style_row['template_path'] == $style_row['imageset_path']) &&
+ // Check if components are valid
+ in_array($style_row['template_path'], $available_styles)
+ )
+ {
+ // Valid style. Keep it
+ $sql_ary = array(
+ 'style_path' => $style_row['template_path'],
+ 'bbcode_bitfield' => $style_row['bbcode_bitfield'],
+ 'style_parent_id' => 0,
+ 'style_parent_tree' => '',
+ );
+ _sql('UPDATE ' . STYLES_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE style_id = ' . $style_row['style_id'], $errored, $error_ary);
+ $valid_styles[] = (int) $style_row['style_id'];
+ }
+ }
+
+ // Remove old styles tables
+ $changes = array(
+ 'drop_columns' => array(
+ STYLES_TABLE => array(
+ 'imageset_id',
+ 'template_id',
+ 'theme_id',
+ ),
+ ),
+
+ 'drop_tables' => array(
+ STYLES_IMAGESET_TABLE,
+ STYLES_IMAGESET_DATA_TABLE,
+ STYLES_TEMPLATE_TABLE,
+ STYLES_TEMPLATE_DATA_TABLE,
+ STYLES_THEME_TABLE,
+ )
+ );
+ $statements = $db_tools->perform_schema_changes($changes);
+
+ foreach ($statements as $sql)
+ {
+ _sql($sql, $errored, $error_ary);
+ }
+
+ // Remove old entries from styles table
+ if (!sizeof($valid_styles))
+ {
+ // No valid styles: remove everything and add prosilver
+ _sql('DELETE FROM ' . STYLES_TABLE, $errored, $error_ary);
+
+ $sql = 'INSERT INTO ' . STYLES_TABLE . " (style_name, style_copyright, style_active, style_path, bbcode_bitfield, style_parent_id, style_parent_tree) VALUES ('prosilver', '&copy; phpBB Group', 1, 'prosilver', 'kNg=', 0, '')";
+ _sql($sql, $errored, $error_ary);
+
+ $sql = 'SELECT style_id
+ FROM ' . $table . "
+ WHERE style_name = 'prosilver'";
+ $result = _sql($sql, $errored, $error_ary);
+ $default_style = $db->sql_fetchfield($result);
+ $db->sql_freeresult($result);
+
+ set_config('default_style', $default_style);
+
+ $sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = 0';
+ _sql($sql, $errored, $error_ary);
+ }
+ else
+ {
+ // There are valid styles in styles table. Remove styles that are outdated
+ _sql('DELETE FROM ' . STYLES_TABLE . ' WHERE ' . $db->sql_in_set('style_id', $valid_styles, true), $errored, $error_ary);
+
+ // Change default style
+ if (!in_array($config['default_style'], $valid_styles))
+ {
+ set_config('default_style', $valid_styles[0]);
+ }
+
+ // Reset styles for users
+ _sql('UPDATE ' . USERS_TABLE . ' SET user_style = 0 WHERE ' . $db->sql_in_set('user_style', $valid_styles, true), $errored, $error_ary);
+ }
+ }
+
+ // Create config value for displaying last subject on forum list
+ if (!isset($config['display_last_subject']))
+ {
+ $config->set('display_last_subject', '1');
+ }
+
+ if (!isset($config['assets_version']))
+ {
+ $config->set('assets_version', '1');
+ }
+
+ // If the column exists, we did not yet update the users timezone
+ if ($db_tools->sql_column_exists(USERS_TABLE, 'user_dst'))
+ {
+ // Update user timezones
+ $sql = 'SELECT user_dst, user_timezone
+ FROM ' . USERS_TABLE . '
+ GROUP BY user_timezone, user_dst';
+ $result = $db->sql_query($sql);
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $sql = 'UPDATE ' . USERS_TABLE . "
+ SET user_timezone = '" . $db->sql_escape($update_helpers->convert_phpbb30_timezone($row['user_timezone'], $row['user_dst'])) . "'
+ WHERE user_timezone = '" . $db->sql_escape($row['user_timezone']) . "'
+ AND user_dst = " . (int) $row['user_dst'];
+ _sql($sql, $errored, $error_ary);
+ }
+ $db->sql_freeresult($result);
+
+ // Update board default timezone
+ set_config('board_timezone', $update_helpers->convert_phpbb30_timezone($config['board_timezone'], $config['board_dst']));
+
+ // After we have calculated the timezones we can delete user_dst column from user table.
+ $statements = $db_tools->sql_column_remove(USERS_TABLE, 'user_dst');
+ foreach ($statements as $sql)
+ {
+ _sql($sql, $errored, $error_ary);
+ }
+ }
+
+ if (!isset($config['site_home_url']))
+ {
+ $config->set('site_home_url', '');
+ $config->set('site_home_text', '');
+ }
+
+ // PHPBB3-10601: Make inbox default. Add basename to ucp's pm category
+
+ // Get the category wanted while checking, at the same time, if this has already been applied
+ $sql = 'SELECT module_id, module_basename
+ FROM ' . MODULES_TABLE . "
+ WHERE module_basename <> 'ucp_pm' AND
+ module_langname='UCP_PM'
+ ";
+ $result = $db->sql_query_limit($sql, 1);
+
+ if ($row = $db->sql_fetchrow($result))
+ {
+ // This update is still not applied. Applying it
+
+ $sql = 'UPDATE ' . MODULES_TABLE . "
+ SET module_basename = 'ucp_pm'
+ WHERE module_id = " . (int) $row['module_id'];
+
+ _sql($sql, $errored, $error_ary);
+ }
+ $db->sql_freeresult($result);
+
+
+ // Add new permissions
+ include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
+ $auth_admin = new auth_admin();
+
+ _add_permission($auth_admin, $db, 'u_chgprofileinfo', true, 'u_sig');
+ _add_permission($auth_admin, $db, 'a_extensions', true, 'a_styles');
+
+ // Update the auth setting for the module
+ $sql = 'UPDATE ' . MODULES_TABLE . "
+ SET module_auth = 'acl_u_chgprofileinfo'
+ WHERE module_class = 'ucp'
+ AND module_basename = 'ucp_profile'
+ AND module_mode = 'profile_info'";
+ _sql($sql, $errored, $error_ary);
+
$no_updates = false;
+
break;
}
}
-
-?>