mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-10 05:18:52 +00:00
[ticket/12775] Move phpbb_convert_30_dbms_to_31 into the config file class
PHPBB3-12775
This commit is contained in:
parent
98e8be966b
commit
ed812a9dfb
10 changed files with 73 additions and 72 deletions
|
@ -5326,52 +5326,6 @@ function phpbb_to_numeric($input)
|
||||||
return ($input > PHP_INT_MAX) ? (float) $input : (int) $input;
|
return ($input > PHP_INT_MAX) ? (float) $input : (int) $input;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert either 3.0 dbms or 3.1 db driver class name to 3.1 db driver class name.
|
|
||||||
*
|
|
||||||
* If $dbms is a valid 3.1 db driver class name, returns it unchanged.
|
|
||||||
* Otherwise prepends phpbb\db\driver\ to the dbms to convert a 3.0 dbms
|
|
||||||
* to 3.1 db driver class name.
|
|
||||||
*
|
|
||||||
* @param string $dbms dbms parameter
|
|
||||||
* @return db driver class
|
|
||||||
*/
|
|
||||||
function phpbb_convert_30_dbms_to_31($dbms)
|
|
||||||
{
|
|
||||||
// Note: this check is done first because mysqli extension
|
|
||||||
// supplies a mysqli class, and class_exists($dbms) would return
|
|
||||||
// true for mysqli class.
|
|
||||||
// However, per the docblock any valid 3.1 driver name should be
|
|
||||||
// recognized by this function, and have priority over 3.0 dbms.
|
|
||||||
if (strpos($dbms, 'phpbb\db\driver') === false && class_exists('phpbb\db\driver\\' . $dbms))
|
|
||||||
{
|
|
||||||
return 'phpbb\db\driver\\' . $dbms;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (class_exists($dbms))
|
|
||||||
{
|
|
||||||
// Additionally we could check that $dbms extends phpbb\db\driver\driver.
|
|
||||||
// http://php.net/manual/en/class.reflectionclass.php
|
|
||||||
// Beware of possible performance issues:
|
|
||||||
// http://stackoverflow.com/questions/294582/php-5-reflection-api-performance
|
|
||||||
// We could check for interface implementation in all paths or
|
|
||||||
// only when we do not prepend phpbb\db\driver\.
|
|
||||||
|
|
||||||
/*
|
|
||||||
$reflection = new \ReflectionClass($dbms);
|
|
||||||
|
|
||||||
if ($reflection->isSubclassOf('phpbb\db\driver\driver'))
|
|
||||||
{
|
|
||||||
return $dbms;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
return $dbms;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new \RuntimeException("You have specified an invalid dbms driver: $dbms");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the board contact details (e.g. for emails)
|
* Get the board contact details (e.g. for emails)
|
||||||
*
|
*
|
||||||
|
|
|
@ -258,10 +258,13 @@ class phpbb_questionnaire_phpbb_data_provider
|
||||||
function get_data()
|
function get_data()
|
||||||
{
|
{
|
||||||
global $phpbb_root_path, $phpEx;
|
global $phpbb_root_path, $phpEx;
|
||||||
include("{$phpbb_root_path}config.$phpEx");
|
|
||||||
|
$phpbb_config_php_file = new \phpbb\config_php_file($phpbb_root_path, $phpEx);
|
||||||
|
$phpbb_config_php_file->set_config_file($phpbb_root_path . 'config.' . $phpEx);
|
||||||
|
extract($phpbb_config_php_file->get_all());
|
||||||
unset($dbhost, $dbport, $dbname, $dbuser, $dbpasswd); // Just a precaution
|
unset($dbhost, $dbport, $dbname, $dbuser, $dbpasswd); // Just a precaution
|
||||||
|
|
||||||
$dbms = phpbb_convert_30_dbms_to_31($dbms);
|
$dbms = $phpbb_config_php_file->convert_30_dbms_to_31($dbms);
|
||||||
|
|
||||||
// Only send certain config vars
|
// Only send certain config vars
|
||||||
$config_vars = array(
|
$config_vars = array(
|
||||||
|
|
|
@ -25,10 +25,11 @@ if (!defined('IN_PHPBB'))
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
include($phpbb_root_path . 'config.' . $phpEx);
|
$phpbb_config_php_file = new \phpbb\config_php_file($phpbb_root_path, $phpEx);
|
||||||
|
extract($phpbb_config_php_file->get_all());
|
||||||
unset($dbpasswd);
|
unset($dbpasswd);
|
||||||
|
|
||||||
$dbms = phpbb_convert_30_dbms_to_31($dbms);
|
$dbms = $phpbb_config_php_file->convert_30_dbms_to_31($dbms);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $convertor_data provides some basic information about this convertor which is
|
* $convertor_data provides some basic information about this convertor which is
|
||||||
|
|
|
@ -142,7 +142,7 @@ class install_convert extends module
|
||||||
require($phpbb_root_path . 'includes/constants.' . $phpEx);
|
require($phpbb_root_path . 'includes/constants.' . $phpEx);
|
||||||
require($phpbb_root_path . 'includes/functions_convert.' . $phpEx);
|
require($phpbb_root_path . 'includes/functions_convert.' . $phpEx);
|
||||||
|
|
||||||
$dbms = phpbb_convert_30_dbms_to_31($dbms);
|
$dbms = $phpbb_config_php_file->convert_30_dbms_to_31($dbms);
|
||||||
|
|
||||||
$db = new $dbms();
|
$db = new $dbms();
|
||||||
$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true);
|
$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true);
|
||||||
|
@ -233,7 +233,7 @@ class install_convert extends module
|
||||||
require($phpbb_root_path . 'includes/constants.' . $phpEx);
|
require($phpbb_root_path . 'includes/constants.' . $phpEx);
|
||||||
require($phpbb_root_path . 'includes/functions_convert.' . $phpEx);
|
require($phpbb_root_path . 'includes/functions_convert.' . $phpEx);
|
||||||
|
|
||||||
$dbms = phpbb_convert_30_dbms_to_31($dbms);
|
$dbms = $phpbb_config_php_file->convert_30_dbms_to_31($dbms);
|
||||||
|
|
||||||
$db = new $dbms();
|
$db = new $dbms();
|
||||||
$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true);
|
$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true);
|
||||||
|
@ -383,7 +383,7 @@ class install_convert extends module
|
||||||
require($phpbb_root_path . 'includes/constants.' . $phpEx);
|
require($phpbb_root_path . 'includes/constants.' . $phpEx);
|
||||||
require($phpbb_root_path . 'includes/functions_convert.' . $phpEx);
|
require($phpbb_root_path . 'includes/functions_convert.' . $phpEx);
|
||||||
|
|
||||||
$dbms = phpbb_convert_30_dbms_to_31($dbms);
|
$dbms = $phpbb_config_php_file->convert_30_dbms_to_31($dbms);
|
||||||
|
|
||||||
$db = new $dbms();
|
$db = new $dbms();
|
||||||
$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true);
|
$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true);
|
||||||
|
@ -465,7 +465,8 @@ class install_convert extends module
|
||||||
{
|
{
|
||||||
$error[] = sprintf($lang['TABLE_PREFIX_SAME'], $src_table_prefix);
|
$error[] = sprintf($lang['TABLE_PREFIX_SAME'], $src_table_prefix);
|
||||||
}
|
}
|
||||||
$src_dbms = phpbb_convert_30_dbms_to_31($src_dbms);
|
|
||||||
|
$src_dbms = $phpbb_config_php_file->convert_30_dbms_to_31($src_dbms);
|
||||||
|
|
||||||
// Check table prefix
|
// Check table prefix
|
||||||
if (!sizeof($error))
|
if (!sizeof($error))
|
||||||
|
@ -629,7 +630,7 @@ class install_convert extends module
|
||||||
require($phpbb_root_path . 'includes/constants.' . $phpEx);
|
require($phpbb_root_path . 'includes/constants.' . $phpEx);
|
||||||
require($phpbb_root_path . 'includes/functions_convert.' . $phpEx);
|
require($phpbb_root_path . 'includes/functions_convert.' . $phpEx);
|
||||||
|
|
||||||
$dbms = phpbb_convert_30_dbms_to_31($dbms);
|
$dbms = $phpbb_config_php_file->convert_30_dbms_to_31($dbms);
|
||||||
|
|
||||||
$db = new $dbms();
|
$db = new $dbms();
|
||||||
$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true);
|
$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true);
|
||||||
|
|
|
@ -103,7 +103,7 @@ class install_update extends module
|
||||||
define('MERGE_NEW_FILE', 3);
|
define('MERGE_NEW_FILE', 3);
|
||||||
define('MERGE_MOD_FILE', 4);
|
define('MERGE_MOD_FILE', 4);
|
||||||
|
|
||||||
$dbms = phpbb_convert_30_dbms_to_31($dbms);
|
$dbms = $phpbb_config_php_file->convert_30_dbms_to_31($dbms);
|
||||||
|
|
||||||
$db = new $dbms();
|
$db = new $dbms();
|
||||||
|
|
||||||
|
|
|
@ -124,4 +124,51 @@ class config_php_file
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert either 3.0 dbms or 3.1 db driver class name to 3.1 db driver class name.
|
||||||
|
*
|
||||||
|
* If $dbms is a valid 3.1 db driver class name, returns it unchanged.
|
||||||
|
* Otherwise prepends phpbb\db\driver\ to the dbms to convert a 3.0 dbms
|
||||||
|
* to 3.1 db driver class name.
|
||||||
|
*
|
||||||
|
* @param string $dbms dbms parameter
|
||||||
|
* @return string driver class
|
||||||
|
* @throws \RuntimeException
|
||||||
|
*/
|
||||||
|
public function convert_30_dbms_to_31($dbms)
|
||||||
|
{
|
||||||
|
// Note: this check is done first because mysqli extension
|
||||||
|
// supplies a mysqli class, and class_exists($dbms) would return
|
||||||
|
// true for mysqli class.
|
||||||
|
// However, per the docblock any valid 3.1 driver name should be
|
||||||
|
// recognized by this function, and have priority over 3.0 dbms.
|
||||||
|
if (strpos($dbms, 'phpbb\db\driver') === false && class_exists('phpbb\db\driver\\' . $dbms))
|
||||||
|
{
|
||||||
|
return 'phpbb\db\driver\\' . $dbms;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (class_exists($dbms))
|
||||||
|
{
|
||||||
|
// Additionally we could check that $dbms extends phpbb\db\driver\driver.
|
||||||
|
// http://php.net/manual/en/class.reflectionclass.php
|
||||||
|
// Beware of possible performance issues:
|
||||||
|
// http://stackoverflow.com/questions/294582/php-5-reflection-api-performance
|
||||||
|
// We could check for interface implementation in all paths or
|
||||||
|
// only when we do not prepend phpbb\db\driver\.
|
||||||
|
|
||||||
|
/*
|
||||||
|
$reflection = new \ReflectionClass($dbms);
|
||||||
|
|
||||||
|
if ($reflection->isSubclassOf('phpbb\db\driver\driver'))
|
||||||
|
{
|
||||||
|
return $dbms;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
return $dbms;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new \RuntimeException("You have specified an invalid dbms driver: $dbms");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -302,7 +302,7 @@ class container_builder
|
||||||
{
|
{
|
||||||
if ($this->dbal_connection === null)
|
if ($this->dbal_connection === null)
|
||||||
{
|
{
|
||||||
$dbal_driver_class = phpbb_convert_30_dbms_to_31($this->config_php_handler->get('dbms'));
|
$dbal_driver_class = $this->config_php_handler->convert_30_dbms_to_31($this->config_php_handler->get('dbms'));
|
||||||
$this->dbal_connection = new $dbal_driver_class();
|
$this->dbal_connection = new $dbal_driver_class();
|
||||||
$this->dbal_connection->sql_connect(
|
$this->dbal_connection->sql_connect(
|
||||||
$this->config_php_handler->get('dbhost'),
|
$this->config_php_handler->get('dbhost'),
|
||||||
|
|
|
@ -42,7 +42,7 @@ class config extends Extension
|
||||||
$container->setParameter('core.adm_relative_path', ($this->config_php->get('phpbb_adm_relative_path') ? $this->config_php->get('phpbb_adm_relative_path') : 'adm/'));
|
$container->setParameter('core.adm_relative_path', ($this->config_php->get('phpbb_adm_relative_path') ? $this->config_php->get('phpbb_adm_relative_path') : 'adm/'));
|
||||||
$container->setParameter('core.table_prefix', $this->config_php->get('table_prefix'));
|
$container->setParameter('core.table_prefix', $this->config_php->get('table_prefix'));
|
||||||
$container->setParameter('cache.driver.class', $this->convert_30_acm_type($this->config_php->get('acm_type')));
|
$container->setParameter('cache.driver.class', $this->convert_30_acm_type($this->config_php->get('acm_type')));
|
||||||
$container->setParameter('dbal.driver.class', phpbb_convert_30_dbms_to_31($this->config_php->get('dbms')));
|
$container->setParameter('dbal.driver.class', $this->config_php->convert_30_dbms_to_31($this->config_php->get('dbms')));
|
||||||
$container->setParameter('dbal.dbhost', $this->config_php->get('dbhost'));
|
$container->setParameter('dbal.dbhost', $this->config_php->get('dbhost'));
|
||||||
$container->setParameter('dbal.dbuser', $this->config_php->get('dbuser'));
|
$container->setParameter('dbal.dbuser', $this->config_php->get('dbuser'));
|
||||||
$container->setParameter('dbal.dbpasswd', $this->config_php->get('dbpasswd'));
|
$container->setParameter('dbal.dbpasswd', $this->config_php->get('dbpasswd'));
|
||||||
|
|
|
@ -36,7 +36,8 @@ class phpbb_convert_30_dbms_to_31_test extends phpbb_test_case
|
||||||
{
|
{
|
||||||
$expected = "phpbb\\db\\driver\\$input";
|
$expected = "phpbb\\db\\driver\\$input";
|
||||||
|
|
||||||
$output = phpbb_convert_30_dbms_to_31($input);
|
$config_php_file = new \phpbb\config_php_file('', '');
|
||||||
|
$output = $config_php_file->convert_30_dbms_to_31($input);
|
||||||
|
|
||||||
$this->assertEquals($expected, $output);
|
$this->assertEquals($expected, $output);
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,17 +142,16 @@ class phpbb_test_case_helpers
|
||||||
$test_config = dirname(__FILE__) . '/../test_config.php';
|
$test_config = dirname(__FILE__) . '/../test_config.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$config_php_file = new \phpbb\config_php_file('', '');
|
||||||
|
|
||||||
if (file_exists($test_config))
|
if (file_exists($test_config))
|
||||||
{
|
{
|
||||||
include($test_config);
|
$config_php_file->set_config_file($test_config);
|
||||||
|
extract($config_php_file->get_all());
|
||||||
if (!function_exists('phpbb_convert_30_dbms_to_31'))
|
unset($dbpasswd);
|
||||||
{
|
|
||||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
|
||||||
}
|
|
||||||
|
|
||||||
$config = array_merge($config, array(
|
$config = array_merge($config, array(
|
||||||
'dbms' => phpbb_convert_30_dbms_to_31($dbms),
|
'dbms' => $config_php_file->convert_30_dbms_to_31($dbms),
|
||||||
'dbhost' => $dbhost,
|
'dbhost' => $dbhost,
|
||||||
'dbport' => $dbport,
|
'dbport' => $dbport,
|
||||||
'dbname' => $dbname,
|
'dbname' => $dbname,
|
||||||
|
@ -183,13 +182,8 @@ class phpbb_test_case_helpers
|
||||||
|
|
||||||
if (isset($_SERVER['PHPBB_TEST_DBMS']))
|
if (isset($_SERVER['PHPBB_TEST_DBMS']))
|
||||||
{
|
{
|
||||||
if (!function_exists('phpbb_convert_30_dbms_to_31'))
|
|
||||||
{
|
|
||||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
|
||||||
}
|
|
||||||
|
|
||||||
$config = array_merge($config, array(
|
$config = array_merge($config, array(
|
||||||
'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? phpbb_convert_30_dbms_to_31($_SERVER['PHPBB_TEST_DBMS']) : '',
|
'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? $config_php_file->convert_30_dbms_to_31($_SERVER['PHPBB_TEST_DBMS']) : '',
|
||||||
'dbhost' => isset($_SERVER['PHPBB_TEST_DBHOST']) ? $_SERVER['PHPBB_TEST_DBHOST'] : '',
|
'dbhost' => isset($_SERVER['PHPBB_TEST_DBHOST']) ? $_SERVER['PHPBB_TEST_DBHOST'] : '',
|
||||||
'dbport' => isset($_SERVER['PHPBB_TEST_DBPORT']) ? $_SERVER['PHPBB_TEST_DBPORT'] : '',
|
'dbport' => isset($_SERVER['PHPBB_TEST_DBPORT']) ? $_SERVER['PHPBB_TEST_DBPORT'] : '',
|
||||||
'dbname' => isset($_SERVER['PHPBB_TEST_DBNAME']) ? $_SERVER['PHPBB_TEST_DBNAME'] : '',
|
'dbname' => isset($_SERVER['PHPBB_TEST_DBNAME']) ? $_SERVER['PHPBB_TEST_DBNAME'] : '',
|
||||||
|
|
Loading…
Add table
Reference in a new issue