<?php
/**
*
* @package install
* @copyright (c) 2006 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
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);
// Which oldest version does this updater support?
define('OLDEST_FROM_VERSION', '3.0.0');
// Return if we "just include it" to find out for which version the database update is responsible for
if (defined('IN_PHPBB') && defined('IN_INSTALL'))
{
$updates_to_version = UPDATES_TO_VERSION;
$debug_from_version = DEBUG_FROM_VERSION;
$oldest_from_version = OLDEST_FROM_VERSION;
return;
}
/**
*/
define('IN_PHPBB', true);
define('IN_INSTALL', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
if (!function_exists('phpbb_require_updated'))
{
function phpbb_require_updated($path, $optional = false)
{
global $phpbb_root_path;
$new_path = $phpbb_root_path . 'install/update/new/' . $path;
$old_path = $phpbb_root_path . $path;
if (file_exists($new_path))
{
require($new_path);
}
else if (!$optional || file_exists($old_path))
{
require($old_path);
}
}
}
phpbb_require_updated('includes/startup.' . $phpEx);
$updates_to_version = UPDATES_TO_VERSION;
$debug_from_version = DEBUG_FROM_VERSION;
$oldest_from_version = OLDEST_FROM_VERSION;
@set_time_limit(0);
// Include essential scripts
include($phpbb_root_path . 'config.' . $phpEx);
if (!defined('PHPBB_INSTALLED') || empty($dbms) || empty($acm_type))
{
die("Please read: <a href='../docs/INSTALL.html'>INSTALL.html</a> before attempting to update.");
}
// Include files
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/utf/utf_tools.' . $phpEx);
phpbb_require_updated('includes/db/db_tools.' . $phpEx);
// new table constants are separately defined here in case the updater is run
// before the files are updated
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_dumped_container_unless_debug(
array(
new phpbb_di_extension_config($phpbb_root_path . 'config.' . $phpEx),
new phpbb_di_extension_core($phpbb_root_path),
),
array(
new phpbb_di_pass_collection_pass(),
new phpbb_di_pass_kernel_pass(),
),
$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');
// 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))
{
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)
{
@include($phpbb_root_path . 'includes/hooks/' . $hook . '.' . $phpEx);
}
}
else
{
$phpbb_hook = false;
}
// Connect to DB
$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 = '';
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 . "
WHERE config_name = 'default_lang'";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$language = basename(request_var('language', ''));
if (!$language)
{
$language = $row['config_value'];
}
if (!file_exists($phpbb_root_path . 'language/' . $language))
{
die('No language found!');
}
// And finally, load the relevant language files
include($phpbb_root_path . 'language/' . $language . '/common.' . $phpEx);
include($phpbb_root_path . 'language/' . $language . '/acp/common.' . $phpEx);
include($phpbb_root_path . 'language/' . $language . '/install.' . $phpEx);
// Set PHP error handler to ours
//set_error_handler('msg_handler');
// Define some variables for the database update
$inline_update = (request_var('type', 0)) ? true : false;
// To let set_config() calls succeed, we need to make the config array available globally
$config = new phpbb_config_db($db, $cache->get_driver(), CONFIG_TABLE);
set_config(null, null, null, $config);
set_config_count(null, null, null, $config);
// Update asset_version
if (isset($config['assets_version']))
{
set_config('assets_version', $config['assets_version'] + 1);
}
// phpbb_db_tools will be taken from new files (under install/update/new)
// if possible, falling back to the board's copy.
$db_tools = new phpbb_db_tools($db, true);
$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="../adm/style/admin.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="wrap">
<div id="page-header"> </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>
<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="../adm/style/admin.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="wrap">
<div id="page-header"> </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 />
<p><?php echo $lang['DATABASE_TYPE']; ?> :: <strong><?php echo $db->sql_layer; ?></strong><br />
<?php
if ($debug_from_version !== false)
{
$config['version'] = $debug_from_version;
}
echo $lang['PREVIOUS_VERSION'] . ' :: <strong>' . $config['version'] . '</strong><br />';
echo $lang['UPDATED_VERSION'] . ' :: <strong>' . $updates_to_version . '</strong></p>';
$current_version = str_replace('rc', 'RC', strtolower($config['version']));
$latest_version = str_replace('rc', 'RC', strtolower($updates_to_version));
$orig_version = $config['version'];
// Fill DB version
if (empty($config['dbms_version']))
{
set_config('dbms_version', $db->sql_server_info(true));
}
// Firebird update from Firebird 2.0 to 2.1+ required?
if ($db->sql_layer == 'firebird')
{
// We do not trust any PHP5 function enabled, we will simply test for a function new in 2.1
$db->sql_return_on_error(true);
$sql = 'SELECT 1 FROM RDB$DATABASE
WHERE BIN_AND(10, 1) = 0';
$result = $db->sql_query($sql);
if (!$result || $db->sql_error_triggered)
{
echo '<br /><br />';
echo '<h1>' . $lang['ERROR'] . '</h1><br />';
echo '<p>' . $lang['FIREBIRD_DBMS_UPDATE_REQUIRED'] . '</p>';
_print_footer();
exit_handler();
exit;
}
$db->sql_freeresult($result);
$db->sql_return_on_error(false);
}
// MySQL update from MySQL 3.x/4.x to > 4.1.x required?
if ($db->sql_layer == 'mysql' || $db->sql_layer == 'mysql4' || $db->sql_layer == 'mysqli')
{
// Verify by fetching column... if the column type matches the new type we update dbms_version...
$sql = "SHOW COLUMNS FROM " . CONFIG_TABLE;
$result = $db->sql_query($sql);
$column_type = '';
while ($row = $db->sql_fetchrow($result))
{
$field = strtolower($row['Field']);
if ($field == 'config_value')
{
$column_type = strtolower($row['Type']);
break;
}
}
$db->sql_freeresult($result);
// If column type is blob, but mysql version says we are on > 4.1.3, then the schema needs an update
if (strpos($column_type, 'blob') !== false && version_compare($db->sql_server_info(true), '4.1.3', '>='))
{
echo '<br /><br />';
echo '<h1>' . $lang['ERROR'] . '</h1><br />';
echo '<p>' . sprintf($lang['MYSQL_SCHEMA_UPDATE_REQUIRED'], $config['dbms_version'], $db->sql_server_info(true)) . '</p>';
_print_footer();
exit_handler();
exit;
}
}
// Now check if the user wants to update from a version we no longer support updates from
if (version_compare($current_version, $oldest_from_version, '<'))
{
echo '<br /><br /><h1>' . $lang['ERROR'] . '</h1><br />';
echo '<p>' . sprintf($lang['DB_UPDATE_NOT_SUPPORTED'], $oldest_from_version, $current_version) . '</p>';
_print_footer();
exit_handler();
exit;
}
// If the latest version and the current version are 'unequal', we will update the version_update_from, else we do not update anything.
if ($inline_update)
{
if ($current_version !== $latest_version)
{
set_config('version_update_from', $orig_version);
}
}
else
{
// If not called from the update script, we will actually remove the traces
$db->sql_query('DELETE FROM ' . CONFIG_TABLE . " WHERE config_name = 'version_update_from'");
}
// Schema updates
?>
<br /><br />
<h1><?php echo $lang['UPDATE_DATABASE_SCHEMA']; ?></h1>
<br />
<p><?php echo $lang['PROGRESS']; ?> :: <strong>
<?php
flush();
// We go through the schema changes from the lowest to the highest version
// We try to also include versions 'in-between'...
$no_updates = true;
$versions = array_keys($database_update_info);
for ($i = 0; $i < sizeof($versions); $i++)
{
$version = $versions[$i];
$schema_changes = $database_update_info[$version];
$next_version = (isset($versions[$i + 1])) ? $versions[$i + 1] : $updates_to_version;
// 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
if (version_compare($version, $current_version, '<') && version_compare($current_version, $next_version, '>='))
{
continue;
}
if (!sizeof($schema_changes))
{
continue;
}
$no_updates = false;
// We run one index after the other... to be consistent with schema changes...
foreach ($schema_changes as $key => $changes)
{
$statements = $db_tools->perform_schema_changes(array($key => $changes));
foreach ($statements as $sql)
{
_sql($sql, $errored, $error_ary);
}
}
}
_write_result($no_updates, $errored, $error_ary);
// Data updates
$error_ary = array();
$errored = $no_updates = false;
?>
<br /><br />
<h1><?php echo $lang['UPDATING_DATA']; ?></h1>
<br />
<p><?php echo $lang['PROGRESS']; ?> :: <strong>
<?php
flush();
$no_updates = true;
$versions = array_keys($database_update_info);
// some code magic
for ($i = 0; $i < sizeof($versions); $i++)
{
$version = $versions[$i];
$next_version = (isset($versions[$i + 1])) ? $versions[$i + 1] : $updates_to_version;
// 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
if (version_compare($version, $current_version, '<') && version_compare($current_version, $next_version, '>='))
{
continue;
}
change_database_data($no_updates, $version);
}
_write_result($no_updates, $errored, $error_ary);
$error_ary = array();
$errored = $no_updates = false;
?>
<br /><br />
<h1><?php echo $lang['UPDATE_VERSION_OPTIMIZE']; ?></h1>
<br />
<p><?php echo $lang['PROGRESS']; ?> :: <strong>
<?php
flush();
if ($debug_from_version === false)
{
// update the version
$sql = "UPDATE " . CONFIG_TABLE . "
SET config_value = '$updates_to_version'
WHERE config_name = 'version'";
_sql($sql, $errored, $error_ary);
}
// Reset permissions
$sql = 'UPDATE ' . USERS_TABLE . "
SEHUTnlsIqkօL'Ga#3qY`Fzxgi<@Z&AI+/]4sEMxLmQQqJh{1e;R:$*68@*;ARIp^QgM@yDn}"2`hi*`IXt `ŕGH -w$ڌt&h1@>g[R-vȍTMzcAnH]"i6Ȼ}ZtĵS\nGkB$)6ݕS,d.g#qVxP=F6ėъ)O3Bn$J,mKkϚe-=[Ā&JlgR?&?ϽT&,Bu@܌7_+^xm
?ɤ{" yEf!ql/mxt,ŔmpCsS0ܛPvuCf:'Ww<*Q"HmP¡Ĉr7&F8!GgӅKFߐL@=@}V\8CqsxnhE^T/=mS=>ZgIF-*V|(5QPo:1VKEKL3u*eHe
$c~x T6o$쭤`@n84>?v7XO ,bc{CP%%H'.TR&H_8d (UM ZP?X R:+juKwQ/m$]0ݧ#[tbqVKPG3z\xO%[&;֒7I6:b0}YhH`Jy`p0Q"לeĴ_݇n*˾$-_ke`lwgW}s)
A?*B"V0Gh d>z3ؾ0)qqI4AQƠ
rmO90)J^绀iYrD'B LA`Rj%ꊫIb`(V/6w5IqkW?~7˴$͞z\&F7sO Np 3Z?fH.Ҧ
AFq7MHNBṳ@L*TwobKꃼ$wV1YҎu\c:E٪tY_xV.Fp10kyɟ[IȂyDGghZU_ygHkݝsԌؕ5|*7ƪviWZ@ѴG$n%cp$~-b<7 yh?W XVQݽ z+9rVc"`=6ʏ'ZZ{e
IfI5NOPYʓ<pzPň/lɁuDbŌgU9X뫧Ѐ=*0 4 nr)7'%ȑуڭ1f]֨)Ht;|oTjJC J#>/+[!XePh
}w}]׆zРJ56BG;g>}]NRx6. w@W.Nx 0likw:qm:McfŔUhbTvU+
8Ónu
9zGkX dss&O?8Iv1 un7$tStELݧ$a0
#-{ƕ¸zj1"8γ~l3>7 0Gќ%lrET$[sg]'e=rSXNO;7G]jdl2*\m2㜊Q)=Ќw##BMWfpH nXacK ,%Pb:Z}!
~ui1"XίD;!i뿉מ&~ij"v"gD&Aw)GՅN
WRz'{]s$""[)m6gMwm'eFf`C\d(=w^ 0~|Pvx:1˺~2;#%ը#R4FtxZJEp;efN9 df,q9ȯS_'d6T<Rćg4
p5U"Di5;c'/[Y8;#` Vb]ȥo^?* Jy>8QCUJŊkciEjA16P?#hSA5%,i4Ȳp _+7B8sQ#U?{4 GJm ]tucZA6m,p,Tv" /$Rm|ɱ&
|