MDL-18293 removed obsoleted checking of return values from insert and update_record + unused strings cleanup

This commit is contained in:
skodak 2009-06-13 17:17:10 +00:00
parent b8ac7ecec8
commit bb4b6010f3
26 changed files with 81 additions and 279 deletions

View File

@ -102,9 +102,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$coursesummary = restore_decode_content_links_worker($coursesummary, $restore);
if ($coursesummary != $course->summary) {
$course->summary = $coursesummary;
if (!$DB->update_record('course', $course)) {
$status = false;
}
$DB->update_record('course', $course);
}
if (!defined('RESTORE_SILENTLY')) {
echo '</li>';
@ -120,9 +118,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$sectionsummary = restore_decode_content_links_worker($section->summary, $restore);
if ($sectionsummary != $section->summary) {
$section->summary = $sectionsummary;
if (!$DB->update_record('course_sections', $section)) {
$status = false;
}
$DB->update_record('course_sections', $section);
}
}
if (!defined('RESTORE_SILENTLY')) {

View File

@ -141,9 +141,7 @@ if ($act == 'updfeed') {
}
$dataobject->url = $url;
if (!$DB->update_record('block_rss_client', $dataobject)) {
print_error('updatersserror', 'error', '', $rssid);
}
$DB->update_record('block_rss_client', $dataobject);
$message .= '<br />'. get_string('feedupdated', 'block_rss_client');
redirect($referrer, $message);
@ -200,9 +198,7 @@ if ($act == 'updfeed') {
if (!empty($rss->channel['title'])) {
$dataobject->title = $rss->channel['title'];
}
if (!$DB->update_record('block_rss_client', $dataobject)) {
print_error('updatersserror', 'error', '', $rssid);
}
$DB->update_record('block_rss_client', $dataobject);
$message .= '<br />'. get_string('feedadded', 'block_rss_client');
}
redirect($referrer, $message);

View File

@ -2708,9 +2708,7 @@ function moveto_module($mod, $section, $beforemod=NULL) {
if ($mod->section != $section->id) {
$mod->section = $section->id;
if (!$DB->update_record("course_modules", $mod)) {
return false;
}
$DB->update_record("course_modules", $mod);
// if moving to a hidden section then hide module
if (!$section->visible) {
set_coursemodule_visible($mod->id, 0);
@ -3191,9 +3189,7 @@ function move_courses($courseids, $categoryid) {
$course->category = $categoryid;
$course->sortorder = $category->sortorder + MAX_COURSES_IN_CATEGORY - $i++;
if (!$DB->update_record('course', $course)) {
notify("An error occurred - course not moved!");
}
$DB->update_record('course', $course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$newparent = get_context_instance(CONTEXT_COURSECAT, $course->category);

View File

@ -139,10 +139,7 @@ switch($_SERVER['REQUEST_METHOD']) {
$newcourse = new object;
$newcourse->id = $course->id;
$newcourse->marker = $value;
if (!$DB->update_record('course', $newcourse)) {
error_log('AJAX commands.php: Failed to update course marker for course '.$newcourse->id);
die;
}
$DB->update_record('course', $newcourse);
break;
}
break;

View File

@ -297,9 +297,7 @@ class AuthorizeNet
$order->status = AN_STATUS_UNDERREVIEW;
}
if (!$DB->update_record('enrol_authorize', $order)) {
message_to_admin("Error while trying to update data in table enrol_authorize. Please edit manually this record: ID=$order->id.", $order);
}
$DB->update_record('enrol_authorize', $order);
}
break;

View File

@ -131,7 +131,6 @@ $string['cannotupdatepasswordonextauth'] = 'Failed to update password on externa
$string['cannotupdateprofile'] = 'Error updating user record';
$string['cannotupdaterss'] = 'Cannot update RSS';
$string['cannotupdatesecret'] = 'Error resetting user secret string';
$string['cannotupdatesubcate'] = 'Could not update a child category!';
$string['cannotupdatesubcourse'] = 'Could not update a child course!';
$string['cannotuploadfile'] = 'Error processing upload file';
$string['cannotunassignrolefrom'] = 'Cannot unassign this user from role id: $a';

View File

@ -6,20 +6,14 @@ $string['availableq'] = 'Available?';
$string['badbase'] = 'Bad base before **: $a**';
$string['broken'] = 'This is a \"broken link\", it points to a nonexistent file.';
$string['byandon'] = 'by <em>$a->user</em> on <em>$a->time</em>';
$string['cannotinsert'] = 'Could not insert entry in question_sessions';
$string['cannotcreate'] = 'Could not create new entry in question_attempts table';
$string['cannotcreatedataset'] = 'Unable to create dataset $a';
$string['cannotcreaterelation'] = 'Unable to create relation to dataset $a[0] $a[1]';
$string['cannotcreatepath'] = 'Cannot create path: $a';
$string['cannotcopybackup'] = 'Could not copy backup file';
$string['cannotdeletecate'] = 'You can\'t delete that category it is the default category for this context.';
$string['cannotenable'] = 'Question type $a cannot be created directly.';
$string['cannotfindcate'] = 'Could not find category record';
$string['cannotinsertitem'] = 'Unable to insert dataset item $a[0] with $a[1] for $a[2]';
$string['cannotinsert'] = 'Error: Unable to insert dataset item';
$string['cannotinsertquestion'] = 'Could not insert new question!';
$string['cannotinsertquestioncatecontext'] = 'Could not insert the new question category $a[0] illegal contextid $a[1]';
$string['cannotinsertquestioncate'] = 'Could not insert the new question category: $a';
$string['cannotimportformat'] = 'Sorry, importing this format is not yet implemented!';
$string['cannotfindquestionfile'] = 'Could not find question data file in zip';
$string['cannotgetdsforquestion'] = 'Cannot get the specified dataset for a calculated question! (question: {$a})';
@ -28,20 +22,10 @@ $string['cannothidequestion'] = 'Was not able to hide question';
$string['cannotloadquestion'] = 'Could not load question';
$string['cannotpreview'] = 'You can\'t preview these questions!';
$string['cannotretrieveqcat'] = 'Could retrieve question category';
$string['cannotupdatecount'] = 'Error: Unable to update itemcount';
$string['cannotupdatecate'] = 'Could not update the category $a';
$string['cannotmovecate'] = 'Cannot move the category $a. It is the last in this context.';
$string['cannotmovefromto'] = 'Could not move the category $a[0] to $a[1]';
$string['cannotmovequestion'] = 'You can\'t use this script to move questions that have files associated with them from different areas.';
$string['cannotopenforwriting'] = 'Cannot open for writing: $a';
$string['cannotunhidequestion'] = 'Failed to unhide the question.';
$string['cannotunzip'] = 'Could not unzip file.';
$string['cannotupdatesubcate'] = 'Could not update a child category!';
$string['cannotupdaterandomqname'] = 'Could not update random question name';
$string['cannotupdateitem'] = 'Error: Unable to update dataset item';
$string['cannotupdatequestion'] = 'Could not update question!';
$string['cannotupdatequestionver'] = 'Could not update question version field';
$string['cannotsavequiz'] = 'Failed to save the current quiz attempt!';
$string['cannotwriteto'] = 'Cannot write exported questions to $a';
$string['categorydoesnotexist'] = 'This category does not exist';
$string['categorycurrent'] = 'Current Category';

View File

@ -21,8 +21,6 @@ $string['cannotaccessgroup'] = 'Cannot access any groups for this wiki';
$string['cannotacceptbin'] = 'This wiki does not accept binaries';
$string['cannotaddentry'] = 'Could not add wiki entry.';
$string['cannotchangepage'] = 'This page cannot be changed.';
$string['cannotdeletelockrecored'] = 'Unable to delete lock record';
$string['cannotinsertlockrecored'] = 'Unable to insert lock record';
$string['cannotgetentry'] = 'Cannot get entry.';
$string['cannotstartwith'] = 'Binary entry does not start with ($a)';
$string['changes'] = '$a changes';

View File

@ -3036,9 +3036,7 @@ function role_assign($roleid, $userid, $groupid, $contextid, $timestart=0, $time
$ra->timemodified = $timemodified;
$ra->modifierid = empty($USER->id) ? 0 : $USER->id;
if (!$DB->update_record('role_assignments', $ra)) {
return false;
}
$DB->update_record('role_assignments', $ra);
}
/// mark context as dirty - modules might use has_capability() in xxx_role_assing()

View File

@ -1355,9 +1355,7 @@ function save_question_session($question, $state) {
$session->manualcomment = $session->manualcomment;
}
$session->flagged = !empty($state->newflaggedstate);
if (!$DB->update_record('question_sessions', $session)) {
return false;
}
$DB->update_record('question_sessions', $session);
}
unset($state->answer);
@ -1975,9 +1973,7 @@ function question_process_comment($question, &$state, &$attempt, $comment, $grad
if ($grade !== '' && (abs($state->last_graded->grade - $grade) > 0.002 || $state->last_graded->event != QUESTION_EVENTMANUALGRADE)) {
$attempt->sumgrades = $attempt->sumgrades - $state->last_graded->grade + $grade;
$attempt->timemodified = time();
if (!$DB->update_record('quiz_attempts', $attempt)) {
return get_string('errorupdatingattempt', 'question', $attempt);
}
$DB->update_record('quiz_attempts', $attempt);
// We want to update existing state (rather than creating new one) if it
// was itself created by a manual grading event.

View File

@ -2051,9 +2051,7 @@ function wiki_obtain_lock($wikiid,$pagename) {
return array(false,$lock);
} else {
// Not locked any more. Get rid of the old lock record.
if(!$DB->delete_records('wiki_locks', array('pagename'=>$pagename,'wikiid'=>$wikiid))) {
print_error('cannotdeletelockrecored', 'wiki');
}
$DB->delete_records('wiki_locks', array('pagename'=>$pagename,'wikiid'=>$wikiid));
}
}
@ -2066,9 +2064,7 @@ function wiki_obtain_lock($wikiid,$pagename) {
$newlock->lockedseen=$newlock->lockedsince;
$newlock->wikiid=$wikiid;
$newlock->pagename=$pagename;
if(!$lockid=$DB->insert_record('wiki_locks',$newlock)) {
print_error('cannotinsertlockrecored', 'wiki');
}
$lockid = $DB->insert_record('wiki_locks',$newlock);
}
// Store lock information in session so we can clear it later
@ -2105,9 +2101,7 @@ function wiki_release_lock($wikiid,$pagename) {
if(array_key_exists($key,$_SESSION[SESSION_WIKI_LOCKS])) {
$lockid=$_SESSION[SESSION_WIKI_LOCKS][$key];
unset($_SESSION[SESSION_WIKI_LOCKS][$key]);
if (!$DB->delete_records('wiki_locks', array('id'=>$lockid))) {
print_error('cannotdeletelockrecored', 'wiki');
}
$DB->delete_records('wiki_locks', array('id'=>$lockid));
}
}

View File

@ -44,9 +44,7 @@ if(count($actions)!=2) {
print_error('invalidpageval', 'wiki');
}
$pagename=$actions[1];
if(!$DB->delete_records('wiki_locks', array('pagename'=>$pagename, 'wikiid'=>$wiki->id))) {
print_error('cannotdeletelockrecored', 'wiki');
}
$DB->delete_records('wiki_locks', array('pagename'=>$pagename, 'wikiid'=>$wiki->id));
redirect("view.php?id=$id&page=".urlencode($page));
?>

View File

@ -358,9 +358,7 @@ class question_category_object {
print_error('unknowcategory');
}
/// Send the children categories to live with their grandparent
if (!$DB->set_field("question_categories", "parent", $category->parent, array("parent" => $category->id))) {
print_error('cannotupdatesubcate', 'question');
}
$DB->set_field("question_categories", "parent", $category->parent, array("parent" => $category->id));
/// Finally delete the category itself
$DB->delete_records("question_categories", array("id" => $category->id));
@ -414,14 +412,11 @@ class question_category_object {
$cat->info = $newinfo;
$cat->sortorder = 999;
$cat->stamp = make_unique_id_code();
if (!$categoryid=$DB->insert_record("question_categories", $cat)) {
print_error('cannotinsertquestioncate', 'question', '', $newcategory);
$categoryid = $DB->insert_record("question_categories", $cat);
if ($return) {
return $categoryid;
} else {
if($return){
return $categoryid;
}else{
redirect($this->pageurl->out());//always redirect after successful action
}
redirect($this->pageurl->out());//always redirect after successful action
}
}
@ -462,9 +457,7 @@ class question_category_object {
$cat->info = $newinfo;
$cat->parent = $parentid;
// We don't change $cat->contextid here, if necessary we redirect to contextmove.php later.
if (!$DB->update_record('question_categories', $cat)) {
print_error('cannotupdatecate', 'question', $this->pageurl->out(), $newname);
}
$DB->update_record('question_categories', $cat);
// If the category name has changed, rename any random questions in that category.
if ($oldcat->name != $cat->name) {

View File

@ -179,13 +179,9 @@
list($usql, $params) = $DB->get_in_or_equal(explode(',', $cattomove->categorylist));
$params = array_merge(array($contextto->id), $params);
if (!$DB->execute("UPDATE {question_categories} SET contextid = ? WHERE id $usql", $params)){
print_error('cannotmovefromto', 'question', $onerrorurl, array($newname, $contexttostring));
}
$DB->execute("UPDATE {question_categories} SET contextid = ? WHERE id $usql", $params);
//finally set the new parent id
if (!$DB->update_record("question_categories", $cat)) {
print_error('cannotupdatecate', 'question', $onerrorurl, $updatename);
}
$DB->update_record("question_categories", $cat);
$thispageurl->remove_params('cattomove', 'toparent', 'totop');
redirect($CFG->wwwroot."/question/category.php?".$thispageurl->get_query_string(array('cat'=>"{$cattomove->id},{$contextto->id}")));
}

View File

@ -313,9 +313,7 @@ class qformat_default {
$question->createdby = $USER->id;
$question->timecreated = time();
if (!$question->id = $DB->insert_record("question", $question)) {
print_error('cannotinsert','quiz');
}
$question->id = $DB->insert_record("question", $question);
$this->questionids[] = $question->id;

View File

@ -965,9 +965,7 @@
if ($questiontext != $question->questiontext || $generalfeedback != $question->generalfeedback) {
$question->questiontext = $questiontext;
$question->generalfeedback = $generalfeedback;
if (!$DB->update_record('question', $question)) {
$status = false;
}
$DB->update_record('question', $question);
}
// Do some output.
@ -1007,9 +1005,7 @@
unset($answer->qtype);
$answer->feedback = $feedback;
$answer->answer = $answertext;
if (!$DB->update_record('question_answers', $answer)) {
$status = false;
}
$DB->update_record('question_answers', $answer);
}
// Do some output.

View File

@ -262,28 +262,20 @@ class question_calculated_qtype extends default_questiontype {
}
}
if ( $todo=='create'){
if (!$datasetdef->id = $DB->insert_record( 'question_dataset_definitions', $datasetdef)) {
print_error('cannotcreatedataset', 'question', '', $defid);
}
$datasetdef->id = $DB->insert_record( 'question_dataset_definitions', $datasetdef);
}
// Create relation to the dataset:
$questiondataset = new stdClass;
$questiondataset->question = $question->id;
$questiondataset->datasetdefinition = $datasetdef->id;
if (!$DB->insert_record('question_datasets', $questiondataset)) {
print_error("cannotcreaterelation", 'question', '',
array($dataset->name, $todo));
}
$DB->insert_record('question_datasets', $questiondataset);
if ($todo=='create'){ // add the items
foreach ($dataset->datasetitem as $dataitem ){
$datasetitem = new stdClass;
$datasetitem->definition=$datasetdef->id ;
$datasetitem->itemnumber = $dataitem->itemnumber ;
$datasetitem->value = $dataitem->value ;
if (!$DB->insert_record('question_dataset_items', $datasetitem)) {
print_error('cannotinsertitem', 'question', '',
array($item->itemnumber, $item->value, $datasetdef->name));
}
$DB->insert_record('question_dataset_items', $datasetitem);
}
}
}
@ -959,13 +951,9 @@ class question_calculated_qtype extends default_questiontype {
if ($fromform->itemid[$i]) {
// Reuse any previously used record
$addeditem->id = $fromform->itemid[$i];
if (!$DB->update_record('question_dataset_items', $addeditem)) {
print_error('cannotupdateitem', 'question');
}
$DB->update_record('question_dataset_items', $addeditem);
} else {
if (!$DB->insert_record('question_dataset_items', $addeditem)) {
print_error('cannotinsert', 'question');
}
$DB->insert_record('question_dataset_items', $addeditem);
}
$i++;
@ -1004,9 +992,7 @@ class question_calculated_qtype extends default_questiontype {
$datasetitem->definition = $datasetdef->id ;
$datasetitem->itemnumber = $numberadded;
$datasetitem->value = $this->generate_dataset_item($datasetdef->options);
if (!$DB->update_record('question_dataset_items', $datasetitem)) {
print_error('cannotupdateitem', 'question');
}
$DB->update_record('question_dataset_items', $datasetitem);
}
//if not regenerate do nothing as there is already a record
} else {
@ -1018,9 +1004,7 @@ class question_calculated_qtype extends default_questiontype {
} else {
$datasetitem->value = '';
}
if (!$DB->insert_record('question_dataset_items', $datasetitem)) {
print_error('cannotinsert', 'question');
}
$DB->insert_record('question_dataset_items', $datasetitem);
}
}//for number added
}// datasetsdefs end
@ -1041,10 +1025,7 @@ class question_calculated_qtype extends default_questiontype {
foreach ($datasetdefs as $datasetdef) {
if ($datasetdef->itemcount == $maxnumber) {
$datasetdef->itemcount= $newmaxnumber ;
if (!$DB->update_record('question_dataset_definitions',
$datasetdef)) {
print_error('cannotupdatecount', 'question');
}
$DB->update_record('question_dataset_definitions', $datasetdef);
}
}
}
@ -1311,9 +1292,7 @@ class question_calculated_qtype extends default_questiontype {
continue;
}
if (!$datasetdef->id = $DB->insert_record('question_dataset_definitions', $datasetdef)) {
print_error("cannotcreatedataset", 'question', '', $defid);
}
$datasetdef->id = $DB->insert_record('question_dataset_definitions', $datasetdef);
if (0 != $datasetdef->category) {
// We need to look for already existing
@ -1339,9 +1318,7 @@ class question_calculated_qtype extends default_questiontype {
$questiondataset = new stdClass;
$questiondataset->question = $form->id;
$questiondataset->datasetdefinition = $datasetdef->id;
if (!$DB->insert_record('question_datasets', $questiondataset)) {
print_error('cannotcreaterelation', 'question', '', $name);
}
$DB->insert_record('question_datasets', $questiondataset);
unset($datasetdefinitions[$defid]);
}
@ -1384,19 +1361,15 @@ class question_calculated_qtype extends default_questiontype {
$olddatasetid = $datasetdef->id ;
$olditemcount = $datasetdef->itemcount ;
$datasetdef->itemcount =0;
if (!$datasetdef->id = $DB->insert_record('question_dataset_definitions', $datasetdef)) {
print_error('cannotcreatedataset', 'question', '', $defid);
}
$datasetdef->id = $DB->insert_record('question_dataset_definitions', $datasetdef);
//copy the dataitems
$olditems = $this->get_database_dataset_items($olddatasetid);
if (count($olditems) > 0 ) {
$itemcount = 0;
foreach($olditems as $item ){
$item->definition = $datasetdef->id;
if (!$DB->insert_record('question_dataset_items', $item)) {
print_error('cannotinsertitem', 'question', '', array($item->itemnumber, $item->value, $datasetdef->name));
}
$itemcount++;
$DB->insert_record('question_dataset_items', $item);
$itemcount++;
}
//update item count
$datasetdef->itemcount =$itemcount;
@ -1408,16 +1381,12 @@ class question_calculated_qtype extends default_questiontype {
$questiondataset = new stdClass;
$questiondataset->question = $form->id;
$questiondataset->datasetdefinition = $datasetdef->id;
if (!$DB->insert_record('question_datasets', $questiondataset)) {
print_error('cannotcreaterelation', 'question', '', $name);
}
$DB->insert_record('question_datasets', $questiondataset);
unset($datasetdefinitions[$defid]);
continue;
}// end of datasetdefs from the initial question
// really new one code similar to save_dataset_definitions()
if (!$datasetdef->id = $DB->insert_record('question_dataset_definitions', $datasetdef)) {
print_error('cannotcreatedataset', 'question', '', $defid);
}
$datasetdef->id = $DB->insert_record('question_dataset_definitions', $datasetdef);
if (0 != $datasetdef->category) {
// We need to look for already existing
@ -1444,9 +1413,7 @@ class question_calculated_qtype extends default_questiontype {
$questiondataset = new stdClass;
$questiondataset->question = $form->id;
$questiondataset->datasetdefinition = $datasetdef->id;
if (!$DB->insert_record('question_datasets', $questiondataset)) {
print_error('cannotcreaterelation', 'question', '', $name);
}
$DB->insert_record('question_datasets', $questiondataset);
unset($datasetdefinitions[$defid]);
}

View File

@ -142,16 +142,12 @@ class question_calculatedsimple_qtype extends question_calculated_qtype {
unset($datasetdefinitions[$defid]);
continue;
}
if (!$datasetdef->id = $DB->insert_record('question_dataset_definitions', $datasetdef)) {
print_error("cannotcreatedataset", 'question', '', $defid);
}
$datasetdef->id = $DB->insert_record('question_dataset_definitions', $datasetdef);
$datasetdefs[]= clone($datasetdef);
$questiondataset = new stdClass;
$questiondataset->question = $question->id;
$questiondataset->datasetdefinition = $datasetdef->id;
if (!$DB->insert_record('question_datasets', $questiondataset)) {
print_error('cannotcreaterelation', 'question', '', $name);
}
$DB->insert_record('question_datasets', $questiondataset);
unset($datasetdefinitions[$defid]);
}
// Remove local obsolete datasets as well as relations
@ -177,13 +173,9 @@ class question_calculatedsimple_qtype extends question_calculated_qtype {
if (empty($question->makecopy) && $question->itemid[$i]) {
// Reuse any previously used record
$addeditem->id = $question->itemid[$i];
if (!$DB->update_record('question_dataset_items', $addeditem)) {
print_error('cannotupdateitem', 'question');
}
$DB->update_record('question_dataset_items', $addeditem);
} else {
if (!$DB->insert_record('question_dataset_items', $addeditem)) {
print_error('cannotinsert', 'question');
}
$DB->insert_record('question_dataset_items', $addeditem);
}
$i++;
}
@ -200,11 +192,9 @@ class question_calculatedsimple_qtype extends question_calculated_qtype {
}
// Report any problems.
//convert to calculated
if(!empty($question->makecopy) && !empty($question->convert) ){
if (!$DB->set_field('question', 'qtype', 'calculated', array('id'=> $question->id))) {
print_error('cannotupdateitem', 'question');
}
}
if(!empty($question->makecopy) && !empty($question->convert)) {
$DB->set_field('question', 'qtype', 'calculated', array('id'=> $question->id));
}
if (!empty($result->notice)) {
return $result;
}

View File

@ -33,15 +33,9 @@ class question_essay_qtype extends default_questiontype {
$answer->feedback = $question->feedback;
$answer->fraction = $question->fraction;
if ($update) {
if (!$DB->update_record("question_answers", $answer)) {
$result = new stdClass;
$result->error = "Could not update quiz answer!";
}
$DB->update_record("question_answers", $answer);
} else {
if (!$answer->id = $DB->insert_record("question_answers", $answer)) {
$result = new stdClass;
$result->error = "Could not insert quiz answer!";
}
$answer->id = $DB->insert_record("question_answers", $answer);
}
return $result;
}

View File

@ -41,10 +41,7 @@ class question_match_qtype extends default_questiontype {
if ($subquestion = array_shift($oldsubquestions)) { // Existing answer, so reuse it
$subquestion->questiontext = $questiontext;
$subquestion->answertext = $answertext;
if (!$DB->update_record("question_match_sub", $subquestion)) {
$result->error = "Could not insert match subquestion! (id=$subquestion->id)";
return $result;
}
$DB->update_record("question_match_sub", $subquestion);
} else {
$subquestion = new stdClass;
// Determine a unique random code
@ -55,10 +52,7 @@ class question_match_qtype extends default_questiontype {
$subquestion->question = $question->id;
$subquestion->questiontext = $questiontext;
$subquestion->answertext = $answertext;
if (!$subquestion->id = $DB->insert_record("question_match_sub", $subquestion)) {
$result->error = "Could not insert match subquestion!";
return $result;
}
$subquestion->id = $DB->insert_record("question_match_sub", $subquestion);
}
$subquestions[] = $subquestion->id;
}
@ -77,19 +71,13 @@ class question_match_qtype extends default_questiontype {
if ($options = $DB->get_record("question_match", array("question" => $question->id))) {
$options->subquestions = implode(",",$subquestions);
$options->shuffleanswers = $question->shuffleanswers;
if (!$DB->update_record("question_match", $options)) {
$result->error = "Could not update match options! (id=$options->id)";
return $result;
}
$DB->update_record("question_match", $options);
} else {
unset($options);
$options->question = $question->id;
$options->subquestions = implode(",",$subquestions);
$options->shuffleanswers = $question->shuffleanswers;
if (!$DB->insert_record("question_match", $options)) {
$result->error = "Could not insert match options!";
return $result;
}
$DB->insert_record("question_match", $options);
}
if (!empty($result->notice)) {
@ -700,9 +688,7 @@ class question_match_qtype extends default_questiontype {
$questiontext = restore_decode_content_links_worker($subquestion->questiontext, $restore);
if ($questiontext != $subquestion->questiontext) {
$subquestion->questiontext = $questiontext;
if (!$DB->update_record('question_match_sub', $subquestion)) {
$status = false;
}
$DB->update_record('question_match_sub', $subquestion);
}
// Do some output.
@ -746,10 +732,7 @@ class question_match_qtype extends default_questiontype {
$subquestionchanged = false;
$subquestion->questiontext = question_replace_file_links_in_html($subquestion->questiontext, $fromcourseid, $tocourseid, $url, $destination, $subquestionchanged);
if ($subquestionchanged){//need to update rec in db
if (!$DB->update_record('question_match_sub', $subquestion)) {
print_error('Couldn\'t update \'question_match_sub\' record '.$subquestion->id);
}
$DB->update_record('question_match_sub', $subquestion);
}
}
}

View File

@ -153,16 +153,9 @@ class embedded_cloze_qtype extends default_questiontype {
$multianswer->sequence = implode(',', $sequence);
if ($oldid = $DB->get_field('question_multianswer', 'id', array('question' => $question->id))) {
$multianswer->id = $oldid;
if (!$DB->update_record("question_multianswer", $multianswer)) {
$result->error = "Could not update cloze question options! " .
"(id=$multianswer->id)";
return $result;
}
$DB->update_record("question_multianswer", $multianswer);
} else {
if (!$DB->insert_record("question_multianswer", $multianswer)) {
$result->error = "Could not insert cloze question options!";
return $result;
}
$DB->insert_record("question_multianswer", $multianswer);
}
}
}

View File

@ -69,20 +69,14 @@ class question_multichoice_qtype extends default_questiontype {
$answer->answer = $dataanswer;
$answer->fraction = $question->fraction[$key];
$answer->feedback = $question->feedback[$key];
if (!$DB->update_record("question_answers", $answer)) {
$result->error = "Could not update quiz answer! (id=$answer->id)";
return $result;
}
$DB->update_record("question_answers", $answer);
} else {
unset($answer);
$answer->answer = $dataanswer;
$answer->question = $question->id;
$answer->fraction = $question->fraction[$key];
$answer->feedback = $question->feedback[$key];
if (!$answer->id = $DB->insert_record("question_answers", $answer)) {
$result->error = "Could not insert quiz answer! ";
return $result;
}
$answer->id = $DB->insert_record("question_answers", $answer);
}
$answers[] = $answer->id;
@ -114,15 +108,9 @@ class question_multichoice_qtype extends default_questiontype {
$options->partiallycorrectfeedback = trim($question->partiallycorrectfeedback);
$options->incorrectfeedback = trim($question->incorrectfeedback);
if ($update) {
if (!$DB->update_record("question_multichoice", $options)) {
$result->error = "Could not update quiz multichoice options! (id=$options->id)";
return $result;
}
$DB->update_record("question_multichoice", $options)
} else {
if (!$DB->insert_record("question_multichoice", $options)) {
$result->error = "Could not insert quiz multichoice options!";
return $result;
}
$DB->insert_record("question_multichoice", $options);
}
// delete old answer records
@ -600,9 +588,7 @@ class question_multichoice_qtype extends default_questiontype {
$subquestion->correctfeedback = $correctfeedback;
$subquestion->partiallycorrectfeedback = $partiallycorrectfeedback;
$subquestion->incorrectfeedback = $incorrectfeedback;
if (!$DB->update_record('question_multichoice', $multichoice)) {
$status = false;
}
$DB->update_record('question_multichoice', $multichoice);
}
// Do some output.
@ -684,17 +670,13 @@ class question_multichoice_qtype extends default_questiontype {
$newoptions->partiallycorrectfeedback = question_replace_file_links_in_html($question->options->partiallycorrectfeedback, $fromcourseid, $tocourseid, $url, $destination, $optionschanged);
$newoptions->incorrectfeedback = question_replace_file_links_in_html($question->options->incorrectfeedback, $fromcourseid, $tocourseid, $url, $destination, $optionschanged);
if ($optionschanged){
if (!$DB->update_record('question_multichoice', $newoptions)) {
print_error('Couldn\'t update \'question_multichoice\' record '.$newoptions->id);
}
$DB->update_record('question_multichoice', $newoptions);
}
$answerchanged = false;
foreach ($question->options->answers as $answer) {
$answer->answer = question_replace_file_links_in_html($answer->answer, $fromcourseid, $tocourseid, $url, $destination, $answerchanged);
if ($answerchanged){
if (!$DB->update_record('question_answers', $answer)){
print_error('Couldn\'t update \'question_answers\' record '.$answer->id);
}
$DB->update_record('question_answers', $answer);
}
}
}

View File

@ -335,9 +335,7 @@ class default_questiontype {
/// Question already exists, update.
$question->modifiedby = $USER->id;
$question->timemodified = time();
if (!$DB->update_record('question', $question)) {
print_error('cannotupdatequestion', 'question');
}
$DB->update_record('question', $question);
} else {
/// New question.
@ -347,9 +345,7 @@ class default_questiontype {
$question->modifiedby = $USER->id;
$question->timecreated = time();
$question->timemodified = time();
if (!$question->id = $DB->insert_record('question', $question)) {
print_error('cannotinsertquestion', 'question');
}
$question->id = $DB->insert_record('question', $question);
}
// Now to save all the answers and type-specific options
@ -376,9 +372,7 @@ class default_questiontype {
}
// Give the question a unique version stamp determined by question_hash()
if (!$DB->set_field('question', 'version', question_hash($question), array('id' => $question->id))) {
print_error('cannotupdatequestionver', 'question');
}
$DB->set_field('question', 'version', question_hash($question), array('id' => $question->id));
return $question;
}
@ -1591,9 +1585,7 @@ class default_questiontype {
/// If anything has changed, update it in the database.
if ($updateqrec){
if (!$DB->update_record('question', $question)){
print_error('cannotupdatequestion', 'question');
}
$DB->update_record('question', $question);
}
@ -1610,9 +1602,7 @@ class default_questiontype {
$answer->feedback = question_replace_file_links_in_html($answer->feedback, $fromcourseid, $tocourseid, $url, $destination, $answerchanged);
/// If anything has changed, update it in the database.
if ($answerchanged){
if (!$DB->update_record('question_answers', $answer)){
print_error('cannotupdatequestion', 'question');
}
$DB->update_record('question_answers', $answer);
}
}
}

View File

@ -54,15 +54,9 @@ class question_randomsamatch_qtype extends question_match_qtype {
if ($existing = $DB->get_record("question_randomsamatch", array("question" => $options->question))) {
$options->id = $existing->id;
if (!$DB->update_record("question_randomsamatch", $options)) {
$result->error = "Could not update quiz randomsamatch options!";
return $result;
}
$DB->update_record("question_randomsamatch", $options);
} else {
if (!$DB->insert_record("question_randomsamatch", $options)) {
$result->error = "Could not insert quiz randomsamatch options!";
return $result;
}
$DB->insert_record("question_randomsamatch", $options);
}
return true;
}

View File

@ -58,20 +58,14 @@ class question_shortanswer_qtype extends default_questiontype {
$answer->answer = trim($dataanswer);
$answer->fraction = $question->fraction[$key];
$answer->feedback = $question->feedback[$key];
if (!$DB->update_record("question_answers", $answer)) {
$result->error = "Could not update quiz answer! (id=$answer->id)";
return $result;
}
$DB->update_record("question_answers", $answer);
} else { // This is a completely new answer
$answer = new stdClass;
$answer->answer = trim($dataanswer);
$answer->question = $question->id;
$answer->fraction = $question->fraction[$key];
$answer->feedback = $question->feedback[$key];
if (!$answer->id = $DB->insert_record("question_answers", $answer)) {
$result->error = "Could not insert quiz answer!";
return $result;
}
$answer->id = $DB->insert_record("question_answers", $answer);
}
$answers[] = $answer->id;
if ($question->fraction[$key] > $maxfraction) {

View File

@ -29,20 +29,14 @@ class question_truefalse_qtype extends default_questiontype {
$true->answer = get_string("true", "quiz");
$true->fraction = $question->correctanswer;
$true->feedback = $question->feedbacktrue;
if (!$DB->update_record("question_answers", $true)) {
$result->error = "Could not update quiz answer \"true\")!";
return $result;
}
$DB->update_record("question_answers", $true);
} else {
unset($true);
$true->answer = get_string("true", "quiz");
$true->question = $question->id;
$true->fraction = $question->correctanswer;
$true->feedback = $question->feedbacktrue;
if (!$true->id = $DB->insert_record("question_answers", $true)) {
$result->error = "Could not insert quiz answer \"true\")!";
return $result;
}
$true->id = $DB->insert_record("question_answers", $true);
}
// Save answer 'False'
@ -50,20 +44,14 @@ class question_truefalse_qtype extends default_questiontype {
$false->answer = get_string("false", "quiz");
$false->fraction = 1 - (int)$question->correctanswer;
$false->feedback = $question->feedbackfalse;
if (!$DB->update_record("question_answers", $false)) {
$result->error = "Could not insert quiz answer \"false\")!";
return $result;
}
$DB->update_record("question_answers", $false);
} else {
unset($false);
$false->answer = get_string("false", "quiz");
$false->question = $question->id;
$false->fraction = 1 - (int)$question->correctanswer;
$false->feedback = $question->feedbackfalse;
if (!$false->id = $DB->insert_record("question_answers", $false)) {
$result->error = "Could not insert quiz answer \"false\")!";
return $result;
}
$false->id = $DB->insert_record("question_answers", $false);
}
// delete any leftover old answer records (there couldn't really be any, but who knows)
@ -79,19 +67,13 @@ class question_truefalse_qtype extends default_questiontype {
// But we'll do it anyway, just for robustness
$options->trueanswer = $true->id;
$options->falseanswer = $false->id;
if (!$DB->update_record("question_truefalse", $options)) {
$result->error = "Could not update quiz truefalse options! (id=$options->id)";
return $result;
}
$DB->update_record("question_truefalse", $options);
} else {
unset($options);
$options->question = $question->id;
$options->trueanswer = $true->id;
$options->falseanswer = $false->id;
if (!$DB->insert_record("question_truefalse", $options)) {
$result->error = "Could not insert quiz truefalse options!";
return $result;
}
$DB->insert_record("question_truefalse", $options);
}
return true;
}