Revert "Can't determine if debug mode is defined until we read the config"

This reverts commit 969e43c87b.
This commit is contained in:
Bart Visscher 2013-06-27 22:24:17 +02:00
parent ae2b3732de
commit 194b61b4c5
3 changed files with 16 additions and 13 deletions

View File

@ -47,8 +47,11 @@ class Config {
protected $configDir; protected $configDir;
protected $configFilename; protected $configFilename;
public function __construct($configDir) { protected $debugMode;
public function __construct($configDir, $debugMode) {
$this->configDir = $configDir; $this->configDir = $configDir;
$this->debugMode = $debugMode;
$this->configFilename = $this->configDir.'config.php'; $this->configFilename = $this->configDir.'config.php';
$this->readData(); $this->readData();
} }
@ -149,7 +152,7 @@ class Config {
private function writeData() { private function writeData() {
// Create a php file ... // Create a php file ...
$content = "<?php\n"; $content = "<?php\n";
if (defined('DEBUG') && DEBUG) { if ($this->debugMode) {
$content .= "define('DEBUG',true);\n"; $content .= "define('DEBUG',true);\n";
} }
$content .= '$CONFIG = '; $content .= '$CONFIG = ';
@ -164,7 +167,7 @@ class Config {
'You can usually fix this by giving the webserver user write access' 'You can usually fix this by giving the webserver user write access'
.' to the config directory in ownCloud'); .' to the config directory in ownCloud');
} }
// Prevent others from reading the config // Prevent others not to read the config
@chmod($this->configFilename, 0640); @chmod($this->configFilename, 0640);
\OC_Util::clearOpcodeCache(); \OC_Util::clearOpcodeCache();
} }

View File

@ -38,7 +38,7 @@
* This class is responsible for reading and writing config.php, the very basic * This class is responsible for reading and writing config.php, the very basic
* configuration file of ownCloud. * configuration file of ownCloud.
*/ */
OC_Config::$object = new \OC\Config(OC::$SERVERROOT.'/config/'); OC_Config::$object = new \OC\Config(OC::$SERVERROOT.'/config/', defined('DEBUG') && DEBUG);
class OC_Config { class OC_Config {
public static $object; public static $object;

View File

@ -13,25 +13,25 @@ class Test_Config extends PHPUnit_Framework_TestCase {
public function testReadData() public function testReadData()
{ {
$config = new OC\Config(self::CONFIG_DIR); $config = new OC\Config(self::CONFIG_DIR, false);
$this->assertAttributeEquals(array(), 'cache', $config); $this->assertAttributeEquals(array(), 'cache', $config);
file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); file_put_contents(self::CONFIG_FILE, self::TESTCONTENT);
$config = new OC\Config(self::CONFIG_DIR); $config = new OC\Config(self::CONFIG_DIR, false);
$this->assertAttributeEquals(array('foo'=>'bar'), 'cache', $config); $this->assertAttributeEquals(array('foo'=>'bar'), 'cache', $config);
} }
public function testGetKeys() public function testGetKeys()
{ {
file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); file_put_contents(self::CONFIG_FILE, self::TESTCONTENT);
$config = new OC\Config(self::CONFIG_DIR); $config = new OC\Config(self::CONFIG_DIR, false);
$this->assertEquals(array('foo'), $config->getKeys()); $this->assertEquals(array('foo'), $config->getKeys());
} }
public function testGetValue() public function testGetValue()
{ {
file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); file_put_contents(self::CONFIG_FILE, self::TESTCONTENT);
$config = new OC\Config(self::CONFIG_DIR); $config = new OC\Config(self::CONFIG_DIR, false);
$this->assertEquals('bar', $config->getValue('foo')); $this->assertEquals('bar', $config->getValue('foo'));
$this->assertEquals(null, $config->getValue('bar')); $this->assertEquals(null, $config->getValue('bar'));
$this->assertEquals('moo', $config->getValue('bar', 'moo')); $this->assertEquals('moo', $config->getValue('bar', 'moo'));
@ -40,7 +40,7 @@ class Test_Config extends PHPUnit_Framework_TestCase {
public function testSetValue() public function testSetValue()
{ {
file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); file_put_contents(self::CONFIG_FILE, self::TESTCONTENT);
$config = new OC\Config(self::CONFIG_DIR); $config = new OC\Config(self::CONFIG_DIR, false);
$config->setValue('foo', 'moo'); $config->setValue('foo', 'moo');
$this->assertAttributeEquals(array('foo'=>'moo'), 'cache', $config); $this->assertAttributeEquals(array('foo'=>'moo'), 'cache', $config);
$content = file_get_contents(self::CONFIG_FILE); $content = file_get_contents(self::CONFIG_FILE);
@ -69,7 +69,7 @@ EOL
public function testDeleteKey() public function testDeleteKey()
{ {
file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); file_put_contents(self::CONFIG_FILE, self::TESTCONTENT);
$config = new OC\Config(self::CONFIG_DIR); $config = new OC\Config(self::CONFIG_DIR, false);
$config->deleteKey('foo'); $config->deleteKey('foo');
$this->assertAttributeEquals(array(), 'cache', $config); $this->assertAttributeEquals(array(), 'cache', $config);
$content = file_get_contents(self::CONFIG_FILE); $content = file_get_contents(self::CONFIG_FILE);
@ -84,11 +84,11 @@ EOL
public function testSavingDebugMode() public function testSavingDebugMode()
{ {
define('DEBUG',true);
file_put_contents(self::CONFIG_FILE, self::TESTCONTENT); file_put_contents(self::CONFIG_FILE, self::TESTCONTENT);
$config = new OC\Config(self::CONFIG_DIR); $config = new OC\Config(self::CONFIG_DIR, true);
$config->deleteKey('foo'); // change something so we save to the config file $config->deleteKey('foo'); // change something so we save to the config file
$this->assertAttributeEquals(array(), 'cache', $config); $this->assertAttributeEquals(array(), 'cache', $config);
$this->assertAttributeEquals(true, 'debug_mode', $config);
$content = file_get_contents(self::CONFIG_FILE); $content = file_get_contents(self::CONFIG_FILE);
$this->assertEquals(<<<EOL $this->assertEquals(<<<EOL
<?php <?php
@ -102,7 +102,7 @@ EOL
public function testWriteData() public function testWriteData()
{ {
$config = new OC\Config('/non-writable'); $config = new OC\Config('/non-writable', false);
try { try {
$config->setValue('foo', 'bar'); $config->setValue('foo', 'bar');
} catch (\OC\HintException $e) { } catch (\OC\HintException $e) {