Update code_sniffer build.xml file to be executable on our system
[phpbb.git] / phpBB / install / database_update.php
blob0be2e0f5b87f85501ddd88fde51c15f5e45412f4
1 <?php
2 /**
4 * @package install
5 * @version $Id$
6 * @copyright (c) 2006 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 */
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'))
19 return;
22 /**
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;
31 @set_time_limit(0);
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)
40 login_box();
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
59 '3.0.5' => array(),
62 $error_ary = array();
63 $errored = false;
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']; ?>">
70 <head>
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" />
81 </head>
83 <body>
84 <div id="wrap">
85 <div id="page-header">&nbsp;</div>
87 <div id="page-body">
88 <div id="acp">
89 <div class="panel">
90 <span class="corners-top"><span></span></span>
91 <div id="content">
92 <div id="main" class="install-body">
94 <h1><?php echo phpbb::$user->lang['UPDATING_TO_LATEST_STABLE']; ?></h1>
96 <br />
98 <p><?php echo phpbb::$user->lang['DATABASE_TYPE']; ?> :: <strong><?php echo phpbb::$db->sql_layer; ?></strong><br />
99 <?php
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'];
112 // Fill DB 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.
119 if ($inline_update)
121 if ($current_version !== $latest_version)
123 set_config('version_update_from', $orig_version);
126 else
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'");
132 // Schema updates
134 <br /><br />
136 <h1><?php echo phpbb::$user->lang['UPDATE_DATABASE_SCHEMA']; ?></h1>
138 <br />
139 <p><?php echo phpbb::$user->lang['PROGRESS']; ?> :: <strong>
141 <?php
143 flush();
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'...
149 $no_updates = true;
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, '>='))
161 continue;
164 if (!sizeof($schema_changes))
166 continue;
169 // Get statements for schema updates
170 $statements = $db_tools->sql_schema_changes($schema_changes);
172 if (sizeof($statements))
174 $no_updates = false;
176 foreach ($statements as $sql)
178 _sql($sql, $errored, $error_ary);
183 _write_result($no_updates, $errored, $error_ary);
185 // Data updates
186 $error_ary = array();
187 $errored = $no_updates = false;
191 <br /><br />
192 <h1><?php echo phpbb::$user->lang['UPDATING_DATA']; ?></h1>
193 <br />
194 <p><?php echo phpbb::$user->lang['PROGRESS']; ?> :: <strong>
196 <?php
198 flush();
200 $no_updates = true;
202 $no_updates = true;
203 $versions = array_keys($database_update_info);
205 // some code magic
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, '>='))
214 continue;
217 change_database_data($no_updates, $version);
220 _write_result($no_updates, $errored, $error_ary);
222 $error_ary = array();
223 $errored = $no_updates = false;
227 <br /><br />
228 <h1><?php echo phpbb::$user->lang['UPDATE_VERSION_OPTIMIZE']; ?></h1>
229 <br />
230 <p><?php echo phpbb::$user->lang['PROGRESS']; ?> :: <strong>
232 <?php
234 flush();
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);
245 // Reset permissions
246 $sql = 'UPDATE ' . USERS_TABLE . "
247 SET user_permissions = '',
248 user_perm_from = 0";
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)
256 case 'mysql':
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);
259 break;
261 case 'postgresql':
262 _sql("VACUUM ANALYZE", $errored, $error_ary);
263 break;
267 _write_result($no_updates, $errored, $error_ary);
271 <br />
272 <h1><?php echo phpbb::$user->lang['UPDATE_COMPLETED']; ?></h1>
274 <br />
276 <?php
278 if (!$inline_update)
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>
288 <?php
290 else
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&amp;sub=file_check&amp;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>
298 <?php
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();
309 </div>
310 </div>
311 <span class="corners-bottom"><span></span></span>
312 </div>
313 </div>
314 </div>
316 <div id="page-footer">
317 Powered by phpBB &copy; 2000, 2002, 2005, 2007 <a href="http://www.phpbb.com/">phpBB Group</a>
318 </div>
319 </div>
321 </body>
322 </html>
324 <?php
326 garbage_collection();
328 if (function_exists('exit_handler'))
330 exit_handler();
334 * Function where all data changes are executed
336 function change_database_data($version)
338 global $errored, $error_ary;
340 switch ($version)
342 default:
343 // Changes from 3.0.5 to 3.1.0-dev1
344 case '3.0.5':
345 break;
346 break;
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)
365 $errored = true;
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);
372 if ($echo_dot)
374 echo ". \n";
375 flush();
378 return $result;
381 function _write_result($no_updates, $errored, $error_ary)
383 if ($no_updates)
385 echo ' ' . phpbb::$user->lang['NO_UPDATES_REQUIRED'] . '</strong></p>';
387 else
389 echo ' <span class="success">' . phpbb::$user->lang['DONE'] . '</span></strong><br />' . phpbb::$user->lang['RESULT'] . ' :: ';
391 if ($errored)
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>';
403 else
405 echo '<strong>' . phpbb::$user->lang['NO_ERRORS'] . '</strong></p>';