/** * {@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(); } }
/** * {@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']); } } }
/** * {@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); } }