Skip to content

Commit

Permalink
MDL-14129, create a new debug.php, and fix print_error() call
Browse files Browse the repository at this point in the history
  • Loading branch information
dongsheng committed Apr 9, 2008
1 parent 5bf2650 commit 78664df
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 37 deletions.
2 changes: 1 addition & 1 deletion admin/auth_config.php
Expand Up @@ -34,7 +34,7 @@
$plugin = "auth/$auth";
$name = $matches[1];
if (!set_config($name, $value, $plugin)) {
print_error("Problem saving config $name as $value for plugin $plugin");
print_error("cannotsaveconfig", 'error', '', array($name, $value, $plugin));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions admin/block.php
Expand Up @@ -9,14 +9,14 @@
$blockid = required_param('block', PARAM_INT);

if(!$blockrecord = blocks_get_record($blockid)) {
print_error('This block does not exist');
print_error('blockdoesnotexist', 'error');
}

admin_externalpage_setup('blocksetting'.$blockrecord->name);

$block = block_instance($blockrecord->name);
if($block === false) {
print_error('Problem in instantiating block object');
print_error('blockcannotinistantiate', 'error');
}

// Define the data we're going to silently include in the instance config form here,
Expand All @@ -34,7 +34,7 @@
print_error('confirmsesskeybad', 'error');
}
if(!$block->has_config()) {
print_error('This block does not support global configuration');
print_error('blockcannotconfig', 'error');
}
$remove = array_keys($hiddendata);
foreach($remove as $item) {
Expand Down
8 changes: 4 additions & 4 deletions admin/blocks.php
Expand Up @@ -33,23 +33,23 @@

if (!empty($hide) && confirm_sesskey()) {
if (!$block = get_record('block', 'id', $hide)) {
print_error("Block doesn't exist!");
print_error('blockdoesnotexist', 'error');
}
set_field('block', 'visible', '0', 'id', $block->id); // Hide block
admin_get_root(true, false); // settings not required - only pages
}

if (!empty($show) && confirm_sesskey() ) {
if (!$block = get_record('block', 'id', $show)) {
print_error("Block doesn't exist!");
print_error('blockdoesnotexist', 'error');
}
set_field('block', 'visible', '1', 'id', $block->id); // Show block
admin_get_root(true, false); // settings not required - only pages
}

if (!empty($multiple) && confirm_sesskey()) {
if (!$block = blocks_get_record($multiple)) {
print_error("Block doesn't exist!");
print_error('blockdoesnotexist', 'error');
}
$block->multiple = !$block->multiple;
update_record('block', $block);
Expand All @@ -61,7 +61,7 @@
print_heading($strmanageblocks);

if (!$block = blocks_get_record($delete)) {
print_error("Block doesn't exist!");
print_error('blockdoesnotexist', 'error');
}

if (!block_is_compatible($block->name)) {
Expand Down
2 changes: 1 addition & 1 deletion admin/delete.php
Expand Up @@ -37,7 +37,7 @@
}

if (!confirm_sesskey()) {
print_error('This script was called wrongly');
print_error('wrongcall', 'error');
}

/// OK, here goes ...
Expand Down
8 changes: 4 additions & 4 deletions admin/filters.php
Expand Up @@ -52,8 +52,8 @@

case 'show':
// check filterpath is valid
if (!array_key_exists($filterpath, $installedfilters)) {
print_error("Filter $filterpath is not currently installed", '', $url);
if (!array_key_exists($filterpath, $installedfilters))
print_error('filternotinstalled', 'error', $url, $filterpath);
} elseif (array_search($filterpath,$activefilters)) {
// filterpath is already active - doubleclick??
} else {
Expand All @@ -67,7 +67,7 @@
$key=array_search($filterpath, $activefilters);
// check filterpath is valid
if ($key===false) {
print_error("Filter $filterpath is not currently active", '', $url);
print_error("filternotactive", 'error', $url, $filterpath );
} elseif ($key>=(count($activefilters)-1)) {
// cannot be moved any further down - doubleclick??
} else {
Expand All @@ -82,7 +82,7 @@
$key=array_search($filterpath, $activefilters);
// check filterpath is valid
if ($key===false) {
print_error("Filter $filterpath is not currently active", '', $url);
print_error("filternotactive", 'error', $url, $filterpath );
} elseif ($key<1) {
//cannot be moved any further up - doubleclick??
} else {
Expand Down
37 changes: 16 additions & 21 deletions admin/index.php
Expand Up @@ -50,42 +50,37 @@
$documentationlink = '<a href="http://docs.moodle.org/en/Installation">Installation docs</a>';

if (ini_get_bool('session.auto_start')) {
print_error("The PHP server variable 'session.auto_start' should be Off - $documentationlink");
print_error('phpvaroff', 'debug', '', array('session.auto_start', $documentationlink));
}

if (ini_get_bool('magic_quotes_runtime')) {
print_error("The PHP server variable 'magic_quotes_runtime' should be Off - $documentationlink");
print_error('phpvaroff', 'debug', '', array('magic_quotes_runtime', $documentationlink));
}

if (!ini_get_bool('file_uploads')) {
print_error("The PHP server variable 'file_uploads' is not turned On - $documentationlink");
print_error('phpvaron', 'debug', '', array('file_uploads', $documentationlink));
}

if (empty($CFG->prefix) && $CFG->dbfamily != 'mysql') { //Enforce prefixes for everybody but mysql
print_error('$CFG->prefix can\'t be empty for your target DB (' . $CFG->dbtype . ')');
print_error('prefixcannotbeempty', 'debug', '', array($CFG->prefix, $CFG->dbtype));
}

if ($CFG->dbfamily == 'oracle' && strlen($CFG->prefix) > 2) { //Max prefix length for Oracle is 2cc
print_error('$CFG->prefix maximum allowed length for Oracle DBs is 2cc.');
print_error('prefixlimit', 'debug', '', $CFG->prefix);
}

/// Check that config.php has been edited

if ($CFG->wwwroot == "http://example.com/moodle") {
print_error("Moodle has not been configured yet. You need to edit config.php first.");
print_error('configmoodle', 'debug');
}


/// Check settings in config.php

$dirroot = dirname(realpath("../index.php"));
if (!empty($dirroot) and $dirroot != $CFG->dirroot) {
print_error("Please fix your settings in config.php:
<p>You have:
<p>\$CFG->dirroot = \"".addslashes($CFG->dirroot)."\";
<p>but it should be:
<p>\$CFG->dirroot = \"".addslashes($dirroot)."\";",
"./");
print_error('fixsetting', 'debug', '', array(addslashes($CFG->dirroot), addslashes($dirroot)));
}

/// Set some necessary variables during set-up to avoid PHP warnings later on this page
Expand All @@ -104,7 +99,7 @@
}

if (!$version or !$release) {
print_error('Main version.php was not readable or specified'); // without version, stop
print_error('withoutversion', 'debug'); // without version, stop
}

/// Check if the main tables have been installed yet or not.
Expand Down Expand Up @@ -186,7 +181,7 @@
} else if (file_exists("$CFG->libdir/db/$CFG->dbtype.sql")) {
$status = modify_database("$CFG->libdir/db/$CFG->dbtype.sql"); //Old method
} else {
print_error("Error: Your database ($CFG->dbtype) is not yet fully supported by Moodle or install.xml is not present. See the lib/db directory.");
print_error('dbnotsupport', 'debug', '', $CFG->dbtype);
}

// all new installs are in unicode - keep for backwards compatibility and 1.8 upgrade checks
Expand Down Expand Up @@ -223,7 +218,7 @@
notify($strdatabasesuccess, "green");
require_once $CFG->dirroot.'/mnet/lib.php';
} else {
print_error("Error: Main databases NOT set up successfully");
print_error('dbnotsetup', 'debug');
}
print_continue('index.php');
print_footer('none');
Expand Down Expand Up @@ -367,7 +362,7 @@
moodle_install_roles();
set_config('rolesactive', 1);
} else if (!update_capabilities()) {
print_error('Had trouble upgrading the core capabilities for the Roles System');
print_error('cannotupgradecapabilities', 'debug');
}
// update core events
events_update_definition();
Expand All @@ -383,7 +378,7 @@
print_footer('none');
exit;
} else {
print_error('Upgrade failed! (Could not update version in config table)');
print_error('cannotupdateversion', 'debug');
}
/// Main upgrade not success
} else {
Expand All @@ -401,15 +396,15 @@
}
} else {
if (!set_config("version", $version)) {
print_error("A problem occurred inserting current version into databases");
print_error('cannotupdateversion', 'debug');
}
}

/// Updated human-readable release version if necessary

if ($release <> $CFG->release) { // Update the release version
if (!set_config("release", $release)) {
print_error("ERROR: Could not update release version in database!!");
print_error("cannotupdaterelease", 'debug');
}
}

Expand Down Expand Up @@ -495,7 +490,7 @@
$newsite->timemodified = time();

if (!$newid = insert_record('course', $newsite)) {
print_error("Serious Error! Could not set up the site!");
print_error('cannotsetupsite', 'error');
}
// make sure course context exists
get_context_instance(CONTEXT_COURSE, $newid);
Expand All @@ -508,7 +503,7 @@
$cat->name = get_string('miscellaneous');
$cat->depth = 1;
if (!$catid = insert_record('course_categories', $cat)) {
print_error("Serious Error! Could not set up a default course category!");
print_error('cannotsetupcategory', 'error');
}
// make sure category context exists
get_context_instance(CONTEXT_COURSECAT, $catid);
Expand Down
6 changes: 3 additions & 3 deletions admin/langdoc.php
Expand Up @@ -51,7 +51,7 @@
if (langdoc_save_file($langdir, $currentfile, $_POST['filedata'])) {
notify(get_string("changessaved")." ($langdir/$currentfile)", "green");
} else {
print_error("Could not save the file '$currentfile'!", '', "langdoc.php?currentfile=$currentfile&sesskey=$USER->sesskey");
print_error("cannotsavefile", 'error', "langdoc.php?currentfile=$currentfile&sesskey=$USER->sesskey", $currentfile);
}
}
}
Expand All @@ -63,7 +63,7 @@
// Get all files from /docs directory

if (! $files = get_directory_list("$CFG->dirroot/lang/en_utf8/docs", "CVS")) {
print_error("Could not find English language docs files!");
print_error('cannotfinddocs', 'error', '', 'English');
}

$options = array();
Expand All @@ -83,7 +83,7 @@
// Get all files from /help directory

if (! $files = get_directory_list("$CFG->dirroot/lang/en_utf8/help", "CVS")) {
print_error("Could not find English language help files!");
print_error("cannotfindhelp", "error", "", "English");
}

foreach ($files as $filekey => $file) { // check all the help files.
Expand Down
19 changes: 19 additions & 0 deletions lang/en_utf8/debug.php
@@ -0,0 +1,19 @@
<?php
/*
* debug information for developer only
*/
$string['cannotupgradecapabilities'] = 'Had trouble upgrading the core capabilities for the Roles System';
$string['cannotupdateversion'] = 'Upgrade failed! (Could not update version in config table)';
$string['cannotupdaterelease'] = 'ERROR: Could not update release version in database!!';
$string['cannotsetupsite'] = 'Serious Error! Could not set up the site!';
$string['configmoodle'] = 'Moodle has not been configured yet. You need to edit config.php first.';
$string['dbnotsupport'] = 'Error: Your database ($a) is not yet fully supported by Moodle or install.xml is not present. See the lib/db directory.';
$string['dbnotsetup'] = 'Error: Main databases NOT set up successfully';
$string['fixsetting'] = 'Please fix your settings in config.php: <p>You have:</p> <p>\$CFG->dirroot = \"$a[0]\";</p> <p>but it should be:</p> <p>\$CFG->dirroot = \"$a[1]\"</p>';
$string['phpvaroff'] = 'The PHP server variable \'$a[0]\' should be Off - $a[1]';
$string['phpvaron'] = 'The PHP server variable \'$a[0]\' is not turned On - $a[1]';
$string['prefixcannotbeempty'] = 'Table prefix \"$a[0]\" cannot be empty for your target DB ($a[1])';
$string['prefixlimit'] = 'Table prefix \"$a\" maximum allowed length for Oracle DBs is 2cc.';
$string['withoutversion'] = 'Main version.php was not readable or specified';

?>
5 changes: 5 additions & 0 deletions lang/en_utf8/error.php
Expand Up @@ -22,6 +22,8 @@
$string['cannotsavefile'] = 'Cannot save the file \"$a\".';
$string['cannotsavemd5file'] = 'Cannot save md5 file.';
$string['cannotsavezipfile'] = 'Cannot save ZIP file.';
$string['cannotsetupcategory'] = 'Serious Error! Could not set up a default course category!';
$string['cannotsetupsite'] = 'Serious Error! Could not set up the site!';
$string['cannotunzipfile'] = 'Cannot unzip file.';
$string['cannotviewprofile'] = 'You can not view the profile of this user.';
$string['cantunenrollfrommetacourse'] = 'You can not unenrol from this meta course.';
Expand All @@ -47,6 +49,8 @@
$string['errorunzippingfiles'] = 'Error unzipping files';
$string['fieldrequired'] = '\"$a\" is a required field';
$string['filenotfound'] = 'Sorry, the requested file could not be found';
$string['filternotinstalled'] = 'Filter $a is not currently installed';
$string['filternotactive'] = 'Filter $a is not currently active';
$string['forumblockingtoomanyposts'] = 'You have exceeded the posting threshold set for this forum.';
$string['groupalready'] = 'User already belongs to group $a';
$string['groupexistforcourse'] = 'Group \"$a\" already exists for this course';
Expand Down Expand Up @@ -127,6 +131,7 @@
$string['usernotupdatedadmin'] = 'Can not update admin accounts.';
$string['usernotupdatederror'] = 'User not updated - error.';
$string['usernotupdatednotexists'] = 'User not updated - does not exist.';
$string['wrongcall'] = 'This script is called wrongly';
$string['wrongdestpath'] = 'Wrong destination path.';
$string['wrongsourcebase'] = 'Wrong source URL base.';
$string['wrongzipfilename'] = 'Wrong ZIP filename.';
Expand Down

0 comments on commit 78664df

Please sign in to comment.