implemented INI cenversion functionality
This commit is contained in:
parent
b60d55236e
commit
6e8eafe129
|
@ -101,6 +101,33 @@ class Configuration
|
||||||
{
|
{
|
||||||
$config = array();
|
$config = array();
|
||||||
$configFile = PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.php';
|
$configFile = PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.php';
|
||||||
|
$configIni = PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini';
|
||||||
|
|
||||||
|
// rename INI files to avoid configuration leakage
|
||||||
|
if (is_readable($configIni)) {
|
||||||
|
// don't overwrite already converted file
|
||||||
|
if (!is_file($configFile)) {
|
||||||
|
$iniUpgradeError = false;
|
||||||
|
$context = stream_context_create();
|
||||||
|
$iniHandle = fopen($configIni, 'r', 1, $context);
|
||||||
|
$written = file_put_contents($configFile, ';<?php /*' . PHP_EOL);
|
||||||
|
$written = file_put_contents($configFile, $iniHandle, FILE_APPEND);
|
||||||
|
fclose($iniHandle);
|
||||||
|
unlink($configIni);
|
||||||
|
}
|
||||||
|
|
||||||
|
// cleanup sample, too
|
||||||
|
$configSample = PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.sample.php';
|
||||||
|
$configIniSample = PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini.sample';
|
||||||
|
if (is_readable($configIniSample)) {
|
||||||
|
if (is_readable($configSample)) {
|
||||||
|
unlink($configIniSample);
|
||||||
|
} else {
|
||||||
|
rename($configIniSample, $configSample);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (is_readable($configFile)) {
|
if (is_readable($configFile)) {
|
||||||
$config = parse_ini_file($configFile, true);
|
$config = parse_ini_file($configFile, true);
|
||||||
foreach (array('main', 'model', 'model_options') as $section) {
|
foreach (array('main', 'model', 'model_options') as $section) {
|
||||||
|
@ -109,6 +136,7 @@ class Configuration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$opts = '_options';
|
$opts = '_options';
|
||||||
foreach (self::getDefaults() as $section => $values) {
|
foreach (self::getDefaults() as $section => $values) {
|
||||||
// fill missing sections with default values
|
// fill missing sections with default values
|
||||||
|
|
|
@ -693,9 +693,8 @@ class Database extends AbstractData
|
||||||
'CREATE INDEX IF NOT EXISTS comment_parent ON ' .
|
'CREATE INDEX IF NOT EXISTS comment_parent ON ' .
|
||||||
self::_sanitizeIdentifier('comment') . '(pasteid);'
|
self::_sanitizeIdentifier('comment') . '(pasteid);'
|
||||||
);
|
);
|
||||||
// no break, continue with updates for 0.22
|
// no break, continue with updates for 0.22 and later
|
||||||
case '0.22':
|
default:
|
||||||
case '1.0':
|
|
||||||
self::_exec(
|
self::_exec(
|
||||||
'UPDATE ' . self::_sanitizeIdentifier('config') .
|
'UPDATE ' . self::_sanitizeIdentifier('config') .
|
||||||
' SET value = ? WHERE id = ?',
|
' SET value = ? WHERE id = ?',
|
||||||
|
|
|
@ -157,4 +157,20 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
|
||||||
'configuration values get converted'
|
'configuration values get converted'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testRenameIniSample()
|
||||||
|
{
|
||||||
|
$iniSample = PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini.sample';
|
||||||
|
$phpSample = PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.sample.php';
|
||||||
|
|
||||||
|
Helper::createIniFile(PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini', $this->_options);
|
||||||
|
if (is_file(CONF)) {
|
||||||
|
chmod(CONF, 0600);
|
||||||
|
unlink(CONF);
|
||||||
|
}
|
||||||
|
rename($phpSample, $iniSample);
|
||||||
|
new Configuration;
|
||||||
|
$this->assertFileNotExists($iniSample, 'old sample file gets removed');
|
||||||
|
$this->assertFileExists($phpSample, 'new sample file gets created');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue