PageRenderTime 30ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/phpBB/install/database_update.php

https://github.com/naderman/phpbb-orchestra
PHP | 1690 lines | 1174 code | 284 blank | 232 comment | 107 complexity | 3a8a80e65f71f00dd6a5030229970717 MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. * @package install
  5. * @version $Id$
  6. * @copyright (c) 2006 phpBB Group
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. define('UPDATES_TO_VERSION', '3.0.9');
  11. // Enter any version to update from to test updates. The version within the db will not be updated.
  12. define('DEBUG_FROM_VERSION', false);
  13. // Which oldest version does this updater support?
  14. define('OLDEST_FROM_VERSION', '3.0.0');
  15. // Return if we "just include it" to find out for which version the database update is responsible for
  16. if (defined('IN_PHPBB') && defined('IN_INSTALL'))
  17. {
  18. $updates_to_version = UPDATES_TO_VERSION;
  19. $debug_from_version = DEBUG_FROM_VERSION;
  20. $oldest_from_version = OLDEST_FROM_VERSION;
  21. return;
  22. }
  23. /**
  24. */
  25. define('IN_PHPBB', true);
  26. define('IN_INSTALL', true);
  27. $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../';
  28. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  29. if (!function_exists('phpbb_require_updated'))
  30. {
  31. function phpbb_require_updated($path, $optional = false)
  32. {
  33. global $phpbb_root_path;
  34. $new_path = $phpbb_root_path . 'install/update/new/' . $path;
  35. $old_path = $phpbb_root_path . $path;
  36. if (file_exists($new_path))
  37. {
  38. require($new_path);
  39. }
  40. else if (!$optional || file_exists($old_path))
  41. {
  42. require($old_path);
  43. }
  44. }
  45. }
  46. phpbb_require_updated('includes/startup.' . $phpEx);
  47. $updates_to_version = UPDATES_TO_VERSION;
  48. $debug_from_version = DEBUG_FROM_VERSION;
  49. $oldest_from_version = OLDEST_FROM_VERSION;
  50. error_reporting(E_ALL);
  51. @set_time_limit(0);
  52. // Include essential scripts
  53. include($phpbb_root_path . 'config.' . $phpEx);
  54. if (!defined('PHPBB_INSTALLED') || empty($dbms) || empty($acm_type))
  55. {
  56. die("Please read: <a href='../docs/INSTALL.html'>INSTALL.html</a> before attempting to update.");
  57. }
  58. // Load Extensions
  59. if (!empty($load_extensions) && function_exists('dl'))
  60. {
  61. $load_extensions = explode(',', $load_extensions);
  62. foreach ($load_extensions as $extension)
  63. {
  64. @dl(trim($extension));
  65. }
  66. }
  67. // Include files
  68. require($phpbb_root_path . 'includes/acm/acm_' . $acm_type . '.' . $phpEx);
  69. require($phpbb_root_path . 'includes/cache.' . $phpEx);
  70. require($phpbb_root_path . 'includes/template.' . $phpEx);
  71. require($phpbb_root_path . 'includes/session.' . $phpEx);
  72. require($phpbb_root_path . 'includes/auth.' . $phpEx);
  73. require($phpbb_root_path . 'includes/functions.' . $phpEx);
  74. phpbb_require_updated('includes/functions_content.' . $phpEx, true);
  75. require($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
  76. require($phpbb_root_path . 'includes/constants.' . $phpEx);
  77. require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
  78. require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
  79. // new table constants are separately defined here in case the updater is run
  80. // before the files are updated
  81. if (!defined('LOGIN_ATTEMPT_TABLE'))
  82. {
  83. define('LOGIN_ATTEMPT_TABLE', $table_prefix . 'login_attempts');
  84. }
  85. $user = new user();
  86. $cache = new cache();
  87. $db = new $sql_db();
  88. // Add own hook handler, if present. :o
  89. if (file_exists($phpbb_root_path . 'includes/hooks/index.' . $phpEx))
  90. {
  91. require($phpbb_root_path . 'includes/hooks/index.' . $phpEx);
  92. $phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('template', 'display')));
  93. foreach ($cache->obtain_hooks() as $hook)
  94. {
  95. @include($phpbb_root_path . 'includes/hooks/' . $hook . '.' . $phpEx);
  96. }
  97. }
  98. else
  99. {
  100. $phpbb_hook = false;
  101. }
  102. // Connect to DB
  103. $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false);
  104. // We do not need this any longer, unset for safety purposes
  105. unset($dbpasswd);
  106. $user->ip = (!empty($_SERVER['REMOTE_ADDR'])) ? htmlspecialchars($_SERVER['REMOTE_ADDR']) : '';
  107. $user->ip = (stripos($user->ip, '::ffff:') === 0) ? substr($user->ip, 7) : $user->ip;
  108. $sql = "SELECT config_value
  109. FROM " . CONFIG_TABLE . "
  110. WHERE config_name = 'default_lang'";
  111. $result = $db->sql_query($sql);
  112. $row = $db->sql_fetchrow($result);
  113. $db->sql_freeresult($result);
  114. $language = basename(request_var('language', ''));
  115. if (!$language)
  116. {
  117. $language = $row['config_value'];
  118. }
  119. if (!file_exists($phpbb_root_path . 'language/' . $language))
  120. {
  121. die('No language found!');
  122. }
  123. // And finally, load the relevant language files
  124. include($phpbb_root_path . 'language/' . $language . '/common.' . $phpEx);
  125. include($phpbb_root_path . 'language/' . $language . '/acp/common.' . $phpEx);
  126. include($phpbb_root_path . 'language/' . $language . '/install.' . $phpEx);
  127. // Set PHP error handler to ours
  128. //set_error_handler('msg_handler');
  129. // Define some variables for the database update
  130. $inline_update = (request_var('type', 0)) ? true : false;
  131. // To let set_config() calls succeed, we need to make the config array available globally
  132. $config = array();
  133. $sql = 'SELECT *
  134. FROM ' . CONFIG_TABLE;
  135. $result = $db->sql_query($sql);
  136. while ($row = $db->sql_fetchrow($result))
  137. {
  138. $config[$row['config_name']] = $row['config_value'];
  139. }
  140. $db->sql_freeresult($result);
  141. // We do not include DB Tools here, because we can not be sure the file is up-to-date ;)
  142. // Instead, this file defines a clean db_tools version (we are also not able to provide a different file, else the database update will not work standalone)
  143. $db_tools = new updater_db_tools($db, true);
  144. $database_update_info = database_update_info();
  145. $error_ary = array();
  146. $errored = false;
  147. header('Content-type: text/html; charset=UTF-8');
  148. ?>
  149. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  150. <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']; ?>">
  151. <head>
  152. <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  153. <meta http-equiv="content-language" content="<?php echo $lang['USER_LANG']; ?>" />
  154. <meta http-equiv="content-style-type" content="text/css" />
  155. <meta http-equiv="imagetoolbar" content="no" />
  156. <title><?php echo $lang['UPDATING_TO_LATEST_STABLE']; ?></title>
  157. <link href="../adm/style/admin.css" rel="stylesheet" type="text/css" media="screen" />
  158. </head>
  159. <body>
  160. <div id="wrap">
  161. <div id="page-header">&nbsp;</div>
  162. <div id="page-body">
  163. <div id="acp">
  164. <div class="panel">
  165. <span class="corners-top"><span></span></span>
  166. <div id="content">
  167. <div id="main" class="install-body">
  168. <h1><?php echo $lang['UPDATING_TO_LATEST_STABLE']; ?></h1>
  169. <br />
  170. <p><?php echo $lang['DATABASE_TYPE']; ?> :: <strong><?php echo $db->sql_layer; ?></strong><br />
  171. <?php
  172. if ($debug_from_version !== false)
  173. {
  174. $config['version'] = $debug_from_version;
  175. }
  176. echo $lang['PREVIOUS_VERSION'] . ' :: <strong>' . $config['version'] . '</strong><br />';
  177. echo $lang['UPDATED_VERSION'] . ' :: <strong>' . $updates_to_version . '</strong></p>';
  178. $current_version = str_replace('rc', 'RC', strtolower($config['version']));
  179. $latest_version = str_replace('rc', 'RC', strtolower($updates_to_version));
  180. $orig_version = $config['version'];
  181. // Fill DB version
  182. if (empty($config['dbms_version']))
  183. {
  184. set_config('dbms_version', $db->sql_server_info(true));
  185. }
  186. // Firebird update from Firebird 2.0 to 2.1+ required?
  187. if ($db->sql_layer == 'firebird')
  188. {
  189. // We do not trust any PHP5 function enabled, we will simply test for a function new in 2.1
  190. $db->sql_return_on_error(true);
  191. $sql = 'SELECT 1 FROM RDB$DATABASE
  192. WHERE BIN_AND(10, 1) = 0';
  193. $result = $db->sql_query($sql);
  194. if (!$result || $db->sql_error_triggered)
  195. {
  196. echo '<br /><br />';
  197. echo '<h1>' . $lang['ERROR'] . '</h1><br />';
  198. echo '<p>' . $lang['FIREBIRD_DBMS_UPDATE_REQUIRED'] . '</p>';
  199. _print_footer();
  200. exit_handler();
  201. exit;
  202. }
  203. $db->sql_freeresult($result);
  204. $db->sql_return_on_error(false);
  205. }
  206. // MySQL update from MySQL 3.x/4.x to > 4.1.x required?
  207. if ($db->sql_layer == 'mysql' || $db->sql_layer == 'mysql4' || $db->sql_layer == 'mysqli')
  208. {
  209. // Verify by fetching column... if the column type matches the new type we update dbms_version...
  210. $sql = "SHOW COLUMNS FROM " . CONFIG_TABLE;
  211. $result = $db->sql_query($sql);
  212. $column_type = '';
  213. while ($row = $db->sql_fetchrow($result))
  214. {
  215. $field = strtolower($row['Field']);
  216. if ($field == 'config_value')
  217. {
  218. $column_type = strtolower($row['Type']);
  219. break;
  220. }
  221. }
  222. $db->sql_freeresult($result);
  223. // If column type is blob, but mysql version says we are on > 4.1.3, then the schema needs an update
  224. if (strpos($column_type, 'blob') !== false && version_compare($db->sql_server_info(true), '4.1.3', '>='))
  225. {
  226. echo '<br /><br />';
  227. echo '<h1>' . $lang['ERROR'] . '</h1><br />';
  228. echo '<p>' . sprintf($lang['MYSQL_SCHEMA_UPDATE_REQUIRED'], $config['dbms_version'], $db->sql_server_info(true)) . '</p>';
  229. _print_footer();
  230. exit_handler();
  231. exit;
  232. }
  233. }
  234. // Now check if the user wants to update from a version we no longer support updates from
  235. if (version_compare($current_version, $oldest_from_version, '<'))
  236. {
  237. echo '<br /><br /><h1>' . $lang['ERROR'] . '</h1><br />';
  238. echo '<p>' . sprintf($lang['DB_UPDATE_NOT_SUPPORTED'], $oldest_from_version, $current_version) . '</p>';
  239. _print_footer();
  240. exit_handler();
  241. exit;
  242. }
  243. // If the latest version and the current version are 'unequal', we will update the version_update_from, else we do not update anything.
  244. if ($inline_update)
  245. {
  246. if ($current_version !== $latest_version)
  247. {
  248. set_config('version_update_from', $orig_version);
  249. }
  250. }
  251. else
  252. {
  253. // If not called from the update script, we will actually remove the traces
  254. $db->sql_query('DELETE FROM ' . CONFIG_TABLE . " WHERE config_name = 'version_update_from'");
  255. }
  256. // Schema updates
  257. ?>
  258. <br /><br />
  259. <h1><?php echo $lang['UPDATE_DATABASE_SCHEMA']; ?></h1>
  260. <br />
  261. <p><?php echo $lang['PROGRESS']; ?> :: <strong>
  262. <?php
  263. flush();
  264. // We go through the schema changes from the lowest to the highest version
  265. // We try to also include versions 'in-between'...
  266. $no_updates = true;
  267. $versions = array_keys($database_update_info);
  268. for ($i = 0; $i < sizeof($versions); $i++)
  269. {
  270. $version = $versions[$i];
  271. $schema_changes = $database_update_info[$version];
  272. $next_version = (isset($versions[$i + 1])) ? $versions[$i + 1] : $updates_to_version;
  273. // 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
  274. if (version_compare($version, $current_version, '<') && version_compare($current_version, $next_version, '>='))
  275. {
  276. continue;
  277. }
  278. if (!sizeof($schema_changes))
  279. {
  280. continue;
  281. }
  282. $no_updates = false;
  283. // We run one index after the other... to be consistent with schema changes...
  284. foreach ($schema_changes as $key => $changes)
  285. {
  286. $statements = $db_tools->perform_schema_changes(array($key => $changes));
  287. foreach ($statements as $sql)
  288. {
  289. _sql($sql, $errored, $error_ary);
  290. }
  291. }
  292. }
  293. _write_result($no_updates, $errored, $error_ary);
  294. // Data updates
  295. $error_ary = array();
  296. $errored = $no_updates = false;
  297. ?>
  298. <br /><br />
  299. <h1><?php echo $lang['UPDATING_DATA']; ?></h1>
  300. <br />
  301. <p><?php echo $lang['PROGRESS']; ?> :: <strong>
  302. <?php
  303. flush();
  304. $no_updates = true;
  305. $versions = array_keys($database_update_info);
  306. // some code magic
  307. for ($i = 0; $i < sizeof($versions); $i++)
  308. {
  309. $version = $versions[$i];
  310. $next_version = (isset($versions[$i + 1])) ? $versions[$i + 1] : $updates_to_version;
  311. // 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
  312. if (version_compare($version, $current_version, '<') && version_compare($current_version, $next_version, '>='))
  313. {
  314. continue;
  315. }
  316. change_database_data($no_updates, $version);
  317. }
  318. _write_result($no_updates, $errored, $error_ary);
  319. $error_ary = array();
  320. $errored = $no_updates = false;
  321. ?>
  322. <br /><br />
  323. <h1><?php echo $lang['UPDATE_VERSION_OPTIMIZE']; ?></h1>
  324. <br />
  325. <p><?php echo $lang['PROGRESS']; ?> :: <strong>
  326. <?php
  327. flush();
  328. if ($debug_from_version === false)
  329. {
  330. // update the version
  331. $sql = "UPDATE " . CONFIG_TABLE . "
  332. SET config_value = '$updates_to_version'
  333. WHERE config_name = 'version'";
  334. _sql($sql, $errored, $error_ary);
  335. }
  336. // Reset permissions
  337. $sql = 'UPDATE ' . USERS_TABLE . "
  338. SET user_permissions = '',
  339. user_perm_from = 0";
  340. _sql($sql, $errored, $error_ary);
  341. // Update the dbms version if everything is ok...
  342. set_config('dbms_version', $db->sql_server_info(true));
  343. /* Optimize/vacuum analyze the tables where appropriate
  344. // this should be done for each version in future along with
  345. // the version number update
  346. switch ($db->sql_layer)
  347. {
  348. case 'mysql':
  349. case 'mysqli':
  350. case 'mysql4':
  351. $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';
  352. _sql($sql, $errored, $error_ary);
  353. break;
  354. case 'postgresql':
  355. _sql("VACUUM ANALYZE", $errored, $error_ary);
  356. break;
  357. }
  358. */
  359. _write_result($no_updates, $errored, $error_ary);
  360. ?>
  361. <br />
  362. <h1><?php echo $lang['UPDATE_COMPLETED']; ?></h1>
  363. <br />
  364. <?php
  365. if (!$inline_update)
  366. {
  367. ?>
  368. <p style="color:red"><?php echo $lang['UPDATE_FILES_NOTICE']; ?></p>
  369. <p><?php echo $lang['COMPLETE_LOGIN_TO_BOARD']; ?></p>
  370. <?php
  371. }
  372. else
  373. {
  374. ?>
  375. <p><?php echo ((isset($lang['INLINE_UPDATE_SUCCESSFUL'])) ? $lang['INLINE_UPDATE_SUCCESSFUL'] : 'The database update was successful. Now you need to continue the update process.'); ?></p>
  376. <p><a href="<?php echo append_sid("{$phpbb_root_path}install/index.{$phpEx}", "mode=update&amp;sub=file_check&amp;language=$language"); ?>" class="button1"><?php echo (isset($lang['CONTINUE_UPDATE_NOW'])) ? $lang['CONTINUE_UPDATE_NOW'] : 'Continue the update process now'; ?></a></p>
  377. <?php
  378. }
  379. // Add database update to log
  380. add_log('admin', 'LOG_UPDATE_DATABASE', $orig_version, $updates_to_version);
  381. // Now we purge the session table as well as all cache files
  382. $cache->purge();
  383. _print_footer();
  384. garbage_collection();
  385. if (function_exists('exit_handler'))
  386. {
  387. exit_handler();
  388. }
  389. /**
  390. * Print out footer
  391. */
  392. function _print_footer()
  393. {
  394. echo <<<EOF
  395. </div>
  396. </div>
  397. <span class="corners-bottom"><span></span></span>
  398. </div>
  399. </div>
  400. </div>
  401. <div id="page-footer">
  402. Powered by <a href="http://www.phpbb.com/">phpBB</a>&reg; Forum Software &copy; phpBB Group
  403. </div>
  404. </div>
  405. </body>
  406. </html>
  407. EOF;
  408. }
  409. /**
  410. * Function for triggering an sql statement
  411. */
  412. function _sql($sql, &$errored, &$error_ary, $echo_dot = true)
  413. {
  414. global $db;
  415. if (defined('DEBUG_EXTRA'))
  416. {
  417. echo "<br />\n{$sql}\n<br />";
  418. }
  419. $db->sql_return_on_error(true);
  420. if ($sql === 'begin')
  421. {
  422. $result = $db->sql_transaction('begin');
  423. }
  424. else if ($sql === 'commit')
  425. {
  426. $result = $db->sql_transaction('commit');
  427. }
  428. else
  429. {
  430. $result = $db->sql_query($sql);
  431. if ($db->sql_error_triggered)
  432. {
  433. $errored = true;
  434. $error_ary['sql'][] = $db->sql_error_sql;
  435. $error_ary['error_code'][] = $db->sql_error_returned;
  436. }
  437. }
  438. $db->sql_return_on_error(false);
  439. if ($echo_dot)
  440. {
  441. echo ". \n";
  442. flush();
  443. }
  444. return $result;
  445. }
  446. function _write_result($no_updates, $errored, $error_ary)
  447. {
  448. global $lang;
  449. if ($no_updates)
  450. {
  451. echo ' ' . $lang['NO_UPDATES_REQUIRED'] . '</strong></p>';
  452. }
  453. else
  454. {
  455. echo ' <span class="success">' . $lang['DONE'] . '</span></strong><br />' . $lang['RESULT'] . ' :: ';
  456. if ($errored)
  457. {
  458. echo ' <strong>' . $lang['SOME_QUERIES_FAILED'] . '</strong> <ul>';
  459. for ($i = 0; $i < sizeof($error_ary['sql']); $i++)
  460. {
  461. echo '<li>' . $lang['ERROR'] . ' :: <strong>' . htmlspecialchars($error_ary['error_code'][$i]['message']) . '</strong><br />';
  462. echo $lang['SQL'] . ' :: <strong>' . htmlspecialchars($error_ary['sql'][$i]) . '</strong><br /><br /></li>';
  463. }
  464. echo '</ul> <br /><br />' . $lang['SQL_FAILURE_EXPLAIN'] . '</p>';
  465. }
  466. else
  467. {
  468. echo '<strong>' . $lang['NO_ERRORS'] . '</strong></p>';
  469. }
  470. }
  471. }
  472. function _add_modules($modules_to_install)
  473. {
  474. global $phpbb_root_path, $phpEx, $db;
  475. include_once($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx);
  476. $_module = new acp_modules();
  477. foreach ($modules_to_install as $module_mode => $module_data)
  478. {
  479. $_module->module_class = $module_data['class'];
  480. // Determine parent id first
  481. $sql = 'SELECT module_id
  482. FROM ' . MODULES_TABLE . "
  483. WHERE module_class = '" . $db->sql_escape($module_data['class']) . "'
  484. AND module_langname = '" . $db->sql_escape($module_data['cat']) . "'
  485. AND module_mode = ''
  486. AND module_basename = ''";
  487. $result = $db->sql_query($sql);
  488. // There may be more than one categories with the same name
  489. $categories = array();
  490. while ($row = $db->sql_fetchrow($result))
  491. {
  492. $categories[] = (int) $row['module_id'];
  493. }
  494. $db->sql_freeresult($result);
  495. if (!sizeof($categories))
  496. {
  497. continue;
  498. }
  499. // Add the module to all categories found
  500. foreach ($categories as $parent_id)
  501. {
  502. // Check if the module already exists
  503. $sql = 'SELECT *
  504. FROM ' . MODULES_TABLE . "
  505. WHERE module_basename = '" . $db->sql_escape($module_data['base']) . "'
  506. AND module_class = '" . $db->sql_escape($module_data['class']) . "'
  507. AND module_langname = '" . $db->sql_escape($module_data['title']) . "'
  508. AND module_mode = '" . $db->sql_escape($module_mode) . "'
  509. AND module_auth = '" . $db->sql_escape($module_data['auth']) . "'
  510. AND parent_id = {$parent_id}";
  511. $result = $db->sql_query($sql);
  512. $row = $db->sql_fetchrow($result);
  513. $db->sql_freeresult($result);
  514. // If it exists, we simply continue with the next category
  515. if ($row)
  516. {
  517. continue;
  518. }
  519. // Build the module sql row
  520. $module_row = array(
  521. 'module_basename' => $module_data['base'],
  522. 'module_enabled' => (isset($module_data['enabled'])) ? (int) $module_data['enabled'] : 1,
  523. 'module_display' => (isset($module_data['display'])) ? (int) $module_data['display'] : 1,
  524. 'parent_id' => $parent_id,
  525. 'module_class' => $module_data['class'],
  526. 'module_langname' => $module_data['title'],
  527. 'module_mode' => $module_mode,
  528. 'module_auth' => $module_data['auth'],
  529. );
  530. $_module->update_module_data($module_row, true);
  531. // Ok, do we need to re-order the module, move it up or down?
  532. if (!isset($module_data['after']))
  533. {
  534. continue;
  535. }
  536. $after_mode = $module_data['after'][0];
  537. $after_langname = $module_data['after'][1];
  538. // First of all, get the module id for the module this one has to be placed after
  539. $sql = 'SELECT left_id
  540. FROM ' . MODULES_TABLE . "
  541. WHERE module_class = '" . $db->sql_escape($module_data['class']) . "'
  542. AND module_basename = '" . $db->sql_escape($module_data['base']) . "'
  543. AND module_langname = '" . $db->sql_escape($after_langname) . "'
  544. AND module_mode = '" . $db->sql_escape($after_mode) . "'
  545. AND parent_id = '{$parent_id}'";
  546. $result = $db->sql_query($sql);
  547. $first_left_id = (int) $db->sql_fetchfield('left_id');
  548. $db->sql_freeresult($result);
  549. if (!$first_left_id)
  550. {
  551. continue;
  552. }
  553. // Ok, count the number of modules between $after_mode and the added module
  554. $sql = 'SELECT COUNT(module_id) as num_modules
  555. FROM ' . MODULES_TABLE . "
  556. WHERE module_class = '" . $db->sql_escape($module_data['class']) . "'
  557. AND parent_id = {$parent_id}
  558. AND left_id BETWEEN {$first_left_id} AND {$module_row['left_id']}";
  559. $result = $db->sql_query($sql);
  560. $steps = (int) $db->sql_fetchfield('num_modules');
  561. $db->sql_freeresult($result);
  562. // We need to substract 2
  563. $steps -= 2;
  564. if ($steps <= 0)
  565. {
  566. continue;
  567. }
  568. // Ok, move module up $num_modules times. ;)
  569. $_module->move_module_by($module_row, 'move_up', $steps);
  570. }
  571. }
  572. $_module->remove_cache_file();
  573. }
  574. /****************************************************************************
  575. * ADD YOUR DATABASE SCHEMA CHANGES HERE *
  576. *****************************************************************************/
  577. function database_update_info()
  578. {
  579. return array(
  580. // Changes from 3.0.0 to the next version
  581. '3.0.0' => array(
  582. // Add the following columns
  583. 'add_columns' => array(
  584. FORUMS_TABLE => array(
  585. 'display_subforum_list' => array('BOOL', 1),
  586. ),
  587. SESSIONS_TABLE => array(
  588. 'session_forum_id' => array('UINT', 0),
  589. ),
  590. ),
  591. 'drop_keys' => array(
  592. GROUPS_TABLE => array('group_legend'),
  593. ),
  594. 'add_index' => array(
  595. SESSIONS_TABLE => array(
  596. 'session_forum_id' => array('session_forum_id'),
  597. ),
  598. GROUPS_TABLE => array(
  599. 'group_legend_name' => array('group_legend', 'group_name'),
  600. ),
  601. ),
  602. ),
  603. // No changes from 3.0.1-RC1 to 3.0.1
  604. '3.0.1-RC1' => array(),
  605. // No changes from 3.0.1 to 3.0.2-RC1
  606. '3.0.1' => array(),
  607. // Changes from 3.0.2-RC1 to 3.0.2-RC2
  608. '3.0.2-RC1' => array(
  609. 'change_columns' => array(
  610. DRAFTS_TABLE => array(
  611. 'draft_subject' => array('STEXT_UNI', ''),
  612. ),
  613. FORUMS_TABLE => array(
  614. 'forum_last_post_subject' => array('STEXT_UNI', ''),
  615. ),
  616. POSTS_TABLE => array(
  617. 'post_subject' => array('STEXT_UNI', '', 'true_sort'),
  618. ),
  619. PRIVMSGS_TABLE => array(
  620. 'message_subject' => array('STEXT_UNI', ''),
  621. ),
  622. TOPICS_TABLE => array(
  623. 'topic_title' => array('STEXT_UNI', '', 'true_sort'),
  624. 'topic_last_post_subject' => array('STEXT_UNI', ''),
  625. ),
  626. ),
  627. 'drop_keys' => array(
  628. SESSIONS_TABLE => array('session_forum_id'),
  629. ),
  630. 'add_index' => array(
  631. SESSIONS_TABLE => array(
  632. 'session_fid' => array('session_forum_id'),
  633. ),
  634. ),
  635. ),
  636. // No changes from 3.0.2-RC2 to 3.0.2
  637. '3.0.2-RC2' => array(),
  638. // Changes from 3.0.2 to 3.0.3-RC1
  639. '3.0.2' => array(
  640. // Add the following columns
  641. 'add_columns' => array(
  642. STYLES_TEMPLATE_TABLE => array(
  643. 'template_inherits_id' => array('UINT:4', 0),
  644. 'template_inherit_path' => array('VCHAR', ''),
  645. ),
  646. GROUPS_TABLE => array(
  647. 'group_max_recipients' => array('UINT', 0),
  648. ),
  649. ),
  650. ),
  651. // No changes from 3.0.3-RC1 to 3.0.3
  652. '3.0.3-RC1' => array(),
  653. // Changes from 3.0.3 to 3.0.4-RC1
  654. '3.0.3' => array(
  655. 'add_columns' => array(
  656. PROFILE_FIELDS_TABLE => array(
  657. 'field_show_profile' => array('BOOL', 0),
  658. ),
  659. ),
  660. 'change_columns' => array(
  661. STYLES_TABLE => array(
  662. 'style_id' => array('UINT', NULL, 'auto_increment'),
  663. 'template_id' => array('UINT', 0),
  664. 'theme_id' => array('UINT', 0),
  665. 'imageset_id' => array('UINT', 0),
  666. ),
  667. STYLES_IMAGESET_TABLE => array(
  668. 'imageset_id' => array('UINT', NULL, 'auto_increment'),
  669. ),
  670. STYLES_IMAGESET_DATA_TABLE => array(
  671. 'image_id' => array('UINT', NULL, 'auto_increment'),
  672. 'imageset_id' => array('UINT', 0),
  673. ),
  674. STYLES_THEME_TABLE => array(
  675. 'theme_id' => array('UINT', NULL, 'auto_increment'),
  676. ),
  677. STYLES_TEMPLATE_TABLE => array(
  678. 'template_id' => array('UINT', NULL, 'auto_increment'),
  679. ),
  680. STYLES_TEMPLATE_DATA_TABLE => array(
  681. 'template_id' => array('UINT', 0),
  682. ),
  683. FORUMS_TABLE => array(
  684. 'forum_style' => array('UINT', 0),
  685. ),
  686. USERS_TABLE => array(
  687. 'user_style' => array('UINT', 0),
  688. ),
  689. ),
  690. ),
  691. // Changes from 3.0.4-RC1 to 3.0.4
  692. '3.0.4-RC1' => array(),
  693. // Changes from 3.0.4 to 3.0.5-RC1
  694. '3.0.4' => array(
  695. 'change_columns' => array(
  696. FORUMS_TABLE => array(
  697. 'forum_style' => array('UINT', 0),
  698. ),
  699. ),
  700. ),
  701. // No changes from 3.0.5-RC1 to 3.0.5
  702. '3.0.5-RC1' => array(),
  703. // Changes from 3.0.5 to 3.0.6-RC1
  704. '3.0.5' => array(
  705. 'add_columns' => array(
  706. CONFIRM_TABLE => array(
  707. 'attempts' => array('UINT', 0),
  708. ),
  709. USERS_TABLE => array(
  710. 'user_new' => array('BOOL', 1),
  711. 'user_reminded' => array('TINT:4', 0),
  712. 'user_reminded_time'=> array('TIMESTAMP', 0),
  713. ),
  714. GROUPS_TABLE => array(
  715. 'group_skip_auth' => array('BOOL', 0, 'after' => 'group_founder_manage'),
  716. ),
  717. PRIVMSGS_TABLE => array(
  718. 'message_reported' => array('BOOL', 0),
  719. ),
  720. REPORTS_TABLE => array(
  721. 'pm_id' => array('UINT', 0),
  722. ),
  723. PROFILE_FIELDS_TABLE => array(
  724. 'field_show_on_vt' => array('BOOL', 0),
  725. ),
  726. FORUMS_TABLE => array(
  727. 'forum_options' => array('UINT:20', 0),
  728. ),
  729. ),
  730. 'change_columns' => array(
  731. USERS_TABLE => array(
  732. 'user_options' => array('UINT:11', 230271),
  733. ),
  734. ),
  735. 'add_index' => array(
  736. REPORTS_TABLE => array(
  737. 'post_id' => array('post_id'),
  738. 'pm_id' => array('pm_id'),
  739. ),
  740. POSTS_TABLE => array(
  741. 'post_username' => array('post_username:255'),
  742. ),
  743. ),
  744. ),
  745. // No changes from 3.0.6-RC1 to 3.0.6-RC2
  746. '3.0.6-RC1' => array(),
  747. // No changes from 3.0.6-RC2 to 3.0.6-RC3
  748. '3.0.6-RC2' => array(),
  749. // No changes from 3.0.6-RC3 to 3.0.6-RC4
  750. '3.0.6-RC3' => array(),
  751. // No changes from 3.0.6-RC4 to 3.0.6
  752. '3.0.6-RC4' => array(),
  753. // Changes from 3.0.6 to 3.0.7-RC1
  754. '3.0.6' => array(
  755. 'drop_keys' => array(
  756. LOG_TABLE => array('log_time'),
  757. ),
  758. 'add_index' => array(
  759. TOPICS_TRACK_TABLE => array(
  760. 'topic_id' => array('topic_id'),
  761. ),
  762. ),
  763. ),
  764. // No changes from 3.0.7-RC1 to 3.0.7-RC2
  765. '3.0.7-RC1' => array(),
  766. // No changes from 3.0.7-RC2 to 3.0.7
  767. '3.0.7-RC2' => array(),
  768. // No changes from 3.0.7 to 3.0.7-PL1
  769. '3.0.7' => array(),
  770. // No changes from 3.0.7-PL1 to 3.0.8-RC1
  771. '3.0.7-PL1' => array(),
  772. // No changes from 3.0.8-RC1 to 3.0.8
  773. '3.0.8-RC1' => array(),
  774. // Changes from 3.0.8 to 3.0.9-RC1
  775. '3.0.8' => array(
  776. 'add_tables' => array(
  777. LOGIN_ATTEMPT_TABLE => array(
  778. 'COLUMNS' => array(
  779. // this column was removed from the database updater
  780. // after 3.0.9-RC3 was released. It might still exist
  781. // in 3.0.9-RCX installations and has to be dropped in
  782. // 3.0.10 after the db_tools class is capable of properly
  783. // removing a primary key.
  784. // 'attempt_id' => array('UINT', NULL, 'auto_increment'),
  785. 'attempt_ip' => array('VCHAR:40', ''),
  786. 'attempt_browser' => array('VCHAR:150', ''),
  787. 'attempt_forwarded_for' => array('VCHAR:255', ''),
  788. 'attempt_time' => array('TIMESTAMP', 0),
  789. 'user_id' => array('UINT', 0),
  790. 'username' => array('VCHAR_UNI:255', 0),
  791. 'username_clean' => array('VCHAR_CI', 0),
  792. ),
  793. //'PRIMARY_KEY' => 'attempt_id',
  794. 'KEYS' => array(
  795. 'att_ip' => array('INDEX', array('attempt_ip', 'attempt_time')),
  796. 'att_for' => array('INDEX', array('attempt_forwarded_for', 'attempt_time')),
  797. 'att_time' => array('INDEX', array('attempt_time')),
  798. 'user_id' => array('INDEX', 'user_id'),
  799. ),
  800. ),
  801. ),
  802. 'change_columns' => array(
  803. BBCODES_TABLE => array(
  804. 'bbcode_id' => array('USINT', 0),
  805. ),
  806. ),
  807. ),
  808. // No changes from 3.0.9-RC1 to 3.0.9-RC2
  809. '3.0.9-RC1' => array(),
  810. // No changes from 3.0.9-RC2 to 3.0.9-RC3
  811. '3.0.9-RC2' => array(),
  812. // No changes from 3.0.9-RC3 to 3.0.9-RC4
  813. '3.0.9-RC3' => array(),
  814. // No changes from 3.0.9-RC4 to 3.0.9
  815. '3.0.9-RC4' => array(),
  816. /** @todo DROP LOGIN_ATTEMPT_TABLE.attempt_id in 3.0.10-RC1 */
  817. );
  818. }
  819. /****************************************************************************
  820. * ADD YOUR DATABASE DATA CHANGES HERE *
  821. * REMEMBER: You NEED to enter a schema array above and a data array here, *
  822. * even if both or one of them are empty. *
  823. *****************************************************************************/
  824. function change_database_data(&$no_updates, $version)
  825. {
  826. global $db, $errored, $error_ary, $config, $phpbb_root_path, $phpEx;
  827. switch ($version)
  828. {
  829. case '3.0.0':
  830. $sql = 'UPDATE ' . TOPICS_TABLE . "
  831. SET topic_last_view_time = topic_last_post_time
  832. WHERE topic_last_view_time = 0";
  833. _sql($sql, $errored, $error_ary);
  834. // Update smiley sizes
  835. $smileys = array('icon_e_surprised.gif', 'icon_eek.gif', 'icon_cool.gif', 'icon_lol.gif', 'icon_mad.gif', 'icon_razz.gif', 'icon_redface.gif', 'icon_cry.gif', 'icon_evil.gif', 'icon_twisted.gif', 'icon_rolleyes.gif', 'icon_exclaim.gif', 'icon_question.gif', 'icon_idea.gif', 'icon_arrow.gif', 'icon_neutral.gif', 'icon_mrgreen.gif', 'icon_e_ugeek.gif');
  836. foreach ($smileys as $smiley)
  837. {
  838. if (file_exists($phpbb_root_path . 'images/smilies/' . $smiley))
  839. {
  840. list($width, $height) = getimagesize($phpbb_root_path . 'images/smilies/' . $smiley);
  841. $sql = 'UPDATE ' . SMILIES_TABLE . '
  842. SET smiley_width = ' . $width . ', smiley_height = ' . $height . "
  843. WHERE smiley_url = '" . $db->sql_escape($smiley) . "'";
  844. _sql($sql, $errored, $error_ary);
  845. }
  846. }
  847. $no_updates = false;
  848. break;
  849. // No changes from 3.0.1-RC1 to 3.0.1
  850. case '3.0.1-RC1':
  851. break;
  852. // changes from 3.0.1 to 3.0.2-RC1
  853. case '3.0.1':
  854. set_config('referer_validation', '1');
  855. set_config('check_attachment_content', '1');
  856. set_config('mime_triggers', 'body|head|html|img|plaintext|a href|pre|script|table|title');
  857. $no_updates = false;
  858. break;
  859. // No changes from 3.0.2-RC1 to 3.0.2-RC2
  860. case '3.0.2-RC1':
  861. break;
  862. // No changes from 3.0.2-RC2 to 3.0.2
  863. case '3.0.2-RC2':
  864. break;
  865. // Changes from 3.0.2 to 3.0.3-RC1
  866. case '3.0.2':
  867. set_config('enable_queue_trigger', '0');
  868. set_config('queue_trigger_posts', '3');
  869. set_config('pm_max_recipients', '0');
  870. // Set maximum number of recipients for the registered users, bots, guests group
  871. $sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_max_recipients = 5
  872. WHERE ' . $db->sql_in_set('group_name', array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA', 'BOTS'));
  873. _sql($sql, $errored, $error_ary);
  874. // Not prefilling yet
  875. set_config('dbms_version', '');
  876. // Add new permission u_masspm_group and duplicate settings from u_masspm
  877. include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
  878. $auth_admin = new auth_admin();
  879. // Only add the new permission if it does not already exist
  880. if (empty($auth_admin->acl_options['id']['u_masspm_group']))
  881. {
  882. $auth_admin->acl_add_option(array('global' => array('u_masspm_group')));
  883. // Now the tricky part, filling the permission
  884. $old_id = $auth_admin->acl_options['id']['u_masspm'];
  885. $new_id = $auth_admin->acl_options['id']['u_masspm_group'];
  886. $tables = array(ACL_GROUPS_TABLE, ACL_ROLES_DATA_TABLE, ACL_USERS_TABLE);
  887. foreach ($tables as $table)
  888. {
  889. $sql = 'SELECT *
  890. FROM ' . $table . '
  891. WHERE auth_option_id = ' . $old_id;
  892. $result = _sql($sql, $errored, $error_ary);
  893. $sql_ary = array();
  894. while ($row = $db->sql_fetchrow($result))
  895. {
  896. $row['auth_option_id'] = $new_id;
  897. $sql_ary[] = $row;
  898. }
  899. $db->sql_freeresult($result);
  900. if (sizeof($sql_ary))
  901. {
  902. $db->sql_multi_insert($table, $sql_ary);
  903. }
  904. }
  905. // Remove any old permission entries
  906. $auth_admin->acl_clear_prefetch();
  907. }
  908. /**
  909. * Do not resync post counts here. An admin may do this later from the ACP
  910. $start = 0;
  911. $step = ($config['num_posts']) ? (max((int) ($config['num_posts'] / 5), 20000)) : 20000;
  912. $sql = 'UPDATE ' . USERS_TABLE . ' SET user_posts = 0';
  913. _sql($sql, $errored, $error_ary);
  914. do
  915. {
  916. $sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
  917. FROM ' . POSTS_TABLE . '
  918. WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . '
  919. AND post_postcount = 1 AND post_approved = 1
  920. GROUP BY poster_id';
  921. $result = _sql($sql, $errored, $error_ary);
  922. if ($row = $db->sql_fetchrow($result))
  923. {
  924. do
  925. {
  926. $sql = 'UPDATE ' . USERS_TABLE . " SET user_posts = user_posts + {$row['num_posts']} WHERE user_id = {$row['poster_id']}";
  927. _sql($sql, $errored, $error_ary);
  928. }
  929. while ($row = $db->sql_fetchrow($result));
  930. $start += $step;
  931. }
  932. else
  933. {
  934. $start = 0;
  935. }
  936. $db->sql_freeresult($result);
  937. }
  938. while ($start);
  939. */
  940. $sql = 'UPDATE ' . MODULES_TABLE . '
  941. SET module_auth = \'acl_a_email && cfg_email_enable\'
  942. WHERE module_class = \'acp\'
  943. AND module_basename = \'email\'';
  944. _sql($sql, $errored, $error_ary);
  945. $no_updates = false;
  946. break;
  947. // Changes from 3.0.3-RC1 to 3.0.3
  948. case '3.0.3-RC1':
  949. if ($db->sql_layer == 'oracle')
  950. {
  951. // log_operation is CLOB - but we can change this later
  952. $sql = 'UPDATE ' . LOG_TABLE . "
  953. SET log_operation = 'LOG_DELETE_TOPIC'
  954. WHERE log_operation LIKE 'LOG_TOPIC_DELETED'";
  955. _sql($sql, $errored, $error_ary);
  956. }
  957. else
  958. {
  959. $sql = 'UPDATE ' . LOG_TABLE . "
  960. SET log_operation = 'LOG_DELETE_TOPIC'
  961. WHERE log_operation = 'LOG_TOPIC_DELETED'";
  962. _sql($sql, $errored, $error_ary);
  963. }
  964. $no_updates = false;
  965. break;
  966. // Changes from 3.0.3 to 3.0.4-RC1
  967. case '3.0.3':
  968. // Update the Custom Profile Fields based on previous settings to the new format
  969. $sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide
  970. FROM ' . PROFILE_FIELDS_TABLE;
  971. $result = _sql($sql, $errored, $error_ary);
  972. while ($row = $db->sql_fetchrow($result))
  973. {
  974. $sql_ary = array(
  975. 'field_required' => 0,
  976. 'field_show_on_reg' => 0,
  977. 'field_hide' => 0,
  978. 'field_show_profile'=> 0,
  979. );
  980. if ($row['field_required'])
  981. {
  982. $sql_ary['field_required'] = $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1;
  983. }
  984. else if ($row['field_show_on_reg'])
  985. {
  986. $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1;
  987. }
  988. else if ($row['field_hide'])
  989. {
  990. // Only administrators and moderators can see this CPF, if the view is enabled, they can see it, otherwise just admins in the acp_users module
  991. $sql_ary['field_hide'] = 1;
  992. }
  993. else
  994. {
  995. // equivelant to "none", which is the "Display in user control panel" option
  996. $sql_ary['field_show_profile'] = 1;
  997. }
  998. _sql('UPDATE ' . PROFILE_FIELDS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary);
  999. }
  1000. $no_updates = false;
  1001. break;
  1002. // Changes from 3.0.4-RC1 to 3.0.4
  1003. case '3.0.4-RC1':
  1004. break;
  1005. // Changes from 3.0.4 to 3.0.5-RC1
  1006. case '3.0.4':
  1007. // Captcha config variables
  1008. set_config('captcha_gd_wave', 0);
  1009. set_config('captcha_gd_3d_noise', 1);
  1010. set_config('captcha_gd_fonts', 1);
  1011. set_config('confirm_refresh', 1);
  1012. // Maximum number of keywords
  1013. set_config('max_num_search_keywords', 10);
  1014. // Remove static config var and put it back as dynamic variable
  1015. $sql = 'UPDATE ' . CONFIG_TABLE . "
  1016. SET is_dynamic = 1
  1017. WHERE config_name = 'search_indexing_state'";
  1018. _sql($sql, $errored, $error_ary);
  1019. // Hash old MD5 passwords
  1020. $sql = 'SELECT user_id, user_password
  1021. FROM ' . USERS_TABLE . '
  1022. WHERE user_pass_convert = 1';
  1023. $result = _sql($sql, $errored, $error_ary);
  1024. while ($row = $db->sql_fetchrow($result))
  1025. {
  1026. if (strlen($row['user_password']) == 32)
  1027. {
  1028. $sql_ary = array(
  1029. 'user_password' => phpbb_hash($row['user_password']),
  1030. );
  1031. _sql('UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $row['user_id'], $errored, $error_ary);
  1032. }
  1033. }
  1034. $db->sql_freeresult($result);
  1035. // Adjust bot entry
  1036. $sql = 'UPDATE ' . BOTS_TABLE . "
  1037. SET bot_agent = 'ichiro/'
  1038. WHERE bot_agent = 'ichiro/2'";
  1039. _sql($sql, $errored, $error_ary);
  1040. // Before we are able to add a unique key to auth_option, we need to remove duplicate entries
  1041. // We get duplicate entries first
  1042. $sql = 'SELECT auth_option
  1043. FROM ' . ACL_OPTIONS_TABLE . '
  1044. GROUP BY auth_option
  1045. HAVING COUNT(*) >= 2';
  1046. $result = $db->sql_query($sql);
  1047. $auth_options = array();
  1048. while ($row = $db->sql_fetchrow($result))
  1049. {
  1050. $auth_options[] = $row['auth_option'];
  1051. }
  1052. $db->sql_freeresult($result);
  1053. // Remove specific auth options
  1054. if (!empty($auth_options))
  1055. {
  1056. foreach ($auth_options as $option)
  1057. {
  1058. // Select auth_option_ids... the largest id will be preserved
  1059. $sql = 'SELECT auth_option_id
  1060. FROM ' . ACL_OPTIONS_TABLE . "
  1061. WHERE auth_option = '" . $db->sql_escape($option) . "'
  1062. ORDER BY auth_option_id DESC";
  1063. // sql_query_limit not possible here, due to bug in postgresql layer
  1064. $result = $db->sql_query($sql);
  1065. // Skip first row, this is our original auth option we want to preserve
  1066. $row = $db->sql_fetchrow($result);
  1067. while ($row = $db->sql_fetchrow($result))
  1068. {
  1069. // Ok, remove this auth option...
  1070. _sql('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary);
  1071. _sql('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary);
  1072. _sql('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary);
  1073. _sql('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary);
  1074. }
  1075. $db->sql_freeresult($result);
  1076. }
  1077. }
  1078. // Now make auth_option UNIQUE, by dropping the old index and adding a UNIQUE one.
  1079. $changes = array(
  1080. 'drop_keys' => array(
  1081. ACL_OPTIONS_TABLE => array('auth_option'),
  1082. ),
  1083. );
  1084. global $db_tools;
  1085. $statements = $db_tools->perform_schema_changes($changes);
  1086. foreach ($statements as $sql)
  1087. {
  1088. _sql($sql, $errored, $error_ary);
  1089. }
  1090. $changes = array(
  1091. 'add_unique_index' => array(
  1092. ACL_OPTIONS_TABLE => array(
  1093. 'auth_option' => array('auth_option'),
  1094. ),
  1095. ),
  1096. );
  1097. $statements = $db_tools->perform_schema_changes($changes);
  1098. foreach ($statements as $sql)
  1099. {
  1100. _sql($sql, $errored, $error_ary);
  1101. }
  1102. $no_updates = false;
  1103. break;
  1104. // No changes from 3.0.5-RC1 to 3.0.5
  1105. case '3.0.5-RC1':
  1106. break;
  1107. // Changes from 3.0.5 to 3.0.6-RC1
  1108. case '3.0.5':
  1109. // Let's see if the GD Captcha can be enabled... we simply look for what *is* enabled...
  1110. if (!empty($config['captcha_gd']) && !isset($config['captcha_plugin']))
  1111. {
  1112. set_config('captcha_plugin', 'phpbb_captcha_gd');
  1113. }
  1114. else if (!isset($config['captcha_plugin']))
  1115. {
  1116. set_config('captcha_plugin', 'phpbb_captcha_nogd');
  1117. }
  1118. // Entries for the Feed Feature
  1119. set_config('feed_enable', '0');
  1120. set_config('feed_limit', '10');
  1121. set_config('feed_overall_forums', '1');
  1122. set_config('feed_overall_forums_limit', '15');
  1123. set_config('feed_overall_topics', '0');
  1124. set_config('feed_overall_topics_limit', '15');
  1125. set_config('feed_forum', '1');
  1126. set_config('feed_topic', '1');
  1127. set_config('feed_item_statistics', '1');
  1128. // Entries for smiley pagination
  1129. set_config('smilies_per_page', '50');
  1130. // Entry for reporting PMs
  1131. set_config('allow_pm_report', '1');
  1132. // Install modules
  1133. $modules_to_install = array(
  1134. 'feed' => array(
  1135. 'base' => 'board',
  1136. 'class' => 'acp',
  1137. 'title' => 'ACP_FEED_SETTINGS',
  1138. 'auth' => 'acl_a_board',
  1139. 'cat' => 'ACP_BOARD_CONFIGURATION',
  1140. 'after' => array('signature', 'ACP_SIGNATURE_SETTINGS')
  1141. ),
  1142. 'warnings' => array(
  1143. 'base' => 'users',
  1144. 'class' => 'acp',
  1145. 'title' => 'ACP_USER_WARNINGS',
  1146. 'auth' => 'acl_a_user',
  1147. 'display' => 0,
  1148. 'cat' => 'ACP_CAT_USERS',
  1149. 'after' => array('feedback', 'ACP_USER_FEEDBACK')
  1150. ),
  1151. 'send_statistics' => array(
  1152. 'base' => 'send_statistics',
  1153. 'class' => 'acp',
  1154. 'title' => 'ACP_SEND_STATISTICS',
  1155. 'auth' => 'acl_a_server',
  1156. 'cat' => 'ACP_SERVER_CONFIGURATION'
  1157. ),
  1158. 'setting_forum_copy' => array(
  1159. 'base' => 'permissions',
  1160. 'class' => 'acp',
  1161. 'title' => 'ACP_FORUM_PERMISSIONS_COPY',
  1162. 'auth' => 'acl_a_fauth && acl_a_authusers && acl_a_authgroups && acl_a_mauth',
  1163. 'cat' => 'ACP_FORUM_BASED_PERMISSIONS',
  1164. 'after' => array('setting_forum_local', 'ACP_FORUM_PERMISSIONS')
  1165. ),
  1166. 'pm_reports' => array(
  1167. 'base' => 'pm_reports',
  1168. 'class' => 'mcp',
  1169. 'title' => 'MCP_PM_REPORTS_OPEN',
  1170. 'auth' => 'aclf_m_report',
  1171. 'cat' => 'MCP_REPORTS'
  1172. ),
  1173. 'pm_reports_closed' => array(
  1174. 'base' => 'pm_reports',
  1175. 'class' => 'mcp',
  1176. 'title' => 'MCP_PM_REPORTS_CLOSED',
  1177. 'auth' => 'aclf_m_report',
  1178. 'cat' => 'MCP_REPORTS'
  1179. ),
  1180. 'pm_report_details' => array(
  1181. 'base' => 'pm_reports',
  1182. 'class' => 'mcp',
  1183. 'title' => 'MCP_PM_REPORT_DETAILS',
  1184. 'auth' => 'aclf_m_report',
  1185. 'cat' => 'MCP_REPORTS'
  1186. ),
  1187. );
  1188. _add_modules($modules_to_install);
  1189. // Add newly_registered group... but check if it already exists (we always supported running the updater on any schema)
  1190. $sql = 'SELECT group_id
  1191. FROM ' . GROUPS_TABLE . "
  1192. WHERE group_name = 'NEWLY_REGISTERED'";
  1193. $result = $db->sql_query($sql);
  1194. $group_id = (int) $db->sql_fetchfield('group_id');
  1195. $db->sql_freeresult($result);
  1196. if (!$group_id)
  1197. {
  1198. $sql = 'INSERT INTO ' . GROUPS_TABLE . " (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('NEWLY_REGISTERED', 3, 0, '', 0, '', '', '', 5)";
  1199. _sql($sql, $errored, $error_ary);
  1200. $group_id = $db->sql_nextid();
  1201. }
  1202. // Insert new user role... at the end of the chain
  1203. $sql = 'SELECT role_id
  1204. FROM ' . ACL_ROLES_TABLE . "
  1205. WHERE role_name = 'ROLE_USER_NEW_MEMBER'
  1206. AND role_type = 'u_'";
  1207. $result = $db->sql_query($sql);
  1208. $u_role = (int) $db->sql_fetchfield('role_id');
  1209. $db->sql_freeresult($result);
  1210. if (!$u_role)
  1211. {
  1212. $sql = 'SELECT MAX(role_order) as max_order_id
  1213. FROM ' . ACL_ROLES_TABLE . "
  1214. WHERE role_type = 'u_'";
  1215. $result = $db->sql_query($sql);
  1216. $next_order_id = (int) $db->sql_fetchfield('max_order_id');
  1217. $db->sql_freeresult($result);
  1218. $next_order_id++;
  1219. $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_USER_NEW_MEMBER', 'ROLE_DESCRIPTION_USER_NEW_MEMBER', 'u_', $next_order_id)";
  1220. _sql($sql, $errored, $error_ary);
  1221. $u_role = $db->sql_nextid();
  1222. if (!$errored)
  1223. {
  1224. // Now add the correct data to the roles...
  1225. // The standard role says that new users are not able to send a PM, Mass PM, are not able to PM groups
  1226. $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $u_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'u_%' AND auth_option IN ('u_sendpm', 'u_masspm', 'u_masspm_group')";
  1227. _sql($sql, $errored, $error_ary);
  1228. // Add user role to group
  1229. $sql = 'INSERT INTO ' . ACL_GROUPS_TABLE . " (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES ($group_id, 0, 0, $u_role, 0)";
  1230. _sql($sql, $errored, $error_ary);
  1231. }
  1232. }
  1233. // Insert new forum role
  1234. $sql = 'SELECT role_id
  1235. FROM ' . ACL_ROLES_TABLE . "
  1236. WHERE role_name = 'ROLE_FORUM_NEW_MEMBER'
  1237. AND role_type = 'f_'";
  1238. $result = $db->sql_query($sql);
  1239. $f_role = (int) $db->sql_fetchfield('role_id');
  1240. $db->sql_freeresult($result);
  1241. if (!$f_role)
  1242. {
  1243. $sql = 'SELECT MAX(role_order) as max_order_id
  1244. FROM ' . ACL_ROLES_TABLE . "
  1245. WHERE role_type = 'f_'";
  1246. $result = $db->sql_query($sql);
  1247. $next_order_id = (int) $db->sql_fetchfield('max_order_id');
  1248. $db->sql_freeresult($result);
  1249. $next_order_id++;
  1250. $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_FORUM_NEW_MEMBER', 'ROLE_DESCRIPTION_FORUM_NEW_MEMBER', 'f_', $next_order_id)";
  1251. _sql($sql, $errored, $error_ary);
  1252. $f_role = $db->sql_nextid();
  1253. if (!$errored)
  1254. {
  1255. $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $f_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'f_%' AND auth_option IN ('f_noapprove')";
  1256. _sql($sql, $errored, $error_ary);
  1257. }
  1258. }
  1259. // Set every members user_new column to 0 (old users) only if there is no one yet (this makes sure we do not execute this more than once)
  1260. $sql = 'SELECT 1
  1261. FROM ' . USERS_TABLE . '
  1262. WHERE user_new = 0';
  1263. $result = $db->sql_query_limit($sql, 1);
  1264. $row = $db->sql_fetchrow($result);
  1265. $db->sql_freeresult($result);
  1266. if (!$row)
  1267. {
  1268. $sql = 'UPDATE ' . USERS_TABLE . ' SET user_new = 0';
  1269. _sql($sql, $errored, $error_ary);
  1270. }
  1271. // Newly registered users limit
  1272. if (!isset($config['new_member_post_limit']))
  1273. {
  1274. set_config('new_member_post_limit', (!empty($config['enable_queue_trigger'])) ? $config['queue_trigger_posts'] : 0);
  1275. }
  1276. if (!isset($config['new_member_group_default']))
  1277. {
  1278. set_config('new_member_group_default', 0);
  1279. }
  1280. // To mimick the old "feature" we will assign the forum role to every forum, regardless of the setting (this makes sure there are no "this does not work!!!! YUO!!!" posts...
  1281. // Check if the role is already assigned...
  1282. $sql = 'SELECT forum_id
  1283. FROM ' . ACL_GROUPS_TABLE . '
  1284. WHERE group_id = ' . $group_id . '
  1285. AND auth_role_id = ' . $f_role;
  1286. $result = $db->sql_query($sql);
  1287. $is_options = (int) $db->sql_fetchfield('forum_id');
  1288. $db->sql_freeresult($result);
  1289. // Not assigned at all... :/
  1290. if (!$is_options)
  1291. {
  1292. // Get postable forums
  1293. $sql = 'SELECT forum_id
  1294. FROM ' . FORUMS_TABLE . '
  1295. WHERE forum_type != ' . FORUM_LINK;
  1296. $result = $db->sql_query($sql);
  1297. while ($row = $db->sql_fetchrow($result))
  1298. {
  1299. _sql('INSERT INTO ' . ACL_GROUPS_TABLE . ' (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (' . $group_id . ', ' . (int) $row['forum_id'] . ', 0, ' . $f_role . ', 0)', $errored, $error_ary);
  1300. }
  1301. $db->sql_freeresult($result);
  1302. }
  1303. // Clear permissions...
  1304. include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
  1305. $auth_admin = new auth_admin();
  1306. $auth_admin->acl_clear_prefetch();
  1307. if (!isset($config['allow_avatar']))
  1308. {
  1309. if ($config['allow_avatar_upload'] || $config['allow_avatar_local'] || $config['allow_avatar_remote'])
  1310. {
  1311. set_config('allow_avatar', '1');
  1312. }
  1313. else
  1314. {
  1315. set_config('allow_avatar', '0');
  1316. }
  1317. }
  1318. if (!isset($config['allow_avatar_remote_upload']))
  1319. {
  1320. if ($config['allow_avatar_remote'] && $config['allow_avatar_upload'])
  1321. {
  1322. set_config('allow_avatar_remote_upload', '1');
  1323. }
  1324. else
  1325. {
  1326. set_config('allow_avatar_remote_upload', '0');
  1327. }
  1328. }
  1329. // Minimum number of characters
  1330. if (!isset($config['min_post_chars']))
  1331. {
  1332. set_config('min_post_chars', '1');
  1333. }
  1334. if (!isset($config['allow_quick_reply']))
  1335. {
  1336. set_config('allow_quick_reply', '1');
  1337. }
  1338. // Set every members user_options column to enable
  1339. // bbcode, smilies and URLs for signatures by default
  1340. $sql = 'SELECT user_options
  1341. FROM ' . USERS_TABLE . '
  1342. WHERE user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')';
  1343. $result = $db->sql_query_limit($sql, 1);
  1344. $user_option = (int) $db->sql_fetchfield('user_options');
  1345. $db->sql_freeresult($result);
  1346. // Check if we already updated the database by checking bit 15 which we used to store the sig_bbcode option
  1347. if (!($user_option & 1 << 15))
  1348. {
  1349. // 229376 is the added value to enable all three signature options
  1350. $sql = 'UPDATE ' . USERS_TABLE . ' SET user_options = user_options + 229376';
  1351. _sql($sql, $errored, $error_ary);
  1352. }
  1353. if (!isset($config['delete_time']))
  1354. {
  1355. set_config('delete_time', $config['edit_time']);
  1356. }
  1357. $no_updates = false;
  1358. break;
  1359. // No changes from 3.0.6-RC1 to 3.0.6-RC2
  1360. case '3.0.6-RC1':
  1361. break;
  1362. // Changes from 3.0.6-RC2 to 3.0.6-RC3
  1363. case '3.0.6-RC2':
  1364. // Update the Custom Profile Fields based on previous settings to the new format
  1365. $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . '
  1366. SET field_show_on_vt = 1
  1367. WHERE field_hide = 0
  1368. AND (field_required = 1 OR field_show_on_reg = 1 OR field_show_profile = 1)';
  1369. _sql($sql, $errored, $error_ary);
  1370. $no_updates = false;
  1371. break;
  1372. // No changes from 3.0.6-RC3 to 3.0.6-RC4
  1373. case '3.0.6-RC3':
  1374. break;
  1375. // No changes from 3.0.6-RC4 to 3.0.6
  1376. case '3.0.6-RC4':
  1377. break;
  1378. // Changes from 3.0.6 to 3.0.7-RC1
  1379. case '3.0.6':
  1380. // ATOM Feeds
  1381. set_config('feed_overall', '1');
  1382. set_config('feed_http_auth', '0');
  1383. set_config('feed_limit_post', (string) (isset($config['feed_limit']) ? (int) $config['feed_limit'] : 15));
  1384. set_config('feed_limit_topic', (string) (isset($config['feed_overall_topics_limit']) ? (int) $config['feed_overall_topics_limit'] : 10));
  1385. set_config('feed_topics_new', (!empty($config['feed_overall_topics']) ? '1' : '0'));
  1386. set_config('feed_topics_active', (!empty($config['feed_overall_topics']) ? '1' : '0'));
  1387. // Delete all text-templates from the template_data
  1388. $sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . '
  1389. WHERE template_filename ' . $db->sql_like_expression($db->any_char . '.txt');
  1390. _sql($sql, $errored, $error_ary);
  1391. $no_updates = false;
  1392. break;
  1393. // Changes from 3.0.7-RC1 to 3.0.7-RC2
  1394. case '3.0.7-RC1':
  1395. $sql = 'SELECT user_id, user_email, user_email_hash
  1396. FROM ' . USERS_TABLE . '
  1397. WHERE user_type <> ' . USER_IGNORE . "
  1398. AND user_email <> ''";
  1399. $result = $db->sql_query($sql);
  1400. $i = 0;
  1401. while ($row = $db->sql_fetchrow($res