MDL-39474 introduce $CFG->debugdeveloper and cleanup $CFG init

This commit is contained in:
Petr Škoda
2013-08-12 13:01:47 +02:00
parent 50ff861263
commit 96f81ea385
43 changed files with 192 additions and 185 deletions
+63 -78
View File
@@ -143,6 +143,11 @@ if (!defined('BEHAT_SITE_RUNNING') && !empty($CFG->behat_dataroot) &&
}
}
// Make sure there is some database table prefix.
if (!isset($CFG->prefix)) {
$CFG->prefix = '';
}
// Define admin directory
if (!isset($CFG->admin)) { // Just in case it isn't defined in config.php
$CFG->admin = 'admin'; // This is relative to the wwwroot and dirroot
@@ -166,6 +171,16 @@ if (!isset($CFG->localcachedir)) {
$CFG->localcachedir = "$CFG->dataroot/localcache";
}
// Location of all languages except core English pack.
if (!isset($CFG->langotherroot)) {
$CFG->langotherroot = $CFG->dataroot.'/lang';
}
// Location of local lang pack customisations (dirs with _local suffix).
if (!isset($CFG->langlocalroot)) {
$CFG->langlocalroot = $CFG->dataroot.'/lang';
}
// The current directory in PHP version 4.3.0 and above isn't necessarily the
// directory of the script when run from the command line. The require_once()
// would fail, so we'll have to chdir()
@@ -309,6 +324,23 @@ umask($CFG->umaskpermissions);
$CFG->yui2version = '2.9.0';
$CFG->yui3version = '3.9.1';
// Store settings from config.php in array in $CFG - we can use it later to detect problems and overrides.
if (!isset($CFG->config_php_settings)) {
$CFG->config_php_settings = (array)$CFG;
// Forced plugin settings override values from config_plugins table.
unset($CFG->config_php_settings['forced_plugin_settings']);
if (!isset($CFG->forced_plugin_settings)) {
$CFG->forced_plugin_settings = array();
}
}
if (isset($CFG->debug)) {
$CFG->debug = (int)$CFG->debug;
} else {
$CFG->debug = 0;
}
$CFG->debugdeveloper = ($CFG->debug & E_ALL and $CFG->debug & E_STRICT); // DEBUG_DEVELOPER is not available yet.
if (!defined('MOODLE_INTERNAL')) { // Necessary because cli installer has to define it earlier.
/** Used by library scripts to check they are being called by Moodle. */
define('MOODLE_INTERNAL', true);
@@ -321,11 +353,7 @@ require_once($CFG->libdir .'/classes/component.php');
if (defined('ABORT_AFTER_CONFIG')) {
if (!defined('ABORT_AFTER_CONFIG_CANCEL')) {
// hide debugging if not enabled in config.php - we do not want to disclose sensitive info
if (isset($CFG->debug)) {
error_reporting($CFG->debug);
} else {
error_reporting(0);
}
error_reporting($CFG->debug);
if (NO_DEBUG_DISPLAY) {
// Some parts of Moodle cannot display errors and debug at all.
ini_set('display_errors', '0');
@@ -454,13 +482,6 @@ global $FULLSCRIPT;
*/
global $SCRIPT;
// Store settings from config.php in array in $CFG - we can use it later to detect problems and overrides
$CFG->config_php_settings = (array)$CFG;
// Forced plugin settings override values from config_plugins table
unset($CFG->config_php_settings['forced_plugin_settings']);
if (!isset($CFG->forced_plugin_settings)) {
$CFG->forced_plugin_settings = array();
}
// Set httpswwwroot default value (this variable will replace $CFG->wwwroot
// inside some URLs used in HTTPSPAGEREQUIRED pages.
$CFG->httpswwwroot = $CFG->wwwroot;
@@ -505,20 +526,6 @@ if (!empty($_SERVER['HTTP_X_moz']) && $_SERVER['HTTP_X_moz'] === 'prefetch'){
exit(1);
}
if (!isset($CFG->prefix)) { // Just in case it isn't defined in config.php
$CFG->prefix = '';
}
// location of all languages except core English pack
if (!isset($CFG->langotherroot)) {
$CFG->langotherroot = $CFG->dataroot.'/lang';
}
// location of local lang pack customisations (dirs with _local suffix)
if (!isset($CFG->langlocalroot)) {
$CFG->langlocalroot = $CFG->dataroot.'/lang';
}
//point pear include path to moodles lib/pear so that includes and requires will search there for files before anywhere else
//the problem is that we need specific version of quickforms and hacked excel files :-(
ini_set('include_path', $CFG->libdir.'/pear' . PATH_SEPARATOR . ini_get('include_path'));
@@ -579,22 +586,42 @@ if (PHPUNIT_TEST and !PHPUNIT_UTIL) {
unset($dbhash);
}
// Disable errors for now - needed for installation when debug enabled in config.php
if (isset($CFG->debug)) {
$originalconfigdebug = $CFG->debug;
unset($CFG->debug);
} else {
$originalconfigdebug = null;
}
// Load up any configuration from the config table
// Load up any configuration from the config table or MUC cache.
if (PHPUNIT_TEST) {
phpunit_util::initialise_cfg();
} else {
initialise_cfg();
}
if (isset($CFG->debug)) {
$CFG->debug = (int)$CFG->debug;
error_reporting($CFG->debug);
} else {
$CFG->debug = 0;
}
$CFG->debugdeveloper = ($CFG->debug & DEBUG_DEVELOPER);
// Find out if PHP configured to display warnings,
// this is a security problem because some moodle scripts may
// disclose sensitive information.
if (ini_get_bool('display_errors')) {
define('WARN_DISPLAY_ERRORS_ENABLED', true);
}
// If we want to display Moodle errors, then try and set PHP errors to match.
if (!isset($CFG->debugdisplay)) {
// Keep it "as is" during installation.
} else if (NO_DEBUG_DISPLAY) {
// Some parts of Moodle cannot display errors and debug at all.
ini_set('display_errors', '0');
ini_set('log_errors', '1');
} else if (empty($CFG->debugdisplay)) {
ini_set('display_errors', '0');
ini_set('log_errors', '1');
} else {
// This is very problematic in XHTML strict mode!
ini_set('display_errors', '1');
}
// Verify upgrade is not running unless we are in a script that needs to execute in any case
if (!defined('NO_UPGRADE_CHECK') and isset($CFG->upgraderunning)) {
if ($CFG->upgraderunning < time()) {
@@ -609,14 +636,6 @@ if (!empty($CFG->logsql)) {
$DB->set_logging(true);
}
// Prevent warnings from roles when upgrading with debug on
if (isset($CFG->debug)) {
$originaldatabasedebug = $CFG->debug;
unset($CFG->debug);
} else {
$originaldatabasedebug = null;
}
// enable circular reference collector in PHP 5.3,
// it helps a lot when using large complex OOP structures such as in amos or gradebook
if (function_exists('gc_enable')) {
@@ -628,40 +647,6 @@ if (function_exists('register_shutdown_function')) {
register_shutdown_function('moodle_request_shutdown');
}
// Set error reporting back to normal
if ($originaldatabasedebug === null) {
$CFG->debug = DEBUG_MINIMAL;
} else {
$CFG->debug = $originaldatabasedebug;
}
if ($originalconfigdebug !== null) {
$CFG->debug = $originalconfigdebug;
}
unset($originalconfigdebug);
unset($originaldatabasedebug);
error_reporting($CFG->debug);
// find out if PHP configured to display warnings,
// this is a security problem because some moodle scripts may
// disclose sensitive information
if (ini_get_bool('display_errors')) {
define('WARN_DISPLAY_ERRORS_ENABLED', true);
}
// If we want to display Moodle errors, then try and set PHP errors to match
if (!isset($CFG->debugdisplay)) {
// keep it "as is" during installation
} else if (NO_DEBUG_DISPLAY) {
// some parts of Moodle cannot display errors and debug at all.
ini_set('display_errors', '0');
ini_set('log_errors', '1');
} else if (empty($CFG->debugdisplay)) {
ini_set('display_errors', '0');
ini_set('log_errors', '1');
} else {
// This is very problematic in XHTML strict mode!
ini_set('display_errors', '1');
}
// detect unsupported upgrade jump as soon as possible - do not change anything, do not use system functions
if (!empty($CFG->version) and $CFG->version < 2007101509) {
print_error('upgraderequires19', 'error');