From 10f6716566fce9d9c38f3dd99419595b2a1cba4c Mon Sep 17 00:00:00 2001 From: Mate Bartus Date: Tue, 30 Jun 2015 16:36:34 +0200 Subject: [ticket/13740] Restore original install folder This reverts commit 934e2821f1cef5e2e21ad6d96f7beb45647ed81c. PHPBB3-13740 --- phpBB/install/database_update.php | 267 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 267 insertions(+) create mode 100644 phpBB/install/database_update.php (limited to 'phpBB/install/database_update.php') diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php new file mode 100644 index 0000000000..7ba11c37c4 --- /dev/null +++ b/phpBB/install/database_update.php @@ -0,0 +1,267 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +$update_start_time = time(); + +/** +* @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); + +?> +

+ + + + + + + + + + + + +register(); + +$phpbb_config_php_file = new \phpbb\config_php_file($phpbb_root_path, $phpEx); +extract($phpbb_config_php_file->get_all()); + +if (!defined('PHPBB_INSTALLED') || empty($dbms) || empty($acm_type)) +{ + die("Please read: INSTALL.html 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 . 'includes/functions.' . $phpEx); +require($phpbb_root_path . 'includes/functions_content.' . $phpEx); + +require($phpbb_root_path . 'includes/constants.' . $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'); + +// Set up container (must be done here because extensions table may not exist) +$phpbb_container_builder = new \phpbb\di\container_builder($phpbb_root_path, $phpEx); +$phpbb_container = $phpbb_container_builder + ->with_config($phpbb_config_php_file) + ->without_extensions() + ->without_cache() + ->get_container() +; + +// set up caching +/* @var $cache \phpbb\cache\service */ +$cache = $phpbb_container->get('cache'); + +// Instantiate some basic classes +/* @var $phpbb_dispatcher \phpbb\event\dispatcher */ +$phpbb_dispatcher = $phpbb_container->get('dispatcher'); + +/* @var $request \phpbb\request\request_interface */ +$request = $phpbb_container->get('request'); + +/* @var $user \phpbb\user */ +$user = $phpbb_container->get('user'); + +/* @var $auth \phpbb\auth\auth */ +$auth = $phpbb_container->get('auth'); + +/* @var $db \phpbb\db\driver\driver_interface */ +$db = $phpbb_container->get('dbal.conn'); + +/* @var $phpbb_log \phpbb\log\log_interface */ +$phpbb_log = $phpbb_container->get('log'); + +// Grab global variables, re-cache if necessary +/* @var $config \phpbb\config\config */ +$config = $phpbb_container->get('config'); + +if (!isset($config['version_update_from'])) +{ + $config->set('version_update_from', $config['version']); +} + +$orig_version = $config['version_update_from']; + +$user->add_lang(array('common', 'acp/common', 'old_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'))); + + /* @var $phpbb_hook_finder \phpbb\hook\finder */ + $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'); +?> + + + + + +<?php echo $user->lang['UPDATING_TO_LATEST_STABLE']; ?> + + + + + + +
+ + +
+
+
+ +
+
+ +

lang['UPDATING_TO_LATEST_STABLE']; ?>

+ +
+ +

lang['DATABASE_TYPE']; ?> :: get_sql_layer(); ?>
+ lang['PREVIOUS_VERSION']; ?> ::
+ +get('migrator'); + +/** @var \phpbb\filesystem\filesystem_interface $phpbb_filesystem */ +$phpbb_filesystem = $phpbb_container->get('filesystem'); +$migrator->set_output_handler(new \phpbb\db\log_wrapper_migrator_output_handler($user, new \phpbb\db\html_migrator_output_handler($user), $phpbb_root_path . 'store/migrations_' . time() . '.log', $phpbb_filesystem)); + +$migrator->create_migrations_table(); + +/* @var $phpbb_extension_manager \phpbb\extension\manager */ +$phpbb_extension_manager = $phpbb_container->get('ext.manager'); + +$migrations = $phpbb_extension_manager + ->get_finder() + ->core_path('phpbb/db/migration/data/') + ->extension_directory('/migrations') + ->get_classes(); + +$migrator->set_migrations($migrations); + +// What is a safe limit of execution time? Half the max execution time should be safe. +// No more than 15 seconds so the user isn't sitting and waiting for a very long time +$phpbb_ini = new \phpbb\php\ini(); +$safe_time_limit = min(15, ($phpbb_ini->get_int('max_execution_time') / 2)); + +// While we're going to try limit this to half the max execution time, +// we want to try and take additional measures to prevent hitting the +// max execution time (if, say, one migration step takes much longer +// than the max execution time) +@set_time_limit(0); + +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'] + ); + + // 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 '
' . $user->lang['DATABASE_UPDATE_NOT_COMPLETED'] . '

'; + echo '' . $user->lang['DATABASE_UPDATE_CONTINUE'] . ''; + + phpbb_end_update($cache, $config); + } +} + +if ($orig_version != $config['version']) +{ + $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_UPDATE_DATABASE', false, array($orig_version, $config['version'])); +} + +echo $user->lang['DATABASE_UPDATE_COMPLETE'] . '
'; + +if ($request->variable('type', 0)) +{ + echo $user->lang['INLINE_UPDATE_SUCCESSFUL'] . '

'; + echo '' . $user->lang['CONTINUE_UPDATE_NOW'] . ''; +} +else +{ + echo '

' . $user->lang['UPDATE_FILES_NOTICE'] . '
'; + echo $user->lang['COMPLETE_LOGIN_TO_BOARD']; +} + +$config->delete('version_update_from'); + +phpbb_end_update($cache, $config); -- cgit v1.2.1