$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')) {
$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;
}
}
} 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
$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);
$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);
$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;
$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]
}
$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';
$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;
}
}
$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;
$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')) {
$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.
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
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;
}
$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);
}
//saving the feedback in db
- if (!$feedbackid = $DB->insert_record("feedback", $feedback)) {
- return false;
- }
+ $feedbackid = $DB->insert_record("feedback", $feedback);
$feedback->id = $feedbackid;
$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));
//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);
}
}
$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();
$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);
$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));
$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);
$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;
$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))) {
$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;
$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;
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)) {
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);
$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];
$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) {
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;
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;
// 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];
// 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++;
}
$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) {
}
$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));