diff options
42 files changed, 1185 insertions, 369 deletions
diff --git a/phpBB/adm/style/installer_footer.html b/phpBB/adm/style/installer_footer.html index 63aebec993..fefa8f6d3f 100644 --- a/phpBB/adm/style/installer_footer.html +++ b/phpBB/adm/style/installer_footer.html @@ -11,6 +11,15 @@  	</div>  </div> +<script type="text/javascript"> +<!-- +installLang = { +	title: '{LA_TIMEOUT_DETECTED_TITLE}', +	msg: '{LA_TIMEOUT_DETECTED_MESSAGE}' +}; +//--> +</script> +  <script type="text/javascript" src="{T_JQUERY_LINK}"></script>  <!-- IF S_ALLOW_CDN --><script type="text/javascript">window.jQuery || document.write('\x3Cscript src="{T_ASSETS_PATH}/javascript/jquery.min.js">\x3C/script>');</script><!-- ENDIF -->  <script type="text/javascript" src="{T_ASSETS_PATH}/javascript/core.js?assets_version={T_ASSETS_VERSION}"></script> diff --git a/phpBB/assets/javascript/installer.js b/phpBB/assets/javascript/installer.js index 4a4f381844..d9f446a28d 100644 --- a/phpBB/assets/javascript/installer.js +++ b/phpBB/assets/javascript/installer.js @@ -12,6 +12,7 @@  	var progressTimer = null;  	var currentProgress = 0;  	var refreshRequested = false; +	var transmissionOver = false;  	// Template related variables  	var $contentWrapper = $('.install-body').find('.main'); @@ -329,6 +330,12 @@  		if (responseObject.hasOwnProperty('redirect')) {  			redirect(responseObject.redirect.url, responseObject.redirect.use_ajax);  		} + +		if (responseObject.hasOwnProperty('over')) { +			if (responseObject.over) { +				transmissionOver = true; +			} +		}  	}  	/** @@ -357,10 +364,21 @@  			$('#loading_indicator').css('display', 'none');  			resetPolling(); +			var timeoutDetected = !transmissionOver; +  			if (refreshRequested) {  				refreshRequested = false;  				doRefresh();  			} + +			if (timeoutDetected) { +				addMessage('error', +					[{ +						title: installLang.title, +						description: installLang.msg +					}] +				); +			}  		}  	} @@ -420,6 +438,7 @@  	 */  	function startPolling(xhReq) {  		resetPolling(); +		transmissionOver = false;  		pollTimer = setInterval(function () {  			pollContent(xhReq);  		}, 250); diff --git a/phpBB/config/installer/container/services_install_controller.yml b/phpBB/config/installer/container/services_install_controller.yml index 5688c61db9..394eb95c06 100644 --- a/phpBB/config/installer/container/services_install_controller.yml +++ b/phpBB/config/installer/container/services_install_controller.yml @@ -53,6 +53,7 @@ services:      phpbb.installer.controller.convert:          class: phpbb\convert\controller\convertor          arguments: +            - '@cache.driver'              - '@installer.helper.container_factory'              - '@installer.helper.database'              - '@phpbb.installer.controller.helper' diff --git a/phpBB/config/installer/container/services_install_data.yml b/phpBB/config/installer/container/services_install_data.yml index d119ba6ebb..df63d16d0d 100644 --- a/phpBB/config/installer/container/services_install_data.yml +++ b/phpBB/config/installer/container/services_install_data.yml @@ -23,6 +23,7 @@ services:      installer.install_data.add_modules:          class: phpbb\install\module\install_data\task\add_modules          arguments: +            - '@installer.helper.config'              - '@installer.helper.iohandler'              - '@installer.helper.container_factory'          tags: diff --git a/phpBB/config/installer/container/services_install_database.yml b/phpBB/config/installer/container/services_install_database.yml index 8324cd6086..33f596506d 100644 --- a/phpBB/config/installer/container/services_install_database.yml +++ b/phpBB/config/installer/container/services_install_database.yml @@ -1,16 +1,36 @@  services: -    installer.install_database.create_schema: -        class: phpbb\install\module\install_database\task\create_schema +    installer.install_database.create_schema_file: +        class: phpbb\install\module\install_database\task\create_schema_file          arguments:              - '@installer.helper.config'              - '@installer.helper.database'              - '@filesystem' -            - '@installer.helper.iohandler'              - '%core.root_path%'              - '%core.php_ext%'          tags:              - { name: install_database_install, order: 10 } +    installer.install_database.set_up_database: +        class: phpbb\install\module\install_database\task\set_up_database +        arguments: +            - '@installer.helper.config' +            - '@installer.helper.database' +            - '@filesystem' +            - '@installer.helper.iohandler' +            - '%core.root_path%' +        tags: +            - { name: install_database_install, order: 20 } + +    installer.install_database.add_tables: +        class: phpbb\install\module\install_database\task\add_tables +        arguments: +            - '@installer.helper.config' +            - '@installer.helper.database' +            - '@filesystem' +            - '%core.root_path%' +        tags: +            - { name: install_database_install, order: 30 } +      installer.install_database.add_default_data:          class: phpbb\install\module\install_database\task\add_default_data          arguments: @@ -21,7 +41,7 @@ services:              - '@language'              - '%core.root_path%'          tags: -            - { name: install_database_install, order: 20 } +            - { name: install_database_install, order: 40 }      installer.install_database.add_config_settings:          class: phpbb\install\module\install_database\task\add_config_settings @@ -33,7 +53,7 @@ services:              - '@language'              - '%core.root_path%'          tags: -            - { name: install_database_install, order: 30 } +            - { name: install_database_install, order: 50 }      installer.module.install_database_collection:          class: phpbb\di\ordered_service_collection diff --git a/phpBB/config/installer/container/services_install_finish.yml b/phpBB/config/installer/container/services_install_finish.yml index 854b129b69..f144cc6317 100644 --- a/phpBB/config/installer/container/services_install_finish.yml +++ b/phpBB/config/installer/container/services_install_finish.yml @@ -2,6 +2,7 @@ services:      installer.install_finish.populate_migrations:          class: phpbb\install\module\install_finish\task\populate_migrations          arguments: +            - '@installer.helper.config'              - '@installer.helper.container_factory'          tags:              - { name: install_finish, order: 10 } diff --git a/phpBB/config/installer/container/services_installer.yml b/phpBB/config/installer/container/services_installer.yml index bf9d28ec65..19b1b4f08e 100644 --- a/phpBB/config/installer/container/services_installer.yml +++ b/phpBB/config/installer/container/services_installer.yml @@ -89,6 +89,7 @@ services:              - '@cache.driver'              - '@installer.helper.config'              - '@path_helper' +            - '@installer.helper.container_factory'      installer.install.module_collection:          class: phpbb\di\ordered_service_collection @@ -108,8 +109,10 @@ services:          parent: installer.installer.abstract          calls:              - [set_modules, ['@installer.install.module_collection']] +            - [set_purge_cache_before, [false]]      installer.installer.update:          parent: installer.installer.abstract          calls:              - [set_modules, ['@installer.update.module_collection']] +            - [set_purge_cache_before, [true]] diff --git a/phpBB/install/convert/controller/convertor.php b/phpBB/install/convert/controller/convertor.php index a36494c7e6..a40f1d0b52 100644 --- a/phpBB/install/convert/controller/convertor.php +++ b/phpBB/install/convert/controller/convertor.php @@ -13,6 +13,7 @@  namespace phpbb\convert\controller; +use phpbb\cache\driver\driver_interface;  use phpbb\exception\http_exception;  use phpbb\install\controller\helper;  use phpbb\install\helper\container_factory; @@ -36,11 +37,16 @@ use Symfony\Component\HttpFoundation\StreamedResponse;  class convertor  {  	/** -	 * @var \phpbb\cache\driver\driver_interface +	 * @var driver_interface  	 */  	protected $cache;  	/** +	 * @var driver_interface +	 */ +	protected $installer_cache; + +	/**  	 * @var \phpbb\config\db  	 */  	protected $config; @@ -123,6 +129,7 @@ class convertor  	/**  	 * Constructor  	 * +	 * @param driver_interface		$cache  	 * @param container_factory		$container  	 * @param database				$db_helper  	 * @param helper				$controller_helper @@ -135,8 +142,9 @@ class convertor  	 * @param string				$phpbb_root_path  	 * @param string				$php_ext  	 */ -	public function __construct(container_factory $container, database $db_helper, helper $controller_helper, install_helper $install_helper, factory $iohandler, language $language, navigation_provider $nav, request_interface $request, template $template, $phpbb_root_path, $php_ext) +	public function __construct(driver_interface $cache, container_factory $container, database $db_helper, helper $controller_helper, install_helper $install_helper, factory $iohandler, language $language, navigation_provider $nav, request_interface $request, template $template, $phpbb_root_path, $php_ext)  	{ +		$this->installer_cache		= $cache;  		$this->controller_helper	= $controller_helper;  		$this->db_helper			= $db_helper;  		$this->install_helper		= $install_helper; @@ -379,6 +387,7 @@ class convertor  		// If we reached this step (conversion completed) we want to purge the cache and log the user out.  		// This is for making sure the session get not screwed due to the 3.0.x users table being completely new.  		$this->cache->purge(); +		$this->installer_cache->purge();  		require_once($this->phpbb_root_path . 'includes/constants.' . $this->php_ext);  		require_once($this->phpbb_root_path . 'includes/functions_convert.' . $this->php_ext); @@ -583,7 +592,7 @@ class convertor  			$url = $this->controller_helper->route('phpbb_convert_convert', array('converter' => $convertor));  			$this->iohandler->redirect($url); -			$this->iohandler->send_response(); +			$this->iohandler->send_response(true);  		}  		else  		{ @@ -677,7 +686,7 @@ class convertor  		if ($this->request->is_ajax())  		{  			$this->iohandler->add_user_form_group($form_title, $form_data); -			$this->iohandler->send_response(); +			$this->iohandler->send_response(true);  		}  		else  		{ @@ -770,7 +779,7 @@ class convertor  		if ($this->request->is_ajax())  		{  			$this->iohandler->add_error_message($msg, $desc); -			$this->iohandler->send_response(); +			$this->iohandler->send_response(true);  		}  		else  		{ @@ -794,7 +803,7 @@ class convertor  	public function redirect_to_html($url)  	{  		$this->iohandler->redirect($url); -		$this->iohandler->send_response(); +		$this->iohandler->send_response(true);  	}  	private function setup_navigation($stage) diff --git a/phpBB/language/en/install.php b/phpBB/language/en/install.php index e643dd06c1..31578824ef 100644 --- a/phpBB/language/en/install.php +++ b/phpBB/language/en/install.php @@ -120,7 +120,11 @@ $lang = array_merge($lang, array(  // General error messages  $lang = array_merge($lang, array(  	'INST_ERR_MISSING_DATA'		=> 'You must fill out all fields in this block.', -	'PHPBB_ALREADY_INSTALLED'	=> 'phpBB is already installed.' + +	'PHPBB_ALREADY_INSTALLED'	=> 'phpBB is already installed.', + +	'TIMEOUT_DETECTED_TITLE'	=> 'The installer detected a timeout', +	'TIMEOUT_DETECTED_MESSAGE'	=> 'The installer has detected a timeout, you may try to refresh the page, which may lead to data corruption. We suggest that you either increase your timeout settings or try to use the CLI.',  ));  // Data obtaining translations @@ -200,6 +204,7 @@ $lang = array_merge($lang, array(  	'INST_ERR_DB_NO_SQLITE3'		=> 'The version of the SQLite extension you have installed is too old, it must be upgraded to at least 3.6.15.',  	'INST_ERR_DB_NO_ORACLE'			=> 'The version of Oracle installed on this machine requires you to set the <var>NLS_CHARACTERSET</var> parameter to <var>UTF8</var>. Either upgrade your installation to 9.2+ or change the parameter.',  	'INST_ERR_DB_NO_POSTGRES'		=> 'The database you have selected was not created in <var>UNICODE</var> or <var>UTF8</var> encoding. Try installing with a database in <var>UNICODE</var> or <var>UTF8</var> encoding.', +	'INST_SCHEMA_FILE_NOT_WRITABLE'	=> 'The schema file is not writable',  	//  	// Email data @@ -275,9 +280,11 @@ $lang = array_merge($lang, array(  	'TASK_CREATE_CONFIG_FILE'	=> 'Creating configuration file',  	// Install database -	'TASK_ADD_CONFIG_SETTINGS'		=> 'Adding configuration settings', -	'TASK_ADD_DEFAULT_DATA'			=> 'Adding default settings to the database', -	'TASK_CREATE_DATABASE_SCHEMA'	=> 'Creating database schema', +	'TASK_ADD_CONFIG_SETTINGS'			=> 'Adding configuration settings', +	'TASK_ADD_DEFAULT_DATA'				=> 'Adding default settings to the database', +	'TASK_CREATE_DATABASE_SCHEMA_FILE'	=> 'Creating database schema file', +	'TASK_SETUP_DATABASE'				=> 'Setting up database', +	'TASK_CREATE_TABLES'				=> 'Creating tables',  	// Install data  	'TASK_ADD_BOTS'			=> 'Registering bots', diff --git a/phpBB/phpbb/install/helper/config.php b/phpBB/phpbb/install/helper/config.php index f58925899b..fad6749019 100644 --- a/phpBB/phpbb/install/helper/config.php +++ b/phpBB/phpbb/install/helper/config.php @@ -96,7 +96,8 @@ class config  		$this->system_data		= array();  		$this->progress_data	= array(  			'last_task_module_name'		=> '', // Stores the service name of the latest finished module -			'last_task_name'			=> '', // Stores the service name of the latest finished task +			'last_task_module_index'	=> 0, // Stores the index of the latest finished module +			'last_task_index'			=> 0, // Stores the index of the latest finished task  			'max_task_progress'			=> 0,  			'current_task_progress'		=> 0,  			'_restart_points'			=> array(), @@ -187,21 +188,23 @@ class config  	/**  	 * Saves the latest executed task  	 * -	 * @param string	$task_service_name	Name of the installer task service +	 * @param int	$task_service_index	Index of the installer task service in the module  	 */ -	public function set_finished_task($task_service_name) +	public function set_finished_task($task_service_index)  	{ -		$this->progress_data['last_task_name']	= $task_service_name; +		$this->progress_data['last_task_index']	= $task_service_index;  	}  	/**  	 * Set active module  	 *  	 * @param string	$module_service_name	Name of the installer module service +	 * @param int		$module_service_index	Index of the installer module service  	 */ -	public function set_active_module($module_service_name) +	public function set_active_module($module_service_name, $module_service_index)  	{  		$this->progress_data['last_task_module_name']	= $module_service_name; +		$this->progress_data['last_task_module_index']	= $module_service_index;  	}  	/** @@ -391,6 +394,11 @@ class config  	 */  	public function set_finished_navigation_stage($nav_path)  	{ +		if (isset($this->navigation_data['finished']) && in_array($nav_path, $this->navigation_data['finished'])) +		{ +			return; +		} +  		$this->navigation_data['finished'][] = $nav_path;  	} diff --git a/phpBB/phpbb/install/helper/container_factory.php b/phpBB/phpbb/install/helper/container_factory.php index 6c1ecd2d02..5cf4f8a283 100644 --- a/phpBB/phpbb/install/helper/container_factory.php +++ b/phpBB/phpbb/install/helper/container_factory.php @@ -13,7 +13,6 @@  namespace phpbb\install\helper; -use phpbb\cache\driver\dummy;  use phpbb\install\exception\cannot_build_container_exception;  use phpbb\language\language;  use phpbb\request\request; @@ -157,25 +156,20 @@ class container_factory  			->with_environment('production')  			->with_config($phpbb_config_php_file)  			->with_config_path($config_path) -			->without_cache()  			->without_compiled_container()  			->get_container();  		// Setting request is required for the compatibility globals as those are generated from  		// this container -		$this->container->register('request')->setSynthetic(true); -		$this->container->set('request', $this->request); - -		$this->container->register('language')->setSynthetic(true); -		$this->container->set('language', $this->language); - -		// Replace cache service, as config gets cached, and we don't want that when we are installing -		if (!is_dir($other_config_path)) +		if (!$this->container->isFrozen())  		{ -			$this->container->register('cache.driver')->setSynthetic(true); -			$this->container->set('cache.driver', new dummy()); +			$this->container->register('request')->setSynthetic(true); +			$this->container->register('language')->setSynthetic(true);  		} +		$this->container->set('request', $this->request); +		$this->container->set('language', $this->language); +  		$this->container->compile();  		$phpbb_container = $this->container; diff --git a/phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php b/phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php index 31474ae4e9..8c62ec7bd0 100644 --- a/phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php +++ b/phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php @@ -209,9 +209,15 @@ class ajax_iohandler extends iohandler_base  	/**  	 * {@inheritdoc}  	 */ -	public function send_response() +	public function send_response($no_more_output = false)  	{ -		$json_data_array = $this->prepare_json_array(); +		$json_data_array = $this->prepare_json_array($no_more_output); + +		if (empty($json_data_array)) +		{ +			return; +		} +  		$json_data = json_encode($json_data_array);  		// Try to push content to the browser @@ -223,23 +229,43 @@ class ajax_iohandler extends iohandler_base  	/**  	 * Prepares iohandler's data to be sent out to the client.  	 * +	 * @param bool	$no_more_output	Whether or not there will be more output in this response +	 *  	 * @return array  	 */ -	protected function prepare_json_array() +	protected function prepare_json_array($no_more_output = false)  	{ -		$json_array = array( -			'errors' => $this->errors, -			'warnings' => $this->warnings, -			'logs' => $this->logs, -			'success' => $this->success, -			'download' => $this->download, -		); +		$json_array = array(); + +		if (!empty($this->errors)) +		{ +			$json_array['errors'] = $this->errors; +			$this->errors = array(); +		} + +		if (!empty($this->warnings)) +		{ +			$json_array['warnings'] = $this->warnings; +			$this->warnings = array(); +		} -		$this->errors = array(); -		$this->warnings = array(); -		$this->logs = array(); -		$this->success = array(); -		$this->download = array(); +		if (!empty($this->logs)) +		{ +			$json_array['logs'] = $this->logs; +			$this->logs = array(); +		} + +		if (!empty($this->success)) +		{ +			$json_array['success'] = $this->success; +			$this->success = array(); +		} + +		if (!empty($this->download)) +		{ +			$json_array['download'] = $this->download; +			$this->download = array(); +		}  		if (!empty($this->form))  		{ @@ -293,6 +319,11 @@ class ajax_iohandler extends iohandler_base  			$this->redirect_url = array();  		} +		if ($no_more_output) +		{ +			$json_array['over'] = true; +		} +  		return $json_array;  	} @@ -398,7 +429,7 @@ class ajax_iohandler extends iohandler_base  	public function redirect($url, $use_ajax = false)  	{  		$this->redirect_url = array('url' => $url, 'use_ajax' => $use_ajax); -		$this->send_response(); +		$this->send_response(true);  	}  	/** diff --git a/phpBB/phpbb/install/helper/iohandler/cli_iohandler.php b/phpBB/phpbb/install/helper/iohandler/cli_iohandler.php index 7945904524..94550d2db0 100644 --- a/phpBB/phpbb/install/helper/iohandler/cli_iohandler.php +++ b/phpBB/phpbb/install/helper/iohandler/cli_iohandler.php @@ -114,7 +114,7 @@ class cli_iohandler extends iohandler_base  	/**  	 * {@inheritdoc}  	 */ -	public function send_response() +	public function send_response($no_more_output = false)  	{  	} diff --git a/phpBB/phpbb/install/helper/iohandler/iohandler_interface.php b/phpBB/phpbb/install/helper/iohandler/iohandler_interface.php index 6b3839506f..f22f33d9cb 100644 --- a/phpBB/phpbb/install/helper/iohandler/iohandler_interface.php +++ b/phpBB/phpbb/install/helper/iohandler/iohandler_interface.php @@ -20,8 +20,10 @@ interface iohandler_interface  {  	/**  	 * Renders or returns response message +	 * +	 * @param bool	$no_more_output	Whether or not there will be more output in this output unit  	 */ -	public function send_response(); +	public function send_response($no_more_output = false);  	/**  	 * Returns input variable diff --git a/phpBB/phpbb/install/installer.php b/phpBB/phpbb/install/installer.php index a41b4cd6a6..b5709e96c7 100644 --- a/phpBB/phpbb/install/installer.php +++ b/phpBB/phpbb/install/installer.php @@ -15,11 +15,13 @@ namespace phpbb\install;  use phpbb\cache\driver\driver_interface;  use phpbb\di\ordered_service_collection; +use phpbb\install\exception\cannot_build_container_exception;  use phpbb\install\exception\installer_config_not_writable_exception;  use phpbb\install\exception\jump_to_restart_point_exception;  use phpbb\install\exception\resource_limit_reached_exception;  use phpbb\install\exception\user_interaction_required_exception;  use phpbb\install\helper\config; +use phpbb\install\helper\container_factory;  use phpbb\install\helper\iohandler\cli_iohandler;  use phpbb\install\helper\iohandler\iohandler_interface;  use phpbb\path_helper; @@ -32,12 +34,17 @@ class installer  	protected $cache;  	/** +	 * @var container_factory +	 */ +	protected $container_factory; + +	/**  	 * @var config  	 */  	protected $install_config;  	/** -	 * @var array +	 * @var ordered_service_collection  	 */  	protected $installer_modules; @@ -59,18 +66,26 @@ class installer  	protected $module_step_count;  	/** +	 * @var bool +	 */ +	protected $purge_cache_before; + +	/**  	 * Constructor  	 *  	 * @param driver_interface	$cache			Cache service  	 * @param config			$config			Installer config handler  	 * @param path_helper		$path_helper	Path helper +	 * @param container_factory	$container		Container  	 */ -	public function __construct(driver_interface $cache, config $config, path_helper $path_helper) +	public function __construct(driver_interface $cache, config $config, path_helper $path_helper, container_factory $container)  	{  		$this->cache				= $cache;  		$this->install_config		= $config; +		$this->container_factory	= $container;  		$this->installer_modules	= null;  		$this->web_root				= $path_helper->get_web_root_path(); +		$this->purge_cache_before	= false;  	}  	/** @@ -97,6 +112,16 @@ class installer  	}  	/** +	 * Sets whether to purge cache before the installation process +	 * +	 * @param bool	$purge_cache_before +	 */ +	public function set_purge_cache_before($purge_cache_before) +	{ +		$this->purge_cache_before = $purge_cache_before; +	} + +	/**  	 * Run phpBB installer  	 */  	public function run() @@ -104,9 +129,16 @@ class installer  		// Load install progress  		$this->install_config->load_config(); +		if (!$this->install_config->get('cache_purged_before', false) && $this->purge_cache_before) +		{ +			/** @var \phpbb\cache\driver\driver_interface $cache */ +			$cache = $this->container_factory->get('cache.driver'); +			$cache->purge(); +			$this->install_config->set('cache_purged_before', true); +		} +  		// Recover install progress -		$module_name = $this->recover_progress(); -		$module_found = false; +		$module_index = $this->recover_progress();  		// Variable used to check if the install process have been finished  		$install_finished	= false; @@ -141,29 +173,13 @@ class installer  		try  		{ -			foreach ($this->installer_modules as $name => $module) -			{ -				// Skip forward until the current task is reached -				if (!$module_found) -				{ -					if ($module_name === $name || empty($module_name)) -					{ -						$module_found = true; -					} -					else -					{ -						continue; -					} -				} +			$iterator = $this->installer_modules->getIterator(); +			$iterator->seek($module_index); -				// Log progress -				$this->install_config->set_active_module($name); - -				// Run until there are available resources -				if ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0) -				{ -					throw new resource_limit_reached_exception(); -				} +			while ($iterator->valid()) +			{ +				$module	= $iterator->current(); +				$name	= $iterator->key();  				// Check if module should be executed  				if (!$module->is_essential() && !$module->check_requirements()) @@ -176,17 +192,31 @@ class installer  						$name,  					));  					$this->install_config->increment_current_task_progress($this->module_step_count[$name]); -					continue; +				} +				else +				{ +					// Set the correct stage in the navigation bar +					$this->install_config->set_active_navigation_stage($module->get_navigation_stage_path()); +					$this->iohandler->set_active_stage_menu($module->get_navigation_stage_path()); + +					$this->iohandler->send_response(); + +					$module->run(); + +					$this->install_config->set_finished_navigation_stage($module->get_navigation_stage_path()); +					$this->iohandler->set_finished_stage_menu($module->get_navigation_stage_path());  				} -				// Set the correct stage in the navigation bar -				$this->install_config->set_active_navigation_stage($module->get_navigation_stage_path()); -				$this->iohandler->set_active_stage_menu($module->get_navigation_stage_path()); +				$module_index++; +				$iterator->next(); -				$module->run(); +				// Save progress +				$this->install_config->set_active_module($name, $module_index); -				$this->install_config->set_finished_navigation_stage($module->get_navigation_stage_path()); -				$this->iohandler->set_finished_stage_menu($module->get_navigation_stage_path()); +				if ($iterator->valid() && ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0)) +				{ +					throw new resource_limit_reached_exception(); +				}  			}  			// Installation finished @@ -208,7 +238,7 @@ class installer  		}  		catch (user_interaction_required_exception $e)  		{ -			// Do nothing +			$this->iohandler->send_response(true);  		}  		catch (resource_limit_reached_exception $e)  		{ @@ -222,7 +252,7 @@ class installer  		catch (\Exception $e)  		{  			$this->iohandler->add_error_message($e->getMessage()); -			$this->iohandler->send_response(); +			$this->iohandler->send_response(true);  			$fail_cleanup = true;  		} @@ -230,11 +260,12 @@ class installer  		{  			// Send install finished message  			$this->iohandler->set_progress('INSTALLER_FINISHED', $this->install_config->get_task_progress_count()); +			$this->iohandler->send_response(true);  		}  		else if ($send_refresh)  		{  			$this->iohandler->request_refresh(); -			$this->iohandler->send_response(); +			$this->iohandler->send_response(true);  		}  		// Save install progress @@ -244,6 +275,17 @@ class installer  			{  				$this->install_config->clean_up_config_file();  				$this->cache->purge(); + +				try +				{ +					/** @var \phpbb\cache\driver\driver_interface $cache */ +					$cache = $this->container_factory->get('cache.driver'); +					$cache->purge(); +				} +				catch (cannot_build_container_exception $e) +				{ +					// Do not do anything, this just means there is no config.php yet +				}  			}  			else  			{ @@ -270,6 +312,6 @@ class installer  	protected function recover_progress()  	{  		$progress_array = $this->install_config->get_progress_data(); -		return $progress_array['last_task_module_name']; +		return $progress_array['last_task_module_index'];  	}  } diff --git a/phpBB/phpbb/install/module/install_data/task/add_bots.php b/phpBB/phpbb/install/module/install_data/task/add_bots.php index 2ee641ff63..d45a6839a0 100644 --- a/phpBB/phpbb/install/module/install_data/task/add_bots.php +++ b/phpBB/phpbb/install/module/install_data/task/add_bots.php @@ -13,6 +13,8 @@  namespace phpbb\install\module\install_data\task; +use phpbb\install\exception\resource_limit_reached_exception; +  class add_bots extends \phpbb\install\task_base  {  	/** @@ -179,7 +181,10 @@ class add_bots extends \phpbb\install\task_base  			$this->io_handler->add_error_message('NO_GROUP');  		} -		foreach ($this->bot_list as $bot_name => $bot_ary) +		$i = $this->install_config->get('add_bot_index', 0); +		$bot_list = array_slice($this->bot_list, $i); + +		foreach ($bot_list as $bot_name => $bot_ary)  		{  			$user_row = array(  				'user_type'				=> USER_IGNORE, @@ -221,6 +226,21 @@ class add_bots extends \phpbb\install\task_base  			));  			$this->db->sql_query($sql); + +			$i++; + +			// Stop execution if resource limit is reached +			if ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0) +			{ +				break; +			} +		} + +		$this->install_config->set('add_bot_index', $i); + +		if ($i < sizeof($this->bot_list)) +		{ +			throw new resource_limit_reached_exception();  		}  	} diff --git a/phpBB/phpbb/install/module/install_data/task/add_modules.php b/phpBB/phpbb/install/module/install_data/task/add_modules.php index bfbe6282bc..d21a5be823 100644 --- a/phpBB/phpbb/install/module/install_data/task/add_modules.php +++ b/phpBB/phpbb/install/module/install_data/task/add_modules.php @@ -13,9 +13,19 @@  namespace phpbb\install\module\install_data\task; +use phpbb\install\exception\resource_limit_reached_exception; +use phpbb\install\helper\config; +use phpbb\install\helper\container_factory; +use phpbb\install\helper\iohandler\iohandler_interface; +  class add_modules extends \phpbb\install\task_base  {  	/** +	 * @var config +	 */ +	protected $config; + +	/**  	 * @var \phpbb\db\driver\driver_interface  	 */  	protected $db; @@ -136,12 +146,13 @@ class add_modules extends \phpbb\install\task_base  	/**  	 * Constructor  	 * -	 * @param \phpbb\install\helper\iohandler\iohandler_interface	$iohandler	Installer's input-output handler -	 * @param \phpbb\install\helper\container_factory				$container	Installer's DI container +	 * @parma config				$config		Installer's config +	 * @param iohandler_interface	$iohandler	Installer's input-output handler +	 * @param container_factory		$container	Installer's DI container  	 */ -	public function __construct(\phpbb\install\helper\iohandler\iohandler_interface $iohandler, -								\phpbb\install\helper\container_factory $container) +	public function __construct(config $config, iohandler_interface $iohandler, container_factory $container)  	{ +		$this->config				= $config;  		$this->db					= $container->get('dbal.conn');  		$this->extension_manager	= $container->get('ext.manager');  		$this->iohandler			= $iohandler; @@ -158,11 +169,19 @@ class add_modules extends \phpbb\install\task_base  		$this->db->sql_return_on_error(true);  		$module_classes = array('acp', 'mcp', 'ucp'); +		$total = sizeof($module_classes); +		$i = $this->config->get('module_class_index', 0); +		$module_classes = array_slice($module_classes, $i); +  		foreach ($module_classes as $module_class)  		{ -			$categories = array(); +			$categories = $this->config->get('module_categories_array', array()); + +			$k = $this->config->get('module_categories_index', 0); +			$module_categories = array_slice($this->module_categories[$module_class], $k); +			$timed_out = false; -			foreach ($this->module_categories[$module_class] as $cat_name => $subs) +			foreach ($module_categories as $cat_name => $subs)  			{  				// Check if this sub-category has a basename. If it has, use it.  				$basename = (isset($this->module_categories_basenames[$cat_name])) ? $this->module_categories_basenames[$cat_name] : ''; @@ -221,11 +240,31 @@ class add_modules extends \phpbb\install\task_base  						$categories[$level2_name]['parent_id'] = (int) $categories[$cat_name]['id'];  					}  				} + +				$k++; + +				// Stop execution if resource limit is reached +				if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0) +				{ +					$timed_out = true; +					break; +				} +			} + +			$this->config->set('module_categories_array', $categories); +			$this->config->set('module_categories_index', $k); + +			if ($timed_out) +			{ +				throw new resource_limit_reached_exception();  			}  			// Get the modules we want to add... returned sorted by name  			$module_info = $this->module_manager->get_module_infos($module_class); +			$k = $this->config->get('module_info_index', 0); +			$module_info = array_slice($module_info, $k); +  			foreach ($module_info as $module_basename => $fileinfo)  			{  				foreach ($fileinfo['modes'] as $module_mode => $row) @@ -258,189 +297,256 @@ class add_modules extends \phpbb\install\task_base  						}  					}  				} -			} -			// Move some of the modules around since the code above will put them in the wrong place -			if ($module_class === 'acp') -			{ -				// Move main module 4 up... -				$sql = 'SELECT * -					FROM ' . MODULES_TABLE . " -					WHERE module_basename = 'acp_main' -						AND module_class = 'acp' -						AND module_mode = 'main'"; -				$result = $this->db->sql_query($sql); -				$row = $this->db->sql_fetchrow($result); -				$this->db->sql_freeresult($result); +				$k++; -				$this->module_manager->move_module_by($row, 'acp', 'move_up', 4); - -				// Move permissions intro screen module 4 up... -				$sql = 'SELECT * -					FROM ' . MODULES_TABLE . " -					WHERE module_basename = 'acp_permissions' -						AND module_class = 'acp' -						AND module_mode = 'intro'"; -				$result = $this->db->sql_query($sql); -				$row = $this->db->sql_fetchrow($result); -				$this->db->sql_freeresult($result); +				// Stop execution if resource limit is reached +				if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0) +				{ +					$timed_out = true; +					break; +				} +			} -				$this->module_manager->move_module_by($row, 'acp', 'move_up', 4); +			$this->config->set('module_info_index', $k); -				// Move manage users screen module 5 up... -				$sql = 'SELECT * -					FROM ' . MODULES_TABLE . " -					WHERE module_basename = 'acp_users' -						AND module_class = 'acp' -						AND module_mode = 'overview'"; -				$result = $this->db->sql_query($sql); -				$row = $this->db->sql_fetchrow($result); -				$this->db->sql_freeresult($result); - -				$this->module_manager->move_module_by($row, 'acp', 'move_up', 5); +			// Stop execution if resource limit is reached +			if ($timed_out) +			{ +				throw new resource_limit_reached_exception(); +			} -				// Move extension management module 1 up... -				$sql = 'SELECT * -					FROM ' . MODULES_TABLE . " -					WHERE module_langname = 'ACP_EXTENSION_MANAGEMENT' -						AND module_class = 'acp' -						AND module_mode = '' -						AND module_basename = ''"; -				$result = $this->db->sql_query($sql); -				$row = $this->db->sql_fetchrow($result); -				$this->db->sql_freeresult($result); +			// Move some of the modules around since the code above will put them in the wrong place +			if (!$this->config->get('modules_ordered', false)) +			{ +				$this->order_modules($module_class); +				$this->config->set('modules_ordered', true); -				$this->module_manager->move_module_by($row, 'acp', 'move_up', 1); +				// Stop execution if resource limit is reached +				if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0) +				{ +					throw new resource_limit_reached_exception(); +				}  			} -			if ($module_class == 'mcp') +			// And now for the special ones +			// (these are modules which appear in multiple categories and thus get added manually +			// to some for more control) +			if (isset($this->module_extras[$module_class]))  			{ -				// Move pm report details module 3 down... -				$sql = 'SELECT * -					FROM ' . MODULES_TABLE . " -					WHERE module_basename = 'mcp_pm_reports' -						AND module_class = 'mcp' -						AND module_mode = 'pm_report_details'"; -				$result = $this->db->sql_query($sql); -				$row = $this->db->sql_fetchrow($result); -				$this->db->sql_freeresult($result); +				$this->add_module_extras($module_class); +			} -				$this->module_manager->move_module_by($row, 'mcp', 'move_down', 3); +			$this->module_manager->remove_cache_file($module_class); -				// Move closed pm reports module 3 down... -				$sql = 'SELECT * -					FROM ' . MODULES_TABLE . " -					WHERE module_basename = 'mcp_pm_reports' -						AND module_class = 'mcp' -						AND module_mode = 'pm_reports_closed'"; -				$result = $this->db->sql_query($sql); -				$row = $this->db->sql_fetchrow($result); -				$this->db->sql_freeresult($result); +			$i++; -				$this->module_manager->move_module_by($row, 'mcp', 'move_down', 3); +			$this->config->set('module_class_index', $i); +			$this->config->set('module_categories_index', 0); +			$this->config->set('module_info_index', 0); +			$this->config->set('added_extra_modules', false); +			$this->config->set('modules_ordered', false); +			$this->config->set('module_categories_array', array()); -				// Move open pm reports module 3 down... -				$sql = 'SELECT * -					FROM ' . MODULES_TABLE . " -					WHERE module_basename = 'mcp_pm_reports' -						AND module_class = 'mcp' -						AND module_mode = 'pm_reports'"; -				$result = $this->db->sql_query($sql); -				$row = $this->db->sql_fetchrow($result); -				$this->db->sql_freeresult($result); - -				$this->module_manager->move_module_by($row, 'mcp', 'move_down', 3); +			// Stop execution if resource limit is reached +			if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0) +			{ +				break;  			} +		} -			if ($module_class == 'ucp') -			{ -				// Move attachment module 4 down... -				$sql = 'SELECT * -					FROM ' . MODULES_TABLE . " -					WHERE module_basename = 'ucp_attachments' -						AND module_class = 'ucp' -						AND module_mode = 'attachments'"; -				$result = $this->db->sql_query($sql); -				$row = $this->db->sql_fetchrow($result); -				$this->db->sql_freeresult($result); +		if ($i < $total) +		{ +			throw new resource_limit_reached_exception(); +		} +	} -				$this->module_manager->move_module_by($row, 'ucp', 'move_down', 4); +	/** +	 * Move modules to their correct place +	 * +	 * @param string	$module_class +	 */ +	protected function order_modules($module_class) +	{ +		if ($module_class == 'acp') +		{ +			// Move main module 4 up... +			$sql = 'SELECT * +				FROM ' . MODULES_TABLE . " +				WHERE module_basename = 'acp_main' +					AND module_class = 'acp' +					AND module_mode = 'main'"; +			$result = $this->db->sql_query($sql); +			$row = $this->db->sql_fetchrow($result); +			$this->db->sql_freeresult($result); + +			$this->module_manager->move_module_by($row, 'acp', 'move_up', 4); + +			// Move permissions intro screen module 4 up... +			$sql = 'SELECT * +				FROM ' . MODULES_TABLE . " +				WHERE module_basename = 'acp_permissions' +					AND module_class = 'acp' +					AND module_mode = 'intro'"; +			$result = $this->db->sql_query($sql); +			$row = $this->db->sql_fetchrow($result); +			$this->db->sql_freeresult($result); + +			$this->module_manager->move_module_by($row, 'acp', 'move_up', 4); + +			// Move manage users screen module 5 up... +			$sql = 'SELECT * +				FROM ' . MODULES_TABLE . " +				WHERE module_basename = 'acp_users' +					AND module_class = 'acp' +					AND module_mode = 'overview'"; +			$result = $this->db->sql_query($sql); +			$row = $this->db->sql_fetchrow($result); +			$this->db->sql_freeresult($result); + +			$this->module_manager->move_module_by($row, 'acp', 'move_up', 5); + +			// Move extension management module 1 up... +			$sql = 'SELECT * +				FROM ' . MODULES_TABLE . " +				WHERE module_langname = 'ACP_EXTENSION_MANAGEMENT' +					AND module_class = 'acp' +					AND module_mode = '' +					AND module_basename = ''"; +			$result = $this->db->sql_query($sql); +			$row = $this->db->sql_fetchrow($result); +			$this->db->sql_freeresult($result); + +			$this->module_manager->move_module_by($row, 'acp', 'move_up', 1); +		} -				// Move notification options module 4 down... -				$sql = 'SELECT * -					FROM ' . MODULES_TABLE . " -					WHERE module_basename = 'ucp_notifications' -						AND module_class = 'ucp' -						AND module_mode = 'notification_options'"; -				$result = $this->db->sql_query($sql); -				$row = $this->db->sql_fetchrow($result); -				$this->db->sql_freeresult($result); +		if ($module_class == 'mcp') +		{ +			// Move pm report details module 3 down... +			$sql = 'SELECT * +				FROM ' . MODULES_TABLE . " +				WHERE module_basename = 'mcp_pm_reports' +					AND module_class = 'mcp' +					AND module_mode = 'pm_report_details'"; +			$result = $this->db->sql_query($sql); +			$row = $this->db->sql_fetchrow($result); +			$this->db->sql_freeresult($result); + +			$this->module_manager->move_module_by($row, 'mcp', 'move_down', 3); + +			// Move closed pm reports module 3 down... +			$sql = 'SELECT * +				FROM ' . MODULES_TABLE . " +				WHERE module_basename = 'mcp_pm_reports' +					AND module_class = 'mcp' +					AND module_mode = 'pm_reports_closed'"; +			$result = $this->db->sql_query($sql); +			$row = $this->db->sql_fetchrow($result); +			$this->db->sql_freeresult($result); + +			$this->module_manager->move_module_by($row, 'mcp', 'move_down', 3); + +			// Move open pm reports module 3 down... +			$sql = 'SELECT * +				FROM ' . MODULES_TABLE . " +				WHERE module_basename = 'mcp_pm_reports' +					AND module_class = 'mcp' +					AND module_mode = 'pm_reports'"; +			$result = $this->db->sql_query($sql); +			$row = $this->db->sql_fetchrow($result); +			$this->db->sql_freeresult($result); + +			$this->module_manager->move_module_by($row, 'mcp', 'move_down', 3); +		} -				$this->module_manager->move_module_by($row, 'ucp', 'move_down', 4); +		if ($module_class == 'ucp') +		{ +			// Move attachment module 4 down... +			$sql = 'SELECT * +				FROM ' . MODULES_TABLE . " +				WHERE module_basename = 'ucp_attachments' +					AND module_class = 'ucp' +					AND module_mode = 'attachments'"; +			$result = $this->db->sql_query($sql); +			$row = $this->db->sql_fetchrow($result); +			$this->db->sql_freeresult($result); + +			$this->module_manager->move_module_by($row, 'ucp', 'move_down', 4); + +			// Move notification options module 4 down... +			$sql = 'SELECT * +				FROM ' . MODULES_TABLE . " +				WHERE module_basename = 'ucp_notifications' +					AND module_class = 'ucp' +					AND module_mode = 'notification_options'"; +			$result = $this->db->sql_query($sql); +			$row = $this->db->sql_fetchrow($result); +			$this->db->sql_freeresult($result); + +			$this->module_manager->move_module_by($row, 'ucp', 'move_down', 4); + +			// Move OAuth module 5 down... +			$sql = 'SELECT * +				FROM ' . MODULES_TABLE . " +				WHERE module_basename = 'ucp_auth_link' +					AND module_class = 'ucp' +					AND module_mode = 'auth_link'"; +			$result = $this->db->sql_query($sql); +			$row = $this->db->sql_fetchrow($result); +			$this->db->sql_freeresult($result); + +			$this->module_manager->move_module_by($row, 'ucp', 'move_down', 5); +		} +	} -				// Move OAuth module 5 down... +	/** +	 * Add extra modules +	 * +	 * @param string	$module_class +	 */ +	protected function add_module_extras($module_class) +	{ +		foreach ($this->module_extras[$module_class] as $cat_name => $mods) +		{ +			$sql = 'SELECT module_id, left_id, right_id +				FROM ' . MODULES_TABLE . " +				WHERE module_langname = '" . $this->db->sql_escape($cat_name) . "' +					AND module_class = '" . $this->db->sql_escape($module_class) . "'"; +			$result = $this->db->sql_query_limit($sql, 1); +			$row2 = $this->db->sql_fetchrow($result); +			$this->db->sql_freeresult($result); + +			foreach ($mods as $mod_name) +			{  				$sql = 'SELECT *  					FROM ' . MODULES_TABLE . " -					WHERE module_basename = 'ucp_auth_link' -						AND module_class = 'ucp' -						AND module_mode = 'auth_link'"; -				$result = $this->db->sql_query($sql); +					WHERE module_langname = '" . $this->db->sql_escape($mod_name) . "' +						AND module_class = '" . $this->db->sql_escape($module_class) . "' +						AND module_basename <> ''"; +				$result = $this->db->sql_query_limit($sql, 1);  				$row = $this->db->sql_fetchrow($result);  				$this->db->sql_freeresult($result); -				$this->module_manager->move_module_by($row, 'ucp', 'move_down', 5); -			} - -			// And now for the special ones -			// (these are modules which appear in multiple categories and thus get added manually -			// to some for more control) -			if (isset($this->module_extras[$module_class])) -			{ -				foreach ($this->module_extras[$module_class] as $cat_name => $mods) -				{ -					$sql = 'SELECT module_id, left_id, right_id -						FROM ' . MODULES_TABLE . " -						WHERE module_langname = '" . $this->db->sql_escape($cat_name) . "' -							AND module_class = '" . $this->db->sql_escape($module_class) . "'"; -					$result = $this->db->sql_query_limit($sql, 1); -					$row2 = $this->db->sql_fetchrow($result); -					$this->db->sql_freeresult($result); - -					foreach ($mods as $mod_name) -					{ -						$sql = 'SELECT * -							FROM ' . MODULES_TABLE . " -							WHERE module_langname = '" . $this->db->sql_escape($mod_name) . "' -								AND module_class = '" . $this->db->sql_escape($module_class) . "' -								AND module_basename <> ''"; -						$result = $this->db->sql_query_limit($sql, 1); -						$row = $this->db->sql_fetchrow($result); -						$this->db->sql_freeresult($result); - -						$module_data = array( -							'module_basename'	=> $row['module_basename'], -							'module_enabled'	=> (int) $row['module_enabled'], -							'module_display'	=> (int) $row['module_display'], -							'parent_id'			=> (int) $row2['module_id'], -							'module_class'		=> $row['module_class'], -							'module_langname'	=> $row['module_langname'], -							'module_mode'		=> $row['module_mode'], -							'module_auth'		=> $row['module_auth'], -						); +				$module_data = array( +					'module_basename'	=> $row['module_basename'], +					'module_enabled'	=> (int) $row['module_enabled'], +					'module_display'	=> (int) $row['module_display'], +					'parent_id'			=> (int) $row2['module_id'], +					'module_class'		=> $row['module_class'], +					'module_langname'	=> $row['module_langname'], +					'module_mode'		=> $row['module_mode'], +					'module_auth'		=> $row['module_auth'], +				); -						$this->module_manager->update_module_data($module_data); +				$this->module_manager->update_module_data($module_data); -						// Check for last sql error happened -						if ($this->db->get_sql_error_triggered()) -						{ -							$error = $this->db->sql_error($this->db->get_sql_error_sql()); -							$this->iohandler->add_error_message('INST_ERR_DB', $error['message']); -						} -					} +				// Check for last sql error happened +				if ($this->db->get_sql_error_triggered()) +				{ +					$error = $this->db->sql_error($this->db->get_sql_error_sql()); +					$this->iohandler->add_error_message('INST_ERR_DB', $error['message']);  				}  			} - -			$this->module_manager->remove_cache_file($module_class);  		}  	} diff --git a/phpBB/phpbb/install/module/install_database/task/add_config_settings.php b/phpBB/phpbb/install/module/install_database/task/add_config_settings.php index 6fb03ff73d..20b7679ec1 100644 --- a/phpBB/phpbb/install/module/install_database/task/add_config_settings.php +++ b/phpBB/phpbb/install/module/install_database/task/add_config_settings.php @@ -13,6 +13,8 @@  namespace phpbb\install\module\install_database\task; +use phpbb\install\exception\resource_limit_reached_exception; +  /**   * Create database schema   */ @@ -313,6 +315,10 @@ class add_config_settings extends \phpbb\install\task_base  				WHERE config_name = 'allow_avatar_upload'";  		} +		$i = $this->install_config->get('add_config_settings_index', 0); +		$total = sizeof($sql_ary); +		$sql_ary = array_slice($sql_ary, $i); +  		foreach ($sql_ary as $sql)  		{  			if (!$this->db->sql_query($sql)) @@ -320,6 +326,20 @@ class add_config_settings extends \phpbb\install\task_base  				$error = $this->db->sql_error($this->db->get_sql_error_sql());  				$this->iohandler->add_error_message('INST_ERR_DB', $error['message']);  			} + +			$i++; + +			// Stop execution if resource limit is reached +			if ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0) +			{ +				break; +			} +		} + +		if ($i < $total) +		{ +			$this->install_config->set('add_config_settings_index', $i); +			throw new resource_limit_reached_exception();  		}  	} diff --git a/phpBB/phpbb/install/module/install_database/task/add_default_data.php b/phpBB/phpbb/install/module/install_database/task/add_default_data.php index 3d73a74618..f5157637ee 100644 --- a/phpBB/phpbb/install/module/install_database/task/add_default_data.php +++ b/phpBB/phpbb/install/module/install_database/task/add_default_data.php @@ -13,6 +13,8 @@  namespace phpbb\install\module\install_database\task; +use phpbb\install\exception\resource_limit_reached_exception; +  /**   * Create database schema   */ @@ -96,6 +98,10 @@ class add_default_data extends \phpbb\install\task_base  		$sql_query = $this->database_helper->remove_comments($sql_query);  		$sql_query = $this->database_helper->split_sql_file($sql_query, $dbms_info[$dbms]['DELIM']); +		$i = $this->config->get('add_default_data_index', 0); +		$total = sizeof($sql_query); +		$sql_query = array_slice($sql_query, $i); +  		foreach ($sql_query as $sql)  		{  			if (!$this->db->sql_query($sql)) @@ -103,6 +109,21 @@ class add_default_data extends \phpbb\install\task_base  				$error = $this->db->sql_error($this->db->get_sql_error_sql());  				$this->iohandler->add_error_message('INST_ERR_DB', $error['message']);  			} + +			$i++; + +			// Stop execution if resource limit is reached +			if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0) +			{ +				break; +			} +		} + +		$this->config->set('add_default_data_index', $i); + +		if ($i < $total) +		{ +			throw new resource_limit_reached_exception();  		}  	} diff --git a/phpBB/phpbb/install/module/install_database/task/add_tables.php b/phpBB/phpbb/install/module/install_database/task/add_tables.php new file mode 100644 index 0000000000..f344f91582 --- /dev/null +++ b/phpBB/phpbb/install/module/install_database/task/add_tables.php @@ -0,0 +1,151 @@ +<?php +/** + * + * This file is part of the phpBB Forum Software package. + * + * @copyright (c) phpBB Limited <https://www.phpbb.com> + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace phpbb\install\module\install_database\task; + +use phpbb\install\exception\resource_limit_reached_exception; + +/** + * Create tables + */ +class add_tables extends \phpbb\install\task_base +{ +	/** +	 * @var \phpbb\install\helper\config +	 */ +	protected $config; + +	/** +	 * @var \phpbb\db\driver\driver_interface +	 */ +	protected $db; + +	/** +	 * @var \phpbb\db\tools\tools_interface +	 */ +	protected $db_tools; + +	/** +	 * @var \phpbb\filesystem\filesystem_interface +	 */ +	protected $filesystem; + +	/** +	 * @var string +	 */ +	protected $schema_file_path; + +	/** +	 * Constructor +	 * +	 * @param \phpbb\install\helper\config				$config +	 * @param \phpbb\install\helper\database			$db_helper +	 * @param \phpbb\filesystem\filesystem_interface	$filesystem +	 * @param string									$phpbb_root_path +	 */ +	public function __construct(\phpbb\install\helper\config $config, +								\phpbb\install\helper\database $db_helper, +								\phpbb\filesystem\filesystem_interface $filesystem, +								$phpbb_root_path) +	{ +		$dbms = $db_helper->get_available_dbms($config->get('dbms')); +		$dbms = $dbms[$config->get('dbms')]['DRIVER']; +		$factory = new \phpbb\db\tools\factory(); + +		$this->db				= new $dbms(); +		$this->db->sql_connect( +			$config->get('dbhost'), +			$config->get('dbuser'), +			$config->get('dbpasswd'), +			$config->get('dbname'), +			$config->get('dbport'), +			false, +			false +		); + +		$this->config			= $config; +		$this->db_tools			= $factory->get($this->db); +		$this->filesystem		= $filesystem; +		$this->schema_file_path	= $phpbb_root_path . 'store/schema.json'; + +		parent::__construct(true); +	} + +	/** +	 * {@inheritdoc} +	 */ +	public function run() +	{ +		$this->db->sql_return_on_error(true); + +		$table_prefix = $this->config->get('table_prefix'); +		$change_prefix = $this->config->get('change_table_prefix', true); + +		if (!defined('CONFIG_TABLE')) +		{ +			// CONFIG_TABLE is required by sql_create_index() to check the +			// length of index names. However table_prefix is not defined +			// here yet, so we need to create the constant ourselves. +			define('CONFIG_TABLE', $table_prefix . 'config'); +		} + +		$db_table_schema = @file_get_contents($this->schema_file_path); +		$db_table_schema = json_decode($db_table_schema, true); +		$total = sizeof($db_table_schema); +		$i = $this->config->get('add_table_index', 0); +		$db_table_schema = array_slice($db_table_schema, $i); + +		foreach ($db_table_schema as $table_name => $table_data) +		{ +			$i++; + +			$this->db_tools->sql_create_table( +				( ($change_prefix) ? ($table_prefix . substr($table_name, 6)) : $table_name ), +				$table_data +			); + +			// Stop execution if resource limit is reached +			if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0) +			{ +				break; +			} +		} + +		$this->config->set('add_table_index', $i); + +		if ($i < $total) +		{ +			throw new resource_limit_reached_exception(); +		} +		else +		{ +			@unlink($this->schema_file_path); +		} +	} + +	/** +	 * {@inheritdoc} +	 */ +	static public function get_step_count() +	{ +		return 1; +	} + +	/** +	 * {@inheritdoc} +	 */ +	public function get_task_lang_name() +	{ +		return 'TASK_CREATE_TABLES'; +	} +} diff --git a/phpBB/phpbb/install/module/install_database/task/create_schema_file.php b/phpBB/phpbb/install/module/install_database/task/create_schema_file.php new file mode 100644 index 0000000000..b6d6ece17f --- /dev/null +++ b/phpBB/phpbb/install/module/install_database/task/create_schema_file.php @@ -0,0 +1,164 @@ +<?php +/** + * + * This file is part of the phpBB Forum Software package. + * + * @copyright (c) phpBB Limited <https://www.phpbb.com> + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace phpbb\install\module\install_database\task; + +use phpbb\install\exception\resource_limit_reached_exception; + +/** + * Create database schema + */ +class create_schema_file extends \phpbb\install\task_base +{ +	/** +	 * @var \phpbb\install\helper\config +	 */ +	protected $config; + +	/** +	 * @var \phpbb\db\driver\driver_interface +	 */ +	protected $db; + +	/** +	 * @var \phpbb\filesystem\filesystem_interface +	 */ +	protected $filesystem; + +	/** +	 * @var string +	 */ +	protected $phpbb_root_path; + +	/** +	 * @var string +	 */ +	protected $php_ext; + +	/** +	 * Constructor +	 * +	 * @param \phpbb\install\helper\config							$config				Installer's config provider +	 * @param \phpbb\install\helper\database						$db_helper			Installer's database helper +	 * @param \phpbb\filesystem\filesystem_interface				$filesystem			Filesystem service +	 * @param string												$phpbb_root_path	Path phpBB's root +	 * @param string												$php_ext			Extension of PHP files +	 */ +	public function __construct(\phpbb\install\helper\config $config, +								\phpbb\install\helper\database $db_helper, +								\phpbb\filesystem\filesystem_interface $filesystem, +								$phpbb_root_path, +								$php_ext) +	{ +		$dbms = $db_helper->get_available_dbms($config->get('dbms')); +		$dbms = $dbms[$config->get('dbms')]['DRIVER']; + +		$this->db				= new $dbms(); +		$this->db->sql_connect( +			$config->get('dbhost'), +			$config->get('dbuser'), +			$config->get('dbpasswd'), +			$config->get('dbname'), +			$config->get('dbport'), +			false, +			false +		); + +		$this->config			= $config; +		$this->filesystem		= $filesystem; +		$this->phpbb_root_path	= $phpbb_root_path; +		$this->php_ext			= $php_ext; + +		parent::__construct(true); +	} + +	/** +	 * {@inheritdoc} +	 */ +	public function run() +	{ +		// Generate database schema +		if ($this->filesystem->exists($this->phpbb_root_path . 'install/schemas/schema.json')) +		{ +			$db_table_schema = @file_get_contents($this->phpbb_root_path . 'install/schemas/schema.json'); +			$this->config->set('change_table_prefix', true); +		} +		else +		{ +			global $table_prefix; + +			// As this task may take a large amount of time to complete refreshing the page might be necessary for some +			// server configurations with limited resources +			if (!$this->config->get('pre_schema_forced_refresh', false)) +			{ +				if ($this->config->get_time_remaining() < 5) +				{ +					$this->config->set('pre_schema_forced_refresh', true); +					throw new resource_limit_reached_exception(); +				} +			} + +			$table_prefix = $this->config->get('table_prefix'); + +			if (!defined('CONFIG_TABLE')) +			{ +				// We need to include the constants file for the table constants +				// when we generate the schema from the migration files. +				include ($this->phpbb_root_path . 'includes/constants.' . $this->php_ext); +			} + +			$finder = new \phpbb\finder($this->filesystem, $this->phpbb_root_path, null, $this->php_ext); +			$migrator_classes = $finder->core_path('phpbb/db/migration/data/')->get_classes(); +			$factory = new \phpbb\db\tools\factory(); +			$db_tools = $factory->get($this->db, true); +			$schema_generator = new \phpbb\db\migration\schema_generator( +				$migrator_classes, +				new \phpbb\config\config(array()), +				$this->db, +				$db_tools, +				$this->phpbb_root_path, +				$this->php_ext, +				$table_prefix +			); +			$db_table_schema = $schema_generator->get_schema(); +			$db_table_schema = json_encode($db_table_schema, JSON_PRETTY_PRINT); + +			$this->config->set('change_table_prefix', false); +		} + +		$fp = @fopen($this->phpbb_root_path . 'store/schema.json', 'wb'); +		if (!$fp) +		{ +			throw new \Exception('INST_SCHEMA_FILE_NOT_WRITABLE'); +		} + +		fwrite($fp, $db_table_schema); +		fclose($fp); +	} + +	/** +	 * {@inheritdoc} +	 */ +	static public function get_step_count() +	{ +		return 1; +	} + +	/** +	 * {@inheritdoc} +	 */ +	public function get_task_lang_name() +	{ +		return 'TASK_CREATE_DATABASE_SCHEMA_FILE'; +	} +} diff --git a/phpBB/phpbb/install/module/install_database/task/set_up_database.php b/phpBB/phpbb/install/module/install_database/task/set_up_database.php new file mode 100644 index 0000000000..49c8ea23ad --- /dev/null +++ b/phpBB/phpbb/install/module/install_database/task/set_up_database.php @@ -0,0 +1,164 @@ +<?php +/** + * + * This file is part of the phpBB Forum Software package. + * + * @copyright (c) phpBB Limited <https://www.phpbb.com> + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace phpbb\install\module\install_database\task; + +/** + * Set up database for table generation + */ +class set_up_database extends \phpbb\install\task_base +{ +	/** +	 * @var \phpbb\install\helper\config +	 */ +	protected $config; + +	/** +	 * @var \phpbb\db\driver\driver_interface +	 */ +	protected $db; + +	/** +	 * @var \phpbb\install\helper\database +	 */ +	protected $database_helper; + +	/** +	 * @var \phpbb\filesystem\filesystem_interface +	 */ +	protected $filesystem; + +	/** +	 * @var \phpbb\install\helper\iohandler\iohandler_interface +	 */ +	protected $iohandler; + +	/** +	 * @var string +	 */ +	protected $schema_file_path; + +	/** +	 * @var string +	 */ +	protected $phpbb_root_path; + +	/** +	 * Constructor +	 * +	 * @param \phpbb\install\helper\config							$config +	 * @param \phpbb\install\helper\database						$db_helper +	 * @param \phpbb\filesystem\filesystem_interface				$filesystem +	 * @param \phpbb\install\helper\iohandler\iohandler_interface	$iohandler +	 * @param string												$phpbb_root_path +	 */ +	public function __construct(\phpbb\install\helper\config $config, +								\phpbb\install\helper\database $db_helper, +								\phpbb\filesystem\filesystem_interface $filesystem, +								\phpbb\install\helper\iohandler\iohandler_interface $iohandler, +								$phpbb_root_path) +	{ +		$dbms = $db_helper->get_available_dbms($config->get('dbms')); +		$dbms = $dbms[$config->get('dbms')]['DRIVER']; + +		$this->db				= new $dbms(); +		$this->db->sql_connect( +			$config->get('dbhost'), +			$config->get('dbuser'), +			$config->get('dbpasswd'), +			$config->get('dbname'), +			$config->get('dbport'), +			false, +			false +		); + +		$this->config			= $config; +		$this->database_helper	= $db_helper; +		$this->filesystem		= $filesystem; +		$this->iohandler		= $iohandler; +		$this->phpbb_root_path	= $phpbb_root_path; + +		parent::__construct(false); +	} + +	/** +	 * {@inheritdoc} +	 */ +	public function check_requirements() +	{ +		$dbms = $this->config->get('dbms'); +		$dbms_info = $this->database_helper->get_available_dbms($dbms); +		$schema_name = $dbms_info[$dbms]['SCHEMA']; + +		if ($dbms === 'mysql') +		{ +			if (version_compare($this->db->sql_server_info(true), '4.1.3', '>=')) +			{ +				$schema_name .= '_41'; +			} +			else +			{ +				$schema_name .= '_40'; +			} +		} + +		$this->schema_file_path = $this->phpbb_root_path . 'install/schemas/' . $schema_name . '_schema.sql'; + +		return $this->filesystem->exists($this->schema_file_path); +	} + +	/** +	 * {@inheritdoc} +	 */ +	public function run() +	{ +		$this->db->sql_return_on_error(true); + +		$dbms = $this->config->get('dbms'); +		$dbms_info = $this->database_helper->get_available_dbms($dbms); +		$delimiter = $dbms_info[$dbms]['DELIM']; +		$table_prefix = $this->config->get('table_prefix'); + +		$sql_query = @file_get_contents($this->schema_file_path); +		$sql_query = preg_replace('#phpbb_#i', $table_prefix, $sql_query); +		$sql_query = $this->database_helper->remove_comments($sql_query); +		$sql_query = $this->database_helper->split_sql_file($sql_query, $delimiter); + +		foreach ($sql_query as $sql) +		{ +			if (!$this->db->sql_query($sql)) +			{ +				$error = $this->db->sql_error($this->db->get_sql_error_sql()); +				$this->iohandler->add_error_message('INST_ERR_DB', $error['message']); +			} +		} + +		unset($sql_query); +	} + +	/** +	 * {@inheritdoc} +	 */ +	static public function get_step_count() +	{ +		return 1; +	} + +	/** +	 * {@inheritdoc} +	 */ +	public function get_task_lang_name() +	{ +		return 'TASK_SETUP_DATABASE'; +	} +} diff --git a/phpBB/phpbb/install/module/install_filesystem/task/create_config_file.php b/phpBB/phpbb/install/module/install_filesystem/task/create_config_file.php index e0890a929c..5bc425b929 100644 --- a/phpBB/phpbb/install/module/install_filesystem/task/create_config_file.php +++ b/phpBB/phpbb/install/module/install_filesystem/task/create_config_file.php @@ -129,7 +129,6 @@ class create_config_file extends \phpbb\install\task_base  		else  		{  			$this->iohandler->add_error_message('UNABLE_TO_WRITE_CONFIG_FILE'); -			$this->iohandler->send_response();  			throw new user_interaction_required_exception();  		} @@ -139,7 +138,6 @@ class create_config_file extends \phpbb\install\task_base  		{  			// We were unable to create the lock file - abort  			$this->iohandler->add_error_message('UNABLE_TO_WRITE_LOCK'); -			$this->iohandler->send_response();  			throw new user_interaction_required_exception();  		}  		@fclose($fp); diff --git a/phpBB/phpbb/install/module/install_finish/task/notify_user.php b/phpBB/phpbb/install/module/install_finish/task/notify_user.php index 5268b85a42..292be57f5f 100644 --- a/phpBB/phpbb/install/module/install_finish/task/notify_user.php +++ b/phpBB/phpbb/install/module/install_finish/task/notify_user.php @@ -87,9 +87,13 @@ class notify_user extends \phpbb\install\task_base  		$this->php_ext			= $php_ext;  		// We need to reload config for cases when it doesn't have all values +		/** @var \phpbb\cache\driver\driver_interface $cache */ +		$cache = $container->get('cache.driver'); +		$cache->destroy('config'); +  		$this->config = new db(  			$container->get('dbal.conn'), -			$container->get('cache.driver'), +			$cache,  			$container->get_parameter('tables.config')  		); diff --git a/phpBB/phpbb/install/module/install_finish/task/populate_migrations.php b/phpBB/phpbb/install/module/install_finish/task/populate_migrations.php index 8629d9aea3..34541c361e 100644 --- a/phpBB/phpbb/install/module/install_finish/task/populate_migrations.php +++ b/phpBB/phpbb/install/module/install_finish/task/populate_migrations.php @@ -13,12 +13,21 @@  namespace phpbb\install\module\install_finish\task; +use phpbb\install\exception\resource_limit_reached_exception; +use phpbb\install\helper\config; +use phpbb\install\helper\container_factory; +  /**   * Populates migrations   */  class populate_migrations extends \phpbb\install\task_base  {  	/** +	 * @var config +	 */ +	protected $config; + +	/**  	 * @var \phpbb\extension\manager  	 */  	protected $extension_manager; @@ -31,10 +40,12 @@ class populate_migrations extends \phpbb\install\task_base  	/**  	 * Constructor  	 * -	 * @param \phpbb\install\helper\container_factory	$container	phpBB's DI contianer +	 * @param config			$config		Installer's config +	 * @param container_factory	$container	phpBB's DI contianer  	 */ -	public function __construct(\phpbb\install\helper\container_factory $container) +	public function __construct(config $config, container_factory $container)  	{ +		$this->config				= $config;  		$this->extension_manager	= $container->get('ext.manager');  		$this->migrator				= $container->get('migrator'); @@ -46,6 +57,15 @@ class populate_migrations extends \phpbb\install\task_base  	 */  	public function run()  	{ +		if (!$this->config->get('populate_migration_refresh_before', false)) +		{ +			if ($this->config->get_time_remaining() < 1) +			{ +				$this->config->set('populate_migration_refresh_before', true); +				throw new resource_limit_reached_exception(); +			} +		} +  		$finder = $this->extension_manager->get_finder();  		$migrations = $finder diff --git a/phpBB/phpbb/install/module/obtain_data/task/obtain_admin_data.php b/phpBB/phpbb/install/module/obtain_data/task/obtain_admin_data.php index ac305e8ab5..d1f1af6b83 100644 --- a/phpBB/phpbb/install/module/obtain_data/task/obtain_admin_data.php +++ b/phpBB/phpbb/install/module/obtain_data/task/obtain_admin_data.php @@ -136,7 +136,6 @@ class obtain_admin_data extends \phpbb\install\task_base implements \phpbb\insta  		$this->io_handler->add_user_form_group('ADMIN_CONFIG', $admin_form);  		// Require user interaction -		$this->io_handler->send_response();  		throw new user_interaction_required_exception();  	} diff --git a/phpBB/phpbb/install/module/obtain_data/task/obtain_board_data.php b/phpBB/phpbb/install/module/obtain_data/task/obtain_board_data.php index 6c54561d14..ff2a0a2f86 100644 --- a/phpBB/phpbb/install/module/obtain_data/task/obtain_board_data.php +++ b/phpBB/phpbb/install/module/obtain_data/task/obtain_board_data.php @@ -164,7 +164,6 @@ class obtain_board_data extends \phpbb\install\task_base implements \phpbb\insta  		$this->io_handler->add_user_form_group('BOARD_CONFIG', $board_form); -		$this->io_handler->send_response();  		throw new user_interaction_required_exception();  	} diff --git a/phpBB/phpbb/install/module/obtain_data/task/obtain_database_data.php b/phpBB/phpbb/install/module/obtain_data/task/obtain_database_data.php index 3458aab63e..ce720dbf76 100644 --- a/phpBB/phpbb/install/module/obtain_data/task/obtain_database_data.php +++ b/phpBB/phpbb/install/module/obtain_data/task/obtain_database_data.php @@ -188,7 +188,6 @@ class obtain_database_data extends \phpbb\install\task_base implements \phpbb\in  		$this->io_handler->add_user_form_group('DB_CONFIG', $database_form);  		// Require user interaction -		$this->io_handler->send_response();  		throw new user_interaction_required_exception();  	} diff --git a/phpBB/phpbb/install/module/obtain_data/task/obtain_email_data.php b/phpBB/phpbb/install/module/obtain_data/task/obtain_email_data.php index b04b8e353f..606e4a2ddd 100644 --- a/phpBB/phpbb/install/module/obtain_data/task/obtain_email_data.php +++ b/phpBB/phpbb/install/module/obtain_data/task/obtain_email_data.php @@ -144,7 +144,6 @@ class obtain_email_data extends \phpbb\install\task_base implements \phpbb\insta  			$this->io_handler->add_user_form_group('EMAIL_CONFIG', $email_form); -			$this->io_handler->send_response();  			throw new user_interaction_required_exception();  		}  	} diff --git a/phpBB/phpbb/install/module/obtain_data/task/obtain_file_updater_method.php b/phpBB/phpbb/install/module/obtain_data/task/obtain_file_updater_method.php index 9bcb73a6a9..d5a8855c37 100644 --- a/phpBB/phpbb/install/module/obtain_data/task/obtain_file_updater_method.php +++ b/phpBB/phpbb/install/module/obtain_data/task/obtain_file_updater_method.php @@ -115,7 +115,6 @@ class obtain_file_updater_method extends task_base  				),  			)); -			$this->iohandler->send_response();  			throw new user_interaction_required_exception();  		}  	} diff --git a/phpBB/phpbb/install/module/obtain_data/task/obtain_server_data.php b/phpBB/phpbb/install/module/obtain_data/task/obtain_server_data.php index 654b5534a9..1ef70eae08 100644 --- a/phpBB/phpbb/install/module/obtain_data/task/obtain_server_data.php +++ b/phpBB/phpbb/install/module/obtain_data/task/obtain_server_data.php @@ -180,7 +180,6 @@ class obtain_server_data extends \phpbb\install\task_base implements \phpbb\inst  			$this->io_handler->add_user_form_group('SERVER_CONFIG', $server_form); -			$this->io_handler->send_response();  			throw new user_interaction_required_exception();  		}  	} diff --git a/phpBB/phpbb/install/module/obtain_data/task/obtain_update_ftp_data.php b/phpBB/phpbb/install/module/obtain_data/task/obtain_update_ftp_data.php index a4d362a0f1..f31472fc58 100644 --- a/phpBB/phpbb/install/module/obtain_data/task/obtain_update_ftp_data.php +++ b/phpBB/phpbb/install/module/obtain_data/task/obtain_update_ftp_data.php @@ -141,7 +141,6 @@ class obtain_update_ftp_data extends task_base  				),  			)); -			$this->iohandler->send_response();  			throw new user_interaction_required_exception();  		}  	} diff --git a/phpBB/phpbb/install/module/obtain_data/task/obtain_update_settings.php b/phpBB/phpbb/install/module/obtain_data/task/obtain_update_settings.php index be6404dcd8..c139b70fa4 100644 --- a/phpBB/phpbb/install/module/obtain_data/task/obtain_update_settings.php +++ b/phpBB/phpbb/install/module/obtain_data/task/obtain_update_settings.php @@ -93,7 +93,6 @@ class obtain_update_settings extends task_base  				),  			)); -			$this->iohandler->send_response();  			throw new user_interaction_required_exception();  		}  	} diff --git a/phpBB/phpbb/install/module/requirements/abstract_requirements_module.php b/phpBB/phpbb/install/module/requirements/abstract_requirements_module.php index 26593e6777..121b4ff4e5 100644 --- a/phpBB/phpbb/install/module/requirements/abstract_requirements_module.php +++ b/phpBB/phpbb/install/module/requirements/abstract_requirements_module.php @@ -13,7 +13,6 @@  namespace phpbb\install\module\requirements; -use phpbb\install\exception\resource_limit_reached_exception;  use phpbb\install\exception\user_interaction_required_exception;  use phpbb\install\module_base; @@ -25,41 +24,8 @@ abstract class abstract_requirements_module extends module_base  	public function run()  	{  		$tests_passed = true; - -		// Recover install progress -		$task_name = $this->recover_progress(); -		$task_found = false; - -		/** -		 * @var string							$name	ID of the service -		 * @var \phpbb\install\task_interface	$task	Task object -		 */  		foreach ($this->task_collection as $name => $task)  		{ -			// Run until there are available resources -			if ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0) -			{ -				throw new resource_limit_reached_exception(); -			} - -			// Skip forward until the next task is reached -			if (!$task_found) -			{ -				if ($name === $task_name || empty($task_name)) -				{ -					$task_found = true; - -					if ($name === $task_name) -					{ -						continue; -					} -				} -				else -				{ -					continue; -				} -			} -  			// Check if we can run the task  			if (!$task->is_essential() && !$task->check_requirements())  			{ @@ -76,7 +42,7 @@ abstract class abstract_requirements_module extends module_base  		}  		// Module finished, so clear task progress -		$this->install_config->set_finished_task(''); +		$this->install_config->set_finished_task(0);  		// Check if tests have failed  		if (!$tests_passed) @@ -91,7 +57,6 @@ abstract class abstract_requirements_module extends module_base  			));  			// Send the response and quit -			$this->iohandler->send_response();  			throw new user_interaction_required_exception();  		}  	} diff --git a/phpBB/phpbb/install/module/update_database/task/update.php b/phpBB/phpbb/install/module/update_database/task/update.php index aa44d403dd..4b2baf2c23 100644 --- a/phpBB/phpbb/install/module/update_database/task/update.php +++ b/phpBB/phpbb/install/module/update_database/task/update.php @@ -158,7 +158,6 @@ class update extends task_base  				array_unshift($msg, $e->getMessage());  				$this->iohandler->add_error_message($msg); -				$this->iohandler->send_response();  				throw new user_interaction_required_exception();  			} diff --git a/phpBB/phpbb/install/module/update_filesystem/task/download_updated_files.php b/phpBB/phpbb/install/module/update_filesystem/task/download_updated_files.php index 9271e8fd50..f911b7ac62 100644 --- a/phpBB/phpbb/install/module/update_filesystem/task/download_updated_files.php +++ b/phpBB/phpbb/install/module/update_filesystem/task/download_updated_files.php @@ -101,7 +101,6 @@ class download_updated_files extends task_base  				),  			)); -			$this->iohandler->send_response();  			throw new user_interaction_required_exception();  		}  	} diff --git a/phpBB/phpbb/install/module/update_filesystem/task/show_file_status.php b/phpBB/phpbb/install/module/update_filesystem/task/show_file_status.php index e712b8ad6a..c46c05500a 100644 --- a/phpBB/phpbb/install/module/update_filesystem/task/show_file_status.php +++ b/phpBB/phpbb/install/module/update_filesystem/task/show_file_status.php @@ -136,7 +136,6 @@ class show_file_status extends task_base  			));  			// Show results to the user -			$this->iohandler->send_response();  			throw new user_interaction_required_exception();  		}  		else diff --git a/phpBB/phpbb/install/module_base.php b/phpBB/phpbb/install/module_base.php index fb68c3aca2..527447b4a1 100644 --- a/phpBB/phpbb/install/module_base.php +++ b/phpBB/phpbb/install/module_base.php @@ -105,47 +105,23 @@ abstract class module_base implements module_interface  	public function run()  	{  		// Recover install progress -		$task_name = $this->recover_progress(); -		$task_found = false; - -		/** -		 * @var string							$name	ID of the service -		 * @var \phpbb\install\task_interface	$task	Task object -		 */ -		foreach ($this->task_collection as $name => $task) -		{ -			// Run until there are available resources -			if ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0) -			{ -				throw new resource_limit_reached_exception(); -			} +		$task_index	= $this->recover_progress(); +		$iterator	= $this->task_collection->getIterator(); -			// Skip forward until the next task is reached -			if (!$task_found) -			{ -				if ($name === $task_name || empty($task_name)) -				{ -					$task_found = true; - -					if ($name === $task_name) -					{ -						continue; -					} -				} -				else -				{ -					continue; -				} -			} +		if ($task_index < $iterator->count()) +		{ +			$iterator->seek($task_index); +		} +		else +		{ +			$this->install_config->set_finished_task(0); +			return; +		} -			// Send progress information -			if ($this->allow_progress_bar) -			{ -				$this->iohandler->set_progress( -					$task->get_task_lang_name(), -					$this->install_config->get_current_task_progress() -				); -			} +		while ($iterator->valid()) +		{ +			$task = $iterator->current(); +			$name = $iterator->key();  			// Check if we can run the task  			if (!$task->is_essential() && !$task->check_requirements()) @@ -156,20 +132,33 @@ abstract class module_base implements module_interface  				));  				$this->install_config->increment_current_task_progress($this->task_step_count[$name]); -				continue;  			} - -			if ($this->allow_progress_bar) +			else  			{ -				// Only increment progress by one, as if a task has more than one steps -				// then that should be incremented in the task itself -				$this->install_config->increment_current_task_progress(); -			} +				// Send progress information +				if ($this->allow_progress_bar) +				{ +					$this->iohandler->set_progress( +						$task->get_task_lang_name(), +						$this->install_config->get_current_task_progress() +					); + +					$this->iohandler->send_response(); +				} + +				$task->run(); -			$task->run(); +				if ($this->allow_progress_bar) +				{ +					// Only increment progress by one, as if a task has more than one steps +					// then that should be incremented in the task itself +					$this->install_config->increment_current_task_progress(); +				} +			} -			// Log install progress -			$this->install_config->set_finished_task($name); +			$task_index++; +			$this->install_config->set_finished_task($task_index); +			$iterator->next();  			// Send progress information  			if ($this->allow_progress_bar) @@ -181,10 +170,16 @@ abstract class module_base implements module_interface  			}  			$this->iohandler->send_response(); + +			// Stop execution if resource limit is reached +			if ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0) +			{ +				throw new resource_limit_reached_exception(); +			}  		}  		// Module finished, so clear task progress -		$this->install_config->set_finished_task(''); +		$this->install_config->set_finished_task(0);  	}  	/** @@ -195,7 +190,7 @@ abstract class module_base implements module_interface  	protected function recover_progress()  	{  		$progress_array = $this->install_config->get_progress_data(); -		return $progress_array['last_task_name']; +		return $progress_array['last_task_index'];  	}  	/** diff --git a/tests/installer/installer_config_test.php b/tests/installer/installer_config_test.php index c8e482e260..13ac325a79 100644 --- a/tests/installer/installer_config_test.php +++ b/tests/installer/installer_config_test.php @@ -52,8 +52,8 @@ class phpbb_installer_config_test extends phpbb_test_case  	public function test_progress_tracking()  	{ -		$this->config->set_finished_task('foo'); -		$this->config->set_active_module('bar'); +		$this->config->set_finished_task(0); +		$this->config->set_active_module('bar', 5);  		$this->config->set_task_progress_count(10);  		$this->config->increment_current_task_progress(); @@ -66,7 +66,8 @@ class phpbb_installer_config_test extends phpbb_test_case  		$result = $this->config->get_progress_data();  		$expected_result = array(  			'last_task_module_name'		=> 'bar', -			'last_task_name'			=> 'foo', +			'last_task_module_index'	=> 5, +			'last_task_index'			=> 0,  			'max_task_progress'			=> 10,  			'current_task_progress'		=> 3,  		); diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 34fbcec0e2..53519617b3 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -20,6 +20,7 @@ class phpbb_functional_test_case extends phpbb_test_case  	static protected $client;  	static protected $cookieJar;  	static protected $root_url; +	static protected $install_success = false;  	protected $cache = null;  	protected $db = null; @@ -78,6 +79,11 @@ class phpbb_functional_test_case extends phpbb_test_case  	{  		parent::setUp(); +		if (!self::$install_success) +		{ +			$this->fail('Installing phpBB has failed.'); +		} +  		$this->bootstrap();  		self::$cookieJar = new CookieJar; @@ -360,17 +366,21 @@ class phpbb_functional_test_case extends phpbb_test_case  		$iohandler->set_input('script_path', $parseURL['path']);  		$iohandler->set_input('submit_server', 'submit'); -		do -		{ -			$installer->run(); -		} -		while (file_exists($phpbb_root_path . 'store/install_config.php')); +		$installer->run();  		copy($config_file, $config_file_test); +		self::$install_success = true; + +		if (file_exists($phpbb_root_path . 'store/install_config.php')) +		{ +			self::$install_success = false; +			@unlink($phpbb_root_path . 'store/install_config.php'); +		} +  		if (file_exists($phpbb_root_path . 'cache/install_lock'))  		{ -			unlink($phpbb_root_path . 'cache/install_lock'); +			@unlink($phpbb_root_path . 'cache/install_lock');  		}  		global $phpbb_container, $cache, $phpbb_dispatcher, $request, $user, $auth, $db, $config, $phpbb_log, $symfony_request, $phpbb_filesystem, $phpbb_path_helper, $phpbb_extension_manager, $template; diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php index 3c09ff96d1..8b60096081 100644 --- a/tests/test_framework/phpbb_ui_test_case.php +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -31,6 +31,8 @@ class phpbb_ui_test_case extends phpbb_test_case  	static protected $config;  	static protected $root_url;  	static protected $already_installed = false; +	static protected $install_success = false; +	static protected $db;  	static public function setUpBeforeClass()  	{ @@ -79,6 +81,25 @@ class phpbb_ui_test_case extends phpbb_test_case  		}  	} +	public function setUp() +	{ +		if (!self::$install_success) +		{ +			$this->fail('Installing phpBB has failed.'); +		} +	} + +	protected function tearDown() +	{ +		parent::tearDown(); + +		if (self::$db instanceof \phpbb\db\driver\driver_interface) +		{ +			// Close the database connections again this test +			self::$db->sql_close(); +		} +	} +  	static public function visit($path)  	{  		self::$webDriver->get(self::$root_url . $path); @@ -103,10 +124,12 @@ class phpbb_ui_test_case extends phpbb_test_case  	static public function install_board()  	{ -		global $phpbb_root_path, $phpEx; +		global $phpbb_root_path, $phpEx, $db;  		self::recreate_database(self::$config); +		$db = self::get_db(); +  		$config_file = $phpbb_root_path . "config.$phpEx";  		$config_file_dev = $phpbb_root_path . "config_dev.$phpEx";  		$config_file_test = $phpbb_root_path . "config_test.$phpEx"; @@ -199,21 +222,40 @@ class phpbb_ui_test_case extends phpbb_test_case  		$iohandler->set_input('script_path', $parseURL['path']);  		$iohandler->set_input('submit_server', 'submit'); -		do -		{ -			$installer->run(); -		} -		while (file_exists($phpbb_root_path . 'store/install_config.php')); +		$installer->run();  		copy($config_file, $config_file_test); +		self::$install_success = true; + +		if (file_exists($phpbb_root_path . 'store/install_config.php')) +		{ +			self::$install_success = false; +			@unlink($phpbb_root_path . 'store/install_config.php'); +		} +  		if (file_exists($phpbb_root_path . 'cache/install_lock'))  		{ -			unlink($phpbb_root_path . 'cache/install_lock'); +			@unlink($phpbb_root_path . 'cache/install_lock');  		}  		global $phpbb_container, $cache, $phpbb_dispatcher, $request, $user, $auth, $db, $config, $phpbb_log, $symfony_request, $phpbb_filesystem, $phpbb_path_helper, $phpbb_extension_manager, $template;  		$phpbb_container->reset();  		unset($phpbb_container, $cache, $phpbb_dispatcher, $request, $user, $auth, $db, $config, $phpbb_log, $symfony_request, $phpbb_filesystem, $phpbb_path_helper, $phpbb_extension_manager, $template);  	} + +	static protected function get_db() +	{ +		global $phpbb_root_path, $phpEx; +		// so we don't reopen an open connection +		if (!(self::$db instanceof \phpbb\db\driver\driver_interface)) +		{ +			$dbms = self::$config['dbms']; +			/** @var \phpbb\db\driver\driver_interface $db */ +			$db = new $dbms(); +			$db->sql_connect(self::$config['dbhost'], self::$config['dbuser'], self::$config['dbpasswd'], self::$config['dbname'], self::$config['dbport']); +			self::$db = $db; +		} +		return self::$db; +	}  } diff --git a/tests/ui/quick_links_test.php b/tests/ui/quick_links_test.php index 5bddb44a8b..582aeafcae 100644 --- a/tests/ui/quick_links_test.php +++ b/tests/ui/quick_links_test.php @@ -16,7 +16,6 @@  */  class quick_links_test extends phpbb_ui_test_case  { -  	public function test_quick_links()  	{  		$this->visit('index.php');  | 
