mirror of
https://github.com/phpbb/phpbb.git
synced 2025-04-21 00:02:18 +02:00
[ticket/10492] Separate config generation from the installer
PHPBB3-10492
This commit is contained in:
parent
29a6aec9ad
commit
de70b17b1d
@ -512,4 +512,56 @@ function adjust_language_keys_callback($matches)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the output to be stored in a phpBB config.php file
|
||||
*
|
||||
* @param array $data Array containing the database connection information
|
||||
* @param string $dbms The name of the DBAL class to use
|
||||
* @param array $load_extensions Array of additional extensions that should be loaded
|
||||
* @param bool $debug If the debug constants should be enabled by default or not
|
||||
*
|
||||
* @return string The output to write to the file
|
||||
*/
|
||||
function phpbb_create_config_file_data($data, $dbms, $load_extensions, $debug = false)
|
||||
{
|
||||
$load_extensions = implode(',', $load_extensions);
|
||||
|
||||
$config_data = "<?php\n";
|
||||
$config_data .= "// phpBB 3.0.x auto-generated configuration file\n// Do not change anything in this file!\n";
|
||||
|
||||
$config_data_array = array(
|
||||
'dbms' => $dbms,
|
||||
'dbhost' => $data['dbhost'],
|
||||
'dbport' => $data['dbport'],
|
||||
'dbname' => $data['dbname'],
|
||||
'dbuser' => $data['dbuser'],
|
||||
'dbpasswd' => htmlspecialchars_decode($data['dbpasswd']),
|
||||
'table_prefix' => $data['table_prefix'],
|
||||
'acm_type' => 'file',
|
||||
'load_extensions' => $load_extensions,
|
||||
);
|
||||
|
||||
foreach ($config_data_array as $key => $value)
|
||||
{
|
||||
$config_data .= "\${$key} = '" . str_replace("'", "\\'", str_replace('\\', '\\\\', $value)) . "';\n";
|
||||
}
|
||||
|
||||
$config_data .= "\n@define('PHPBB_INSTALLED', true);\n";
|
||||
|
||||
if ($debug)
|
||||
{
|
||||
$config_data .= "@define('DEBUG', true);\n";
|
||||
$config_data .= "@define('DEBUG_EXTRA', true);\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$config_data .= "// @define('DEBUG', true);\n";
|
||||
$config_data .= "// @define('DEBUG_EXTRA', true);\n";
|
||||
}
|
||||
|
||||
$config_data .= '?' . '>'; // Done this to prevent highlighting editors getting confused!
|
||||
|
||||
return $config_data;
|
||||
}
|
||||
|
||||
?>
|
@ -884,34 +884,8 @@ class install_install extends module
|
||||
|
||||
@chmod($phpbb_root_path . 'cache/install_lock', 0777);
|
||||
|
||||
$load_extensions = implode(',', $load_extensions);
|
||||
|
||||
// Time to convert the data provided into a config file
|
||||
$config_data = "<?php\n";
|
||||
$config_data .= "// phpBB 3.0.x auto-generated configuration file\n// Do not change anything in this file!\n";
|
||||
|
||||
$config_data_array = array(
|
||||
'dbms' => $available_dbms[$data['dbms']]['DRIVER'],
|
||||
'dbhost' => $data['dbhost'],
|
||||
'dbport' => $data['dbport'],
|
||||
'dbname' => $data['dbname'],
|
||||
'dbuser' => $data['dbuser'],
|
||||
'dbpasswd' => htmlspecialchars_decode($data['dbpasswd']),
|
||||
'table_prefix' => $data['table_prefix'],
|
||||
'acm_type' => 'file',
|
||||
'load_extensions' => $load_extensions,
|
||||
);
|
||||
|
||||
foreach ($config_data_array as $key => $value)
|
||||
{
|
||||
$config_data .= "\${$key} = '" . str_replace("'", "\\'", str_replace('\\', '\\\\', $value)) . "';\n";
|
||||
}
|
||||
unset($config_data_array);
|
||||
|
||||
$config_data .= "\n@define('PHPBB_INSTALLED', true);\n";
|
||||
$config_data .= "// @define('DEBUG', true);\n";
|
||||
$config_data .= "// @define('DEBUG_EXTRA', true);\n";
|
||||
$config_data .= '?' . '>'; // Done this to prevent highlighting editors getting confused!
|
||||
$config_data = phpbb_create_config_file_data($data, $available_dbms[$data['dbms']]['DRIVER'], $load_extensions);
|
||||
|
||||
// Attempt to write out the config file directly. If it works, this is the easiest way to do it ...
|
||||
if ((file_exists($phpbb_root_path . 'config.' . $phpEx) && phpbb_is_writable($phpbb_root_path . 'config.' . $phpEx)) || phpbb_is_writable($phpbb_root_path))
|
||||
|
@ -40,46 +40,14 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
|
||||
|
||||
public function get_database_config()
|
||||
{
|
||||
if (isset($_SERVER['PHPBB_TEST_DBMS']))
|
||||
{
|
||||
return array(
|
||||
'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? $_SERVER['PHPBB_TEST_DBMS'] : '',
|
||||
'dbhost' => isset($_SERVER['PHPBB_TEST_DBHOST']) ? $_SERVER['PHPBB_TEST_DBHOST'] : '',
|
||||
'dbport' => isset($_SERVER['PHPBB_TEST_DBPORT']) ? $_SERVER['PHPBB_TEST_DBPORT'] : '',
|
||||
'dbname' => isset($_SERVER['PHPBB_TEST_DBNAME']) ? $_SERVER['PHPBB_TEST_DBNAME'] : '',
|
||||
'dbuser' => isset($_SERVER['PHPBB_TEST_DBUSER']) ? $_SERVER['PHPBB_TEST_DBUSER'] : '',
|
||||
'dbpasswd' => isset($_SERVER['PHPBB_TEST_DBPASSWD']) ? $_SERVER['PHPBB_TEST_DBPASSWD'] : '',
|
||||
);
|
||||
}
|
||||
else if (file_exists(dirname(__FILE__) . '/../test_config.php'))
|
||||
{
|
||||
include(dirname(__FILE__) . '/../test_config.php');
|
||||
$config = phpbb_test_case_helpers::get_test_config();
|
||||
|
||||
return array(
|
||||
'dbms' => $dbms,
|
||||
'dbhost' => $dbhost,
|
||||
'dbport' => $dbport,
|
||||
'dbname' => $dbname,
|
||||
'dbuser' => $dbuser,
|
||||
'dbpasswd' => $dbpasswd,
|
||||
);
|
||||
}
|
||||
else if (extension_loaded('sqlite') && version_compare(PHPUnit_Runner_Version::id(), '3.4.15', '>='))
|
||||
{
|
||||
// Silently use sqlite
|
||||
return array(
|
||||
'dbms' => 'sqlite',
|
||||
'dbhost' => dirname(__FILE__) . '/../phpbb_unit_tests.sqlite2', // filename
|
||||
'dbport' => '',
|
||||
'dbname' => '',
|
||||
'dbuser' => '',
|
||||
'dbpasswd' => '',
|
||||
);
|
||||
}
|
||||
else
|
||||
if (!isset($config['dbms']))
|
||||
{
|
||||
$this->markTestSkipped('Missing test_config.php: See first error.');
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
public function getConnection()
|
||||
|
@ -41,4 +41,49 @@ class phpbb_test_case_helpers
|
||||
$this->expectedTriggerError = true;
|
||||
$this->test_case->setExpectedException($exceptionName, (string) $message, $errno);
|
||||
}
|
||||
|
||||
static public function get_test_config()
|
||||
{
|
||||
$config = array();
|
||||
|
||||
if (extension_loaded('sqlite') && version_compare(PHPUnit_Runner_Version::id(), '3.4.15', '>='))
|
||||
{
|
||||
$config = array_merge($config, array(
|
||||
'dbms' => 'sqlite',
|
||||
'dbhost' => dirname(__FILE__) . '/../phpbb_unit_tests.sqlite2', // filename
|
||||
'dbport' => '',
|
||||
'dbname' => '',
|
||||
'dbuser' => '',
|
||||
'dbpasswd' => '',
|
||||
));
|
||||
}
|
||||
|
||||
if (file_exists(dirname(__FILE__) . '/../test_config.php'))
|
||||
{
|
||||
include(dirname(__FILE__) . '/../test_config.php');
|
||||
|
||||
$config = array_merge($config, array(
|
||||
'dbms' => $dbms,
|
||||
'dbhost' => $dbhost,
|
||||
'dbport' => $dbport,
|
||||
'dbname' => $dbname,
|
||||
'dbuser' => $dbuser,
|
||||
'dbpasswd' => $dbpasswd,
|
||||
));
|
||||
}
|
||||
|
||||
if (isset($_SERVER['PHPBB_TEST_DBMS']))
|
||||
{
|
||||
$config = array_merge($config, array(
|
||||
'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? $_SERVER['PHPBB_TEST_DBMS'] : '',
|
||||
'dbhost' => isset($_SERVER['PHPBB_TEST_DBHOST']) ? $_SERVER['PHPBB_TEST_DBHOST'] : '',
|
||||
'dbport' => isset($_SERVER['PHPBB_TEST_DBPORT']) ? $_SERVER['PHPBB_TEST_DBPORT'] : '',
|
||||
'dbname' => isset($_SERVER['PHPBB_TEST_DBNAME']) ? $_SERVER['PHPBB_TEST_DBNAME'] : '',
|
||||
'dbuser' => isset($_SERVER['PHPBB_TEST_DBUSER']) ? $_SERVER['PHPBB_TEST_DBUSER'] : '',
|
||||
'dbpasswd' => isset($_SERVER['PHPBB_TEST_DBPASSWD']) ? $_SERVER['PHPBB_TEST_DBPASSWD'] : ''
|
||||
));
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user