From bf8e93d704e23fd94729efdd3c2f6bdd248f6257 Mon Sep 17 00:00:00 2001 From: skodak <skodak> Date: Wed, 3 Jun 2009 20:00:08 +0000 Subject: [PATCH] MDL-18293 $DB->somethiong is using exceptions, no need for ifs tehre, removing useless strings --- course/editcategory.php | 4 +--- course/modedit.php | 12 +++--------- lang/en_utf8/error.php | 14 -------------- lib/accesslib.php | 7 ++----- lib/questionlib.php | 4 +--- lib/simpletest/testfilelib.php | 4 +--- mod/data/rate.php | 4 +--- mod/forum/rate.php | 4 +--- mod/hotpot/lib.php | 4 +--- mod/scorm/lib.php | 4 +--- question/format.php | 4 +--- user/edit.php | 4 +--- user/profile/definelib.php | 4 +--- user/profile/lib.php | 4 +--- 14 files changed, 16 insertions(+), 61 deletions(-) diff --git a/course/editcategory.php b/course/editcategory.php index 0064065894..1b5084b082 100644 --- a/course/editcategory.php +++ b/course/editcategory.php @@ -70,9 +70,7 @@ if ($mform->is_cancelled()) { } else { // Create a new category. $newcategory->sortorder = 999; - if (!$newcategory->id = $DB->insert_record('course_categories', $newcategory)) { - print_error('cannotcreatecategory', '', '', format_string($newcategory->name)); - } + $newcategory->id = $DB->insert_record('course_categories', $newcategory); $newcategory->context = get_context_instance(CONTEXT_COURSECAT, $newcategory->id); mark_context_dirty($newcategory->context->path); fix_course_sortorder(); // Required to build course_categories.depth and .path. diff --git a/course/modedit.php b/course/modedit.php index 0e3dd81e41..782a9ff5ac 100644 --- a/course/modedit.php +++ b/course/modedit.php @@ -423,19 +423,13 @@ $fromform->instance = $returnfromfunc; - if (!$DB->set_field('course_modules', 'instance', $returnfromfunc, array('id'=>$fromform->coursemodule))) { - print_error('cannotaddcoursemodule'); - } + $DB->set_field('course_modules', 'instance', $returnfromfunc, array('id'=>$fromform->coursemodule)); // course_modules and course_sections each contain a reference // to each other, so we have to update one of them twice. - if (!$sectionid = add_mod_to_section($fromform)) { - print_error('cannotaddcmtosection'); - } + $sectionid = add_mod_to_section($fromform); - if (!$DB->set_field('course_modules', 'section', $sectionid, array('id'=>$fromform->coursemodule))) { - print_error('cannotupdatecm'); - } + $DB->set_field('course_modules', 'section', $sectionid, array('id'=>$fromform->coursemodule)); // make sure visibility is set correctly (in particular in calendar) set_coursemodule_visible($fromform->coursemodule, $fromform->visible); diff --git a/lang/en_utf8/error.php b/lang/en_utf8/error.php index fb076179f2..d62a59071e 100644 --- a/lang/en_utf8/error.php +++ b/lang/en_utf8/error.php @@ -13,15 +13,12 @@ $string['blockcannotconfig'] = 'This block does not support global configuration $string['blocknameconflict'] = 'Naming conflict: block $a->name has the same title with an existing block: $a->conflict!'; $string['backupcontainexternal'] = 'This backup file contains external Moodle Network Hosts that are not configured locally'; $string['backuptablefail'] = 'Backup tables could NOT be set up successfully!'; -$string['cannotaddblock'] = '$a block could not be added to the block list!'; $string['cannotaddcoursemodule'] = 'Could not add a new course module'; $string['cannotaddcoursemoduletosection'] = 'Could not add the new course module to that section'; -$string['cannotaddcmtosection'] = 'Could not add the new course module to that section'; $string['cannotaddrss'] = 'You do not have permission to add rss feeds'; $string['cannotaddmembergroupiddoesntexist'] = 'Cannot add member group: the group id doesn\'t exist'; $string['cannotaddmodule'] = '$a module could not be added to the module list!'; $string['cannotaddnewmodule'] = 'Could not add a new module of $a'; -$string['cannotaddnewinstance'] = 'Could not add a new instance of $a'; $string['cannotassignanthing'] = 'Cannot assign moodle/site:doanything'; $string['cannotassignrole'] = 'Cannot assign role in course'; $string['cannotassignrolehere'] = 'You are not allowed to assign this role (id = $a->roleid) in this context ($a->context)'; @@ -30,11 +27,9 @@ $string['cannotcallusgetselecteduser'] = 'You cannot called user_selector::get_s $string['cannotcallscript'] = 'You cannot call this script in that way'; $string['cannotcreatebackupdir'] = 'Could not create backupdata folder. The site administrator needs to fix the file permissions'; $string['cannotcreatecategory'] = 'The category was not inserted'; -$string['cannotcreatedefaultcat'] = 'Error creating a default category for context $a'; $string['cannotcreategroup'] = 'Error creating group'; $string['cannotcreatelangdir'] = 'Cannot create lang directory'; $string['cannotcreatelangbase'] = 'Error: Could not create base lang directory'; -$string['cannotcreatefield'] = 'Error creating new field'; $string['cannotcreatetempdir'] = 'Cannot create temp directory'; $string['cannotcreatesitedir'] = 'Cannot create site folder. The site administrator needs to fix the file permissions.'; $string['cannotcreateuploaddir'] = 'Cannot create upload folder. The site administrator needs to fix the file permissions.'; @@ -45,8 +40,6 @@ $string['cannotcustomisefiltersblockuser'] = 'You cannot customise filters setti $string['cannotcustomizelocallang'] = 'You do not have permission to customize the strings translation. This permission is controlled by the capability \"moodle/site:langeditlocal\". Set this capability to allow you to edit local language packages in case you want to modify translations for your site.'; $string['cannotdeletelangcache'] = 'Language cache cannot be deleted, please fix permissions in dataroot/cache/languages!'; $string['cannotdeletebackupids'] = 'Couldn\'t delete previous backup ids'; -$string['cannotdeletecap'] = 'Could not delete deprecated capability $a'; -$string['cannotdeletecate'] = 'Error while deleting category'; $string['cannotdeletecategorycourse'] = 'Course \'$a\' failed to be deleted.'; $string['cannotdeletecategoryquestions'] = 'Could not delete questions from category \'$a\''; $string['cannotdeletecourse'] = 'You do not have the permission to delete this course'; @@ -132,20 +125,13 @@ $string['cannotsetupcapforplugin'] = 'Could not set up the capabilities for $a'; $string['cannotsetupcapformod'] = 'Could not set up the capabilities for $a'; $string['cannotshowhidecoursesincategory'] = 'Cannot show/hide the courses in category $a.'; $string['cannotunzipfile'] = 'Cannot unzip file'; -$string['cannotupdatecm'] = 'Could not update the course module with the correct section'; -$string['cannotupdategroup'] = 'Error updating group'; -$string['cannotupdaterate'] = 'Could not update an old rating ($a->id = $a->rating)'; $string['cannotupdaterecord'] = 'Could not update record ID $a'; -$string['cannotupdaterole'] = 'Cannot update role!'; $string['cannotupdatemod'] = 'Could not update $a'; -$string['cannotupdatemodcap'] = 'Could not update $a capabilities!'; $string['cannotupdateuser'] = 'Updating user failed'; $string['cannotupdateusermsgpref'] = 'Cannot update user message preferences'; $string['cannotupdateuseronexauth'] = 'Failed to update user data on external auth: $a. See the server logs for more details.'; $string['cannotupdatepasswordonextauth'] = 'Failed to update password on external auth: $a. See the server logs for more details.'; -$string['cannotupdateplugincap'] = 'Could not update $a capabilities!'; $string['cannotupdateprofile'] = 'Error updating user record'; -$string['cannotupdatecustomprofile'] = 'Error updating user custom record'; $string['cannotupdaterss'] = 'Cannot update RSS'; $string['cannotupdatesecret'] = 'Error resetting user secret string'; $string['cannotupdatesubcate'] = 'Could not update a child category!'; diff --git a/lib/accesslib.php b/lib/accesslib.php index 8e17ba8ef9..df1e445c3a 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -3512,11 +3512,8 @@ function capabilities_cleanup($component, $newcapdef=NULL) { array_key_exists($cachedcap->name, $newcapdef) === false) { // Remove from capabilities cache. - if (!$DB->delete_records('capabilities', array('name'=>$cachedcap->name))) { - print_error('cannotdeletecap', '', '', $cachedcap->name); - } else { - $removedcount++; - } + $DB->delete_records('capabilities', array('name'=>$cachedcap->name)); + $removedcount++; // Delete from roles. if ($roles = get_roles_with_capability($cachedcap->name)) { foreach($roles as $role) { diff --git a/lib/questionlib.php b/lib/questionlib.php index 798ec03a22..32a4849ec8 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -2458,9 +2458,7 @@ function question_make_default_categories($contexts) { $category->parent = 0; $category->sortorder = 999; // By default, all categories get this number, and are sorted alphabetically. $category->stamp = make_unique_id_code(); - if (!$category->id = $DB->insert_record('question_categories', $category)) { - print_error('cannotcreatedefaultcat', '', '', print_context_name($context)); - } + $category->id = $DB->insert_record('question_categories', $category); } else { $category = question_get_default_category($context->id); } diff --git a/lib/simpletest/testfilelib.php b/lib/simpletest/testfilelib.php index e0d1419a9c..21110cfc4d 100644 --- a/lib/simpletest/testfilelib.php +++ b/lib/simpletest/testfilelib.php @@ -106,9 +106,7 @@ class filelib_test extends UnitTestCaseUsingDatabase { $newcategory = new stdClass(); $newcategory->name = 'test category'; $newcategory->sortorder = 999; - if (!$newcategory->id = $DB->insert_record('course_categories', $newcategory)) { - print_error('cannotcreatecategory', '', '', format_string($newcategory->name)); - } + $newcategory->id = $DB->insert_record('course_categories', $newcategory); $newcategory->context = get_context_instance(CONTEXT_COURSECAT, $newcategory->id); mark_context_dirty($newcategory->context->path); diff --git a/mod/data/rate.php b/mod/data/rate.php index 4faaf5d486..599a804f2c 100755 --- a/mod/data/rate.php +++ b/mod/data/rate.php @@ -71,9 +71,7 @@ } else if ($rating != $oldrating->rating) { $oldrating->rating = $rating; - if (!$DB->update_record('data_ratings', $oldrating)) { - print_error('cannotupdaterate', 'error', '', (object)array('id'=>$record->id, 'rating'=>$rating)); - } + $DB->update_record('data_ratings', $oldrating); data_update_grades($data, $record->userid); } diff --git a/mod/forum/rate.php b/mod/forum/rate.php index 0f7a1240f7..84f5e5dce4 100644 --- a/mod/forum/rate.php +++ b/mod/forum/rate.php @@ -79,9 +79,7 @@ if ($rating != $oldrating->rating) { $oldrating->rating = $rating; $oldrating->time = time(); - if (!$DB->update_record('forum_ratings', $oldrating)) { - print_error('cannotupdaterate', 'error', '', (object)array('id'=>$post->id, 'rating'=>$rating)); - } + $DB->update_record('forum_ratings', $oldrating); forum_update_grades($forum, $post->userid); } diff --git a/mod/hotpot/lib.php b/mod/hotpot/lib.php index ec126d1296..a459a10d4c 100644 --- a/mod/hotpot/lib.php +++ b/mod/hotpot/lib.php @@ -626,9 +626,7 @@ function hotpot_add_chain(&$hotpot) { hotpot_set_name_summary_reference($hotpot, $i); $hotpot->reference = $hotpot->reference; - if (!$hotpot->instance = $DB->insert_record("hotpot", $hotpot)) { - print_error('cannotaddnewinstance', '', 'view.php?id='.$hotpot->course, $hotpot->modulename); - } + $hotpot->instance = $DB->insert_record("hotpot", $hotpot); // store (hotpot table) id of start of chain if ($i==0) { diff --git a/mod/scorm/lib.php b/mod/scorm/lib.php index 2b757875ef..4d952c8193 100755 --- a/mod/scorm/lib.php +++ b/mod/scorm/lib.php @@ -78,9 +78,7 @@ function scorm_add_instance($scorm, $mform=null) { } /// update course module record - from now on this instance properly exists and all function may be used - if (!$DB->set_field('course_modules', 'instance', $id, array('id'=>$cmid))) { - print_error('cannotaddcoursemodule'); - } + $DB->set_field('course_modules', 'instance', $id, array('id'=>$cmid)); /// reload scorm instance $scorm = $DB->get_record('scorm', array('id'=>$id)); diff --git a/question/format.php b/question/format.php index 2c97915971..2f891c943f 100644 --- a/question/format.php +++ b/question/format.php @@ -407,9 +407,7 @@ class qformat_default { $category->parent = $parent; $category->sortorder = 999; $category->stamp = make_unique_id_code(); - if (!($id = $DB->insert_record('question_categories', $category))) { - print_error("cannotcreatecategory"); - } + $id = $DB->insert_record('question_categories', $category); $category->id = $id; $parent = $id; } diff --git a/user/edit.php b/user/edit.php index 1b770aef58..7fc6ef1059 100644 --- a/user/edit.php +++ b/user/edit.php @@ -135,9 +135,7 @@ $usernew->timemodified = time(); - if (!$DB->update_record('user', $usernew)) { - print_error('cannotupdateprofile'); - } + $DB->update_record('user', $usernew); // pass a true $userold here if (! $authplugin->user_update($user, $userform->get_data())) { diff --git a/user/profile/definelib.php b/user/profile/definelib.php index ae744543d2..2e4ee0f9e4 100644 --- a/user/profile/definelib.php +++ b/user/profile/definelib.php @@ -266,9 +266,7 @@ function profile_delete_category($id) { } /// Finally we get to delete the category - if (!$DB->delete_records('user_info_category', array('id'=>$category->id))) { - print_error('cannotdeletecate'); - } + $DB->delete_records('user_info_category', array('id'=>$category->id)); profile_reorder_categories(); return true; } diff --git a/user/profile/lib.php b/user/profile/lib.php index 5b3f8fae49..ca99fe1ac9 100644 --- a/user/profile/lib.php +++ b/user/profile/lib.php @@ -113,9 +113,7 @@ class profile_field_base { if ($dataid = $DB->get_field('user_info_data', 'id', array('userid'=>$data->userid, 'fieldid'=>$data->fieldid))) { $data->id = $dataid; - if (!$DB->update_record('user_info_data', $data)) { - print_error('cannotupdatecustomprofile'); - } + $DB->update_record('user_info_data', $data); } else { $DB->insert_record('user_info_data', $data); } -- 2.39.5