Skip to content

Commit

Permalink
MDL-23948 improved detection of config.php problems
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Aug 26, 2010
1 parent 1e36599 commit fe79c40
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/setup.php
Expand Up @@ -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__));
Expand All @@ -51,15 +61,15 @@
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);
if ($CFG->dataroot === false) {
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);
}

Expand All @@ -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);
}

Expand Down

0 comments on commit fe79c40

Please sign in to comment.