示例#1
0
 protected function setUp()
 {
     parent::setUp();
     $this->cache = new phpbb_mock_cache();
     $this->config = new \phpbb\config\config(array('version' => '3.1.0'));
     $this->db = $this->new_dbal();
     $factory = new \phpbb\db\tools\factory();
     $this->db_tools = $factory->get($this->db);
     $this->phpbb_root_path = dirname(__FILE__) . '/';
     $this->phpEx = 'php';
     $this->table_prefix = 'phpbb_';
     $container = new phpbb_mock_container_builder();
     $cache_path = $this->phpbb_root_path . 'cache/twig';
     $context = new \phpbb\template\context();
     $loader = new \phpbb\template\twig\loader(new \phpbb\filesystem\filesystem(), '');
     $filesystem = new \phpbb\filesystem\filesystem();
     $phpbb_path_helper = new \phpbb\path_helper(new \phpbb\symfony_request(new phpbb_mock_request()), $filesystem, $this->getMock('\\phpbb\\request\\request'), $this->phpbb_root_path, $this->phpEx);
     $twig = new \phpbb\template\twig\environment($this->config, $filesystem, $phpbb_path_helper, $cache_path, null, $loader, array('cache' => false, 'debug' => false, 'auto_reload' => true, 'autoescape' => false));
     $container = new phpbb_mock_container_builder();
     $this->migrator = new \phpbb\db\migrator($container, $this->config, $this->db, $this->db_tools, 'phpbb_migrations', $this->phpbb_root_path, 'php', $this->table_prefix, array(), new \phpbb\db\migration\helper());
     $container->set('migrator', $this->migrator);
     $this->extension_manager = new \phpbb\extension\manager($container, $this->db, $this->config, new \phpbb\filesystem\filesystem(), 'phpbb_ext', $this->phpbb_root_path, $this->phpEx, $this->cache);
     global $phpbb_root_path;
     $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $this->phpEx);
     $lang_loader->set_extension_manager($this->extension_manager);
     $lang = new \phpbb\language\language($lang_loader);
     $this->user = new \phpbb\user($lang, '\\phpbb\\datetime');
     $this->template = new phpbb\template\twig\twig($phpbb_path_helper, $this->config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user)));
     $twig->setLexer(new \phpbb\template\twig\lexer($twig));
 }
示例#2
0
 protected function setUp()
 {
     parent::setUp();
     global $phpbb_root_path, $phpEx;
     $this->db = $this->new_dbal();
     $factory = new \phpbb\db\tools\factory();
     $this->migration = new \phpbb\db\migration\data\v310\notification_options_reconvert(new \phpbb\config\config(array()), $this->db, $factory->get($this->db), $phpbb_root_path, $phpEx, 'phpbb_');
 }
示例#3
0
 public function setUp()
 {
     parent::setUp();
     $this->config = new \phpbb\config\config(array());
     $this->db = new \phpbb\db\driver\sqlite();
     $factory = new \phpbb\db\tools\factory();
     $this->db_tools = $factory->get($this->db);
     $this->table_prefix = 'phpbb_';
 }
示例#4
0
 protected function setUp()
 {
     parent::setUp();
     $this->db = $this->new_dbal();
     $factory = new \phpbb\db\tools\factory();
     $this->tools = $factory->get($this->db);
     $this->table_data = array('COLUMNS' => array('c_id' => array('UINT', NULL, 'auto_increment'), 'c_uint' => array('UINT', 4)), 'PRIMARY_KEY' => 'c_id');
     $this->tools->sql_create_table('prefix_table_name', $this->table_data);
     $this->table_exists = true;
 }
示例#5
0
文件: qa_test.php 项目: phpbb/phpbb
 public function setUp()
 {
     global $db, $request, $phpbb_container;
     $db = $this->new_dbal();
     parent::setUp();
     $request = new \phpbb_mock_request();
     $phpbb_container = new \phpbb_mock_container_builder();
     $factory = new \phpbb\db\tools\factory();
     $phpbb_container->set('dbal.tools', $factory->get($db));
     $this->qa = new \phpbb\captcha\plugins\qa('phpbb_captcha_questions', 'phpbb_captcha_answers', 'phpbb_qa_confirm');
 }
示例#6
0
 /**
  * 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);
 }
示例#7
0
 public function setUp()
 {
     parent::setUp();
     $this->db = $this->new_dbal();
     $factory = new \phpbb\db\tools\factory();
     $this->db_tools = $factory->get($this->db);
     $this->config = new \phpbb\config\db($this->db, new phpbb_mock_cache(), 'phpbb_config');
     $tools = array(new \phpbb\db\migration\tool\config($this->config));
     $container = new phpbb_mock_container_builder();
     $this->migrator = new \phpbb\db\migrator($container, $this->config, $this->db, $this->db_tools, 'phpbb_migrations', dirname(__FILE__) . '/../../phpBB/', 'php', 'phpbb_', $tools, new \phpbb\db\migration\helper());
     $container->set('migrator', $this->migrator);
     $container->set('dispatcher', new phpbb_mock_event_dispatcher());
     $this->extension_manager = new \phpbb\extension\manager($container, $this->db, $this->config, new phpbb\filesystem\filesystem(), 'phpbb_ext', dirname(__FILE__) . '/../../phpBB/', 'php', null);
 }
示例#8
0
    public function test_convert()
    {
        $this->migration->update_timezones(0);
        $sql = 'SELECT user_id, user_timezone
			FROM phpbb_users
			ORDER BY user_id ASC';
        $result = $this->db->sql_query($sql);
        while ($row = $this->db->sql_fetchrow($result)) {
            $this->assertEquals($this->expected_results[$row['user_id']], $row['user_timezone']);
        }
        $this->db->sql_freeresult($result);
        $factory = new \phpbb\db\tools\factory();
        $db_tools = $factory->get($this->db);
        // Remove the user_dst field again
        $db_tools->sql_column_remove('phpbb_users', 'user_dst');
    }
 public static function setUpBeforeClass()
 {
     global $phpbb_root_path, $phpEx;
     $setup_extensions = static::setup_extensions();
     $finder = new \phpbb\finder(new \phpbb\filesystem\filesystem(), $phpbb_root_path, null, $phpEx);
     $finder->core_path('phpbb/db/migration/data/');
     if (!empty($setup_extensions)) {
         $finder->set_extensions($setup_extensions)->extension_directory('/migrations');
     }
     $classes = $finder->get_classes();
     $schema_sha1 = sha1(serialize($classes));
     self::$schema_file = __DIR__ . '/../tmp/' . $schema_sha1 . '.json';
     self::$install_schema_file = __DIR__ . '/../../phpBB/install/schemas/schema.json';
     if (!file_exists(self::$schema_file)) {
         global $table_prefix;
         $db = new \phpbb\db\driver\sqlite();
         $factory = new \phpbb\db\tools\factory();
         $db_tools = $factory->get($db, true);
         $schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, $db_tools, $phpbb_root_path, $phpEx, $table_prefix);
         file_put_contents(self::$schema_file, json_encode($schema_generator->get_schema()));
     }
     copy(self::$schema_file, self::$install_schema_file);
     parent::setUpBeforeClass();
 }
示例#10
0
 /**
  * Validates settings form
  *
  * @param string	$convertor
  */
 public function proccess_settings_form($convertor)
 {
     global $phpbb_root_path, $phpEx, $get_info;
     $phpbb_root_path = $this->phpbb_root_path;
     $phpEx = $this->php_ext;
     $get_info = true;
     require_once $this->phpbb_root_path . 'includes/constants.' . $this->php_ext;
     require_once $this->phpbb_root_path . 'includes/functions_convert.' . $this->php_ext;
     // Include convertor if available
     $convertor_file_path = $this->phpbb_root_path . 'install/convertors/convert_' . $convertor . '.' . $this->php_ext;
     include $convertor_file_path;
     // We expect to have an AJAX request here
     $src_dbms = $this->request->variable('src_dbms', $convertor_data['dbms']);
     $src_dbhost = $this->request->variable('src_dbhost', $convertor_data['dbhost']);
     $src_dbport = $this->request->variable('src_dbport', $convertor_data['dbport']);
     $src_dbuser = $this->request->variable('src_dbuser', $convertor_data['dbuser']);
     $src_dbpasswd = $this->request->variable('src_dbpasswd', $convertor_data['dbpasswd']);
     $src_dbname = $this->request->variable('src_dbname', $convertor_data['dbname']);
     $src_table_prefix = $this->request->variable('src_table_prefix', $convertor_data['table_prefix']);
     $forum_path = $this->request->variable('forum_path', $convertor_data['forum_path']);
     $refresh = $this->request->variable('refresh', 1);
     // Default URL of the old board
     // @todo Are we going to use this for attempting to convert URL references in posts, or should we remove it?
     //		-> We should convert old urls to the new relative urls format
     // $src_url = $request->variable('src_url', 'Not in use at the moment');
     // strip trailing slash from old forum path
     $forum_path = strlen($forum_path) && $forum_path[strlen($forum_path) - 1] == '/' ? substr($forum_path, 0, -1) : $forum_path;
     $error = array();
     if (!file_exists($this->phpbb_root_path . $forum_path . '/' . $test_file)) {
         $error[] = $this->language->lang('COULD_NOT_FIND_PATH', $forum_path);
     }
     $connect_test = false;
     $available_dbms = $this->db_helper->get_available_dbms(false, true, true);
     if (!isset($available_dbms[$src_dbms]) || !$available_dbms[$src_dbms]['AVAILABLE']) {
         $error[] = $this->language->lang('INST_ERR_NO_DB');
     } else {
         $connect_test = $this->db_helper->check_database_connection($src_dbms, $src_dbhost, $src_dbport, $src_dbuser, $src_dbpasswd, $src_dbname, $src_table_prefix);
     }
     extract($this->config_php_file->get_all());
     // The forum prefix of the old and the new forum can only be the same if two different databases are used.
     if ($src_table_prefix === $table_prefix && $src_dbms === $dbms && $src_dbhost === $dbhost && $src_dbport === $dbport && $src_dbname === $dbname) {
         $error[] = $this->language->lang('TABLE_PREFIX_SAME', $src_table_prefix);
     }
     if (!$connect_test) {
         $error[] = $this->language->lang('INST_ERR_DB_CONNECT');
     }
     $src_dbms = $this->config_php_file->convert_30_dbms_to_31($src_dbms);
     // Check table prefix
     if (empty($error)) {
         // initiate database connection to old db if old and new db differ
         global $src_db, $same_db;
         $src_db = $same_db = false;
         if ($src_dbms != $dbms || $src_dbhost != $dbhost || $src_dbport != $dbport || $src_dbname != $dbname || $src_dbuser != $dbuser) {
             /** @var \phpbb\db\driver\driver_interface $src_db */
             $src_db = new $src_dbms();
             $src_db->sql_connect($src_dbhost, $src_dbuser, htmlspecialchars_decode($src_dbpasswd), $src_dbname, $src_dbport, false, true);
             $same_db = false;
         } else {
             $src_db = $this->db;
             $same_db = true;
         }
         $src_db->sql_return_on_error(true);
         $this->db->sql_return_on_error(true);
         // Try to select one row from the first table to see if the prefix is OK
         $result = $src_db->sql_query_limit('SELECT * FROM ' . $src_table_prefix . $tables[0], 1);
         if (!$result) {
             $prefixes = array();
             $db_tools_factory = new \phpbb\db\tools\factory();
             $db_tools = $db_tools_factory->get($src_db);
             $tables_existing = $db_tools->sql_list_tables();
             $tables_existing = array_map('strtolower', $tables_existing);
             foreach ($tables_existing as $table_name) {
                 compare_table($tables, $table_name, $prefixes);
             }
             unset($tables_existing);
             foreach ($prefixes as $prefix => $count) {
                 if ($count >= sizeof($tables)) {
                     $possible_prefix = $prefix;
                     break;
                 }
             }
             $msg = '';
             if (!empty($convertor_data['table_prefix'])) {
                 $msg .= $this->language->lang_array('DEFAULT_PREFIX_IS', array($convertor_data['forum_name'], $convertor_data['table_prefix']));
             }
             if (!empty($possible_prefix)) {
                 $msg .= '<br />';
                 $msg .= $possible_prefix == '*' ? $this->language->lang('BLANK_PREFIX_FOUND') : $this->language->lang_array('PREFIX_FOUND', array($possible_prefix));
                 $src_table_prefix = $possible_prefix == '*' ? '' : $possible_prefix;
             }
             $error[] = $msg;
         }
         $src_db->sql_freeresult($result);
         $src_db->sql_return_on_error(false);
     }
     if (empty($error)) {
         // Save convertor Status
         $this->config->set('convert_progress', serialize(array('step' => '', 'table_prefix' => $src_table_prefix, 'tag' => $convertor)), false);
         $this->config->set('convert_db_server', serialize(array('dbms' => $src_dbms, 'dbhost' => $src_dbhost, 'dbport' => $src_dbport, 'dbname' => $src_dbname)), false);
         $this->config->set('convert_db_user', serialize(array('dbuser' => $src_dbuser, 'dbpasswd' => $src_dbpasswd)), false);
         // Save options
         $this->config->set('convert_options', serialize(array('forum_path' => $this->phpbb_root_path . $forum_path, 'refresh' => $refresh)), false);
         $url = $this->controller_helper->route('phpbb_convert_convert', array('converter' => $convertor));
         $this->iohandler->redirect($url);
         $this->iohandler->send_response(true);
     } else {
         $this->render_settings_form($error);
     }
 }
示例#11
0
/**
* Used to test whether we are able to connect to the database the user has specified
* and identify any problems (eg there are already tables with the names we want to use
* @param	array	$dbms should be of the format of an element of the array returned by {@link get_available_dbms get_available_dbms()}
*					necessary extensions should be loaded already
*/
function connect_check_db($error_connect, &$error, $dbms_details, $table_prefix, $dbhost, $dbuser, $dbpasswd, $dbname, $dbport, $prefix_may_exist = false, $load_dbal = true, $unicode_check = true)
{
    global $phpbb_root_path, $phpEx, $config, $lang, $phpbb_filesystem;
    $dbms = $dbms_details['DRIVER'];
    // Instantiate it and set return on error true
    $db = new $dbms();
    $db->sql_return_on_error(true);
    // Check that we actually have a database name before going any further.....
    if ($dbms_details['DRIVER'] != 'phpbb\\db\\driver\\sqlite' && $dbms_details['DRIVER'] != 'phpbb\\db\\driver\\sqlite3' && $dbms_details['DRIVER'] != 'phpbb\\db\\driver\\oracle' && $dbname === '') {
        $error[] = $lang['INST_ERR_DB_NO_NAME'];
        return false;
    }
    // Make sure we don't have a daft user who thinks having the SQLite database in the forum directory is a good idea
    if (($dbms_details['DRIVER'] == 'phpbb\\db\\driver\\sqlite' || $dbms_details['DRIVER'] == 'phpbb\\db\\driver\\sqlite3') && stripos($phpbb_filesystem->realpath($dbhost), $phpbb_filesystem->realpath('../')) === 0) {
        $error[] = $lang['INST_ERR_DB_FORUM_PATH'];
        return false;
    }
    // Check the prefix length to ensure that index names are not too long and does not contain invalid characters
    switch ($dbms_details['DRIVER']) {
        case 'phpbb\\db\\driver\\mysql':
        case 'phpbb\\db\\driver\\mysqli':
            if (strspn($table_prefix, '-./\\') !== 0) {
                $error[] = $lang['INST_ERR_PREFIX_INVALID'];
                return false;
            }
            // no break;
        // no break;
        case 'phpbb\\db\\driver\\postgres':
            $prefix_length = 36;
            break;
        case 'phpbb\\db\\driver\\mssql':
        case 'phpbb\\db\\driver\\mssql_odbc':
        case 'phpbb\\db\\driver\\mssqlnative':
            $prefix_length = 90;
            break;
        case 'phpbb\\db\\driver\\sqlite':
        case 'phpbb\\db\\driver\\sqlite3':
            $prefix_length = 200;
            break;
        case 'phpbb\\db\\driver\\oracle':
            $prefix_length = 6;
            break;
    }
    if (strlen($table_prefix) > $prefix_length) {
        $error[] = sprintf($lang['INST_ERR_PREFIX_TOO_LONG'], $prefix_length);
        return false;
    }
    // Try and connect ...
    if (is_array($db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true))) {
        $db_error = $db->sql_error();
        $error[] = $lang['INST_ERR_DB_CONNECT'] . '<br />' . ($db_error['message'] ? utf8_convert_message($db_error['message']) : $lang['INST_ERR_DB_NO_ERROR']);
    } else {
        // Likely matches for an existing phpBB installation
        if (!$prefix_may_exist) {
            $temp_prefix = strtolower($table_prefix);
            $table_ary = array($temp_prefix . 'attachments', $temp_prefix . 'config', $temp_prefix . 'sessions', $temp_prefix . 'topics', $temp_prefix . 'users');
            $db_tools_factory = new \phpbb\db\tools\factory();
            $db_tools = $db_tools_factory->get($db);
            $tables = $db_tools->sql_list_tables();
            $tables = array_map('strtolower', $tables);
            $table_intersect = array_intersect($tables, $table_ary);
            if (sizeof($table_intersect)) {
                $error[] = $lang['INST_ERR_PREFIX'];
            }
        }
        // Make sure that the user has selected a sensible DBAL for the DBMS actually installed
        switch ($dbms_details['DRIVER']) {
            case 'phpbb\\db\\driver\\mysqli':
                if (version_compare(mysqli_get_server_info($db->get_db_connect_id()), '4.1.3', '<')) {
                    $error[] = $lang['INST_ERR_DB_NO_MYSQLI'];
                }
                break;
            case 'phpbb\\db\\driver\\sqlite':
                if (version_compare(sqlite_libversion(), '2.8.2', '<')) {
                    $error[] = $lang['INST_ERR_DB_NO_SQLITE'];
                }
                break;
            case 'phpbb\\db\\driver\\sqlite3':
                $version = \SQLite3::version();
                if (version_compare($version['versionString'], '3.6.15', '<')) {
                    $error[] = $lang['INST_ERR_DB_NO_SQLITE3'];
                }
                break;
            case 'phpbb\\db\\driver\\oracle':
                if ($unicode_check) {
                    $sql = "SELECT *\n\t\t\t\t\t\tFROM NLS_DATABASE_PARAMETERS\n\t\t\t\t\t\tWHERE PARAMETER = 'NLS_RDBMS_VERSION'\n\t\t\t\t\t\t\tOR PARAMETER = 'NLS_CHARACTERSET'";
                    $result = $db->sql_query($sql);
                    while ($row = $db->sql_fetchrow($result)) {
                        $stats[$row['parameter']] = $row['value'];
                    }
                    $db->sql_freeresult($result);
                    if (version_compare($stats['NLS_RDBMS_VERSION'], '9.2', '<') && $stats['NLS_CHARACTERSET'] !== 'UTF8') {
                        $error[] = $lang['INST_ERR_DB_NO_ORACLE'];
                    }
                }
                break;
            case 'phpbb\\db\\driver\\postgres':
                if ($unicode_check) {
                    $sql = "SHOW server_encoding;";
                    $result = $db->sql_query($sql);
                    $row = $db->sql_fetchrow($result);
                    $db->sql_freeresult($result);
                    if ($row['server_encoding'] !== 'UNICODE' && $row['server_encoding'] !== 'UTF8') {
                        $error[] = $lang['INST_ERR_DB_NO_POSTGRES'];
                    }
                }
                break;
        }
    }
    if ($error_connect && (!isset($error) || !sizeof($error))) {
        return true;
    }
    return false;
}
示例#12
0
 /**
  */
 function get_convert_settings($sub)
 {
     global $lang, $language, $template, $db, $phpbb_root_path, $phpEx, $config, $cache, $phpbb_config_php_file;
     extract($phpbb_config_php_file->get_all());
     require $phpbb_root_path . 'includes/constants.' . $phpEx;
     require $phpbb_root_path . 'includes/functions_convert.' . $phpEx;
     $dbms = $phpbb_config_php_file->convert_30_dbms_to_31($dbms);
     $db = new $dbms();
     $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true);
     unset($dbpasswd);
     $this->page_title = $lang['STAGE_SETTINGS'];
     // We need to fill the config to let internal functions correctly work
     $config = new \phpbb\config\db($db, new \phpbb\cache\driver\dummy(), CONFIG_TABLE);
     $convertor_tag = $request->variable('tag', '');
     if (empty($convertor_tag)) {
         $this->p_master->error($lang['NO_CONVERT_SPECIFIED'], __LINE__, __FILE__);
     }
     $get_info = true;
     // check security implications of direct inclusion
     $convertor_tag = basename($convertor_tag);
     if (!file_exists('./convertors/convert_' . $convertor_tag . '.' . $phpEx)) {
         $this->p_master->error($lang['CONVERT_NOT_EXIST'], __LINE__, __FILE__);
     }
     include './convertors/convert_' . $convertor_tag . '.' . $phpEx;
     // The test_file is a file that should be present in the location of the old board.
     if (!isset($test_file)) {
         $this->p_master->error($lang['DEV_NO_TEST_FILE'], __LINE__, __FILE__);
     }
     $submit = isset($_POST['submit']) ? true : false;
     $src_dbms = $request->variable('src_dbms', $convertor_data['dbms']);
     $src_dbhost = $request->variable('src_dbhost', $convertor_data['dbhost']);
     $src_dbport = $request->variable('src_dbport', $convertor_data['dbport']);
     $src_dbuser = $request->variable('src_dbuser', $convertor_data['dbuser']);
     $src_dbpasswd = $request->variable('src_dbpasswd', $convertor_data['dbpasswd']);
     $src_dbname = $request->variable('src_dbname', $convertor_data['dbname']);
     $src_table_prefix = $request->variable('src_table_prefix', $convertor_data['table_prefix']);
     $forum_path = $request->variable('forum_path', $convertor_data['forum_path']);
     $refresh = $request->variable('refresh', 1);
     // Default URL of the old board
     // @todo Are we going to use this for attempting to convert URL references in posts, or should we remove it?
     //		-> We should convert old urls to the new relative urls format
     // $src_url = $request->variable('src_url', 'Not in use at the moment');
     // strip trailing slash from old forum path
     $forum_path = strlen($forum_path) && $forum_path[strlen($forum_path) - 1] == '/' ? substr($forum_path, 0, -1) : $forum_path;
     $error = array();
     if ($submit) {
         if (!@file_exists('./../' . $forum_path . '/' . $test_file)) {
             $error[] = sprintf($lang['COULD_NOT_FIND_PATH'], $forum_path);
         }
         $connect_test = false;
         $available_dbms = get_available_dbms(false, true, true);
         if (!isset($available_dbms[$src_dbms]) || !$available_dbms[$src_dbms]['AVAILABLE']) {
             $error[] = $lang['INST_ERR_NO_DB'];
             $connect_test = false;
         } else {
             $connect_test = connect_check_db(true, $error, $available_dbms[$src_dbms], $src_table_prefix, $src_dbhost, $src_dbuser, htmlspecialchars_decode($src_dbpasswd), $src_dbname, $src_dbport, true, $src_dbms == $dbms ? false : true, false);
         }
         // The forum prefix of the old and the new forum can only be the same if two different databases are used.
         if ($src_table_prefix == $table_prefix && $src_dbms == $dbms && $src_dbhost == $dbhost && $src_dbport == $dbport && $src_dbname == $dbname) {
             $error[] = sprintf($lang['TABLE_PREFIX_SAME'], $src_table_prefix);
         }
         $src_dbms = $phpbb_config_php_file->convert_30_dbms_to_31($src_dbms);
         // Check table prefix
         if (!sizeof($error)) {
             // initiate database connection to old db if old and new db differ
             global $src_db, $same_db;
             $src_db = $same_db = false;
             if ($src_dbms != $dbms || $src_dbhost != $dbhost || $src_dbport != $dbport || $src_dbname != $dbname || $src_dbuser != $dbuser) {
                 $src_db = new $src_dbms();
                 $src_db->sql_connect($src_dbhost, $src_dbuser, htmlspecialchars_decode($src_dbpasswd), $src_dbname, $src_dbport, false, true);
                 $same_db = false;
             } else {
                 $src_db = $db;
                 $same_db = true;
             }
             $src_db->sql_return_on_error(true);
             $db->sql_return_on_error(true);
             // Try to select one row from the first table to see if the prefix is OK
             $result = $src_db->sql_query_limit('SELECT * FROM ' . $src_table_prefix . $tables[0], 1);
             if (!$result) {
                 $prefixes = array();
                 $db_tools_factory = new \phpbb\db\tools\factory();
                 $db_tools = $db_tools_factory->get($src_db);
                 $tables_existing = $db_tools->sql_list_tables();
                 $tables_existing = array_map('strtolower', $tables_existing);
                 foreach ($tables_existing as $table_name) {
                     compare_table($tables, $table_name, $prefixes);
                 }
                 unset($tables_existing);
                 foreach ($prefixes as $prefix => $count) {
                     if ($count >= sizeof($tables)) {
                         $possible_prefix = $prefix;
                         break;
                     }
                 }
                 $msg = '';
                 if (!empty($convertor_data['table_prefix'])) {
                     $msg .= sprintf($lang['DEFAULT_PREFIX_IS'], $convertor_data['forum_name'], $convertor_data['table_prefix']);
                 }
                 if (!empty($possible_prefix)) {
                     $msg .= '<br />';
                     $msg .= $possible_prefix == '*' ? $lang['BLANK_PREFIX_FOUND'] : sprintf($lang['PREFIX_FOUND'], $possible_prefix);
                     $src_table_prefix = $possible_prefix == '*' ? '' : $possible_prefix;
                 }
                 $error[] = $msg;
             }
             $src_db->sql_freeresult($result);
             $src_db->sql_return_on_error(false);
         }
         if (!sizeof($error)) {
             // Save convertor Status
             $config->set('convert_progress', serialize(array('step' => '', 'table_prefix' => $src_table_prefix, 'tag' => $convertor_tag)), false);
             $config->set('convert_db_server', serialize(array('dbms' => $src_dbms, 'dbhost' => $src_dbhost, 'dbport' => $src_dbport, 'dbname' => $src_dbname)), false);
             $config->set('convert_db_user', serialize(array('dbuser' => $src_dbuser, 'dbpasswd' => $src_dbpasswd)), false);
             // Save options
             $config->set('convert_options', serialize(array('forum_path' => './../' . $forum_path, 'refresh' => $refresh)), false);
             $template->assign_block_vars('checks', array('TITLE' => $lang['VERIFY_OPTIONS'], 'RESULT' => $lang['CONVERT_SETTINGS_VERIFIED']));
             $template->assign_vars(array('L_SUBMIT' => $lang['BEGIN_CONVERT'], 'U_ACTION' => $this->p_master->module_url . "?mode={$this->mode}&amp;sub=in_progress&amp;tag={$convertor_tag}&amp;language={$language}"));
             return;
         } else {
             $template->assign_block_vars('checks', array('TITLE' => $lang['VERIFY_OPTIONS'], 'RESULT' => '<b style="color:red">' . implode('<br />', $error) . '</b>'));
         }
     }
     // end submit
     foreach ($this->convert_options as $config_key => $vars) {
         if (!is_array($vars) && strpos($config_key, 'legend') === false) {
             continue;
         }
         if (strpos($config_key, 'legend') !== false) {
             $template->assign_block_vars('options', array('S_LEGEND' => true, 'LEGEND' => $lang[$vars]));
             continue;
         }
         $options = isset($vars['options']) ? $vars['options'] : '';
         $template->assign_block_vars('options', array('KEY' => $config_key, 'TITLE' => $lang[$vars['lang']], 'S_EXPLAIN' => $vars['explain'], 'S_LEGEND' => false, 'TITLE_EXPLAIN' => $vars['explain'] ? $lang[$vars['lang'] . '_EXPLAIN'] : '', 'CONTENT' => $this->p_master->input_field($config_key, $vars['type'], ${$config_key}, $options)));
     }
     $template->assign_vars(array('TITLE' => $lang['STAGE_SETTINGS'], 'BODY' => $lang['CONV_OPTIONS_BODY'], 'L_SUBMIT' => $lang['BEGIN_CONVERT'], 'U_ACTION' => $this->p_master->module_url . "?mode={$this->mode}&amp;sub=settings&amp;tag={$convertor_tag}&amp;language={$language}"));
 }
示例#13
0
 /**
  * Check if the user provided database parameters are correct
  *
  * This function checks the database connection data and also checks for
  * any other problems that could cause an error during the installation
  * such as if there is any database table names conflicting.
  *
  * Note: The function assumes that $table_prefix has been already validated
  * with validate_table_prefix().
  *
  * @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 array|bool	Returns true if test is successful, array of errors otherwise
  */
 public function check_database_connection($dbms, $dbhost, $dbport, $dbuser, $dbpass, $dbname, $table_prefix)
 {
     $dbms_info = $this->get_available_dbms($dbms);
     $dbms_info = $dbms_info[$dbms];
     $errors = array();
     // Instantiate it and set return on error true
     /** @var \phpbb\db\driver\driver_interface $db */
     $db = new $dbms_info['DRIVER']();
     $db->sql_return_on_error(true);
     // Check that we actually have a database name before going any further
     if (!in_array($dbms_info['SCHEMA'], array('sqlite', 'oracle'), true) && $dbname === '') {
         $errors[] = array('title' => 'INST_ERR_DB_NO_NAME');
     }
     // Make sure we don't have a daft user who thinks having the SQLite database in the forum directory is a good idea
     if ($dbms_info['SCHEMA'] === 'sqlite' && stripos($this->filesystem->realpath($dbhost), $this->filesystem->realpath($this->phpbb_root_path) === 0)) {
         $errors[] = array('title' => 'INST_ERR_DB_FORUM_PATH');
     }
     // Try to connect to db
     if (is_array($db->sql_connect($dbhost, $dbuser, $dbpass, $dbname, $dbport, false, true))) {
         $db_error = $db->sql_error();
         $errors[] = array('title' => 'INST_ERR_DB_CONNECT', 'description' => $db_error['message'] ? utf8_convert_message($db_error['message']) : 'INST_ERR_DB_NO_ERROR');
     } else {
         // Check if there is any table name collisions
         $temp_prefix = strtolower($table_prefix);
         $table_ary = array($temp_prefix . 'attachments', $temp_prefix . 'config', $temp_prefix . 'sessions', $temp_prefix . 'topics', $temp_prefix . 'users');
         $db_tools_factory = new \phpbb\db\tools\factory();
         $db_tools = $db_tools_factory->get($db);
         $tables = $db_tools->sql_list_tables();
         $tables = array_map('strtolower', $tables);
         $table_intersect = array_intersect($tables, $table_ary);
         if (sizeof($table_intersect)) {
             $errors[] = array('title' => 'INST_ERR_PREFIX');
         }
         // Check if database version is supported
         switch ($dbms) {
             case 'mysqli':
                 if (version_compare($db->sql_server_info(true), '4.1.3', '<')) {
                     $errors[] = array('title' => 'INST_ERR_DB_NO_MYSQLI');
                 }
                 break;
             case 'sqlite':
                 if (version_compare($db->sql_server_info(true), '2.8.2', '<')) {
                     $errors[] = array('title' => 'INST_ERR_DB_NO_SQLITE');
                 }
                 break;
             case 'sqlite3':
                 if (version_compare($db->sql_server_info(true), '3.6.15', '<')) {
                     $errors[] = array('title' => 'INST_ERR_DB_NO_SQLITE3');
                 }
                 break;
             case 'oracle':
                 $sql = "SELECT *\n\t\t\t\t\t\tFROM NLS_DATABASE_PARAMETERS\n\t\t\t\t\t\tWHERE PARAMETER = 'NLS_RDBMS_VERSION'\n\t\t\t\t\t\t\tOR PARAMETER = 'NLS_CHARACTERSET'";
                 $result = $db->sql_query($sql);
                 while ($row = $db->sql_fetchrow($result)) {
                     $stats[$row['parameter']] = $row['value'];
                 }
                 $db->sql_freeresult($result);
                 if (version_compare($stats['NLS_RDBMS_VERSION'], '9.2', '<') && $stats['NLS_CHARACTERSET'] !== 'UTF8') {
                     $errors[] = array('title' => 'INST_ERR_DB_NO_ORACLE');
                 }
                 break;
             case 'postgres':
                 $sql = "SHOW server_encoding;";
                 $result = $db->sql_query($sql);
                 $row = $db->sql_fetchrow($result);
                 $db->sql_freeresult($result);
                 if ($row['server_encoding'] !== 'UNICODE' && $row['server_encoding'] !== 'UTF8') {
                     $errors[] = array('title' => 'INST_ERR_DB_NO_POSTGRES');
                 }
                 break;
         }
     }
     return empty($errors) ? true : $errors;
 }
示例#14
0
function phpbb_convert_timezone($timezone)
{
    global $config, $db, $phpbb_root_path, $phpEx, $table_prefix;
    $factory = new \phpbb\db\tools\factory();
    $timezone_migration = new \phpbb\db\migration\data\v310\timezone($config, $db, $factory->get($db), $phpbb_root_path, $phpEx, $table_prefix);
    return $timezone_migration->convert_phpbb30_timezone($timezone, 0);
}
 /**
  * Compile the correct schema filename (as per create_schema_files) and
  * load it into the database.
  */
 protected function load_schema_from_file($directory, \phpbb\db\driver\driver_interface $db)
 {
     $schema = $this->dbms['SCHEMA'];
     if ($this->config['dbms'] == 'phpbb\\db\\driver\\mysql') {
         $sth = $this->pdo->query('SELECT VERSION() AS version');
         $row = $sth->fetch(PDO::FETCH_ASSOC);
         if (version_compare($row['version'], '4.1.3', '>=')) {
             $schema .= '_41';
         } else {
             $schema .= '_40';
         }
     }
     $filename = $directory . $schema . '_schema.sql';
     if (file_exists($filename)) {
         global $phpbb_root_path;
         $queries = file_get_contents($filename);
         $db_helper = new \phpbb\install\helper\database(new \phpbb\filesystem\filesystem(), $phpbb_root_path);
         $sql = $db_helper->remove_comments($queries);
         $sql = $db_helper->split_sql_file($sql, $this->dbms['DELIM']);
         foreach ($sql as $query) {
             $this->pdo->exec($query);
         }
     }
     // Ok we have the db info go ahead and work on building the table
     if (file_exists($directory . 'schema.json')) {
         $db_table_schema = file_get_contents($directory . 'schema.json');
         $db_table_schema = json_decode($db_table_schema, true);
     } else {
         global $phpbb_root_path, $phpEx, $table_prefix;
         $finder = new \phpbb\finder(new \phpbb\filesystem\filesystem(), $phpbb_root_path, null, $phpEx);
         $classes = $finder->core_path('phpbb/db/migration/data/')->get_classes();
         $db = new \phpbb\db\driver\sqlite3();
         $factory = new \phpbb\db\tools\factory();
         $db_tools = $factory->get($db, true);
         $schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, $db_tools, $phpbb_root_path, $phpEx, $table_prefix);
         $db_table_schema = $schema_generator->get_schema();
     }
     $factory = new \phpbb\db\tools\factory();
     $db_tools = $factory->get($db, true);
     foreach ($db_table_schema as $table_name => $table_data) {
         $queries = $db_tools->sql_create_table($table_name, $table_data);
         foreach ($queries as $query) {
             if ($query === 'begin') {
                 $this->pdo->beginTransaction();
             } else {
                 if ($query === 'commit') {
                     $this->pdo->commit();
                 } else {
                     $this->pdo->exec($query);
                 }
             }
         }
     }
 }
 protected function get_extension_manager()
 {
     global $phpbb_root_path, $phpEx;
     $config = new \phpbb\config\config(array());
     $db = $this->get_db();
     $factory = new \phpbb\db\tools\factory();
     $db_tools = $factory->get($db);
     $container = new phpbb_mock_container_builder();
     $migrator = new \phpbb\db\migrator($container, $config, $db, $db_tools, self::$config['table_prefix'] . 'migrations', $phpbb_root_path, $phpEx, self::$config['table_prefix'], array(), new \phpbb\db\migration\helper());
     $container->set('migrator', $migrator);
     $container->set('dispatcher', new phpbb_mock_event_dispatcher());
     $extension_manager = new \phpbb\extension\manager($container, $db, $config, new phpbb\filesystem\filesystem(), self::$config['table_prefix'] . 'ext', dirname(__FILE__) . '/', $phpEx, $this->get_cache_driver());
     return $extension_manager;
 }
示例#17
0
 /**
  * {@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);
 }
示例#18
0
 /**
  * {@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);
     }
 }
示例#19
0
/**
 * Get tables of a database
 *
 * @deprecated 3.1.0 (To be removed: 3.3.0)
 */
function get_tables(&$db)
{
    $db_tools_factory = new \phpbb\db\tools\factory();
    $db_tools = $db_tools_factory->get($db);
    return $db_tools->sql_list_tables();
}
示例#20
0
 protected function create_extension_manager($with_cache = true)
 {
     $config = new \phpbb\config\config(array('version' => PHPBB_VERSION));
     $db = $this->new_dbal();
     $factory = new \phpbb\db\tools\factory();
     $db_tools = $factory->get($db);
     $phpbb_root_path = __DIR__ . './../../phpBB/';
     $php_ext = 'php';
     $table_prefix = 'phpbb_';
     $container = new phpbb_mock_container_builder();
     $migrator = new \phpbb\db\migrator($container, $config, $db, $db_tools, 'phpbb_migrations', $phpbb_root_path, $php_ext, $table_prefix, array(), new \phpbb\db\migration\helper());
     $container->set('migrator', $migrator);
     return new \phpbb\extension\manager($container, $db, $config, new \phpbb\filesystem\filesystem(), 'phpbb_ext', dirname(__FILE__) . '/', $php_ext, $with_cache ? new phpbb_mock_cache() : null);
 }
示例#21
0
 /**
  * Load the contents of the schema into the database and then alter it based on what has been input during the installation
  */
 function load_schema($mode, $sub)
 {
     global $db, $lang, $template, $phpbb_root_path, $phpEx, $request;
     $this->page_title = $lang['STAGE_CREATE_TABLE'];
     $s_hidden_fields = '';
     // Obtain any submitted data
     $data = $this->get_submitted_data();
     if ($data['dbms'] == '') {
         // Someone's been silly and tried calling this page direct
         // So we send them back to the start to do it again properly
         $this->p_master->redirect("index.{$phpEx}?mode=install");
     }
     // HTTP_HOST is having the correct browser url in most cases...
     $server_name = strtolower(htmlspecialchars_decode($request->header('Host', $request->server('SERVER_NAME'))));
     $referer = strtolower($request->header('Referer'));
     // HTTP HOST can carry a port number...
     if (strpos($server_name, ':') !== false) {
         $server_name = substr($server_name, 0, strpos($server_name, ':'));
     }
     $cookie_domain = $data['server_name'] != '' ? $data['server_name'] : $server_name;
     // Try to come up with the best solution for cookie domain...
     if (strpos($cookie_domain, 'www.') === 0) {
         $cookie_domain = str_replace('www.', '.', $cookie_domain);
     }
     // If we get here and the extension isn't loaded it should be safe to just go ahead and load it
     $available_dbms = get_available_dbms($data['dbms']);
     if (!isset($available_dbms[$data['dbms']])) {
         // Someone's been silly and tried providing a non-existant dbms
         $this->p_master->redirect("index.{$phpEx}?mode=install");
     }
     $dbms = $available_dbms[$data['dbms']]['DRIVER'];
     // Instantiate the database
     $db = new $dbms();
     $db->sql_connect($data['dbhost'], $data['dbuser'], htmlspecialchars_decode($data['dbpasswd']), $data['dbname'], $data['dbport'], false, false);
     // NOTE: trigger_error does not work here.
     $db->sql_return_on_error(true);
     // If mysql is chosen, we need to adjust the schema filename slightly to reflect the correct version. ;)
     if ($data['dbms'] == 'mysql') {
         if (version_compare($db->sql_server_info(true), '4.1.3', '>=')) {
             $available_dbms[$data['dbms']]['SCHEMA'] .= '_41';
         } else {
             $available_dbms[$data['dbms']]['SCHEMA'] .= '_40';
         }
     }
     // Ok we have the db info go ahead and read in the relevant schema
     // and work on building the table
     $dbms_schema = 'schemas/' . $available_dbms[$data['dbms']]['SCHEMA'] . '_schema.sql';
     // How should we treat this schema?
     $delimiter = $available_dbms[$data['dbms']]['DELIM'];
     if (file_exists($dbms_schema)) {
         $sql_query = @file_get_contents($dbms_schema);
         $sql_query = preg_replace('#phpbb_#i', $data['table_prefix'], $sql_query);
         $sql_query = phpbb_remove_comments($sql_query);
         $sql_query = split_sql_file($sql_query, $delimiter);
         foreach ($sql_query as $sql) {
             // Ignore errors when the functions or types already exist
             // to allow installing phpBB twice in the same database with
             // a different prefix
             $db->sql_query($sql);
         }
         unset($sql_query);
     }
     // Ok we have the db info go ahead and work on building the table
     if (file_exists('schemas/schema.json')) {
         $db_table_schema = @file_get_contents('schemas/schema.json');
         $db_table_schema = json_decode($db_table_schema, true);
     } else {
         global $phpbb_root_path, $phpEx, $table_prefix;
         $table_prefix = 'phpbb_';
         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 $phpbb_root_path . 'includes/constants.' . $phpEx;
         }
         $finder = new \phpbb\finder(new \phpbb\filesystem\filesystem(), $phpbb_root_path, null, $phpEx);
         $classes = $finder->core_path('phpbb/db/migration/data/')->get_classes();
         $sqlite_db = new \phpbb\db\driver\sqlite();
         $factory = new \phpbb\db\tools\factory();
         $db_tools = $factory->get($sqlite_db, true);
         $schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $sqlite_db, $db_tools, $phpbb_root_path, $phpEx, $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', $data['table_prefix'] . 'config');
     }
     $factory = new \phpbb\db\tools\factory();
     $db_tools = $factory->get($db);
     foreach ($db_table_schema as $table_name => $table_data) {
         $db_tools->sql_create_table($data['table_prefix'] . substr($table_name, 6), $table_data);
     }
     // Ok tables have been built, let's fill in the basic information
     $sql_query = file_get_contents('schemas/schema_data.sql');
     // Deal with any special comments and characters
     switch ($data['dbms']) {
         case 'mssql':
         case 'mssql_odbc':
         case 'mssqlnative':
             $sql_query = preg_replace('#\\# MSSQL IDENTITY (phpbb_[a-z_]+) (ON|OFF) \\##s', 'SET IDENTITY_INSERT \\1 \\2;', $sql_query);
             break;
         case 'postgres':
             $sql_query = preg_replace('#\\# POSTGRES (BEGIN|COMMIT) \\##s', '\\1; ', $sql_query);
             break;
         case 'mysql':
         case 'mysqli':
             $sql_query = str_replace('\\', '\\\\', $sql_query);
             break;
     }
     // Change prefix
     $sql_query = preg_replace('# phpbb_([^\\s]*) #i', ' ' . $data['table_prefix'] . '\\1 ', $sql_query);
     // Change language strings...
     $sql_query = preg_replace_callback('#\\{L_([A-Z0-9\\-_]*)\\}#s', 'adjust_language_keys_callback', $sql_query);
     $sql_query = phpbb_remove_comments($sql_query);
     $sql_query = split_sql_file($sql_query, ';');
     foreach ($sql_query as $sql) {
         //$sql = trim(str_replace('|', ';', $sql));
         if (!$db->sql_query($sql)) {
             $error = $db->sql_error();
             $this->p_master->db_error($error['message'], $sql, __LINE__, __FILE__);
         }
     }
     unset($sql_query);
     $current_time = time();
     $user_ip = $request->server('REMOTE_ADDR') ? phpbb_ip_normalise($request->server('REMOTE_ADDR')) : '';
     if ($data['script_path'] !== '/') {
         // Adjust destination path (no trailing slash)
         if (substr($data['script_path'], -1) == '/') {
             $data['script_path'] = substr($data['script_path'], 0, -1);
         }
         $data['script_path'] = str_replace(array('../', './'), '', $data['script_path']);
         if ($data['script_path'][0] != '/') {
             $data['script_path'] = '/' . $data['script_path'];
         }
     }
     // Set default config and post data, this applies to all DB's
     $sql_ary = array('INSERT INTO ' . $data['table_prefix'] . "config (config_name, config_value)\n\t\t\t\tVALUES ('board_startdate', '{$current_time}')", 'INSERT INTO ' . $data['table_prefix'] . "config (config_name, config_value)\n\t\t\t\tVALUES ('default_lang', '" . $db->sql_escape($data['default_lang']) . "')", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['img_imagick']) . "'\n\t\t\t\tWHERE config_name = 'img_imagick'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['server_name']) . "'\n\t\t\t\tWHERE config_name = 'server_name'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['server_port']) . "'\n\t\t\t\tWHERE config_name = 'server_port'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['board_email']) . "'\n\t\t\t\tWHERE config_name = 'board_email'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['board_email']) . "'\n\t\t\t\tWHERE config_name = 'board_contact'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($cookie_domain) . "'\n\t\t\t\tWHERE config_name = 'cookie_domain'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($lang['default_dateformat']) . "'\n\t\t\t\tWHERE config_name = 'default_dateformat'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['email_enable']) . "'\n\t\t\t\tWHERE config_name = 'email_enable'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['smtp_delivery']) . "'\n\t\t\t\tWHERE config_name = 'smtp_delivery'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['smtp_host']) . "'\n\t\t\t\tWHERE config_name = 'smtp_host'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['smtp_auth']) . "'\n\t\t\t\tWHERE config_name = 'smtp_auth_method'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['smtp_user']) . "'\n\t\t\t\tWHERE config_name = 'smtp_username'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['smtp_pass']) . "'\n\t\t\t\tWHERE config_name = 'smtp_password'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['cookie_secure']) . "'\n\t\t\t\tWHERE config_name = 'cookie_secure'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['force_server_vars']) . "'\n\t\t\t\tWHERE config_name = 'force_server_vars'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['script_path']) . "'\n\t\t\t\tWHERE config_name = 'script_path'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['server_protocol']) . "'\n\t\t\t\tWHERE config_name = 'server_protocol'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['admin_name']) . "'\n\t\t\t\tWHERE config_name = 'newest_username'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . md5(mt_rand()) . "'\n\t\t\t\tWHERE config_name = 'avatar_salt'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . md5(mt_rand()) . "'\n\t\t\t\tWHERE config_name = 'plupload_salt'", 'UPDATE ' . $data['table_prefix'] . "users\n\t\t\t\tSET username = '******'admin_name']) . "', user_password='******'admin_pass1'])) . "', user_ip = '" . $db->sql_escape($user_ip) . "', user_lang = '" . $db->sql_escape($data['default_lang']) . "', user_email='" . $db->sql_escape($data['board_email']) . "', user_dateformat='" . $db->sql_escape($lang['default_dateformat']) . "', user_email_hash = " . $db->sql_escape(phpbb_email_hash($data['board_email'])) . ", username_clean = '" . $db->sql_escape(utf8_clean_string($data['admin_name'])) . "'\n\t\t\t\tWHERE username = '******'", 'UPDATE ' . $data['table_prefix'] . "moderator_cache\n\t\t\t\tSET username = '******'admin_name']) . "'\n\t\t\t\tWHERE username = '******'", 'UPDATE ' . $data['table_prefix'] . "forums\n\t\t\t\tSET forum_last_poster_name = '" . $db->sql_escape($data['admin_name']) . "'\n\t\t\t\tWHERE forum_last_poster_name = 'Admin'", 'UPDATE ' . $data['table_prefix'] . "topics\n\t\t\t\tSET topic_first_poster_name = '" . $db->sql_escape($data['admin_name']) . "', topic_last_poster_name = '" . $db->sql_escape($data['admin_name']) . "'\n\t\t\t\tWHERE topic_first_poster_name = 'Admin'\n\t\t\t\t\tOR topic_last_poster_name = 'Admin'", 'UPDATE ' . $data['table_prefix'] . "users\n\t\t\t\tSET user_regdate = {$current_time}", 'UPDATE ' . $data['table_prefix'] . "posts\n\t\t\t\tSET post_time = {$current_time}, poster_ip = '" . $db->sql_escape($user_ip) . "'", 'UPDATE ' . $data['table_prefix'] . "topics\n\t\t\t\tSET topic_time = {$current_time}, topic_last_post_time = {$current_time}", 'UPDATE ' . $data['table_prefix'] . "forums\n\t\t\t\tSET forum_last_post_time = {$current_time}", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($db->sql_server_info(true)) . "'\n\t\t\t\tWHERE config_name = 'dbms_version'");
     if (@extension_loaded('gd')) {
         $sql_ary[] = 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = 'core.captcha.plugins.gd'\n\t\t\t\tWHERE config_name = 'captcha_plugin'";
         $sql_ary[] = 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '1'\n\t\t\t\tWHERE config_name = 'captcha_gd'";
     }
     $ref = substr($referer, strpos($referer, '://') + 3);
     if (!(stripos($ref, $server_name) === 0)) {
         $sql_ary[] = 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '0'\n\t\t\t\tWHERE config_name = 'referer_validation'";
     }
     // We set a (semi-)unique cookie name to bypass login issues related to the cookie name.
     $cookie_name = 'phpbb3_';
     $rand_str = md5(mt_rand());
     $rand_str = str_replace('0', 'z', base_convert($rand_str, 16, 35));
     $rand_str = substr($rand_str, 0, 5);
     $cookie_name .= strtolower($rand_str);
     $sql_ary[] = 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\tSET config_value = '" . $db->sql_escape($cookie_name) . "'\n\t\t\tWHERE config_name = 'cookie_name'";
     foreach ($sql_ary as $sql) {
         //$sql = trim(str_replace('|', ';', $sql));
         if (!$db->sql_query($sql)) {
             $error = $db->sql_error();
             $this->p_master->db_error($error['message'], $sql, __LINE__, __FILE__);
         }
     }
     $submit = $lang['NEXT_STEP'];
     $url = $this->p_master->module_url . "?mode={$mode}&amp;sub=final";
     $template->assign_vars(array('BODY' => $lang['STAGE_CREATE_TABLE_EXPLAIN'], 'L_SUBMIT' => $submit, 'S_HIDDEN' => build_hidden_fields($data), 'U_ACTION' => $url));
 }
示例#22
0
*/
/**
* This file creates new schema files for every database.
* The filenames will be prefixed with an underscore to not overwrite the current schema files.
*
* If you overwrite the original schema files please make sure you save the file with UNIX linefeeds.
*/
$schema_path = dirname(__FILE__) . '/../install/schemas/';
$supported_dbms = array('mssql', 'mysql_40', 'mysql_41', 'oracle', 'postgres', 'sqlite');
$table_prefix = 'phpbb_';
if (!is_writable($schema_path)) {
    die('Schema path not writable');
}
define('IN_PHPBB', true);
$phpbb_root_path = dirname(__FILE__) . '/../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include $phpbb_root_path . 'includes/constants.' . $phpEx;
require $phpbb_root_path . 'phpbb/class_loader.' . $phpEx;
$phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx);
$phpbb_class_loader->register();
$finder = new \phpbb\finder(new \phpbb\filesystem\filesystem(), $phpbb_root_path);
$classes = $finder->core_path('phpbb/')->directory('/db/migration/data')->get_classes();
$db = new \phpbb\db\driver\sqlite();
$factory = new \phpbb\db\tools\factory();
$db_tools = $factory->get($db, true);
$schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, $db_tools, $phpbb_root_path, $phpEx, $table_prefix);
$schema_data = $schema_generator->get_schema();
$fp = fopen($schema_path . 'schema.json', 'wb');
fwrite($fp, json_encode($schema_data, JSON_PRETTY_PRINT));
fclose($fp);
echo 'Successfully created schema file';