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

This commit is contained in:
Petr Škoda 2013-08-10 22:46:49 +02:00
parent 50ff861263
commit 96f81ea385
43 changed files with 192 additions and 185 deletions

View File

@ -75,8 +75,7 @@ if (!empty($CFG->showcronsql)) {
$DB->set_debug(true);
}
if (!empty($CFG->showcrondebugging)) {
$CFG->debug = DEBUG_DEVELOPER;
$CFG->debugdisplay = true;
set_debugging(DEBUG_DEVELOPER, true);
}
$starttime = microtime();

View File

@ -162,6 +162,9 @@ $CFG->running_installer = true;
$CFG->early_install_lang = true;
$CFG->ostype = (stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin')) ? 'WINDOWS' : 'UNIX';
$CFG->dboptions = array();
$CFG->debug = (E_ALL | E_STRICT);
$CFG->debugdisplay = true;
$CFG->debugdeveloper = true;
$parts = explode('/', str_replace('\\', '/', dirname(dirname(__FILE__))));
$CFG->admin = array_pop($parts);

View File

@ -28,7 +28,7 @@ define('CLI_SCRIPT', true);
require(dirname(__FILE__) . '/../../../../config.php');
require_once(dirname(__FILE__) . '/../locallib.php');
if (!debugging('', DEBUG_DEVELOPER)) {
if (!$CFG->debugdeveloper) {
echo("This script is for developers only!!!\n");
exit(1);
}

View File

@ -34,7 +34,7 @@ if (!is_siteadmin()) {
error('Only for admins');
}
if (!debugging('', DEBUG_DEVELOPER)) {
if (!$CFG->debugdeveloper) {
error('This script is for developers only!!!');
}

View File

@ -34,7 +34,7 @@ $execute = optional_param('execute', 0, PARAM_BOOL);
navigation_node::override_active_url(new moodle_url('/admin/tool/phpunit/index.php'));
admin_externalpage_setup('toolphpunitwebrunner');
if (!debugging('', DEBUG_DEVELOPER)) {
if (!$CFG->debugdeveloper) {
error('Not available on production sites, sorry.');
}
@ -82,7 +82,7 @@ if ($execute) {
if ($code != 0) {
tool_phpunit_problem('Can not initialize database');
}
$CFG->debug = 0; // no pesky redirect warning, we really want to redirect
set_debugging(DEBUG_NONE, false); // Hack: no redirect warning, we really want to redirect.
redirect(new moodle_url($PAGE->url, array('execute'=>1, 'tespath'=>$testpath, 'testclass'=>$testclass, 'sesskey'=>sesskey())), 'Reloading page');
echo $OUTPUT->footer();
die();
@ -103,7 +103,7 @@ if ($execute) {
if ($code != 0) {
tool_phpunit_problem('Can not initialize database');
}
$CFG->debug = 0; // no pesky redirect warning, we really want to redirect
set_debugging(DEBUG_NONE, false); // Hack: no redirect warning, we really want to redirect.
redirect(new moodle_url($PAGE->url, array('execute'=>1, 'tespath'=>$testpath, 'testclass'=>$testclass, 'sesskey'=>sesskey())), 'Reloading page');
die();

View File

@ -48,7 +48,7 @@ require(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php');
require_once($CFG->dirroot.'/course/lib.php');
// Ensure errors are well explained
$CFG->debug = DEBUG_NORMAL;
set_debugging(DEBUG_DEVELOPER, true);
if (!is_enabled_auth('cas')) {
error_log('[AUTH CAS] '.get_string('pluginnotenabled', 'auth_ldap'));

View File

@ -52,7 +52,7 @@ require(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php'); // global m
require_once($CFG->dirroot.'/course/lib.php');
// Ensure errors are well explained
$CFG->debug = DEBUG_NORMAL;
set_debugging(DEBUG_DEVELOPER, true);
if (!is_enabled_auth('ldap')) {
error_log('[AUTH LDAP] '.get_string('pluginnotenabled', 'auth_ldap'));

View File

@ -40,7 +40,7 @@ abstract class backup_factory {
global $CFG;
$dfltloglevel = backup::LOG_WARNING; // Default logging level
if (debugging('', DEBUG_DEVELOPER)) { // Debug developer raises default logging level
if ($CFG->debugdeveloper) { // Debug developer raises default logging level
$dfltloglevel = backup::LOG_DEBUG;
}

View File

@ -94,7 +94,6 @@ class backup_factories_testcase extends advanced_testcase {
// Instantiate with debugging enabled and $CFG->backup_error_log_logger_level not set
$CFG->debugdisplay = true;
$CFG->debug = DEBUG_DEVELOPER;
unset($CFG->backup_error_log_logger_level);
$logger1 = backup_factory::get_logger_chain(backup::INTERACTIVE_YES, backup::EXECUTION_INMEDIATE, 'test');
$this->assertTrue($logger1 instanceof error_log_logger); // 1st logger is error_log_logger

View File

@ -189,11 +189,8 @@ class core_cache_administration_helper_testcase extends advanced_testcase {
* Test the hash_key functionality.
*/
public function test_hash_key() {
global $CFG;
$currentdebugging = $CFG->debug;
$CFG->debug = E_ALL;
$this->resetAfterTest();
set_debugging(DEBUG_ALL);
// First with simplekeys
$instance = cache_config_phpunittest::instance(true);
@ -230,7 +227,5 @@ class core_cache_administration_helper_testcase extends advanced_testcase {
$result = cache_helper::hash_key('test/test', $definition);
$this->assertEquals(sha1($definition->generate_single_key_prefix().'-test/test'), $result);
$CFG->debug = $currentdebugging;
}
}

View File

@ -46,7 +46,7 @@ require(__DIR__.'/../../../config.php');
require_once("$CFG->libdir/clilib.php");
// Ensure errors are well explained.
$CFG->debug = DEBUG_DEVELOPER;
set_debugging(DEBUG_DEVELOPER, true);
if (!enrol_is_enabled('ldap')) {
cli_error(get_string('pluginnotenabled', 'enrol_ldap'), 2);

View File

@ -181,6 +181,9 @@ $CFG->umaskpermissions = (($CFG->directorypermissions & 0777) ^ 0777);
$CFG->running_installer = true;
$CFG->early_install_lang = true;
$CFG->ostype = (stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin')) ? 'WINDOWS' : 'UNIX';
$CFG->debug = (E_ALL | E_STRICT);
$CFG->debugdisplay = true;
$CFG->debugdeveloper = true;
// Require all needed libs
require_once($CFG->libdir.'/setuplib.php');

View File

@ -3792,7 +3792,7 @@ function get_users_by_capability(context $context, $capability, $fields = '', $s
$fields = 'u.*';
}
} else {
if (debugging('', DEBUG_DEVELOPER) && strpos($fields, 'u.*') === false && strpos($fields, 'u.id') === false) {
if ($CFG->debugdeveloper && strpos($fields, 'u.*') === false && strpos($fields, 'u.id') === false) {
debugging('u.id must be included in the list of fields passed to get_users_by_capability().', DEBUG_DEVELOPER);
}
}

View File

@ -968,6 +968,8 @@ class admin_category implements parentable_part_of_admin_tree {
* @return bool True if successfully added, false if $something can not be added.
*/
public function add($parentname, $something, $beforesibling = null) {
global $CFG;
$parent = $this->locate($parentname);
if (is_null($parent)) {
debugging('parent does not exist!');
@ -979,7 +981,7 @@ class admin_category implements parentable_part_of_admin_tree {
debugging('error - parts of tree can be inserted only into parentable parts');
return false;
}
if (debugging('', DEBUG_DEVELOPER) && !is_null($this->locate($something->name))) {
if ($CFG->debugdeveloper && !is_null($this->locate($something->name))) {
// The name of the node is already used, simply warn the developer that this should not happen.
// It is intentional to check for the debug level before performing the check.
debugging('Duplicate admin page name: ' . $something->name, DEBUG_DEVELOPER);

View File

@ -189,12 +189,9 @@ class core_component {
protected static function is_developer() {
global $CFG;
// Note we can not rely on $CFG->debug here because DB is not initialised yet.
if (isset($CFG->config_php_settings['debug'])) {
// Standard moodle script.
$debug = (int)$CFG->config_php_settings['debug'];
} else if (isset($CFG->debug)) {
// Usually script with ABORT_AFTER_CONFIG.
$debug = (int)$CFG->debug;
} else {
return false;
}

View File

@ -108,7 +108,7 @@ abstract class base implements \IteratorAggregate {
* @throws \coding_exception
*/
public static final function create(array $data = null) {
global $PAGE, $USER;
global $PAGE, $USER, $CFG;
$data = (array)$data;
@ -178,7 +178,7 @@ abstract class base implements \IteratorAggregate {
}
// Warn developers if they do something wrong.
if (debugging('', DEBUG_DEVELOPER)) { // This should be replaced by new $CFG->slowdebug flag if introduced.
if ($CFG->debugdeveloper) {
static $automatickeys = array('eventname', 'component', 'action', 'target', 'contextlevel', 'contextinstanceid', 'timecreated');
static $initkeys = array('crud', 'level', 'objecttable');
@ -187,10 +187,10 @@ abstract class base implements \IteratorAggregate {
continue;
} else if (in_array($key, $automatickeys)) {
debugging("Data key '$key' is not allowed in \\core\\event\\base::create() method, it is set automatically");
debugging("Data key '$key' is not allowed in \\core\\event\\base::create() method, it is set automatically", DEBUG_DEVELOPER);
} else if (in_array($key, $initkeys)) {
debugging("Data key '$key' is not allowed in \\core\\event\\base::create() method, you need to set it in init() method");
debugging("Data key '$key' is not allowed in \\core\\event\\base::create() method, you need to set it in init() method", DEBUG_DEVELOPER);
} else if (!in_array($key, self::$fields)) {
debugging("Data key '$key' does not exist in \\core\\event\\base");
@ -395,7 +395,7 @@ abstract class base implements \IteratorAggregate {
* @throws \coding_exception
*/
protected final function validate_before_trigger() {
global $DB;
global $DB, $CFG;
if (empty($this->data['crud'])) {
throw new \coding_exception('crud must be specified in init() method of each method');
@ -407,38 +407,38 @@ abstract class base implements \IteratorAggregate {
throw new \coding_exception('objecttable must be specified in init() method if objectid present');
}
if (debugging('', DEBUG_DEVELOPER)) { // This should be replaced by new $CFG->slowdebug flag if introduced.
if ($CFG->debugdeveloper) {
// Ideally these should be coding exceptions, but we need to skip these for performance reasons
// on production servers.
if (!in_array($this->data['crud'], array('c', 'r', 'u', 'd'), true)) {
debugging("Invalid event crud value specified.");
debugging("Invalid event crud value specified.", DEBUG_DEVELOPER);
}
if (!is_number($this->data['level'])) {
debugging('Event property level must be a number');
debugging('Event property level must be a number', DEBUG_DEVELOPER);
}
if (self::$fields !== array_keys($this->data)) {
debugging('Number of event data fields must not be changed in event classes');
debugging('Number of event data fields must not be changed in event classes', DEBUG_DEVELOPER);
}
$encoded = json_encode($this->data['other']);
if ($encoded === false or $this->data['other'] !== json_decode($encoded, true)) {
debugging('other event data must be compatible with json encoding');
debugging('other event data must be compatible with json encoding', DEBUG_DEVELOPER);
}
if ($this->data['userid'] and !is_number($this->data['userid'])) {
debugging('Event property userid must be a number');
debugging('Event property userid must be a number', DEBUG_DEVELOPER);
}
if ($this->data['courseid'] and !is_number($this->data['courseid'])) {
debugging('Event property courseid must be a number');
debugging('Event property courseid must be a number', DEBUG_DEVELOPER);
}
if ($this->data['objectid'] and !is_number($this->data['objectid'])) {
debugging('Event property objectid must be a number');
debugging('Event property objectid must be a number', DEBUG_DEVELOPER);
}
if ($this->data['relateduserid'] and !is_number($this->data['relateduserid'])) {
debugging('Event property relateduserid must be a number');
debugging('Event property relateduserid must be a number', DEBUG_DEVELOPER);
}
if ($this->data['objecttable']) {
if (!$DB->get_manager()->table_exists($this->data['objecttable'])) {
debugging('Unknown table specified in objecttable field');
debugging('Unknown table specified in objecttable field', DEBUG_DEVELOPER);
}
}
}
@ -521,7 +521,7 @@ abstract class base implements \IteratorAggregate {
* @throws \coding_exception if used after ::trigger()
*/
public final function add_record_snapshot($tablename, $record) {
global $DB;
global $DB, $CFG;
if ($this->triggered) {
throw new \coding_exception('It is not possible to add snapshots after triggering of events');
@ -529,9 +529,9 @@ abstract class base implements \IteratorAggregate {
// NOTE: this might use some kind of MUC cache,
// hopefully we will not run out of memory here...
if (debugging('', DEBUG_DEVELOPER)) { // This should be replaced by new $CFG->slowdebug flag if introduced.
if ($CFG->debugdeveloper) {
if (!$DB->get_manager()->table_exists($tablename)) {
debugging("Invalid table name '$tablename' specified, database table does not exist.");
debugging("Invalid table name '$tablename' specified, database table does not exist.", DEBUG_DEVELOPER);
}
}
$this->recordsnapshots[$tablename][$record->id] = $record;

View File

@ -46,8 +46,7 @@ function cron_run() {
$DB->set_debug(true);
}
if (!empty($CFG->showcrondebugging)) {
$CFG->debug = DEBUG_DEVELOPER;
$CFG->debugdisplay = true;
set_debugging(DEBUG_DEVELOPER, true);
}
set_time_limit(0);

View File

@ -308,16 +308,17 @@ abstract class pdo_moodle_database extends moodle_database {
* @return array of objects, or empty array if no records were found, or false if an error occurred.
*/
public function get_records_sql($sql, array $params=null, $limitfrom=0, $limitnum=0) {
global $CFG;
$rs = $this->get_recordset_sql($sql, $params, $limitfrom, $limitnum);
if (!$rs->valid()) {
$rs->close(); // Not going to iterate (but exit), close rs
return false;
}
$objects = array();
$debugging = debugging('', DEBUG_DEVELOPER);
foreach($rs as $value) {
$key = reset($value);
if ($debugging && array_key_exists($key, $objects)) {
if ($CFG->debugdeveloper && array_key_exists($key, $objects)) {
debugging("Did you remember to make the first column something unique in your call to get_records? Duplicate value '$key' found in column first column of '$sql'.", DEBUG_DEVELOPER);
}
$objects[$key] = (object)$value;

View File

@ -1475,8 +1475,6 @@ class core_dml_testcase extends database_driver_testcase {
}
public function test_get_records_sql() {
global $CFG;
$DB = $this->tdb;
$dbman = $DB->get_manager();
@ -1518,11 +1516,11 @@ class core_dml_testcase extends database_driver_testcase {
$records = $DB->get_records_sql("SELECT course AS id, course AS course FROM {{$tablename}}", null);
$this->assertDebuggingCalled();
$this->assertEquals(6, count($records));
$CFG->debug = DEBUG_MINIMAL;
set_debugging(DEBUG_MINIMAL);
$records = $DB->get_records_sql("SELECT course AS id, course AS course FROM {{$tablename}}", null);
$this->assertDebuggingNotCalled();
$this->assertEquals(6, count($records));
$CFG->debug = DEBUG_DEVELOPER;
set_debugging(DEBUG_DEVELOPER);
// negative limits = no limits
$records = $DB->get_records_sql("SELECT * FROM {{$tablename}} ORDER BY id", null, -1, -1);
@ -1734,8 +1732,6 @@ class core_dml_testcase extends database_driver_testcase {
}
public function test_get_record_sql() {
global $CFG;
$DB = $this->tdb;
$dbman = $DB->get_manager();
@ -1774,10 +1770,10 @@ class core_dml_testcase extends database_driver_testcase {
$this->assertNotEmpty($DB->get_record_sql("SELECT * FROM {{$tablename}}", array(), IGNORE_MISSING));
$this->assertDebuggingCalled();
$CFG->debug = DEBUG_MINIMAL;
set_debugging(DEBUG_MINIMAL);
$this->assertNotEmpty($DB->get_record_sql("SELECT * FROM {{$tablename}}", array(), IGNORE_MISSING));
$this->assertDebuggingNotCalled();
$CFG->debug = DEBUG_DEVELOPER;
set_debugging(DEBUG_DEVELOPER);
// multiple matches ignored
$this->assertNotEmpty($DB->get_record_sql("SELECT * FROM {{$tablename}}", array(), IGNORE_MULTIPLE));

View File

@ -360,7 +360,7 @@ abstract class editor_tinymce_plugin {
// Version number comes from plugin version.php, except in developer
// mode where the special string 'dev' is used (prevents cacheing and
// serves unminified JS).
if (debugging('', DEBUG_DEVELOPER)) {
if ($CFG->debugdeveloper) {
$version = '-1';
} else {
$version = $this->get_version();

View File

@ -26,7 +26,7 @@ define('CLI_SCRIPT', true);
require __DIR__ . '/../../../../config.php';
if (!debugging('', DEBUG_DEVELOPER)) {
if (!$CFG->debugdeveloper) {
die('Only for developers!!!!!');
}

View File

@ -100,7 +100,7 @@ class tinymce_texteditor extends texteditor {
public function use_editor($elementid, array $options=null, $fpoptions=null) {
global $PAGE, $CFG;
// Note: use full moodle_url instance to prevent standard JS loader, make sure we are using https on profile page if required.
if (debugging('', DEBUG_DEVELOPER)) {
if ($CFG->debugdeveloper) {
$PAGE->requires->js(new moodle_url($CFG->httpswwwroot.'/lib/editor/tinymce/tiny_mce/'.$this->version.'/tiny_mce_src.js'));
} else {
$PAGE->requires->js(new moodle_url($CFG->httpswwwroot.'/lib/editor/tinymce/tiny_mce/'.$this->version.'/tiny_mce.js'));

View File

@ -1624,6 +1624,8 @@ class file_storage {
* @return array (contenthash, filesize, newfile)
*/
public function add_file_to_pool($pathname, $contenthash = NULL) {
global $CFG;
if (!is_readable($pathname)) {
throw new file_exception('storedfilecannotread', '', $pathname);
}
@ -1635,14 +1637,14 @@ class file_storage {
if (is_null($contenthash)) {
$contenthash = sha1_file($pathname);
} else if (debugging('', DEBUG_DEVELOPER)) {
} else if ($CFG->debugdeveloper) {
$filehash = sha1_file($pathname);
if ($filehash === false) {
throw new file_exception('storedfilecannotread', '', $pathname);
}
if ($filehash !== $contenthash) {
// Hopefully this never happens, if yes we need to fix calling code.
debugging("Invalid contenthash submitted for file $pathname");
debugging("Invalid contenthash submitted for file $pathname", DEBUG_DEVELOPER);
$contenthash = $filehash;
}
}

View File

@ -61,7 +61,7 @@ function pear_handle_error($error){
print_object($error->backtrace);
}
if (!empty($CFG->debug) and ($CFG->debug >= DEBUG_ALL or $CFG->debug == -1)){
if ($CFG->debugdeveloper) {
//TODO: this is a wrong place to init PEAR!
$GLOBALS['_PEAR_default_error_mode'] = PEAR_ERROR_CALLBACK;
$GLOBALS['_PEAR_default_error_options'] = 'pear_handle_error';
@ -1261,7 +1261,9 @@ abstract class moodleform {
* @return void
*/
private function detectMissingSetType() {
if (!debugging('', DEBUG_DEVELOPER)) {
global $CFG;
if (!$CFG->debugdeveloper) {
// Only for devs.
return;
}

View File

@ -424,6 +424,7 @@ function install_cli_database(array $options, $interactive) {
@ini_set('display_errors', '1');
$CFG->debug = (E_ALL | E_STRICT);
$CFG->debugdisplay = true;
$CFG->debugdeveloper = true;
$CFG->version = '';
$CFG->release = '';

View File

@ -14,7 +14,7 @@ defined('MOODLE_INTERNAL') || die(); // start of moodle modification
$min_enableBuilder = false;
$min_errorLogger = false;
$min_allowDebugFlag = debugging('', DEBUG_DEVELOPER);
$min_allowDebugFlag = $CFG->debugdeveloper;
$min_cachePath = $CFG->tempdir;
$min_documentRoot = $CFG->dirroot.'/lib/minify';
$min_cacheFileLocking = empty($CFG->preventfilelocking);

View File

@ -7689,8 +7689,8 @@ function get_string($identifier, $component = '', $a = null, $lazyload = false)
return new lang_string($identifier, $component, $a);
}
if (debugging('', DEBUG_DEVELOPER) && clean_param($identifier, PARAM_STRINGID) === '') {
throw new coding_exception('Invalid string identifier. The identifier cannot be empty. Please fix your get_string() call.');
if ($CFG->debugdeveloper && clean_param($identifier, PARAM_STRINGID) === '') {
throw new coding_exception('Invalid string identifier. The identifier cannot be empty. Please fix your get_string() call.', DEBUG_DEVELOPER);
}
// There is now a forth argument again, this time it is a boolean however so
@ -8240,7 +8240,7 @@ function get_list_of_plugins($directory='mod', $exclude='', $basedir='') {
$basedir = $basedir .'/'. $directory;
}
if (empty($exclude) and debugging('', DEBUG_DEVELOPER)) {
if ($CFG->debugdeveloper and empty($exclude)) {
// Make sure devs do not use this to list normal plugins,
// this is intended for general directories that are not plugins!
@ -11166,8 +11166,8 @@ class lang_string {
// Check if we need to process the string.
if ($this->string === null) {
// Check the quality of the identifier.
if (debugging('', DEBUG_DEVELOPER) && clean_param($this->identifier, PARAM_STRINGID) === '') {
throw new coding_exception('Invalid string identifier. Most probably some illegal character is part of the string identifier. Please check your string definition');
if ($CFG->debugdeveloper && clean_param($this->identifier, PARAM_STRINGID) === '') {
throw new coding_exception('Invalid string identifier. Most probably some illegal character is part of the string identifier. Please check your string definition', DEBUG_DEVELOPER);
}
// Process the string.

View File

@ -1678,7 +1678,8 @@ class xhtml_container_stack {
* Constructor
*/
public function __construct() {
$this->isdebugging = debugging('', DEBUG_DEVELOPER);
global $CFG;
$this->isdebugging = $CFG->debugdeveloper;
}
/**

View File

@ -2529,7 +2529,7 @@ EOD;
}
$output .= $this->box($message, 'errorbox', null, array('data-rel' => 'fatalerror'));
if (debugging('', DEBUG_DEVELOPER)) {
if ($CFG->debugdeveloper) {
if (!empty($debuginfo)) {
$debuginfo = s($debuginfo); // removes all nasty JS
$debuginfo = str_replace("\n", '<br />', $debuginfo); // keep newlines
@ -3361,7 +3361,7 @@ class core_renderer_cli extends core_renderer {
public function fatal_error($message, $moreinfourl, $link, $backtrace, $debuginfo = null) {
$output = "!!! $message !!!\n";
if (debugging('', DEBUG_DEVELOPER)) {
if ($CFG->debugdeveloper) {
if (!empty($debuginfo)) {
$output .= $this->notification($debuginfo, 'notifytiny');
}

View File

@ -224,7 +224,7 @@ class page_requirements_manager {
));
// Set some more loader options applying to groups too.
if (debugging('', DEBUG_DEVELOPER)) {
if ($CFG->debugdeveloper) {
// When debugging is enabled, we want to load the non-minified (RAW) versions of YUI library modules rather
// than the DEBUG versions as these generally generate too much logging for our purposes.
// However we do want the DEBUG versions of our Moodle-specific modules.
@ -270,7 +270,7 @@ class page_requirements_manager {
'jsrev' => ((empty($CFG->cachejs) or empty($CFG->jsrev)) ? -1 : $CFG->jsrev),
'svgicons' => $page->theme->use_svg_icons()
);
if (debugging('', DEBUG_DEVELOPER)) {
if ($CFG->debugdeveloper) {
$this->M_cfg['developerdebug'] = true;
}
@ -436,7 +436,7 @@ class page_requirements_manager {
$this->jqueryplugins[$plugin]->urls = array();
foreach ($plugins[$plugin]['files'] as $file) {
if (debugging('', DEBUG_DEVELOPER)) {
if ($CFG->debugdeveloper) {
if (!file_exists("$componentdir/jquery/$file")) {
debugging("Invalid file '$file' specified in jQuery plugin '$plugin' in component '$component'");
continue;
@ -746,7 +746,7 @@ class page_requirements_manager {
// Don't load this module if we already have, no need to!
if ($this->js_module_loaded($module['name'])) {
if (debugging('', DEBUG_DEVELOPER)) {
if ($CFG->debugdeveloper) {
$this->debug_moduleloadstacktraces[$module['name']][] = format_backtrace(debug_backtrace());
}
return;
@ -780,7 +780,7 @@ class page_requirements_manager {
} else {
$this->YUI_config->add_module_config($module['name'], $module);
}
if (debugging('', DEBUG_DEVELOPER)) {
if ($CFG->debugdeveloper) {
if (!array_key_exists($module['name'], $this->debug_moduleloadstacktraces)) {
$this->debug_moduleloadstacktraces[$module['name']] = array();
}

View File

@ -198,6 +198,7 @@ unset($productioncfg);
// force the same CFG settings in all sites
$CFG->debug = (E_ALL | E_STRICT); // can not use DEBUG_DEVELOPER yet
$CFG->debugdeveloper = true;
$CFG->debugdisplay = 1;
error_reporting($CFG->debug);
ini_set('display_errors', '1');

View File

@ -248,7 +248,8 @@ abstract class advanced_testcase extends PHPUnit_Framework_TestCase {
}
/**
* Clear all previous debugging messages in current test.
* Clear all previous debugging messages in current test
* and revert to default DEVELOPER_DEBUG level.
*/
public function resetDebugging() {
phpunit_util::reset_debugging();

View File

@ -594,6 +594,7 @@ class phpunit_util extends testing_util {
*/
public static function reset_debugging() {
self::$debuggings = array();
set_debugging(DEBUG_DEVELOPER);
}
/**

View File

@ -65,9 +65,10 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
$debuggings = $this->getDebuggingMessages();
$this->assertEquals(0, count($debuggings));
$CFG->debug = DEBUG_NONE;
set_debugging(DEBUG_NONE);
debugging('hokus');
$this->assertDebuggingNotCalled();
set_debugging(DEBUG_DEVELOPER);
}
public function test_set_user() {

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');

View File

@ -730,25 +730,28 @@ function setup_validate_php_configuration() {
}
/**
* Initialise global $CFG variable
* @return void
* Initialise global $CFG variable.
* @private to be used only from lib/setup.php
*/
function initialise_cfg() {
global $CFG, $DB;
if (!$DB) {
// This should not happen.
return;
}
try {
if ($DB) {
$localcfg = get_config('core');
foreach ($localcfg as $name => $value) {
if (property_exists($CFG, $name)) {
// config.php settings always take precedence
continue;
}
$CFG->{$name} = $value;
}
}
$localcfg = get_config('core');
} catch (dml_exception $e) {
// most probably empty db, going to install soon
// Most probably empty db, going to install soon.
return;
}
foreach ($localcfg as $name => $value) {
// Note that get_config() keeps forced settings
// and normalises values to string if possible.
$CFG->{$name} = $value;
}
}

View File

@ -637,10 +637,10 @@ class core_event_testcase extends advanced_testcase {
$event2 = \core_tests\event\problematic_event1::create(array('xxx'=>0, 'context'=>\context_system::instance()));
$this->assertDebuggingCalled();
$CFG->debug = 0;
set_debugging(DEBUG_NONE);
$event3 = \core_tests\event\problematic_event1::create(array('xxx'=>0, 'context'=>\context_system::instance()));
$this->assertDebuggingNotCalled();
$CFG->debug = E_ALL | E_STRICT;
set_debugging(DEBUG_DEVELOPER);
$event4 = \core_tests\event\problematic_event1::create(array('context'=>\context_system::instance(), 'other'=>array('a'=>1)));
$event4->trigger();

View File

@ -299,24 +299,22 @@ class core_statslib_testcase extends advanced_testcase {
* Test progress output when debug is on.
*/
public function test_statslib_progress_debug() {
global $CFG;
$CFG->debug = DEBUG_ALL;
set_debugging(DEBUG_ALL);
$this->expectOutputString('1:0 ');
stats_progress('init');
stats_progress('1');
$this->resetDebugging();
}
/**
* Test progress output when debug is off.
*/
public function test_statslib_progress_no_debug() {
global $CFG;
$CFG->debug = DEBUG_NONE;
set_debugging(DEBUG_NONE);
$this->expectOutputString('.');
stats_progress('init');
stats_progress('1');
$this->resetDebugging();
}
/**

View File

@ -13,6 +13,8 @@ information provided here is intended especially for developers.
* New $CFG->localcachedir setting useful for cluster nodes. Admins have to update X-Sendfile aliases if used.
* MS SQL Server drivers are now using NVARCHAR(MAX) instead of NTEXT and VARBINARY(MAX) instead of IMAGE,
this change should be fully transparent and it should help significantly with add-on compatibility.
* Use $CFG->debugdeveloper instead of debugging('', DEBUG_DEVELOPER).
* Use set_debugging(DEBUG_xxx) when changing debugging level for current request.
DEPRECATIONS:
Various previously deprecated functions have now been altered to throw DEBUG_DEVELOPER debugging notices

View File

@ -1142,7 +1142,7 @@ function upgrade_handle_exception($ex, $plugin = null) {
upgrade_log(UPGRADE_LOG_ERROR, $plugin, 'Exception: ' . get_class($ex), $info->message, $info->backtrace);
// Always turn on debugging - admins need to know what is going on
$CFG->debug = DEBUG_DEVELOPER;
set_debugging(DEBUG_DEVELOPER, true);
default_exception_handler($ex, true, $plugin);
}

View File

@ -1216,7 +1216,7 @@ function format_text($text, $format = FORMAT_MOODLE, $options = null, $courseidd
// the text before storing into database which would be itself big bug..
$text = str_replace("\"$CFG->httpswwwroot/draftfile.php", "\"$CFG->httpswwwroot/brokenfile.php#", $text);
if (debugging('', DEBUG_DEVELOPER)) {
if ($CFG->debugdeveloper) {
if (strpos($text, '@@PLUGINFILE@@/') !== false) {
debugging('Before calling format_text(), the content must be processed with file_rewrite_pluginfile_urls()',
DEBUG_DEVELOPER);
@ -2791,6 +2791,24 @@ function print_tabs($tabrows, $selected = null, $inactive = null, $activated = n
}
}
/**
* Alter debugging level for the current request,
* the change is not saved in database.
*
* @param int $level one of the DEBUG_* constants
* @param bool $debugdisplay
*/
function set_debugging($level, $debugdisplay = null) {
global $CFG;
$CFG->debug = (int)$level;
$CFG->debugdeveloper = ($CFG->debug & DEBUG_DEVELOPER);
if ($debugdisplay !== null) {
$CFG->debugdisplay = (bool)$debugdisplay;
}
}
/**
* Standard Debugging Function
*

View File

@ -339,6 +339,7 @@ class mod_workshop_renderer extends plugin_renderer_base {
* @return string HTML to be echoed
*/
protected function render_workshop_allocation_result(workshop_allocation_result $result) {
global $CFG;
$status = $result->get_status();
@ -384,7 +385,7 @@ class mod_workshop_renderer extends plugin_renderer_base {
if (is_array($logs) and !empty($logs)) {
$o .= html_writer::start_tag('ul', array('class' => 'allocation-init-results'));
foreach ($logs as $log) {
if ($log->type == 'debug' and !debugging('', DEBUG_DEVELOPER)) {
if ($log->type == 'debug' and !$CFG->debugdeveloper) {
// display allocation debugging messages for developers only
continue;
}

View File

@ -209,13 +209,9 @@ class report_performance {
DEBUG_NORMAL => 'debugnormal',
DEBUG_ALL => 'debugall',
DEBUG_DEVELOPER => 'debugdeveloper');
// If debug is not set then consider it as 0.
if (!isset($CFG->themedesignermode)) {
$CFG->debug = DEBUG_NONE;
}
$issueresult->statusstr = get_string($debugchoices[$CFG->debug], 'admin');
if ($CFG->debug != DEBUG_DEVELOPER) {
if (!$CFG->debugdeveloper) {
$issueresult->status = self::REPORT_PERFORMANCE_OK;
$issueresult->comment = get_string('check_debugmsg_comment_nodeveloper', 'report_performance');
} else {