示例#1
0
 protected function generate_route_objects()
 {
     $this->request = new phpbb_mock_request();
     $this->request->overwrite('SCRIPT_NAME', $this->get_uri(), \phpbb\request\request_interface::SERVER);
     $this->request->overwrite('SCRIPT_FILENAME', $this->get_script_name(), \phpbb\request\request_interface::SERVER);
     $this->request->overwrite('REQUEST_URI', $this->get_base_uri(), \phpbb\request\request_interface::SERVER);
     $this->request->overwrite('SERVER_NAME', 'localhost', \phpbb\request\request_interface::SERVER);
     $this->request->overwrite('SERVER_PORT', '80', \phpbb\request\request_interface::SERVER);
     $this->symfony_request = new \phpbb\symfony_request($this->request);
     $this->filesystem = new \phpbb\filesystem();
     $this->phpbb_path_helper = new \phpbb\path_helper($this->symfony_request, $this->filesystem, $this->request, $phpbb_root_path, $phpEx);
     $finder = new \phpbb\finder(new \phpbb\filesystem(), dirname(__FILE__) . '/', new phpbb_mock_cache());
     $finder->set_extensions(array_keys($this->extension_manager->all_enabled()));
     $this->provider = new \phpbb\controller\provider();
     $this->provider->find_routing_files($finder);
     $this->provider->find(dirname(__FILE__) . '/');
     // Set correct current phpBB root path
     $this->root_path = $this->get_phpbb_root_path();
 }
 public static function setUpBeforeClass()
 {
     global $phpbb_root_path, $phpEx;
     $setup_extensions = static::setup_extensions();
     $finder = new \phpbb\finder(new \phpbb\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();
         $schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, new \phpbb\db\tools($db, true), $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();
 }
示例#3
0
 public function setUp()
 {
     parent::setUp();
     global $phpbb_dispatcher;
     $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
     $this->user = $this->getMock('\\phpbb\\user', array(), array('\\phpbb\\datetime'));
     $this->user->expects($this->any())->method('lang')->will($this->returnCallback(array($this, 'return_callback_implode')));
     $filesystem = new \phpbb\filesystem();
     $manager = new phpbb_mock_extension_manager(dirname(__FILE__) . '/', array());
     $finder = new \phpbb\finder($filesystem, dirname(__FILE__) . '/', new phpbb_mock_cache());
     $finder->set_extensions(array_keys($manager->all_enabled()));
     $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1'));
     $provider = new \phpbb\controller\provider();
     $provider->find_routing_files($finder);
     $provider->find(dirname(__FILE__) . '/');
     $request = new phpbb_mock_request();
     $request->overwrite('SCRIPT_NAME', '/app.php', \phpbb\request\request_interface::SERVER);
     $request->overwrite('SCRIPT_FILENAME', 'app.php', \phpbb\request\request_interface::SERVER);
     $request->overwrite('REQUEST_URI', '/app.php', \phpbb\request\request_interface::SERVER);
     $symfony_request = new \phpbb\symfony_request($request);
     $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $provider, $manager, $symfony_request, $request, $filesystem, '', 'php', dirname(__FILE__) . '/');
     $this->pagination = new \phpbb\pagination($this->template, $this->user, $this->helper, $phpbb_dispatcher);
 }
示例#4
0
 /**
  * Instantiates a \phpbb\finder.
  *
  * @param bool $use_all_available Should we load all extensions, or just enabled ones
  * @return \phpbb\finder An extension finder instance
  */
 public function get_finder($use_all_available = false)
 {
     $finder = new \phpbb\finder($this->filesystem, $this->phpbb_root_path, $this->cache, $this->php_ext, $this->cache_name . '_finder');
     if ($use_all_available) {
         $finder->set_extensions(array_keys($this->all_available()));
     } else {
         $finder->set_extensions(array_keys($this->all_enabled()));
     }
     return $finder;
 }
 /**
  * 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)) {
         $queries = file_get_contents($filename);
         $sql = phpbb_remove_comments($queries);
         $sql = 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(), $phpbb_root_path, null, $phpEx);
         $classes = $finder->core_path('phpbb/db/migration/data/')->get_classes();
         $db = new \phpbb\db\driver\sqlite();
         $schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, new \phpbb\db\tools($db, true), $phpbb_root_path, $phpEx, $table_prefix);
         $db_table_schema = $schema_generator->get_schema();
     }
     $db_tools = new \phpbb\db\tools($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);
                 }
             }
         }
     }
 }
示例#6
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);
     }
 }
function load_schema_31($install_path = '', $install_dbms = false)
{
    global $db, $settings, $table_prefix, $phpbb_root_path, $phpEx;
    static $available_dbms = false;
    if ($install_dbms === false) {
        $dbms = $settings->get_config('dbms');
        $install_dbms = $dbms;
    }
    if (!$available_dbms) {
        $available_dbms = get_available_dbms($install_dbms);
        // If mysql is chosen, we need to adjust the schema filename slightly to reflect the correct version. ;)
        if ($install_dbms == 'mysql') {
            if (version_compare($db->sql_server_info(true), '4.1.3', '>=')) {
                $available_dbms[$install_dbms]['SCHEMA'] .= '_41';
            } else {
                $available_dbms[$install_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 = $install_path . $available_dbms[$install_dbms]['SCHEMA'] . '_schema.sql';
    // How should we treat this schema?
    $delimiter = $available_dbms[$install_dbms]['DELIM'];
    if (file_exists($dbms_schema)) {
        $sql_query = file_get_contents($dbms_schema);
        $sql_query = preg_replace('#phpbb_#i', $table_prefix, $sql_query);
        $sql_query = phpbb_remove_comments($sql_query);
        $sql_query = split_sql_file($sql_query, $delimiter);
        foreach ($sql_query as $sql) {
            $db->sql_query($sql);
        }
        unset($sql_query);
    }
    // Ok we have the db info go ahead and work on building the table
    if (file_exists($install_path . 'schema.json')) {
        $db_table_schema = file_get_contents($install_path . 'schema.json');
        $db_table_schema = json_decode($db_table_schema, true);
    } else {
        $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(), $phpbb_root_path, null, $phpEx);
        $classes = $finder->core_path('phpbb/db/migration/data/')->get_classes();
        $sqlite_db = new \phpbb\db\driver\sqlite();
        $schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $sqlite_db, new \phpbb\db\tools($sqlite_db, true), $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', $table_prefix . 'config');
    }
    $db_tools = new \phpbb\db\tools($db);
    foreach ($db_table_schema as $table_name => $table_data) {
        $db_tools->sql_create_table($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($install_path . 'schema_data.sql');
    // Deal with any special comments and characters
    switch ($install_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', ' ' . $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) {
        $db->sql_query($sql);
    }
    unset($sql_query);
}
 /**
  * Find all .cfg files in a given directory.
  *
  * @param string $directory		Full path to style directory
  * @return array
  */
 protected function find_cfg_files($directory)
 {
     $finder = new \phpbb\finder(new \phpbb\filesystem());
     return $finder->suffix('.cfg')->find_from_paths(array('/' => $directory));
 }
示例#9
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}&sub=final";
     $template->assign_vars(array('BODY' => $lang['STAGE_CREATE_TABLE_EXPLAIN'], 'L_SUBMIT' => $submit, 'S_HIDDEN' => build_hidden_fields($data), 'U_ACTION' => $url));
 }
示例#10
0
    $newline = '<br>';
}
$sql = 'DESCRIBE ' . POSTS_TABLE . ' post_text';
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$mysql_indexer = $drop_index = false;
if (strtolower($row['Type']) === 'mediumtext') {
    $mysql_indexer = true;
}
if (strtolower($row['Key']) === 'mul') {
    $drop_index = true;
}
echo "USE {$dbname};{$newline}{$newline}";
@set_time_limit(0);
$finder = new \phpbb\finder(new \phpbb\filesystem(), $phpbb_root_path);
$classes = $finder->core_path('phpbb/')->directory('/db/migration/data')->get_classes();
$schema_generator = new \phpbb\db\migration\schema_generator($classes, $config, $db, new \phpbb\db\tools($db, true), $phpbb_root_path, $phpEx, $table_prefix);
$schema_data = $schema_generator->get_schema();
$dbms_type_map = \phpbb\db\tools::get_dbms_type_map();
foreach ($schema_data as $table_name => $table_data) {
    $table_name = str_replace('phpbb_', $prefix, $table_name);
    // Write comment about table
    echo "# Table: '{$table_name}'{$newline}";
    // Create Table statement
    $generator = $textimage = false;
    // Do we need to DROP a fulltext index before we alter the table?
    if ($table_name == $prefix . 'posts' && $drop_index) {
        echo "ALTER TABLE {$table_name}{$newline}";
        echo "DROP INDEX post_text,{$newline}DROP INDEX post_subject,{$newline}DROP INDEX post_content;{$newline}{$newline}";
    }
示例#11
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);
 }