6 * @copyright (c) 2006 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 $updates_to_version = '3.1.0-dev1';
13 // Enter any version to update from to test updates. The version within the db will not be updated.
14 $debug_from_version = false;
16 // Return if we "just include it" to find out for which version the database update is responsible for
17 if (defined('IN_PHPBB') && defined('IN_INSTALL'))
24 define('IN_PHPBB', true);
25 define('IN_INSTALL', true);
27 if (!defined('PHPBB_ROOT_PATH')) define('PHPBB_ROOT_PATH', './../');
28 if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__
, '.'), 1));
29 include PHPBB_ROOT_PATH
. 'common.' . PHP_EXT
;
33 // Start session management
34 phpbb
::$user->session_begin();
35 phpbb
::$acl->init(phpbb
::$user->data
);
36 phpbb
::$user->setup('install');
38 if (!phpbb
::$user->is_registered
)
43 if (!phpbb
::$acl->acl_get('a_board'))
45 trigger_error('NO_AUTH');
48 include PHPBB_ROOT_PATH
. 'includes/db/db_tools.' . PHP_EXT
;
50 $db_tools = new phpbb_db_tools(phpbb
::$db, true);
52 // Define some variables for the database update
53 $inline_update = (request_var('type', 0)) ?
true : false;
55 // Only an example, but also commented out
56 $database_update_info = array(
58 // Changes from 3.0.5 to 3.1.0-dev1
65 header('Content-type: text/html; charset=UTF-8');
68 <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
69 <html xmlns
="http://www.w3.org/1999/xhtml" dir
="<?php echo phpbb::$user->lang['DIRECTION']; ?>" lang
="<?php echo phpbb::$user->lang['USER_LANG']; ?>" xml
:lang
="<?php echo phpbb::$user->lang['USER_LANG']; ?>">
72 <meta http
-equiv
="content-type" content
="text/html; charset=UTF-8" />
73 <meta http
-equiv
="content-language" content
="<?php echo phpbb::$user->lang['USER_LANG']; ?>" />
74 <meta http
-equiv
="content-style-type" content
="text/css" />
75 <meta http
-equiv
="imagetoolbar" content
="no" />
77 <title
><?php
echo phpbb
::$user->lang
['UPDATING_TO_LATEST_STABLE']; ?
></title
>
79 <link href
="../adm/style/admin.css" rel
="stylesheet" type
="text/css" media
="screen" />
85 <div id
="page-header"> 
;</div
>
90 <span
class="corners-top"><span
></span
></span
>
92 <div id
="main" class="install-body">
94 <h1
><?php
echo phpbb
::$user->lang
['UPDATING_TO_LATEST_STABLE']; ?
></h1
>
98 <p
><?php
echo phpbb
::$user->lang
['DATABASE_TYPE']; ?
> :: <strong
><?php
echo phpbb
::$db->sql_layer
; ?
></strong
><br
/>
101 // To let set_config() calls succeed, we need to make the config array available globally
102 phpbb
::$acm->destroy('#config');
103 $config = phpbb_cache
::obtain_config();
105 echo phpbb
::$user->lang
['PREVIOUS_VERSION'] . ' :: <strong>' . phpbb
::$config['version'] . '</strong><br />';
106 echo phpbb
::$user->lang
['UPDATED_VERSION'] . ' :: <strong>' . $updates_to_version . '</strong></p>';
108 $current_version = str_replace('rc', 'RC', strtolower(phpbb
::$config['version']));
109 $latest_version = str_replace('rc', 'RC', strtolower($updates_to_version));
110 $orig_version = phpbb
::$config['version'];
113 if (empty(phpbb
::$config['dbms_version']))
115 set_config('dbms_version', phpbb
::$db->sql_server_info(true));
118 // If the latest version and the current version are 'unequal', we will update the version_update_from, else we do not update anything.
121 if ($current_version !== $latest_version)
123 set_config('version_update_from', $orig_version);
128 // If not called from the update script, we will actually remove the traces
129 phpbb
::$db->sql_query('DELETE FROM ' . CONFIG_TABLE
. " WHERE config_name = 'version_update_from'");
136 <h1
><?php
echo phpbb
::$user->lang
['UPDATE_DATABASE_SCHEMA']; ?
></h1
>
139 <p
><?php
echo phpbb
::$user->lang
['PROGRESS']; ?
> :: <strong
>
145 // We go through the schema changes from the lowest to the highest version
146 // We try to also include versions 'in-between'...
147 // We go through the schema changes from the lowest to the highest version
148 // We try to also include versions 'in-between'...
150 $versions = array_keys($database_update_info);
151 for ($i = 0; $i < sizeof($versions); $i++
)
153 $version = $versions[$i];
154 $schema_changes = $database_update_info[$version];
156 $next_version = (isset($versions[$i +
1])) ?
$versions[$i +
1] : $updates_to_version;
158 // 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
159 if (version_compare($version, $current_version, '<') && version_compare($current_version, $next_version, '>='))
164 if (!sizeof($schema_changes))
169 // Get statements for schema updates
170 $statements = $db_tools->sql_schema_changes($schema_changes);
172 if (sizeof($statements))
176 foreach ($statements as $sql)
178 _sql($sql, $errored, $error_ary);
183 _write_result($no_updates, $errored, $error_ary);
186 $error_ary = array();
187 $errored = $no_updates = false;
192 <h1
><?php
echo phpbb
::$user->lang
['UPDATING_DATA']; ?
></h1
>
194 <p
><?php
echo phpbb
::$user->lang
['PROGRESS']; ?
> :: <strong
>
203 $versions = array_keys($database_update_info);
206 for ($i = 0; $i < sizeof($versions); $i++
)
208 $version = $versions[$i];
209 $next_version = (isset($versions[$i +
1])) ?
$versions[$i +
1] : $updates_to_version;
211 // 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
212 if (version_compare($version, $current_version, '<') && version_compare($current_version, $next_version, '>='))
217 change_database_data($no_updates, $version);
220 _write_result($no_updates, $errored, $error_ary);
222 $error_ary = array();
223 $errored = $no_updates = false;
228 <h1
><?php
echo phpbb
::$user->lang
['UPDATE_VERSION_OPTIMIZE']; ?
></h1
>
230 <p
><?php
echo phpbb
::$user->lang
['PROGRESS']; ?
> :: <strong
>
236 if ($debug_from_version === false)
238 // update the version
239 $sql = "UPDATE " . CONFIG_TABLE
. "
240 SET config_value = '$updates_to_version'
241 WHERE config_name = 'version'";
242 _sql($sql, $errored, $error_ary);
246 $sql = 'UPDATE ' . USERS_TABLE
. "
247 SET user_permissions = '',
249 _sql($sql, $errored, $error_ary);
251 /* Optimize/vacuum analyze the tables where appropriate
252 // this should be done for each version in future along with
253 // the version number update
254 switch (phpbb::$db->dbms_type)
257 $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';
258 _sql($sql, $errored, $error_ary);
262 _sql("VACUUM ANALYZE", $errored, $error_ary);
267 _write_result($no_updates, $errored, $error_ary);
272 <h1
><?php
echo phpbb
::$user->lang
['UPDATE_COMPLETED']; ?
></h1
>
280 // Purge the cache...
281 phpbb
::$acm->purge();
284 <p style
="color:red"><?php
echo phpbb
::$user->lang
['UPDATE_FILES_NOTICE']; ?
></p
>
286 <p
><?php
echo phpbb
::$user->lang
['COMPLETE_LOGIN_TO_BOARD']; ?
></p
>
294 <p
><?php
echo ((isset(phpbb
::$user->lang
['INLINE_UPDATE_SUCCESSFUL'])) ? phpbb
::$user->lang
['INLINE_UPDATE_SUCCESSFUL'] : 'The database update was successful. Now you need to continue the update process.'); ?
></p
>
296 <p
><a href
="<?php echo append_sid('install/index', "mode
=update
&
;sub
=file_check
&
;lang
=$language"); ?>" class="button1"><?php
echo (isset(phpbb
::$user->lang
['CONTINUE_UPDATE_NOW'])) ? phpbb
::$user->lang
['CONTINUE_UPDATE_NOW'] : 'Continue the update process now'; ?
></a
></p
>
301 // Add database update to log
302 add_log('admin', 'LOG_UPDATE_DATABASE', $orig_version, $updates_to_version);
304 // Now we purge the session table as well as all cache files
305 phpbb
::$acm->purge();
311 <span
class="corners-bottom"><span
></span
></span
>
316 <div id
="page-footer">
317 Powered by phpBB
©
; 2000, 2002, 2005, 2007 <a href
="http://www.phpbb.com/">phpBB Group
</a
>
326 garbage_collection();
328 if (function_exists('exit_handler'))
334 * Function where all data changes are executed
336 function change_database_data($version)
338 global $errored, $error_ary;
343 // Changes from 3.0.5 to 3.1.0-dev1
351 * Function for triggering an sql statement
353 function _sql($sql, &$errored, &$error_ary, $echo_dot = true)
355 if (phpbb
::$base_config['debug_extra'])
357 echo "<br />\n{$sql}\n<br />";
360 phpbb
::$db->sql_return_on_error(true);
362 $result = phpbb
::$db->sql_query($sql);
363 if (phpbb
::$db->sql_error_triggered
)
366 $error_ary['sql'][] = phpbb
::$db->sql_error_sql
;
367 $error_ary['error_code'][] = phpbb
::$db->_sql_error();
370 phpbb
::$db->sql_return_on_error(false);
381 function _write_result($no_updates, $errored, $error_ary)
385 echo ' ' . phpbb
::$user->lang
['NO_UPDATES_REQUIRED'] . '</strong></p>';
389 echo ' <span class="success">' . phpbb
::$user->lang
['DONE'] . '</span></strong><br />' . phpbb
::$user->lang
['RESULT'] . ' :: ';
393 echo ' <strong>' . phpbb
::$user->lang
['SOME_QUERIES_FAILED'] . '</strong> <ul>';
395 for ($i = 0; $i < sizeof($error_ary['sql']); $i++
)
397 echo '<li>' . phpbb
::$user->lang
['ERROR'] . ' :: <strong>' . htmlspecialchars($error_ary['error_code'][$i]['message']) . '</strong><br />';
398 echo phpbb
::$user->lang
['SQL'] . ' :: <strong>' . htmlspecialchars($error_ary['sql'][$i]) . '</strong><br /><br /></li>';
401 echo '</ul> <br /><br />' . phpbb
::$user->lang
['SQL_FAILURE_EXPLAIN'] . '</p>';
405 echo '<strong>' . phpbb
::$user->lang
['NO_ERRORS'] . '</strong></p>';