]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-18293 $DB->somethiong is using exceptions, no need for ifs tehre, removing useles...
authorskodak <skodak>
Wed, 3 Jun 2009 20:00:08 +0000 (20:00 +0000)
committerskodak <skodak>
Wed, 3 Jun 2009 20:00:08 +0000 (20:00 +0000)
14 files changed:
course/editcategory.php
course/modedit.php
lang/en_utf8/error.php
lib/accesslib.php
lib/questionlib.php
lib/simpletest/testfilelib.php
mod/data/rate.php
mod/forum/rate.php
mod/hotpot/lib.php
mod/scorm/lib.php
question/format.php
user/edit.php
user/profile/definelib.php
user/profile/lib.php

index 006406589442fcd52a31ce281f4fae3f6be5eb4e..1b5084b082c2c1ba6ab3fa1e3f74b388b0ceb42f 100644 (file)
@@ -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.
index 0e3dd81e41c8e857a379b97d062f6f2610c4929d..782a9ff5acaac373de91c1204a40590c555a9cf9 100644 (file)
 
             $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);
index fb076179f260d2b1cd1ffdd71c37873f8ffff150..d62a59071e3c3dd6754b1c4c8bb6b881dd2eb21f 100644 (file)
@@ -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!';
index 8e17ba8ef91e0cac0573b272c82514d3f3e5ecb2..df1e445c3a052bce9405c895295cb1ae57c7ebb8 100755 (executable)
@@ -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) {
index 798ec03a225548c208b246b2856905116b053b97..32a4849ec8a207a57c3c6092d48425ed62065864 100644 (file)
@@ -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);
         }
index e0d1419a9cab976667444c1d7dc52c51fbd5c025..21110cfc4d0735af28625816926cade1b1d5cce0 100644 (file)
@@ -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);
index 4faaf5d48674abc285290c1172d94ff34eb29e9f..599a804f2c3e4a698762c568b6f54ce91c2170f0 100755 (executable)
@@ -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);
 
             }
index 0f7a1240f7cbf9d69d1c7a319b6318f5c3c2ea9b..84f5e5dce4bbd5e907bebae950d6f626e6619914 100644 (file)
@@ -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);
                 }
 
index ec126d1296fee300455bd1e75352de4294801e99..a459a10d4c64eb40f34a14395374a60a88f2b210 100644 (file)
@@ -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) {
index 2b757875ef545ff187a948966fdbffde5168855e..4d952c8193459810e4bd3f73c70b07404ebd8812 100755 (executable)
@@ -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));
index 2c9791597198f89d44ee91cc7350b542892d5d75..2f891c943f2e4b7704ad3c5be10609e79013d73e 100644 (file)
@@ -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;
             }
index 1b770aef58fd6a8f38b4beeff6baf38d51a3c12f..7fc6ef1059cb0f4686004cc2729bc6cbdaa401b6 100644 (file)
 
         $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())) {
index ae744543d25bf73e51cd89a54254f3da99dcc91b..2e4ee0f9e46ac59ba728824f2af74658da6e3f36 100644 (file)
@@ -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;
 }
index 5b3f8fae498dc14e1e5761d913d7b5b887220cc5..ca99fe1ac903b8b9d5328c053c46a2ef91263abc 100644 (file)
@@ -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);
         }