From d002d31b86af92b07b44ca8541e2ed7d3d0cfd2a Mon Sep 17 00:00:00 2001 From: Cesar G Date: Sat, 15 Feb 2014 17:09:13 -0800 Subject: [PATCH 1/4] [ticket/12160] Add function to check if phpBB is installed. PHPBB3-12160 --- phpBB/includes/functions.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 689a682de3..0c369bea5b 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5303,3 +5303,22 @@ function phpbb_convert_30_dbms_to_31($dbms) throw new \RuntimeException("You have specified an invalid dbms driver: $dbms"); } + +/** +* Check whether phpBB is installed. +* +* @param string $phpbb_root_path Path to the phpBB board root. +* @param string $php_ext PHP file extension. +* +* @return bool Returns true if phpBB is installed. +*/ +function phpbb_check_installation_exists($phpbb_root_path, $php_ext) +{ + // Try opening config file + if (@file_exists($phpbb_root_path . 'config.' . $php_ext)) + { + include($phpbb_root_path . 'config.' . $php_ext); + } + + return defined('PHPBB_INSTALLED'); +} From d6ec463977395d3210c67d207921923a27cb1195 Mon Sep 17 00:00:00 2001 From: Cesar G Date: Sat, 15 Feb 2014 17:11:10 -0800 Subject: [PATCH 2/4] [ticket/12160] Check if phpBB is installed before creating phpBB container. PHPBB3-12160 --- phpBB/install/install_convert.php | 68 ++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 19 deletions(-) diff --git a/phpBB/install/install_convert.php b/phpBB/install/install_convert.php index 1c7e2dca76..a837e9d52a 100644 --- a/phpBB/install/install_convert.php +++ b/phpBB/install/install_convert.php @@ -79,6 +79,21 @@ class convert */ class install_convert extends module { + /** @var array */ + protected $lang; + + /** @var string */ + protected $language; + + /** @var \phpbb\template\template */ + protected $template; + + /** @var string */ + protected $phpbb_root_path; + + /** @var string */ + protected $php_ext; + /** * Variables used while converting, they are accessible from the global variable $convert */ @@ -94,6 +109,16 @@ class install_convert extends module $this->tpl_name = 'install_convert'; $this->mode = $mode; + $this->lang = $lang; + $this->language = $language; + $this->template = $template; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $phpEx; + + if (!$this->check_phpbb_installed()) + { + return; + } $convert = new convert($this->p_master); @@ -108,25 +133,6 @@ class install_convert extends module switch ($sub) { case 'intro': - // Try opening config file - // @todo If phpBB is not installed, we need to do a cut-down installation here - // For now, we redirect to the installation script instead - if (@file_exists($phpbb_root_path . 'config.' . $phpEx)) - { - include($phpbb_root_path . 'config.' . $phpEx); - } - - if (!defined('PHPBB_INSTALLED')) - { - $template->assign_vars(array( - 'S_NOT_INSTALLED' => true, - 'TITLE' => $lang['BOARD_NOT_INSTALLED'], - 'BODY' => sprintf($lang['BOARD_NOT_INSTALLED_EXPLAIN'], append_sid($phpbb_root_path . 'install/index.' . $phpEx, 'mode=install&language=' . $language)), - )); - - return; - } - require($phpbb_root_path . 'config.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/functions_convert.' . $phpEx); @@ -258,6 +264,30 @@ class install_convert extends module } } + /** + * Check whether phpBB is installed. + * Assigns error template vars if not installed. + * + * @return bool Returns true if phpBB is installed. + */ + public function check_phpbb_installed() + { + if (phpbb_check_installation_exists($this->phpbb_root_path, $this->php_ext)) + { + return true; + } + + $this->page_title = 'BOARD_NOT_INSTALLED'; + $install_url = append_sid($this->phpbb_root_path . 'install/index.' . $this->php_ext, 'mode=install&language=' . $this->language); + + $this->template->assign_vars(array( + 'S_NOT_INSTALLED' => true, + 'BODY' => sprintf($this->lang['BOARD_NOT_INSTALLED_EXPLAIN'], $install_url), + )); + + return false; + } + /** * Generate a list of all available conversion modules */ From fc33a0c1763da363ff3063bd0c42a715a673c622 Mon Sep 17 00:00:00 2001 From: Cesar G Date: Sat, 22 Feb 2014 20:22:36 -0800 Subject: [PATCH 3/4] [ticket/12160] Move phpbb_check_installation_exists() to functions_install.php PHPBB3-12160 --- phpBB/includes/functions.php | 19 ------------------- phpBB/includes/functions_install.php | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 0c369bea5b..689a682de3 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5303,22 +5303,3 @@ function phpbb_convert_30_dbms_to_31($dbms) throw new \RuntimeException("You have specified an invalid dbms driver: $dbms"); } - -/** -* Check whether phpBB is installed. -* -* @param string $phpbb_root_path Path to the phpBB board root. -* @param string $php_ext PHP file extension. -* -* @return bool Returns true if phpBB is installed. -*/ -function phpbb_check_installation_exists($phpbb_root_path, $php_ext) -{ - // Try opening config file - if (@file_exists($phpbb_root_path . 'config.' . $php_ext)) - { - include($phpbb_root_path . 'config.' . $php_ext); - } - - return defined('PHPBB_INSTALLED'); -} diff --git a/phpBB/includes/functions_install.php b/phpBB/includes/functions_install.php index deb304b838..476535ae5b 100644 --- a/phpBB/includes/functions_install.php +++ b/phpBB/includes/functions_install.php @@ -581,3 +581,22 @@ function phpbb_ignore_new_file_on_update($phpbb_root_path, $file) return $ignore_new_file; } + +/** +* Check whether phpBB is installed. +* +* @param string $phpbb_root_path Path to the phpBB board root. +* @param string $php_ext PHP file extension. +* +* @return bool Returns true if phpBB is installed. +*/ +function phpbb_check_installation_exists($phpbb_root_path, $php_ext) +{ + // Try opening config file + if (file_exists($phpbb_root_path . 'config.' . $php_ext)) + { + include($phpbb_root_path . 'config.' . $php_ext); + } + + return defined('PHPBB_INSTALLED'); +} From 249b9dcdb5a19e3d380a28f3df403106a41fadff Mon Sep 17 00:00:00 2001 From: Cesar G Date: Sat, 22 Feb 2014 20:23:30 -0800 Subject: [PATCH 4/4] [ticket/12160] Use phpbb_check_installation_exists() in the other modules. PHPBB3-12160 --- phpBB/install/install_install.php | 9 ++------- phpBB/install/install_update.php | 11 +---------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php index a2d44f2b6c..72e6f6affa 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -18,14 +18,9 @@ if (!defined('IN_INSTALL')) if (!empty($setmodules)) { // If phpBB is already installed we do not include this module - if (@file_exists($phpbb_root_path . 'config.' . $phpEx) && !file_exists($phpbb_root_path . 'cache/install_lock')) + if (phpbb_check_installation_exists($phpbb_root_path, $phpEx) && !file_exists($phpbb_root_path . 'cache/install_lock')) { - include_once($phpbb_root_path . 'config.' . $phpEx); - - if (defined('PHPBB_INSTALLED')) - { - return; - } + return; } $module[] = array( diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php index dc6e57c851..87fe56737a 100644 --- a/phpBB/install/install_update.php +++ b/phpBB/install/install_update.php @@ -19,16 +19,7 @@ if (!defined('IN_INSTALL')) if (!empty($setmodules)) { // If phpBB is not installed we do not include this module - if (@file_exists($phpbb_root_path . 'config.' . $phpEx) && !@file_exists($phpbb_root_path . 'cache/install_lock')) - { - include_once($phpbb_root_path . 'config.' . $phpEx); - - if (!defined('PHPBB_INSTALLED')) - { - return; - } - } - else + if (!phpbb_check_installation_exists($phpbb_root_path, $phpEx) || file_exists($phpbb_root_path . 'cache/install_lock')) { return; }