From 969e43c87b7afb6184846fe27849167c9c6f5eab Mon Sep 17 00:00:00 2001
From: Michael Gapczynski <mtgap@owncloud.com>
Date: Mon, 10 Jun 2013 12:07:25 -0400
Subject: [PATCH] Can't determine if debug mode is defined until we read the
 config

---
 lib/config.php        |  9 +++------
 lib/legacy/config.php |  2 +-
 tests/lib/config.php  | 18 +++++++++---------
 3 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/lib/config.php b/lib/config.php
index 4003339ea5c..a3663949d16 100644
--- a/lib/config.php
+++ b/lib/config.php
@@ -47,11 +47,8 @@ class Config {
 	protected $configDir;
 	protected $configFilename;
 
-	protected $debugMode;
-
-	public function __construct($configDir, $debugMode) {
+	public function __construct($configDir) {
 		$this->configDir = $configDir;
-		$this->debugMode = $debugMode;
 		$this->configFilename = $this->configDir.'config.php';
 		$this->readData();
 	}
@@ -152,7 +149,7 @@ class Config {
 	private function writeData() {
 		// Create a php file ...
 		$content = "<?php\n";
-		if ($this->debugMode) {
+		if (defined('DEBUG') && DEBUG) {
 			$content .= "define('DEBUG',true);\n";
 		}
 		$content .= '$CONFIG = ';
@@ -167,7 +164,7 @@ class Config {
 				'You can usually fix this by giving the webserver user write access'
 					.' to the config directory in ownCloud');
 		}
-		// Prevent others not to read the config
+		// Prevent others from reading the config
 		@chmod($this->configFilename, 0640);
 	}
 }
diff --git a/lib/legacy/config.php b/lib/legacy/config.php
index 635f0af66f8..f68d7c31b25 100644
--- a/lib/legacy/config.php
+++ b/lib/legacy/config.php
@@ -38,7 +38,7 @@
  * This class is responsible for reading and writing config.php, the very basic
  * configuration file of ownCloud.
  */
-OC_Config::$object = new \OC\Config(OC::$SERVERROOT.'/config/', defined('DEBUG') && DEBUG);
+OC_Config::$object = new \OC\Config(OC::$SERVERROOT.'/config/');
 class OC_Config {
 
 	public static $object;
diff --git a/tests/lib/config.php b/tests/lib/config.php
index e22bf3fd7de..acc2a536fd0 100644
--- a/tests/lib/config.php
+++ b/tests/lib/config.php
@@ -13,25 +13,25 @@ class Test_Config extends PHPUnit_Framework_TestCase {
 
 	public function testReadData()
 	{
-		$config = new OC\Config(self::CONFIG_DIR, false);
+		$config = new OC\Config(self::CONFIG_DIR);
 		$this->assertAttributeEquals(array(), 'cache', $config);
 
 		file_put_contents(self::CONFIG_FILE, self::TESTCONTENT);
-		$config = new OC\Config(self::CONFIG_DIR, false);
+		$config = new OC\Config(self::CONFIG_DIR);
 		$this->assertAttributeEquals(array('foo'=>'bar'), 'cache', $config);
 	}
 
 	public function testGetKeys()
 	{
 		file_put_contents(self::CONFIG_FILE, self::TESTCONTENT);
-		$config = new OC\Config(self::CONFIG_DIR, false);
+		$config = new OC\Config(self::CONFIG_DIR);
 		$this->assertEquals(array('foo'), $config->getKeys());
 	}
 
 	public function testGetValue()
 	{
 		file_put_contents(self::CONFIG_FILE, self::TESTCONTENT);
-		$config = new OC\Config(self::CONFIG_DIR, false);
+		$config = new OC\Config(self::CONFIG_DIR);
 		$this->assertEquals('bar', $config->getValue('foo'));
 		$this->assertEquals(null, $config->getValue('bar'));
 		$this->assertEquals('moo', $config->getValue('bar', 'moo'));
@@ -40,7 +40,7 @@ class Test_Config extends PHPUnit_Framework_TestCase {
 	public function testSetValue()
 	{
 		file_put_contents(self::CONFIG_FILE, self::TESTCONTENT);
-		$config = new OC\Config(self::CONFIG_DIR, false);
+		$config = new OC\Config(self::CONFIG_DIR);
 		$config->setValue('foo', 'moo');
 		$this->assertAttributeEquals(array('foo'=>'moo'), 'cache', $config);
 		$content = file_get_contents(self::CONFIG_FILE);
@@ -69,7 +69,7 @@ EOL
 	public function testDeleteKey()
 	{
 		file_put_contents(self::CONFIG_FILE, self::TESTCONTENT);
-		$config = new OC\Config(self::CONFIG_DIR, false);
+		$config = new OC\Config(self::CONFIG_DIR);
 		$config->deleteKey('foo');
 		$this->assertAttributeEquals(array(), 'cache', $config);
 		$content = file_get_contents(self::CONFIG_FILE);
@@ -84,11 +84,11 @@ EOL
 
 	public function testSavingDebugMode()
 	{
+		define('DEBUG',true);
 		file_put_contents(self::CONFIG_FILE, self::TESTCONTENT);
-		$config = new OC\Config(self::CONFIG_DIR, true);
+		$config = new OC\Config(self::CONFIG_DIR);
 		$config->deleteKey('foo'); // change something so we save to the config file
 		$this->assertAttributeEquals(array(), 'cache', $config);
-		$this->assertAttributeEquals(true, 'debug_mode', $config);
 		$content = file_get_contents(self::CONFIG_FILE);
 		$this->assertEquals(<<<EOL
 <?php
@@ -102,7 +102,7 @@ EOL
 
 	public function testWriteData()
 	{
-		$config = new OC\Config('/non-writable', false);
+		$config = new OC\Config('/non-writable');
 		try {
 			$config->setValue('foo', 'bar');
 		} catch (\OC\HintException $e) {
-- 
GitLab