From 3dcaa48850bf823b238391fbf9c3f085092010bc Mon Sep 17 00:00:00 2001 From: CHItA Date: Sat, 13 Jun 2015 15:35:19 +0200 Subject: [ticket/13740] Move installer files to phpbb/install directory PHPBB3-13740 --- .../install_filesystem/task/create_config_file.php | 235 +++++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 phpBB/phpbb/install/module/install_filesystem/task/create_config_file.php (limited to 'phpBB/phpbb/install/module/install_filesystem/task/create_config_file.php') 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 new file mode 100644 index 0000000000..337d401216 --- /dev/null +++ b/phpBB/phpbb/install/module/install_filesystem/task/create_config_file.php @@ -0,0 +1,235 @@ + + * @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_filesystem\task; + +use phpbb\install\exception\user_interaction_required_exception; + +/** + * Dumps config file + */ +class create_config_file extends \phpbb\install\task_base +{ + /** + * @var \phpbb\filesystem\filesystem_interface + */ + protected $filesystem; + + /** + * @var \phpbb\install\helper\database + */ + protected $db_helper; + + /** + * @var \phpbb\install\helper\config + */ + protected $install_config; + + /** + * @var \phpbb\install\helper\iohandler\iohandler_interface + */ + protected $iohandler; + + /** + * @var string + */ + protected $phpbb_root_path; + + /** + * @var string + */ + protected $php_ext; + + /** + * Constructor + * + * @param \phpbb\filesystem\filesystem_interface $filesystem + * @param \phpbb\install\helper\config $install_config + * @param \phpbb\install\helper\database $db_helper + * @param \phpbb\install\helper\iohandler\iohandler_interface $iohandler + * @param string $phpbb_root_path + * @param string $php_ext + */ + public function __construct(\phpbb\filesystem\filesystem_interface $filesystem, + \phpbb\install\helper\config $install_config, + \phpbb\install\helper\database $db_helper, + \phpbb\install\helper\iohandler\iohandler_interface $iohandler, + $phpbb_root_path, + $php_ext) + { + $this->install_config = $install_config; + $this->db_helper = $db_helper; + $this->filesystem = $filesystem; + $this->iohandler = $iohandler; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + + parent::__construct(true); + } + + /** + * {@inheritdoc} + */ + public function run() + { + $config_written = true; + + // Create config.php + $path_to_config = $this->phpbb_root_path . 'config.' . $this->php_ext; + + $fp = @fopen($path_to_config, 'w'); + if (!$fp) + { + $config_written = false; + } + + $config_content = $this->get_config_data(); + + if (!@fwrite($fp, $config_content)) + { + $config_written = false; + } + + @fclose($fp); + + // chmod config.php to be only readable + if ($config_written) + { + try + { + $this->filesystem->phpbb_chmod($path_to_config, \phpbb\filesystem\filesystem_interface::CHMOD_READ); + } + catch (\phpbb\filesystem\exception\filesystem_exception $e) + { + // Do nothing, the user will get a notice later + } + } + else + { + $this->iohandler->add_error_message('UNABLE_TO_WRITE_CONFIG_FILE'); + $this->iohandler->send_response(); + throw new user_interaction_required_exception(); + } + + // Create a lock file to indicate that there is an install in progress + $fp = @fopen($this->phpbb_root_path . 'cache/install_lock', 'wb'); + if ($fp === false) + { + // 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); + + try + { + $this->filesystem->phpbb_chmod($this->phpbb_root_path . 'cache/install_lock', 0777); + } + catch (\phpbb\filesystem\exception\filesystem_exception $e) + { + // Do nothing, the user will get a notice later + } + } + + /** + * Returns the content which should be dumped to config.php + * + * @param bool $debug If the debug constants should be enabled by default or not + * @param bool $debug_container If the container should be compiled on + * every page load or not + * @param bool $debug_test If the DEBUG_TEST constant should be added + * NOTE: Only for use within the testing framework + * + * @return string content to be written to the config file + */ + protected function get_config_data($debug = false, $debug_container = false, $debug_test = false) + { + $config_content = "install_config->get('dbms'); + $db_driver = $this->db_helper->get_available_dbms($dbms); + $db_driver = $db_driver[$dbms]['DRIVER']; + + $config_data_array = array( + 'dbms' => $db_driver, + 'dbhost' => $this->install_config->get('dbhost'), + 'dbport' => $this->install_config->get('dbport'), + 'dbname' => $this->install_config->get('dbname'), + 'dbuser' => $this->install_config->get('dbuser'), + 'dbpasswd' => $this->install_config->get('dbpasswd'), + 'table_prefix' => $this->install_config->get('table_prefix'), + + 'phpbb_adm_relative_path' => 'adm/', + + 'acm_type' => 'phpbb\cache\driver\file', + ); + + foreach ($config_data_array as $key => $value) + { + $config_content .= "\${$key} = '" . str_replace("'", "\\'", str_replace('\\', '\\\\', $value)) . "';\n"; + } + + $config_content .= "\n@define('PHPBB_INSTALLED', true);\n"; + $config_content .= "// @define('PHPBB_DISPLAY_LOAD_TIME', true);\n"; + + if ($debug_test) + { + $config_content .= "@define('PHPBB_ENVIRONMENT', 'test');\n"; + } + else if ($debug) + { + $config_content .= "@define('PHPBB_ENVIRONMENT', 'development');\n"; + } + else + { + $config_content .= "@define('PHPBB_ENVIRONMENT', 'production');\n"; + } + + if ($debug_container) + { + $config_content .= "@define('DEBUG_CONTAINER', true);\n"; + } + else + { + $config_content .= "// @define('DEBUG_CONTAINER', true);\n"; + } + + if ($debug_test) + { + $config_content .= "@define('DEBUG_TEST', true);\n"; + + // Mandatory for the functional tests, will be removed by PHPBB3-12623 + $config_content .= "@define('DEBUG', true);\n"; + } + + return $config_content; + } + + /** + * {@inheritdoc} + */ + static public function get_step_count() + { + return 1; + } + + /** + * {@inheritdoc} + */ + public function get_task_lang_name() + { + return 'TASK_CREATE_CONFIG_FILE'; + } +} -- cgit v1.2.1 From 597297b169e2ae14684ad1f40c8e083be22b241d Mon Sep 17 00:00:00 2001 From: Mate Bartus Date: Sun, 18 Oct 2015 22:47:04 +0200 Subject: [ticket/14044] Deduplicate the installers PHPBB3-14044 --- .../install_filesystem/task/create_config_file.php | 29 +++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'phpBB/phpbb/install/module/install_filesystem/task/create_config_file.php') 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 337d401216..e0890a929c 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 @@ -50,6 +50,11 @@ class create_config_file extends \phpbb\install\task_base */ protected $php_ext; + /** + * @var array + */ + protected $options; + /** * Constructor * @@ -59,13 +64,15 @@ class create_config_file extends \phpbb\install\task_base * @param \phpbb\install\helper\iohandler\iohandler_interface $iohandler * @param string $phpbb_root_path * @param string $php_ext + * @param array $options */ public function __construct(\phpbb\filesystem\filesystem_interface $filesystem, \phpbb\install\helper\config $install_config, \phpbb\install\helper\database $db_helper, \phpbb\install\helper\iohandler\iohandler_interface $iohandler, $phpbb_root_path, - $php_ext) + $php_ext, + $options = array()) { $this->install_config = $install_config; $this->db_helper = $db_helper; @@ -73,6 +80,11 @@ class create_config_file extends \phpbb\install\task_base $this->iohandler = $iohandler; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; + $this->options = array_merge(array( + 'debug' => false, + 'debug_container' => false, + 'environment' => null, + ), $options); parent::__construct(true); } @@ -93,7 +105,7 @@ class create_config_file extends \phpbb\install\task_base $config_written = false; } - $config_content = $this->get_config_data(); + $config_content = $this->get_config_data($this->options['debug'], $this->options['debug_container'], $this->options['environment']); if (!@fwrite($fp, $config_content)) { @@ -145,15 +157,14 @@ class create_config_file extends \phpbb\install\task_base /** * Returns the content which should be dumped to config.php * - * @param bool $debug If the debug constants should be enabled by default or not - * @param bool $debug_container If the container should be compiled on + * @param bool $debug If the debug constants should be enabled by default or not + * @param bool $debug_container If the container should be compiled on * every page load or not - * @param bool $debug_test If the DEBUG_TEST constant should be added - * NOTE: Only for use within the testing framework + * @param string $environment The environment to use * * @return string content to be written to the config file */ - protected function get_config_data($debug = false, $debug_container = false, $debug_test = false) + protected function get_config_data($debug = false, $debug_container = false, $environment = null) { $config_content = " Date: Thu, 11 Feb 2016 13:18:30 +0100 Subject: [ticket/14462] Further speed improvements - Cache the secondary container - Only initialize tasks/modules that are being used - Add timeout error message in the AJAX UI PHPBB3-14462 --- .../phpbb/install/module/install_filesystem/task/create_config_file.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'phpBB/phpbb/install/module/install_filesystem/task/create_config_file.php') 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); -- cgit v1.2.1