/** * {@inheritdoc} */ public function run() { $this->db->sql_return_on_error(true); $table_prefix = $this->config->get('table_prefix'); $dbms = $this->config->get('dbms'); $dbms_info = $this->database_helper->get_available_dbms($dbms); // Get schema data from file $sql_query = @file_get_contents($this->phpbb_root_path . 'install/schemas/schema_data.sql'); // Clean up SQL $sql_query = $this->replace_dbms_specific_sql($sql_query); $sql_query = preg_replace('# phpbb_([^\\s]*) #i', ' ' . $table_prefix . '\\1 ', $sql_query); $sql_query = preg_replace_callback('#\\{L_([A-Z0-9\\-_]*)\\}#s', array($this, 'lang_replace_callback'), $sql_query); $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)) { $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(); } }
/** * 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); }
/** * 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); }
/** * 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 = "<?php\n"; $config_content .= "// phpBB 3.2.x auto-generated configuration file\n// Do not change anything in this file!\n"; $dbms = $this->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; }
/** * Check database data * * @param string $dbms Selected database type * @param string $dbhost Database host address * @param int $dbport Database port number * @param string $dbuser Database username * @param string $dbpass Database password * @param string $dbname Database name * @param string $table_prefix Database table prefix * * @return bool True if database data is correct, false otherwise */ protected function check_database_data($dbms, $dbhost, $dbport, $dbuser, $dbpass, $dbname, $table_prefix) { $available_dbms = $this->database_helper->get_available_dbms(); $data_valid = true; // Check if PHP has the database extensions for the specified DBMS if (!isset($available_dbms[$dbms])) { $this->io_handler->add_error_message('INST_ERR_NO_DB'); $data_valid = false; } // Validate table prefix $prefix_valid = $this->database_helper->validate_table_prefix($dbms, $table_prefix); if (is_array($prefix_valid)) { foreach ($prefix_valid as $error) { $this->io_handler->add_error_message($error['title'], isset($error['description']) ? $error['description'] : false); } $data_valid = false; } // Try to connect to database if all provided data is valid if ($data_valid) { $connect_test = $this->database_helper->check_database_connection($dbms, $dbhost, $dbport, $dbuser, $dbpass, $dbname, $table_prefix); if (is_array($connect_test)) { foreach ($connect_test as $error) { $this->io_handler->add_error_message($error['title'], isset($error['description']) ? $error['description'] : false); } $data_valid = false; } } return $data_valid; }
/** * Check if any supported DBMS is available */ protected function check_available_dbms() { $available_dbms = $this->database_helper->get_available_dbms(false, true); if ($available_dbms['ANY_DB_SUPPORT']) { $this->set_test_passed(true); return; } $this->response_helper->add_error_message('PHP_SUPPORTED_DB', 'PHP_SUPPORTED_DB_EXPLAIN'); $this->set_test_passed(false); }
/** * {@inheritdoc} */ public function run() { $this->db->sql_return_on_error(true); $table_prefix = $this->config->get('table_prefix'); $dbms = $this->config->get('dbms'); $dbms_info = $this->database_helper->get_available_dbms($dbms); // Get schema data from file $sql_query = @file_get_contents($this->phpbb_root_path . 'install/schemas/schema_data.sql'); // Clean up SQL $sql_query = $this->replace_dbms_specific_sql($sql_query); $sql_query = preg_replace('# phpbb_([^\\s]*) #i', ' ' . $table_prefix . '\\1 ', $sql_query); $sql_query = preg_replace_callback('#\\{L_([A-Z0-9\\-_]*)\\}#s', array($this, 'lang_replace_callback'), $sql_query); $sql_query = $this->database_helper->remove_comments($sql_query); $sql_query = $this->database_helper->split_sql_file($sql_query, $dbms_info[$dbms]['DELIM']); 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']); } } }
/** * Renders settings form * * @param array $error Array of errors */ public function render_settings_form($error = array()) { foreach ($error as $msg) { $this->iohandler->add_error_message($msg); } $dbms_options = array(); foreach ($this->db_helper->get_available_dbms() as $dbms_key => $dbms_array) { $dbms_options[] = array('value' => $dbms_key, 'label' => 'DB_OPTION_' . strtoupper($dbms_key)); } $form_title = 'SPECIFY_OPTIONS'; $form_data = array('src_dbms' => array('label' => 'DBMS', 'type' => 'select', 'options' => $dbms_options), 'src_dbhost' => array('label' => 'DB_HOST', 'description' => 'DB_HOST_EXPLAIN', 'type' => 'text'), 'src_dbport' => array('label' => 'DB_PORT', 'description' => 'DB_PORT_EXPLAIN', 'type' => 'text'), 'src_dbname' => array('label' => 'DB_NAME', 'type' => 'text'), 'src_dbuser' => array('label' => 'DB_USERNAME', 'type' => 'text'), 'src_dbpasswd' => array('label' => 'DB_PASSWORD', 'type' => 'password'), 'src_table_prefix' => array('label' => 'TABLE_PREFIX', 'description' => 'TABLE_PREFIX_EXPLAIN', 'type' => 'text'), 'forum_path' => array('label' => 'FORUM_PATH', 'description' => 'FORUM_PATH_EXPLAIN', 'type' => 'text'), 'refresh' => array('label' => 'REFRESH_PAGE', 'description' => 'REFRESH_PAGE_EXPLAIN', 'type' => 'radio', 'options' => array(array('value' => 0, 'label' => 'NO', 'selected' => true), array('value' => 1, 'label' => 'YES', 'selected' => false))), 'submit' => array('label' => 'SUBMIT', 'type' => 'submit')); if ($this->request->is_ajax()) { $this->iohandler->add_user_form_group($form_title, $form_data); $this->iohandler->send_response(true); } else { $rendered_form = $this->iohandler->generate_form_render_data($form_title, $form_data); $this->template->assign_vars(array('TITLE' => $this->language->lang('STAGE_SETTINGS'), 'CONTENT' => $rendered_form)); } }
/** * {@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} */ public function run() { $this->db->sql_return_on_error(true); $dbms = $this->config->get('dbms'); $dbms_info = $this->database_helper->get_available_dbms($dbms); $schema_name = $dbms_info[$dbms]['SCHEMA']; $delimiter = $dbms_info[$dbms]['DELIM']; $table_prefix = $this->config->get('table_prefix'); if ($dbms === 'mysql') { if (version_compare($this->db->sql_server_info(true), '4.1.3', '>=')) { $schema_name .= '_41'; } else { $schema_name .= '_40'; } } $db_schema_path = $this->phpbb_root_path . 'install/schemas/' . $schema_name . '_schema.sql'; // Load database vendor specific code if there is any if ($this->filesystem->exists($db_schema_path)) { $sql_query = @file_get_contents($db_schema_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); } $change_prefix = false; // 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'); $db_table_schema = json_decode($db_table_schema, true); $change_prefix = true; } else { global $table_prefix; $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(); } 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'); } foreach ($db_table_schema as $table_name => $table_data) { $this->db_tools->sql_create_table($change_prefix ? $table_prefix . substr($table_name, 6) : $table_name, $table_data); } }