aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/install/database_update.php
blob: fa8ec6b6cef41be8192ad14d80db8265bd35df15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<?php
/**
*
* @package phpBB3
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/

$update_start_time = time();

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;

/**
* @ignore
*/
define('IN_PHPBB', true);
define('IN_INSTALL', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);

function phpbb_end_update($cache, $config)
{
	$cache->purge();

	$config->increment('assets_version', 1);

?>
								</p>
							</div>
						</div>
					<span class="corners-bottom"><span></span></span>
				</div>
			</div>
		</div>

		<div id="page-footer">
			Powered by <a href="https://www.phpbb.com/">phpBB</a>&reg; Forum Software &copy; phpBB Group
		</div>
	</div>
</body>
</html>

<?php

	garbage_collection();
	exit_handler();
}

require($phpbb_root_path . 'includes/startup.' . $phpEx);

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.");
}

// 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 . 'phpbb/class_loader.' . $phpEx);

require($phpbb_root_path . 'includes/functions.' . $phpEx);
require($phpbb_root_path . 'includes/functions_content.' . $phpEx);
require($phpbb_root_path . 'includes/functions_container.' . $phpEx);

require($phpbb_root_path . 'config.' . $phpEx);
require($phpbb_root_path . 'includes/constants.' . $phpEx);
include($phpbb_root_path . 'includes/utf/utf_normalizer.' . $phpEx);
require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);

// Set PHP error handler to ours
set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler');

// Setup class loader first
$phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx);
$phpbb_class_loader->register();

// Set up container (must be done here because extensions table may not exist)
$container_extensions = array(
	new \phpbb\di\extension\config($phpbb_root_path . 'config.' . $phpEx),
	new \phpbb\di\extension\core($phpbb_root_path . 'config/'),
);
$container_passes = array(
	new \phpbb\di\pass\collection_pass(),
);
$phpbb_container = phpbb_create_container($container_extensions, $phpbb_root_path, $phpEx);

// Compile the container
foreach ($container_passes as $pass)
{
	$phpbb_container->addCompilerPass($pass);
}
$phpbb_container->compile();

// 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');
$phpbb_log	= $phpbb_container->get('log');

// make sure request_var uses this request instance
request_var('', 0, false, false, $request); // "dependency injection" for a function

// Grab global variables, re-cache if necessary
$config = $phpbb_container->get('config');
set_config(null, null, null, $config);
set_config_count(null, null, null, $config);
$orig_version = $config['version'];

$user->add_lang(array('common', 'acp/common', 'install', 'migrator'));

// 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')));

	$phpbb_hook_finder = $phpbb_container->get('hook_finder');
	foreach ($phpbb_hook_finder->find() as $hook)
	{
		@include($phpbb_root_path . 'includes/hooks/' . $hook . '.' . $phpEx);
	}
}
else
{
	$phpbb_hook = false;
}

header('Content-type: text/html; charset=UTF-8');
?>
<!DOCTYPE html>
<html dir="<?php echo $user->lang['DIRECTION']; ?>" lang="<?php echo $user->lang['USER_LANG']; ?>">
<head>
<meta charset="utf-8">

<title><?php echo $user->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 $user->lang['UPDATING_TO_LATEST_STABLE']; ?></h1>

								<br />

								<p><?php echo $user->lang['DATABASE_TYPE']; ?> :: <strong><?php echo $db->sql_layer; ?></strong><br />
								<?php echo $user->lang['PREVIOUS_VERSION']; ?> :: <strong><?php echo $config['version']; ?></strong><br />

<?php

/**
* @todo firebird/mysql update?
*/

// End startup code

// Make sure migrations have been installed.
$db_tools = $phpbb_container->get('dbal.tools');
if (!$db_tools->sql_table_exists($table_prefix . 'migrations'))
{
	$db_tools->sql_create_table($table_prefix . 'migrations', array(
		'COLUMNS'		=> array(
			'migration_name'			=> array('VCHAR', ''),
			'migration_depends_on'		=> array('TEXT', ''),
			'migration_schema_done'		=> array('BOOL', 0),
			'migration_data_done'		=> array('BOOL', 0),
			'migration_data_state'		=> array('TEXT', ''),
			'migration_start_time'		=> array('TIMESTAMP', 0),
			'migration_end_time'		=> array('TIMESTAMP', 0),
		),
		'PRIMARY_KEY'	=> 'migration_name',
	));
}

$migrator = $phpbb_container->get('migrator');
$phpbb_extension_manager = $phpbb_container->get('ext.manager');
$finder = $phpbb_extension_manager->get_finder();

$migrations = $finder
	->core_path('phpbb/db/migration/data/')
	->get_classes();
$migrator->set_migrations($migrations);

// What is a safe limit of execution time? Half the max execution time should be safe.
$safe_time_limit = (ini_get('max_execution_time') / 2);

while (!$migrator->finished())
{
	try
	{
		$migrator->update();
	}
	catch (\phpbb\db\migration\exception $e)
	{
		echo $e->getLocalisedMessage($user);

		phpbb_end_update($cache, $config);
	}

	$state = array_merge(array(
			'migration_schema_done' => false,
			'migration_data_done'	=> false,
		),
		$migrator->last_run_migration['state']
	);

	if (isset($migrator->last_run_migration['effectively_installed']) && $migrator->last_run_migration['effectively_installed'])
	{
		echo $user->lang('MIGRATION_EFFECTIVELY_INSTALLED', $migrator->last_run_migration['name']) . '<br />';
	}
	else
	{
		if ($state['migration_data_done'])
		{
			echo $user->lang('MIGRATION_DATA_DONE', $migrator->last_run_migration['name']) . '<br />';
		}
		else if ($state['migration_schema_done'])
		{
			echo $user->lang('MIGRATION_SCHEMA_DONE', $migrator->last_run_migration['name']) . '<br />';
		}
	}

	// Are we approaching the time limit? If so we want to pause the update and continue after refreshing
	if ((time() - $update_start_time) >= $safe_time_limit)
	{
		echo '<br />' . $user->lang['DATABASE_UPDATE_NOT_COMPLETED'] . '<br /><br />';
		echo '<a href="' . append_sid($phpbb_root_path . 'install/database_update.' . $phpEx, 'type=' . $request->variable('type', 0) . '&amp;language=' . $request->variable('language', 'en')) . '" class="button1">' . $user->lang['DATABASE_UPDATE_CONTINUE'] . '</a>';

		phpbb_end_update($cache, $config);
	}
}

if ($orig_version != $config['version'])
{
	add_log('admin', 'LOG_UPDATE_DATABASE', $orig_version, $config['version']);
}

echo $user->lang['DATABASE_UPDATE_COMPLETE'] . '<br />';

if ($request->variable('type', 0))
{
	echo $user->lang['INLINE_UPDATE_SUCCESSFUL'] . '<br /><br />';
	echo '<a href="' . append_sid($phpbb_root_path . 'install/index.' . $phpEx, 'mode=update&amp;sub=update_db&amp;language=' . $request->variable('language', 'en')) . '" class="button1">' . $user->lang['CONTINUE_UPDATE_NOW'] . '</a>';
}
else
{
	echo '<div class="errorbox">' . $user->lang['UPDATE_FILES_NOTICE'] . '</div>';
	echo $user->lang['COMPLETE_LOGIN_TO_BOARD'];
}

phpbb_end_update($cache, $config);