From c758eca0a4c450aa62e54614d6510d02bf638517 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sun, 6 Jun 2021 17:53:08 +0200 Subject: [PATCH] removed automatic .ini configuration file migration, closes #808 --- CHANGELOG.md | 1 + lib/Configuration.php | 12 ------- lib/Persistence/DataStore.php | 5 ++- tst/ConfigurationTest.php | 63 ----------------------------------- 4 files changed, 3 insertions(+), 78 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84f630e..2c4321a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * ADDED: Google Cloud Storage backend support (#795) * CHANGED: Language selection cookie only transmitted over HTTPS (#472) * CHANGED: Upgrading libraries to: random_compat 2.0.20 + * CHANGED: Removed automatic `.ini` configuration file migration (#808) * **1.3.5 (2021-04-05)** * ADDED: Translation for Hebrew, Lithuanian, Indonesian and Catalan * ADDED: Make the project info configurable (#681) diff --git a/lib/Configuration.php b/lib/Configuration.php index 1e92fc9..a56217b 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -106,20 +106,8 @@ class Configuration { $config = array(); $basePath = (getenv('CONFIG_PATH') !== false ? getenv('CONFIG_PATH') : PATH . 'cfg') . DIRECTORY_SEPARATOR; - $configIni = $basePath . 'conf.ini'; $configFile = $basePath . 'conf.php'; - // rename INI files to avoid configuration leakage - if (is_readable($configIni)) { - DataStore::prependRename($configIni, $configFile, ';'); - - // cleanup sample, too - $configIniSample = $configIni . '.sample'; - if (is_readable($configIniSample)) { - DataStore::prependRename($configIniSample, $basePath . 'conf.sample.php', ';'); - } - } - if (is_readable($configFile)) { $config = parse_ini_file($configFile, true); foreach (array('main', 'model', 'model_options') as $section) { diff --git a/lib/Persistence/DataStore.php b/lib/Persistence/DataStore.php index d96f070..d17e5fa 100644 --- a/lib/Persistence/DataStore.php +++ b/lib/Persistence/DataStore.php @@ -80,15 +80,14 @@ class DataStore extends AbstractPersistence * @static * @param string $srcFile * @param string $destFile - * @param string $prefix (optional) * @return void */ - public static function prependRename($srcFile, $destFile, $prefix = '') + public static function prependRename($srcFile, $destFile) { // don't overwrite already converted file if (!is_readable($destFile)) { $handle = fopen($srcFile, 'r', false, stream_context_create()); - file_put_contents($destFile, $prefix . self::PROTECTION_LINE . PHP_EOL); + file_put_contents($destFile, self::PROTECTION_LINE . PHP_EOL); file_put_contents($destFile, $handle, FILE_APPEND); fclose($handle); } diff --git a/tst/ConfigurationTest.php b/tst/ConfigurationTest.php index bb4ce36..246618c 100644 --- a/tst/ConfigurationTest.php +++ b/tst/ConfigurationTest.php @@ -147,44 +147,6 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase $this->assertEquals('Database', $conf->getKey('class', 'model'), 'old db class gets renamed'); } - public function testHandleConfigFileRename() - { - $options = $this->_options; - Helper::createIniFile(PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini.sample', $options); - - $options['main']['opendiscussion'] = true; - $options['main']['fileupload'] = true; - $options['main']['template'] = 'darkstrap'; - Helper::createIniFile(PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini', $options); - - $conf = new Configuration; - $this->assertFileExists(CONF, 'old configuration file gets converted'); - $this->assertFileNotExists(PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini', 'old configuration file gets removed'); - $this->assertFileNotExists(PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini.sample', 'old configuration sample file gets removed'); - $this->assertTrue( - $conf->getKey('opendiscussion') && - $conf->getKey('fileupload') && - $conf->getKey('template') === 'darkstrap', - 'configuration values get converted' - ); - } - - public function testRenameIniSample() - { - $iniSample = PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini.sample'; - - Helper::createIniFile(PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini', $this->_options); - if (is_file(CONF)) { - unlink(CONF); - } - rename(CONF_SAMPLE, $iniSample); - new Configuration; - $this->assertFileNotExists($iniSample, 'old sample file gets removed'); - $this->assertFileExists(CONF_SAMPLE, 'new sample file gets created'); - $this->assertFileExists(CONF, 'old configuration file gets converted'); - $this->assertFileNotExists(PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini', 'old configuration file gets removed'); - } - public function testConfigPath() { // setup @@ -204,29 +166,4 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase } putenv('CONFIG_PATH'); } - - public function testConfigPathIni() - { - // setup - $configFile = $this->_path . DIRECTORY_SEPARATOR . 'conf.ini'; - $configMigrated = $this->_path . DIRECTORY_SEPARATOR . 'conf.php'; - $options = $this->_options; - $options['main']['name'] = 'OtherBin'; - Helper::createIniFile($configFile, $options); - $this->assertFileNotExists(CONF, 'configuration in the default location is non existing'); - - // test - putenv('CONFIG_PATH=' . $this->_path); - $conf = new Configuration; - $this->assertEquals('OtherBin', $conf->getKey('name'), 'changing config path is supported for ini files as well'); - $this->assertFileExists($configMigrated, 'old configuration file gets converted'); - $this->assertFileNotExists($configFile, 'old configuration file gets removed'); - $this->assertFileNotExists(CONF, 'configuration is not created in the default location'); - - // cleanup environment - if (is_file($configFile)) { - unlink($configFile); - } - putenv('CONFIG_PATH'); - } }