]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-18293 removed obsoleted checking of return values from insert and update_record...
authorskodak <skodak>
Sat, 13 Jun 2009 18:16:08 +0000 (18:16 +0000)
committerskodak <skodak>
Sat, 13 Jun 2009 18:16:08 +0000 (18:16 +0000)
20 files changed:
admin/generator.php
backup/restorelib.php
course/format/topics/format.php
course/format/weeks/format.php
enrol/authorize/authorizenet.class.php
grade/import/csv/index.php
lang/en_utf8/hotpot.php
lib/accesslib.php
lib/moodlelib.php
lib/questionlib.php
mod/data/lib.php
mod/feedback/lib.php
mod/forum/lib.php
mod/forum/post.php
mod/hotpot/lib.php
mod/lesson/action/continue.php
mod/lesson/lib.php
mod/lesson/locallib.php
mod/quiz/startattempt.php
mod/scorm/lib.php

index 9f8516e68d53c66158e8eacf519c0fa7e230fde9..90ac64db4170055a1350fc3241d84feadf25f98d 100755 (executable)
@@ -236,18 +236,12 @@ class generator {
             $user->lang        = $CFG->lang;
             $user->timemodified= time();
 
-            if (!$user->id = $DB->insert_record("user", $user)) {
-                $this->verbose("Error inserting a user in the database! Aborting the script!");
-                if (!$this->get('ignore_errors')) {
-                    die();
-                }
-            } else {
-                $users_count++;
-                $users[] = $user->id;
-                $next_user_id = $user->id + 1;
-                $this->verbose("Inserted $user->firstname $user->lastname into DB "
-                    ."(username=$user->username, password=password).");
-            }
+            $user->id = $DB->insert_record("user", $user);
+            $users_count++;
+            $users[] = $user->id;
+            $next_user_id = $user->id + 1;
+            $this->verbose("Inserted $user->firstname $user->lastname into DB "
+                ."(username=$user->username, password=password).");
         }
 
         if (!$this->get('quiet')) {
index 9dfc0c0d55499dbd2a8734c6ddfb1ae0eb499542..ea169ebbbd83144ee9eaafc6aa0d4ce2bdb67071 100644 (file)
@@ -866,9 +866,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
                         $blockinstance->pagetype = PAGE_COURSE_VIEW;
                         $blockinstance->position = $blockposition;
                         $blockinstance->weight   = $blockweight;
-                        if(!$status = $DB->insert_record('block_instance', $blockinstance)) {
-                            $status = false;
-                        }
+                        $DB->insert_record('block_instance', $blockinstance);
                         ++$blockweight;
                     }
                 }
@@ -3626,10 +3624,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
 
                 } else {
                     //The structure is equal to the db, so insert the grouping
-                    if (!$newid = $DB->insert_record('groupings', $gro)) {
-                        $status = false;
-                        continue;
-                    }
+                    $newid = $DB->insert_record('groupings', $gro);
                 }
 
                 //We have the newid, update backup_ids
index 6971c2d5a61faf8e9c94afb0fe4b045332e7bd24..67dee6735cf35b1df3ae9627da6b714055071c65 100644 (file)
             $thissection->section = $section;
             $thissection->summary  = '';
             $thissection->visible  = 1;
-            if (!$thissection->id = $DB->insert_record('course_sections', $thissection)) {
-                notify('Error inserting new topic!');
-            }
+            $thissection->id = $DB->insert_record('course_sections', $thissection);
         }
 
         $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible or !$course->hiddensections);
index 25143e7ab221bd5f84fc176aa6b4108e636377b5..5f90f45844cf05d3b8ab0cd13d7d463831b702b9 100644 (file)
             $thissection->section = $section;
             $thissection->summary = '';
             $thissection->visible = 1;
-            if (!$thissection->id = $DB->insert_record('course_sections', $thissection)) {
-                notify('Error inserting new week!');
-            }
+            $thissection->id = $DB->insert_record('course_sections', $thissection);
         }
 
         $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible or !$course->hiddensections);
index 9ee6b6f4bf7701814a7c51da52c7a8317db5088b..18a7ae80ff25e5ea9763f23019700019d848c687 100644 (file)
@@ -308,10 +308,7 @@ class AuthorizeNet
                         $extra->status = AN_STATUS_CREDIT;
                         $extra->transid = $transid;
                         $extra->settletime = self::getsettletime(time());
-                        if (! $extra->id = $DB->insert_record('enrol_authorize_refunds', $extra)) {
-                            unset($extra->id);
-                            message_to_admin("Error while trying to insert data into table enrol_authorize_refunds. Please add manually this record:", $extra);
-                        }
+                        $extra->id = $DB->insert_record('enrol_authorize_refunds', $extra);
                     }
                     break;
 
index be8d90af0825cb0e8171db3257ea04f3499ccf1a..8d1ccf9263c3c284d5a73dfe65e3443a86ae59ec 100755 (executable)
@@ -313,12 +313,7 @@ if ($formdata = $mform->get_data()) {
                             $newgradeitem->importer   = $USER->id;
 
                             // failed to insert into new grade item buffer
-                            if (!$newgradeitems[$key] = $DB->insert_record('grade_import_newitem', $newgradeitem)) {
-                                $status = false;
-                                import_cleanup($importcode);
-                                notify(get_string('importfailed', 'grades'));
-                                break 3;
-                            }
+                            $newgradeitems[$key] = $DB->insert_record('grade_import_newitem', $newgradeitem);
                             // add this to grade_import_newitem table
                             // add the new id to $newgradeitem[$key]
                         }
index 070dc4bfa504ab399f96bd6d59f6ae3726f90daf..bf749d1e6cab9aca2b0a139d8f85d29c204970f8 100644 (file)
@@ -11,9 +11,6 @@ $string['attemptsbest'] = 'Best attempt';
 $string['attemptsfirst'] = 'First attempt';
 $string['attemptslast'] = 'Last attempt';
 $string['average'] = 'Average';
-$string['cannotaddquestionrecord'] = 'Could not add question record';
-$string['cannotaddresprecord'] = 'Could not add response record';
-$string['cannotaddstrrecord'] = 'Could not add string record';
 $string['cannotfindmethod'] = 'Template block expand method not found: ($a)';
 $string['checks'] = 'Checks';
 $string['clickreporting'] = 'Enable click reporting';
index d0684dfeb0c69aa97f5dc1b7d5ec709d590d344c..f61ccf9a1481b7d8fcac92e3389d49e7c224d436 100755 (executable)
@@ -2319,11 +2319,9 @@ function get_system_context($cache=true) {
         $context->path         = NULL; //not known before insert
 
         try {
-            if (!$context->id = $DB->insert_record('context', $context)) {
-            // can not create context yet, sorry
-                return null;
-            }
+            $context->id = $DB->insert_record('context', $context);
         } catch (dml_exception $e) {
+            // can not create context yet, sorry
             return null;
         }
     }
@@ -3021,9 +3019,7 @@ function role_assign($roleid, $userid, $groupid, $contextid, $timestart=0, $time
         $ra->timemodified = $timemodified;
         $ra->modifierid = empty($USER->id) ? 0 : $USER->id;
 
-        if (!$ra->id = $DB->insert_record('role_assignments', $ra)) {
-            return false;
-        }
+        $ra->id = $DB->insert_record('role_assignments', $ra);
 
     } else {                      // We already have one, just update it
         $ra->id = $ra->id;
index f378bf34d967e898905548e72c2c3f10cf1c1ed5..4286a861954a2ffe87cd6a9378ac679a1aec0a9a 100644 (file)
@@ -6637,9 +6637,7 @@ function endecrypt ($pwd, $data, $case) {
 
     $event->timemodified = time();
 
-    if (!$event->id = $DB->insert_record('event', $event)) {
-        return false;
-    }
+    $event->id = $DB->insert_record('event', $event);
 
     if (!empty($CFG->calendar)) { // call the add_event function of the selected calendar
         if (file_exists($CFG->dirroot .'/calendar/'. $CFG->calendar .'/lib.php')) {
index 326dbf126f7dde157c88d25a4e1c58aa1394b2eb..3690e9c3f905d0fe8ccb7f026b31347ee9b74b68 100644 (file)
@@ -782,9 +782,7 @@ function question_save_from_deletion($questionids, $newcontextid, $oldplace, $ne
         $newcategory->info = get_string('questionsrescuedfrominfo', 'question', $oldplace);
         $newcategory->sortorder = 999;
         $newcategory->stamp = make_unique_id_code();
-        if (!$newcategory->id = $DB->insert_record('question_categories', $newcategory)) {
-            return false;
-        }
+        $newcategory->id = $DB->insert_record('question_categories', $newcategory);
     }
 
     // Move any remaining questions to the 'saved' category.
@@ -1322,11 +1320,7 @@ function save_question_session($question, $state) {
     if (!empty($state->update)) { // this forces the old state record to be overwritten
         $DB->update_record('question_states', $state);
     } else {
-        if (!$state->id = $DB->insert_record('question_states', $state)) {
-            unset($state->id);
-            unset($state->answer);
-            return false;
-        }
+        $state->id = $DB->insert_record('question_states', $state);
     }
 
     // create or update the session
index 1359d528746a76e2b1bc0f2f1b8ba0b886041720..9d85061e93001b5ebb4eb7d81103dd011c88c00c 100755 (executable)
@@ -184,10 +184,7 @@ class data_field_base {     // Base class for Database Field Types (see field/*/
             return false;
         }
 
-        if (!$this->field->id = $DB->insert_record('data_fields',$this->field)){
-            notify('Insertion of new field failed!');
-            return false;
-        }
+        $this->field->id = $DB->insert_record('data_fields',$this->field);
         return true;
     }
 
@@ -843,9 +840,7 @@ function data_add_instance($data) {
 
     $data->timemodified = time();
 
-    if (! $data->id = $DB->insert_record('data', $data)) {
-        return false;
-    }
+    $data->id = $DB->insert_record('data', $data);
 
     data_grade_item_update($data);
 
index 776e189b01ffc1624d9a3e7de6e1e6fc02c927ba..2b6a8b1cf550bb4edd390a433f57a7917987044c 100644 (file)
@@ -96,9 +96,7 @@ function feedback_add_instance($feedback) {
     }
 
     //saving the feedback in db
-    if (!$feedbackid = $DB->insert_record("feedback", $feedback)) {
-        return false;
-    }
+    $feedbackid = $DB->insert_record("feedback", $feedback);
 
     $feedback->id = $feedbackid;
 
@@ -1603,9 +1601,7 @@ function feedback_create_values($data, $usrid, $timemodified, $tmp = false, $gue
     $completed->timemodified       = $timemodified;
     $completed->anonymous_response = $data['anonymous_response'];
 
-    if (!$completedid = $DB->insert_record('feedback_completed'.$tmpstr, $completed)) {
-        return false;
-    }
+    $completedid = $DB->insert_record('feedback_completed'.$tmpstr, $completed);
 
     $completed = $DB->get_record('feedback_completed'.$tmpstr, array('id'=>$completedid));
 
@@ -1629,9 +1625,7 @@ function feedback_create_values($data, $usrid, $timemodified, $tmp = false, $gue
             //the kind of values can be absolutely different so we run create_value directly by the item-class
             $value->value = $itemobj->create_value($data[$key]);
 
-            if (!$DB->insert_record('feedback_value'.$tmpstr, $value)) {
-                $errcount++;
-            }
+            $DB->insert_record('feedback_value'.$tmpstr, $value);
         }
     }
 
index 990bc3ddf7c01b04ddd787067dc96b98e5a17eac..bd64cc7068ab014c0bf923a13f920b95b34bef61 100644 (file)
@@ -78,9 +78,7 @@ function forum_add_instance($forum) {
         $forum->assesstimefinish = 0;
     }
 
-    if (!$forum->id = $DB->insert_record('forum', $forum)) {
-        return false;
-    }
+    $forum->id = $DB->insert_record('forum', $forum);
 
     if ($forum->type == 'single') {  // Create related discussion.
         $discussion = new object();
@@ -4480,9 +4478,7 @@ function forum_add_new_post($post, $mform, &$message) {
     $post->userid     = $USER->id;
     $post->attachment = "";
 
-    if (! $post->id = $DB->insert_record("forum_posts", $post)) {
-        return false;
-    }
+    $post->id = $DB->insert_record("forum_posts", $post);
     $message = file_save_draft_area_files($post->itemid, $context->id, 'forum_post', $post->id, array('subdirs'=>true), $message);
     $DB->set_field('forum_posts', 'message', $message, array('id'=>$post->id));
     forum_add_attachment($post, $forum, $cm, $mform, $message);
@@ -4583,9 +4579,7 @@ function forum_add_discussion($discussion, $mform=null, &$message=null) {
     $post->course        = $forum->course; // speedup
     $post->mailnow       = $discussion->mailnow;
 
-    if (! $post->id = $DB->insert_record("forum_posts", $post) ) {
-        return 0;
-    }
+    $post->id = $DB->insert_record("forum_posts", $post);
 
     $text = file_save_draft_area_files($discussion->itemid, $context->id, 'forum_post', $post->id, array('subdirs'=>true), $post->message);
     $DB->set_field('forum_posts', 'message', $text, array('id'=>$post->id));
@@ -4597,17 +4591,10 @@ function forum_add_discussion($discussion, $mform=null, &$message=null) {
     $discussion->usermodified = $post->userid;
     $discussion->userid       = $USER->id;
 
-    if (! $post->discussion = $DB->insert_record("forum_discussions", $discussion) ) {
-        $DB->delete_records("forum_posts", array("id"=>$post->id));
-        return 0;
-    }
+    $post->discussion = $DB->insert_record("forum_discussions", $discussion);
 
     // Finally, set the pointer on the post.
-    if (! $DB->set_field("forum_posts", "discussion", $post->discussion, array("id"=>$post->id))) {
-        $DB->delete_records("forum_posts", array("id"=>$post->id));
-        $DB->delete_records("forum_discussions", array("id"=>$post->discussion));
-        return 0;
-    }
+    $DB->set_field("forum_posts", "discussion", $post->discussion, array("id"=>$post->id));
 
     if (!empty($cm->id)) {
         forum_add_attachment($post, $forum, $cm, $mform, $message);
index e58c900a436529fec88c1c42b050021aea351863..54b9c0efb6a695b9bcf883ae9ec4bcf1e4ec8e97 100644 (file)
             $newdiscussion->timestart    = $discussion->timestart;
             $newdiscussion->timeend      = $discussion->timeend;
 
-            if (!$newid = $DB->insert_record('forum_discussions', $newdiscussion)) {
-                print_error('cannotcreatediscussion', 'forum');
-            }
+            $newid = $DB->insert_record('forum_discussions', $newdiscussion);
 
             $newpost = new object();
             $newpost->id      = $post->id;
index 1b37f5d2108753d4178ed268384ac15218dd2c96..49ce746d1c99d0ef7d1d73e51a6b46caa40aeeec 100644 (file)
@@ -2566,9 +2566,7 @@ function hotpot_add_response(&$attempt, &$question, &$response) {
         $question->md5key = md5($question->name);
         if (!$question->id = $DB->get_field('hotpot_questions', 'id', array('hotpot'=>$attempt->hotpot, 'md5key'=>$question->md5key, 'name'=>$question->name))) {
             // add question record
-            if (!$question->id = $DB->insert_record('hotpot_questions', $question)) {
-                print_error('cannotaddquestionrecord', 'hotpot', $next_url);
-            }
+            $question->id = $DB->insert_record('hotpot_questions', $question);
         }
 
         if ($DB->record_exists('hotpot_responses', array('attempt'=>$attempt->id, 'question'=>$question->id))) {
@@ -2591,9 +2589,7 @@ function hotpot_add_response(&$attempt, &$question, &$response) {
             $response->question = $question->id;
 
             // add response record
-            if(!$response->id = $DB->insert_record('hotpot_responses', $response)) {
-                print_error('cannotaddresprecord', 'hotpot', $next_url);
-            }
+            $response->id = $DB->insert_record('hotpot_responses', $response);
 
             // we can stop looping now
             $looping = false;
@@ -2762,10 +2758,7 @@ function hotpot_string_id($str) {
             $record->md5key = $md5key;
 
             // try and add the new string record
-            if (!$id = $DB->insert_record('hotpot_strings', $record)) {
-                global $DB;
-                print_error('cannotaddstrrecord', 'hotpot');
-            }
+            $id = $DB->insert_record('hotpot_strings', $record);
         }
     }
     return $id;
index 4b5bf4b190ea080ec807b2e0f6fbb822e4de74ff..622ac3d57f3f9072a4656c26ffefa4e3f219a363 100644 (file)
             if (isset($USER->modattempts[$lesson->id])) {
                 $attempt->retry = $nretakes - 1; // they are going through on review, $nretakes will be too high
             }
-            if (!$newattemptid = $DB->insert_record("lesson_attempts", $attempt)) {
-                print_error("Continue: attempt not inserted");
-            }
+            $newattemptid = $DB->insert_record("lesson_attempts", $attempt);
             // "number of attempts remaining" message if $lesson->maxattempts > 1
             // displaying of message(s) is at the end of page for more ergonomic display
             if (!$correctanswer and ($newpageid == 0)) {
index 5ea746a9f7e338eca4ba2779754044a8a36ebf72..a371b35e740eec406ba5c607f5bf3f0e5bdfe153 100644 (file)
@@ -45,9 +45,7 @@ function lesson_add_instance($lesson) {
 
     lesson_process_pre_save($lesson);
 
-    if (!$lesson->id = $DB->insert_record("lesson", $lesson)) {
-        return false; // bad
-    }
+    $lesson->id = $DB->insert_record("lesson", $lesson);
 
     lesson_process_post_save($lesson);
 
index d263d29510ca279e5ac4d10988f0a3a1f471fa67..d475e1b2dffe902cbb3b99dc16600a675aa84d94 100644 (file)
@@ -674,10 +674,7 @@ function lesson_save_question_options($question) {
                     $answer->grade = $question->fraction[$key] * 100;
                     $answer->answer   = $dataanswer;
                     $answer->response = $question->feedback[$key];
-                    if (!$answer->id = $DB->insert_record("lesson_answers", $answer)) {
-                        $result->error = "Could not insert shortanswer quiz answer!";
-                        return $result;
-                    }
+                    $answer->id = $DB->insert_record("lesson_answers", $answer);
                     $answers[] = $answer->id;
                     if ($question->fraction[$key] > $maxfraction) {
                         $maxfraction = $question->fraction[$key];
@@ -714,10 +711,7 @@ function lesson_save_question_options($question) {
                     $answer->answer   = $min.":".$max;
                     // $answer->answer   = $question->min[$key].":".$question->max[$key]; original line for min/max
                     $answer->response = $question->feedback[$key];
-                    if (!$answer->id = $DB->insert_record("lesson_answers", $answer)) {
-                        $result->error = "Could not insert numerical quiz answer!";
-                        return $result;
-                    }
+                    $answer->id = $DB->insert_record("lesson_answers", $answer);
                     
                     $answers[] = $answer->id;
                     if ($question->fraction[$key] > $maxfraction) {
@@ -749,10 +743,7 @@ function lesson_save_question_options($question) {
             if (isset($question->feedbacktrue)) {
                 $answer->response = $question->feedbacktrue;
             }
-            if (!$true->id = $DB->insert_record("lesson_answers", $answer)) {
-                $result->error = "Could not insert quiz answer \"true\")!";
-                return $result;
-            }
+            $true->id = $DB->insert_record("lesson_answers", $answer);
 
             // the lie    
             $answer = new stdClass;
@@ -767,10 +758,7 @@ function lesson_save_question_options($question) {
             if (isset($question->feedbackfalse)) {
                 $answer->response = $question->feedbackfalse;
             }
-            if (!$false->id = $DB->insert_record("lesson_answers", $answer)) {
-                $result->error = "Could not insert quiz answer \"false\")!";
-                return $result;
-            }
+            $false->id = $DB->insert_record("lesson_answers", $answer);
 
           break;
 
@@ -803,10 +791,7 @@ function lesson_save_question_options($question) {
                     // end Replace
                     $answer->answer   = $dataanswer;
                     $answer->response = $question->feedback[$key];
-                    if (!$answer->id = $DB->insert_record("lesson_answers", $answer)) {
-                        $result->error = "Could not insert multichoice quiz answer! ";
-                        return $result;
-                    }
+                    $answer->id = $DB->insert_record("lesson_answers", $answer);
                     // for Sanity checks
                     if ($question->fraction[$key] > 0) {                 
                         $totalfraction += $question->fraction[$key];
@@ -853,10 +838,7 @@ function lesson_save_question_options($question) {
                         // first answer contains the correct answer jump
                         $answer->jumpto = LESSON_NEXTPAGE;
                     }
-                    if (!$subquestion->id = $DB->insert_record("lesson_answers", $answer)) {
-                        $result->error = "Could not insert quiz match subquestion!";
-                        return $result;
-                    }
+                    $subquestion->id = $DB->insert_record("lesson_answers", $answer);
                     $subquestions[] = $subquestion->id;
                     $i++;
                 }
index 82d234f7b6f971c6da9c2bf2ce30e5a0142bcb32..2967aebd982c63408938c86f07325618495282af 100644 (file)
@@ -95,9 +95,7 @@ quiz_delete_previews($quiz, $USER->id);
 $attempt = quiz_create_attempt($quiz, $attemptnumber, $lastattempt, time(), $quizobj->is_preview_user());
 
 /// Save the attempt in the database.
-if (!$attempt->id = $DB->insert_record('quiz_attempts', $attempt)) {
-    quiz_error($quiz, 'newattemptfail');
-}
+$attempt->id = $DB->insert_record('quiz_attempts', $attempt);
 
 /// Log the new attempt.
 if ($attempt->preview) {
index a894d719323857f797c7eea511366ab82db4970c..3f294ab112d682c3a5d6adabd868142a15ad19df 100755 (executable)
@@ -73,9 +73,7 @@ function scorm_add_instance($scorm, $mform=null) {
     }
     $scorm->grademethod = ($scorm->whatgrade * 10) + $scorm->grademethod;
 
-    if (!$id = $DB->insert_record('scorm', $scorm)) {
-        return false;
-    }
+    $id = $DB->insert_record('scorm', $scorm);
 
 /// update course module record - from now on this instance properly exists and all function may be used
     $DB->set_field('course_modules', 'instance', $id, array('id'=>$cmid));