From 2f137aa13002c26e63742499a80ccfa11223763f Mon Sep 17 00:00:00 2001 From: dongsheng Date: Tue, 20 May 2008 02:53:46 +0000 Subject: [PATCH] "MDL-14129, fix print_error" --- lib/adminlib.php | 26 ++++++++++++------------ lib/authlib.php | 6 +++--- lib/dml/oci8po_adodb_moodle_database.php | 4 ++-- lib/dmllib_todo.php | 5 +++-- lib/editor/htmlarea/coursefiles.php | 6 +++--- lib/grade/grade_category.php | 6 +++--- lib/grade/grade_grade.php | 2 +- lib/grade/grade_item.php | 4 ++-- lib/grade/grade_object.php | 6 +++--- lib/gradelib.php | 6 +++--- lib/locallib.php | 4 ++-- lib/moodlelib.php | 26 ++++++++++++------------ lib/pagelib.php | 14 ++++++------- lib/simpletest/testeventslib.php | 6 +++--- 14 files changed, 61 insertions(+), 60 deletions(-) diff --git a/lib/adminlib.php b/lib/adminlib.php index 994baef1be..cbf960b4b5 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -15,7 +15,7 @@ function upgrade_main_savepoint($result, $version) { if ($result) { if ($CFG->version >= $version) { // something really wrong is going on in main upgrade script - print_error("Upgrade savepoint: Can not upgrade main version from $CFG->version to $version."); + print_error('cannotdowngrade', 'debug', '', array($CFG->version, $version)); } set_config('version', $version); } else { @@ -141,7 +141,7 @@ function upgrade_plugins($type, $dir, $return) { /// Install capabilities if (!update_capabilities($type.'/'.$plug)) { - print_error('Could not set up the capabilities for '.$plugin->name.'!'); + print_error('cannotsetupcapforplugin', '', '', $plugin->name); } /// Install events events_update_definition($type.'/'.$plug); @@ -184,7 +184,7 @@ function upgrade_plugins($type, $dir, $return) { // OK so far, now update the plugins record set_config($pluginversion, $plugin->version); if (!update_capabilities($type.'/'.$plug)) { - print_error('Could not update '.$plugin->name.' capabilities!'); + print_error('cannotupdateplugincap', '', '', $plugin->name); } events_update_definition($type.'/'.$plug); notify(get_string('modulesuccess', '', $plugin->name), 'notifysuccess'); @@ -197,7 +197,7 @@ function upgrade_plugins($type, $dir, $return) { } } else { upgrade_log_start(); - print_error('Version mismatch: '. $plugin->name .' can\'t downgrade '. $CFG->$pluginversion .' -> '. $plugin->version .' !'); + print_error('cannotdowngrade', 'debug', '', array($CFG->pluginversion, $plugin->version)); } } @@ -231,7 +231,7 @@ function upgrade_activity_modules($return) { global $CFG, $interactive, $DB; if (!$mods = get_list_of_plugins('mod') ) { - print_error('No modules installed!'); + print_error('nomodules', 'debug'); } $updated_modules = false; @@ -327,7 +327,7 @@ function upgrade_activity_modules($return) { // OK so far, now update the modules record $module->id = $currmodule->id; if (!$DB->update_record('modules', $module)) { - print_error('Could not update '. $module->name .' record in modules table!'); + print_error('cannotupdatemod', '', '', $module->name); } remove_dir($CFG->dataroot . '/cache', true); // flush cache notify(get_string('modulesuccess', '', $module->name), 'notifysuccess'); @@ -340,7 +340,7 @@ function upgrade_activity_modules($return) { /// Update the capabilities table? if (!update_capabilities('mod/'.$module->name)) { - print_error('Could not update '.$module->name.' capabilities!'); + print_error('cannotupdatemodcap', '', '', $module->name); } events_update_definition('mod/'.$module->name); @@ -348,7 +348,7 @@ function upgrade_activity_modules($return) { } else { upgrade_log_start(); - print_error('Version mismatch: '. $module->name .' can\'t downgrade '. $currmodule->version .' -> '. $module->version .' !'); + print_error('cannotdowngrade', 'debug', '', array($currmodule->version, $module->version)); } } else { // module not installed yet, so install it @@ -383,7 +383,7 @@ function upgrade_activity_modules($return) { /// Capabilities if (!update_capabilities('mod/'.$module->name)) { - print_error('Could not set up the capabilities for '.$module->name.'!'); + print_error('cannotsetupcapformod', '', '', $module->name); } /// Events @@ -564,16 +564,16 @@ function create_admin_user($user_input=NULL) { $user = $user_input; } if (!$user->id = $DB->insert_record('user', $user)) { - print_error('SERIOUS ERROR: Could not create admin user record !!!'); + print_error('cannotcreateadminuser', 'debug'); } if (!$user = $DB->get_record('user', array('id'=>$user->id))) { // Double check. - print_error('User ID was incorrect (can\'t find it)'); + print_error('invaliduserid'); } // Assign the default admin roles to the new user. if (!$adminroles = get_roles_with_capability('moodle/legacy:admin', CAP_ALLOW)) { - print_error('No admin role could be found'); + print_error('noadminrole', 'debug'); } $sitecontext = get_context_instance(CONTEXT_SYSTEM); foreach ($adminroles as $adminrole) { @@ -591,7 +591,7 @@ function create_admin_user($user_input=NULL) { redirect("$CFG->wwwroot/user/editadvanced.php?id=$user->id"); // Edit thyself } } else { - print_error('Can not create admin!'); + print_error('cannotcreateadminuser', 'debug'); } } diff --git a/lib/authlib.php b/lib/authlib.php index 8996a979cf..971c7d68c7 100644 --- a/lib/authlib.php +++ b/lib/authlib.php @@ -80,7 +80,7 @@ class auth_plugin_base { * @return bool Authentication success or failure. */ function user_login($username, $password) { - print_error('Abstract user_login() method must be overriden.'); + print_error('mustbeoveride', 'debug', '', 'user_login()' ); } /** @@ -187,7 +187,7 @@ class auth_plugin_base { */ function user_signup($user, $notify=true) { //override when can signup - print_error('user_signup method must be overriden if signup enabled'); + print_error('mustbeoveride', 'debug', '', 'user_signup()' ); } /** @@ -208,7 +208,7 @@ class auth_plugin_base { */ function user_confirm($username, $confirmsecret) { //override when can confirm - print_error('user_confirm method must be overriden if confirm enabled'); + print_error('mustbeoveride', 'debug', '', 'user_confirm()' ); } /** diff --git a/lib/dml/oci8po_adodb_moodle_database.php b/lib/dml/oci8po_adodb_moodle_database.php index 29bfe7e2b9..86990037f1 100644 --- a/lib/dml/oci8po_adodb_moodle_database.php +++ b/lib/dml/oci8po_adodb_moodle_database.php @@ -231,7 +231,7 @@ error('todo'); if (!empty($CFG->rolesactive)) { if (in_array($table, array('user_students', 'user_teachers', 'user_coursecreators', 'user_admins'))) { if (debugging()) { var_dump(debug_backtrace()); } - print_error('This SQL relies on obsolete tables ('.$table.')! Your code must be fixed by a developer.'); + print_error('sqlrelyonobsoletetable', 'debug', '', $table); } } @@ -342,7 +342,7 @@ error('todo'); if (!empty($CFG->rolesactive)) { if (in_array($table, array('user_students', 'user_teachers', 'user_coursecreators', 'user_admins'))) { if (debugging()) { var_dump(debug_backtrace()); } - print_error('This SQL relies on obsolete tables ('.$table.')! Your code must be fixed by a developer.'); + print_error('sqlrelyonobsoletetable', 'debug', '', $table); } } diff --git a/lib/dmllib_todo.php b/lib/dmllib_todo.php index 03e0e08f2f..94ebc26192 100644 --- a/lib/dmllib_todo.php +++ b/lib/dmllib_todo.php @@ -399,7 +399,8 @@ function get_recordset_sql($sql, $limitfrom=null, $limitnum=null) { strpos($sql, ' '.$CFG->prefix.'user_coursecreators ') || strpos($sql, ' '.$CFG->prefix.'user_admins ')) { if (debugging()) { var_dump(debug_backtrace()); } - print_error('This SQL relies on obsolete tables! Your code must be fixed by a developer.'); + print_error('sqlrelyonobsoletetable', 'debug', '', + 'user_student, user_teachers, user_coursecreators, user_admins'); } } @@ -1295,4 +1296,4 @@ error('todo'); return $status; } -?> \ No newline at end of file +?> diff --git a/lib/editor/htmlarea/coursefiles.php b/lib/editor/htmlarea/coursefiles.php index 7a47f62f3e..435aaf54ca 100644 --- a/lib/editor/htmlarea/coursefiles.php +++ b/lib/editor/htmlarea/coursefiles.php @@ -27,7 +27,7 @@ if (! $course = get_record("course", "id", $id) ) { - print_error("That's an invalid course id"); + print_error('invalidcourseid'); } require_login($course); @@ -184,7 +184,7 @@ } if (! $basedir = make_upload_directory("$course->id")) { - print_error("The site administrator needs to fix the file permissions"); + print_error('cannotcreateuploaddir'); } $baseweb = $CFG->wwwroot; @@ -439,7 +439,7 @@ } if (!zip_files($files,"$basedir/$wdir/$name")) { - print_error("zipfileserror","error"); + print_error('zipfileserror'); } clearfilelist(); diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php index b5fc188040..f6b9d8ff1e 100644 --- a/lib/grade/grade_category.php +++ b/lib/grade/grade_category.php @@ -298,7 +298,7 @@ class grade_category extends grade_object { function insert($source=null) { if (empty($this->courseid)) { - print_error('Can not insert grade category without course id!'); + print_error('cannotinsertgrade'); } if (empty($this->parent)) { @@ -1046,11 +1046,11 @@ class grade_category extends grade_object { } if ($parentid == $this->id) { - print_error('Can not assign self as parent!'); + print_error('cannotassignselfasparent'); } if (empty($this->parent) and $this->is_course_category()) { - print_error('Course category can not have parent!'); + print_error('cannothaveparentcate'); } // find parent and check course id diff --git a/lib/grade/grade_grade.php b/lib/grade/grade_grade.php index 694d2923a6..f367a846b1 100644 --- a/lib/grade/grade_grade.php +++ b/lib/grade/grade_grade.php @@ -560,7 +560,7 @@ class grade_grade extends grade_object { global $CFG; if (count($grade_grades) !== count($grade_items)) { - print_error('Incorrect size of arrays in params of grade_grade::get_hiding_affected()!'); + print_error('invalidarraysize', 'debug', '', 'grade_grade::get_hiding_affected()!'); } $dependson = array(); diff --git a/lib/grade/grade_item.php b/lib/grade/grade_item.php index b5b10c5204..a9c289a958 100644 --- a/lib/grade/grade_item.php +++ b/lib/grade/grade_item.php @@ -370,7 +370,7 @@ class grade_item extends grade_object { global $CFG; if (empty($this->courseid)) { - print_error('Can not insert grade item without course id!'); + print_error('cannotinsertgrade'); } // load scale if needed @@ -1190,7 +1190,7 @@ class grade_item extends grade_object { */ function set_parent($parentid) { if ($this->is_course_item() or $this->is_category_item()) { - print_error('Can not set parent for category or course item!'); + print_error('cannotsetparentforcatoritem'); } if ($this->categoryid == $parentid) { diff --git a/lib/grade/grade_object.php b/lib/grade/grade_object.php index c96a972354..0525c79caf 100644 --- a/lib/grade/grade_object.php +++ b/lib/grade/grade_object.php @@ -110,7 +110,7 @@ class grade_object { * @return object grade_object instance or false if none found. */ function fetch($params) { - print_error('Abstract method fetch() not overridden in '.get_class($this)); + print_error('mustbeoveride', 'debug', '', 'fetch()'); } /** @@ -121,7 +121,7 @@ class grade_object { * @return array array of grade_object insatnces or false if none found. */ function fetch_all($params) { - print_error('Abstract method fetch_all() not overridden in '.get_class($this)); + print_error('mustbeoveride', 'debug', '', 'fetch_all()'); } /** @@ -133,7 +133,7 @@ class grade_object { if ($instances = grade_object::fetch_all_helper($table, $classname, $params)) { if (count($instances) > 1) { // we should not tolerate any errors here - problems might appear later - print_error('Found more than one record in fetch() !'); + print_error('morethanonerecordinfetch'); } return reset($instances); } else { diff --git a/lib/gradelib.php b/lib/gradelib.php index 5607b7dc7e..d697ae7699 100644 --- a/lib/gradelib.php +++ b/lib/gradelib.php @@ -840,7 +840,7 @@ function grade_regrade_final_grades($courseid, $userid=null, $updated_item=null) if ($userid) { // one raw grade updated for one user if (empty($updated_item)) { - print_error("updated_item_id can not be null!"); + print_error("cannotbenull", 'debug', '', "updated_item"); } if ($course_item->needsupdate) { $updated_item->force_regrading(); @@ -951,7 +951,7 @@ function grade_grab_legacy_grades($courseid) { global $CFG; if (!$mods = get_list_of_plugins('mod') ) { - print_error('No modules installed!'); + print_error('nomodules', 'debug'); } foreach ($mods as $mod) { @@ -997,7 +997,7 @@ function grade_grab_course_grades($courseid, $modname=null) { } if (!$mods = get_list_of_plugins('mod') ) { - print_error('No modules installed!'); + print_error('nomodules', 'debug'); } foreach ($mods as $mod) { diff --git a/lib/locallib.php b/lib/locallib.php index 957eb37fd5..16ab63ba06 100644 --- a/lib/locallib.php +++ b/lib/locallib.php @@ -163,13 +163,13 @@ function upgrade_local_db($continueto) { } } } else { - print_error('Upgrade of local database customisations failed! (Could not update version in config table)'); + print_error('cannotupgradedbcustom', 'debug'); } } else { if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) { $DB->set_debug(false); } - print_error('Upgrade failed! See local/version.php'); + print_error('upgradefail', 'debug', '', 'local/version.php'); } } else if ($local_version < $CFG->local_version) { diff --git a/lib/moodlelib.php b/lib/moodlelib.php index f049feb359..ac8c80eb32 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -306,7 +306,7 @@ function required_param($parname, $type=PARAM_CLEAN) { } else if (isset($_GET[$parname])) { $param = $_GET[$parname]; } else { - print_error('A required parameter ('.$parname.') was missing'); + print_error('missingparam', '', '', $parname); } return clean_param($param, $type); @@ -596,7 +596,7 @@ function clean_param($param, $type) { } default: // throw error, switched parameters in optional_param or another serious problem - print_error("Unknown parameter type: $type"); + print_error("unknowparamtype", '', '', $type); } } @@ -1806,7 +1806,7 @@ function course_setup($courseorid=0) { $COURSE = clone($course); } else { if (!$COURSE = get_record('course', 'id', $courseorid)) { - print_error('Invalid course ID'); + print_error('invalidcourseid'); } } } @@ -2148,7 +2148,7 @@ function require_user_key_login($script, $instance=null) { global $nomoodlecookie, $USER, $SESSION, $CFG; if (empty($nomoodlecookie)) { - print_error('Incorrect use of require_key_login() - session cookies must be disabled!'); + print_error('sessioncookiesdisable'); } /// extra safety @@ -2157,22 +2157,22 @@ function require_user_key_login($script, $instance=null) { $keyvalue = required_param('key', PARAM_ALPHANUM); if (!$key = get_record('user_private_key', 'script', $script, 'value', $keyvalue, 'instance', $instance)) { - print_error('Incorrect key'); + print_error('invalidkey'); } if (!empty($key->validuntil) and $key->validuntil < time()) { - print_error('Expired key'); + print_error('expiredkey'); } if ($key->iprestriction) { $remoteaddr = getremoteaddr(); if ($remoteaddr == '' or !address_in_subnet($remoteaddr, $key->iprestriction)) { - print_error('Client IP address mismatch'); + print_error('ipmismatch'); } } if (!$user = get_record('user', 'id', $key->userid)) { - print_error('Incorrect user record'); + print_error('invaliduserid'); } /// emulate normal session @@ -2215,7 +2215,7 @@ function create_user_key($script, $userid, $instance=null, $iprestriction=null, } if (!insert_record('user_private_key', $key)) { - print_error('Can not insert new key'); + print_error('cannotinsertkey'); } return $key->value; @@ -2716,7 +2716,7 @@ function get_auth_plugin($auth) { // check the plugin exists first if (! exists_auth_plugin($auth)) { - print_error("Authentication plugin '$auth' not found."); + print_error('authpluginnotfound', 'debug', '', $auth); } // return auth plugin instance @@ -3478,7 +3478,7 @@ function remove_course_contents($courseid, $showfeedback=true) { $result = true; if (! $course = get_record('course', 'id', $courseid)) { - print_error('Course ID was incorrect (can\'t find it)'); + print_error('invalidcourseid'); } $strdeleted = get_string('deleted'); @@ -3529,7 +3529,7 @@ function remove_course_contents($courseid, $showfeedback=true) { } } } else { - print_error('No modules are installed!'); + print_error('nomodules', 'debug'); } /// Give local code a chance to delete its references to this course. @@ -4275,7 +4275,7 @@ function reset_password_and_mail($user) { $newpassword = generate_password(); if (!$userauth->user_update_password(addslashes_recursive($user), addslashes($newpassword))) { - print_error("Could not set user password!"); + print_error("cannotsetpassword"); } $a = new object(); diff --git a/lib/pagelib.php b/lib/pagelib.php index 2b10047aa5..7477f58655 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -32,7 +32,7 @@ function page_import_types($path) { if(is_file($file)) { require($file); if(!isset($DEFINEDPAGES)) { - print_error('Imported '.$file.' but found no page classes'); + print_error('nopageclass', 'debug', '', $page); } return $types[$path] = $DEFINEDPAGES; } @@ -314,7 +314,7 @@ class page_course extends page_base { // Do NOT load up "expensive" resouces (e.g. SQL data) here! function init_quick($data) { if(empty($data->pageid) && !defined('ADMIN_STICKYBLOCKS')) { - print_error('Cannot quickly initialize page: empty course id'); + print_error('cannotinitpage', '', '', null); } parent::init_quick($data); } @@ -338,7 +338,7 @@ class page_course extends page_base { } if(empty($this->courserecord) && !defined('ADMIN_STICKYBLOCKS')) { - print_error('Cannot fully initialize page: invalid course id '. $this->id); + print_error('cannotinitpage', '', '', $this->id); } $this->context = get_context_instance(CONTEXT_COURSE, $this->id); @@ -588,18 +588,18 @@ class page_generic_activity extends page_base { return; } if(empty($this->activityname)) { - print_error('Page object derived from page_generic_activity but did not define $this->activityname'); + print_error('noactivityname', 'debug'); } if (!$this->modulerecord = get_coursemodule_from_instance($this->activityname, $this->id)) { - print_error('Cannot fully initialize page: invalid '.$this->activityname.' instance id '. $this->id); + print_error('cannotinitpager', 'debug', '', array($this->activityname, $this->id)); } $this->courserecord = get_record('course', 'id', $this->modulerecord->course); if(empty($this->courserecord)) { - print_error('Cannot fully initialize page: invalid course id '. $this->modulerecord->course); + print_error('invalidcourseid'); } $this->activityrecord = get_record($this->activityname, 'id', $this->id); if(empty($this->activityrecord)) { - print_error('Cannot fully initialize page: invalid '.$this->activityname.' id '. $this->id); + print_error('cannotinitpager', 'debug', '', array($this->activityname, $this->id)); } $this->full_init_done = true; } diff --git a/lib/simpletest/testeventslib.php b/lib/simpletest/testeventslib.php index 65bb588def..5288945708 100755 --- a/lib/simpletest/testeventslib.php +++ b/lib/simpletest/testeventslib.php @@ -36,7 +36,7 @@ function sample_function_handler($eventdata) { return true; } - print_error('Incorrect eventadata submitted: '.$eventdata); + print_error('invalideventdata', '', '', $eventdata); } // test handler class with static method @@ -70,7 +70,7 @@ class sample_handler_class { return true; } - print_error('Incorrect eventadata submitted: '.$eventdata); + print_error('invalideventdata', '', '', $eventdata); } } @@ -197,4 +197,4 @@ class eventslib_test extends UnitTestCase { } -?> \ No newline at end of file +?> -- 2.39.5