From e88b380973b54bc7b8bc86f888b1f11ae8e54076 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Mon, 24 Aug 2015 12:00:37 +0200 Subject: [PATCH] Remove DEBUG constant and use config value * introduces config.php option 'debug' that defaults to false * migrate DEBUG constant to config value --- apps/files/appinfo/update.php | 9 +++++++++ apps/files/appinfo/version | 2 +- config/config.sample.php | 14 ++++++++------ core/js/config.php | 2 +- lib/base.php | 9 +++++---- lib/private/config.php | 6 ------ lib/private/server.php | 6 +++--- lib/private/template.php | 2 +- 8 files changed, 28 insertions(+), 22 deletions(-) diff --git a/apps/files/appinfo/update.php b/apps/files/appinfo/update.php index 2691c05c34..ff1369bb1a 100644 --- a/apps/files/appinfo/update.php +++ b/apps/files/appinfo/update.php @@ -94,3 +94,12 @@ if ($installedVersion === '1.1.9' && ( } } } + +/** + * migrate old constant DEBUG to new config value 'debug' + * + * TODO: remove this in ownCloud 8.3 + */ +if(defined('DEBUG') && DEBUG === true) { + \OC::$server->getConfig()->setSystemValue('debug', true); +} diff --git a/apps/files/appinfo/version b/apps/files/appinfo/version index 5ed5faa5f1..9ee1f786d5 100644 --- a/apps/files/appinfo/version +++ b/apps/files/appinfo/version @@ -1 +1 @@ -1.1.10 +1.1.11 diff --git a/config/config.sample.php b/config/config.sample.php index 522cf02ceb..234bf8e0fa 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -20,12 +20,6 @@ * * use RST syntax */ -/** - * Only enable this for local development and not in production environments - * This will disable the minifier and outputs some additional debug informations - */ -define('DEBUG', true); - $CONFIG = array( @@ -1079,6 +1073,14 @@ $CONFIG = array( */ 'memcache.locking' => '\\OC\\Memcache\\Redis', +/** + * Set this ownCloud instance to debugging mode + * + * Only enable this for local development and not in production environments + * This will disable the minifier and outputs some additional debug information + */ +'debug' => false, + /** * This entry is just here to show a warning in case somebody copied the sample * configuration. DO NOT ADD THIS SWITCH TO YOUR CONFIGURATION! diff --git a/core/js/config.php b/core/js/config.php index 95dd733028..21451bf91b 100644 --- a/core/js/config.php +++ b/core/js/config.php @@ -62,7 +62,7 @@ if ($defaultExpireDateEnabled) { $outgoingServer2serverShareEnabled = $config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; $array = array( - "oc_debug" => (defined('DEBUG') && DEBUG) ? 'true' : 'false', + "oc_debug" => $config->getSystemValue('debug', false), "oc_isadmin" => OC_User::isAdminUser(OC_User::getUser()) ? 'true' : 'false', "oc_webroot" => "\"".OC::$WEBROOT."\"", "oc_appswebroots" => str_replace('\\/', '/', json_encode($apps_paths)), // Ugly unescape slashes waiting for better solution diff --git a/lib/base.php b/lib/base.php index 2435661dfa..aceac2e53c 100644 --- a/lib/base.php +++ b/lib/base.php @@ -582,7 +582,7 @@ class OC { if (!defined('PHPUNIT_RUN')) { $logger = \OC::$server->getLogger(); OC\Log\ErrorHandler::setLogger($logger); - if (defined('DEBUG') and DEBUG) { + if (\OC::$server->getConfig()->getSystemValue('debug', false)) { OC\Log\ErrorHandler::register(true); set_exception_handler(array('OC_Template', 'printExceptionErrorPage')); } else { @@ -1040,7 +1040,7 @@ class OC { return false; } - if (defined("DEBUG") && DEBUG) { + if (\OC::$server->getConfig()->getSystemValue('debug', false)) { \OCP\Util::writeLog('core', 'Trying to login from cookie', \OCP\Util::DEBUG); } @@ -1093,11 +1093,12 @@ class OC { self::cleanupLoginTokens($userId); if (!empty($_POST["remember_login"])) { - if (defined("DEBUG") && DEBUG) { + $config = self::$server->getConfig(); + if ($config->getSystemValue('debug', false)) { self::$server->getLogger()->debug('Setting remember login to cookie', array('app' => 'core')); } $token = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(32); - self::$server->getConfig()->setUserValue($userId, 'login_token', $token, time()); + $config->setUserValue($userId, 'login_token', $token, time()); OC_User::setMagicInCookie($userId, $token); } else { OC_User::unsetMagicInCookie(); diff --git a/lib/private/config.php b/lib/private/config.php index 20ff02c1ab..3ad800a00b 100644 --- a/lib/private/config.php +++ b/lib/private/config.php @@ -47,8 +47,6 @@ class Config { protected $configFilePath; /** @var string */ protected $configFileName; - /** @var bool */ - protected $debugMode; /** * @param string $configDir Path to the config dir, needs to end with '/' @@ -59,7 +57,6 @@ class Config { $this->configFilePath = $this->configDir.$fileName; $this->configFileName = $fileName; $this->readData(); - $this->debugMode = (defined('DEBUG') && DEBUG); } /** @@ -225,9 +222,6 @@ class Config { private function writeData() { // Create a php file ... $content = "debugMode) { - $content .= "define('DEBUG',true);\n"; - } $content .= '$CONFIG = '; $content .= var_export($this->cache, true); $content .= ";\n"; diff --git a/lib/private/server.php b/lib/private/server.php index 92a671c721..5a3a6328fa 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -329,14 +329,14 @@ class Server extends SimpleContainer implements IServerContainer { ); }); $this->registerService('EventLogger', function (Server $c) { - if (defined('DEBUG') and DEBUG) { + if ($c->getSystemConfig()->getValue('debug', false)) { return new EventLogger(); } else { return new NullEventLogger(); } }); - $this->registerService('QueryLogger', function ($c) { - if (defined('DEBUG') and DEBUG) { + $this->registerService('QueryLogger', function (Server $c) { + if ($c->getSystemConfig()->getValue('debug', false)) { return new QueryLogger(); } else { return new NullQueryLogger(); diff --git a/lib/private/template.php b/lib/private/template.php index e7acc778de..920be71abb 100644 --- a/lib/private/template.php +++ b/lib/private/template.php @@ -233,7 +233,7 @@ class OC_Template extends \OC\Template\Base { $content->assign('file', $exception->getFile()); $content->assign('line', $exception->getLine()); $content->assign('trace', $exception->getTraceAsString()); - $content->assign('debugMode', defined('DEBUG') && DEBUG === true); + $content->assign('debugMode', \OC::$server->getSystemConfig()->getValue('debug', false)); $content->assign('remoteAddr', $request->getRemoteAddress()); $content->assign('requestID', $request->getId()); $content->printPage();