From fe79c400d902c332f17118534db40d5a8b14b74a Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Thu, 26 Aug 2010 16:25:13 +0000 Subject: [PATCH] MDL-23948 improved detection of config.php problems --- lib/setup.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/setup.php b/lib/setup.php index 9d2b50a63d86c..84fa9dee86eec 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -42,6 +42,16 @@ */ global $CFG; // this should be done much earlier in config.php before creating new $CFG instance +if (!isset($CFG)) { + if (defined('PHPUNIT_SCRIPT') and PHPUNIT_SCRIPT) { + echo('There is a missing "global $CFG;" at the beginning of the config.php file.'."\n"); + exit(1); + } else { + // this should never happen, maybe somebody is accessing this file directly... + exit(1); + } +} + // We can detect real dirroot path reliably since PHP 4.0.2, // it can not be anything else, there is no point in having this in config.php $CFG->dirroot = dirname(dirname(__FILE__)); @@ -51,7 +61,7 @@ if (isset($_SERVER['REMOTE_ADDR'])) { header($_SERVER['SERVER_PROTOCOL'] . ' 503 Service Unavailable'); } - echo('Fatal error: $CFG->dataroot is not specified in config.php! Exiting.'); + echo('Fatal error: $CFG->dataroot is not specified in config.php! Exiting.'."\n"); exit(1); } $CFG->dataroot = realpath($CFG->dataroot); @@ -59,7 +69,7 @@ if (isset($_SERVER['REMOTE_ADDR'])) { header($_SERVER['SERVER_PROTOCOL'] . ' 503 Service Unavailable'); } - echo('Fatal error: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.'); + echo('Fatal error: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.'."\n"); exit(1); } @@ -68,7 +78,7 @@ if (isset($_SERVER['REMOTE_ADDR'])) { header($_SERVER['SERVER_PROTOCOL'] . ' 503 Service Unavailable'); } - echo('Fatal error: $CFG->wwwroot is not configured! Exiting.'); + echo('Fatal error: $CFG->wwwroot is not configured! Exiting.'."\n"); exit(1); }