Skip to content

Commit

Permalink
MDL-18293 removed obsoleted checking of return values from insert and…
Browse files Browse the repository at this point in the history
… update_record + unused strings cleanup
  • Loading branch information
skodak committed Jun 13, 2009
1 parent 9d74933 commit a8c31db
Show file tree
Hide file tree
Showing 21 changed files with 31 additions and 95 deletions.
7 changes: 1 addition & 6 deletions auth/mnet/auth.php
Expand Up @@ -373,12 +373,7 @@ function confirm_mnet_session($token, $remotewwwroot) {

$localuser->mnethostid = $remotepeer->id;

$bool = $DB->update_record('user', $localuser);
if (!$bool) {
// TODO: Jonathan to clean up mess
// Actually, this should never happen (modulo race conditions) - ML
print_error("cannotupdateuser");
}
$DB->update_record('user', $localuser);

// set up the session
$mnet_session = $DB->get_record('mnet_session',
Expand Down
2 changes: 0 additions & 2 deletions lang/en_utf8/error.php
Expand Up @@ -124,13 +124,11 @@
$string['cannotunzipfile'] = 'Cannot unzip file';
$string['cannotupdaterecord'] = 'Could not update record ID $a';
$string['cannotupdatemod'] = 'Could not update $a';
$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['cannotupdateprofile'] = 'Error updating user record';
$string['cannotupdaterss'] = 'Cannot update RSS';
$string['cannotupdatesecret'] = 'Error resetting user secret string';
$string['cannotupdatesubcourse'] = 'Could not update a child course!';
$string['cannotuploadfile'] = 'Error processing upload file';
$string['cannotunassignrolefrom'] = 'Cannot unassign this user from role id: $a';
Expand Down
1 change: 0 additions & 1 deletion lang/en_utf8/forum.php
Expand Up @@ -44,7 +44,6 @@
$string['cannotsubscribe'] = 'Sorry, but you must be a group member to subscribe.';
$string['cannotsplit'] = 'Discussions from this forum cannot be split';
$string['cannotunsubscribe'] = 'Could not unsubscribe you from that forum';
$string['cannotupdatecoursemoudle'] = 'Could not update course module with section id';
$string['cannotupdatepost'] = 'You can not update this post';
$string['cannotremovesubscriber'] = 'Could not remove subscriber with id $a from this forum!';
$string['cannotreply'] = 'You cannot reply to this post';
Expand Down
1 change: 0 additions & 1 deletion lang/en_utf8/hotpot.php
Expand Up @@ -16,7 +16,6 @@
$string['cannotaddstrrecord'] = 'Could not add string record';
$string['cannotfindmethod'] = 'Template block expand method not found: ($a)';
$stirng['cannotinsertattempt'] = 'Could not insert attempt record: $a';
$string['cannotupdateattempt'] = 'Could not update attempt record: $a';
$string['checks'] = 'Checks';
$string['clickreporting'] = 'Enable click reporting';
$string['clues'] = 'Clues';
Expand Down
1 change: 0 additions & 1 deletion lang/en_utf8/lesson.php
Expand Up @@ -35,7 +35,6 @@
$string['cannotfindanswer'] = 'Cannot find answer';
$string['cannotfindattempt'] = 'Error: could not find attempt';
$string['cannotfindessay'] = 'Error: could not find essay';
$string['cannotupdateessayscore'] = 'Could not update essay score';
$string['cannotfindfirstpage'] = 'Could not find first page';
$string['cannotfindfirstgrade'] = 'Error: could not find grades';
$string['cannotfindgrade'] = 'Could not find Grade Records';
Expand Down
1 change: 0 additions & 1 deletion lang/en_utf8/resource.php
Expand Up @@ -9,7 +9,6 @@
$string['back'] = 'Back';
$string['blockdeletingfile'] = 'Block deleting of referenced files';
$string['browserepository'] = 'Browse repository';
$string['cannotupdate'] = 'Cannot update resource.';
$string['choose'] = 'Choose';
$string['chooseafile'] = 'Choose or upload a file';
$string['chooseparameter'] = 'Choose parameter';
Expand Down
8 changes: 2 additions & 6 deletions login/forgot_password.php
Expand Up @@ -62,9 +62,7 @@

// Clear secret so that it can not be used again
$user->secret = '';
if (!$DB->set_field('user', 'secret', $user->secret, array('id'=>$user->id))) {
print_error('cannotupdatesecret');
}
$DB->set_field('user', 'secret', $user->secret, array('id'=>$user->id));

reset_login_count();

Expand Down Expand Up @@ -118,9 +116,7 @@

// set 'secret' string
$user->secret = random_string(15);
if (!$DB->set_field('user', 'secret', $user->secret, array('id'=>$user->id))) {
print_error('cannotupdatesecret');
}
$DB->set_field('user', 'secret', $user->secret, array('id'=>$user->id));

if (!send_password_change_confirmation_email($user)) {
print_error('cannotmailconfirm');
Expand Down
9 changes: 3 additions & 6 deletions mod/chat/lib.php
Expand Up @@ -605,9 +605,8 @@ function chat_login_user($chatid, $version, $groupid, $course) {
if (($chatuser->course != $course->id) or ($chatuser->userid != $USER->id)) {
return false;
}
if (!$DB->update_record('chat_users', $chatuser)) {
return false;
}
$DB->update_record('chat_users', $chatuser);

} else {
$chatuser = new object();
$chatuser->chatid = $chatid;
Expand All @@ -631,9 +630,7 @@ function chat_login_user($chatid, $version, $groupid, $course) {
}


if (!$DB->insert_record('chat_users', $chatuser)) {
return false;
}
$DB->insert_record('chat_users', $chatuser);

if ($version == 'sockets') {
// do not send 'enter' message, chatd will do it
Expand Down
4 changes: 1 addition & 3 deletions mod/data/import.php
Expand Up @@ -162,9 +162,7 @@
}
$oldcontent = $DB->get_record('data_content', array('fieldid'=>$field->id, 'recordid'=>$recordid));
$content->id = $oldcontent->id;
if (! $DB->update_record('data_content', $content)) {
print_error('cannotupdaterecord', '', '', $recordid);
}
$DB->update_record('data_content', $content);
}
$recordsadded++;
print get_string('added', 'moodle', $recordsadded) . ". " . get_string('entry', 'data') . " (ID $recordid)<br />\n";
Expand Down
4 changes: 1 addition & 3 deletions mod/forum/lib.php
Expand Up @@ -7672,9 +7672,7 @@ function forum_convert_to_roles($forum, $forummodid, $teacherroles=array(),
if (!$sectionid = add_mod_to_section($mod)) {
print_error('cannotaddteacherforumto', 'forum');
} else {
if (!$DB->set_field('course_modules', 'section', $sectionid, array('id' => $cmid))) {
print_error('cannotupdatecoursemoudle', 'forum');
}
$DB->set_field('course_modules', 'section', $sectionid, array('id' => $cmid));
}
}

Expand Down
8 changes: 2 additions & 6 deletions mod/glossary/import.php
Expand Up @@ -163,13 +163,9 @@
//We get the section's visible field status
$visible = $DB->get_field("course_sections", "visible", array("id"=>$sectionid));

if (! $DB->set_field("course_modules", "visible", $visible, array("id"=>$mod->coursemodule))) {
print_error('cannotupdatemod', '', '', $mod->coursemodule);
}
$DB->set_field("course_modules", "visible", $visible, array("id"=>$mod->coursemodule));
$DB->set_field("course_modules", "section", $sectionid, array("id"=>$mod->coursemodule));

if (! $DB->set_field("course_modules", "section", $sectionid, array("id"=>$mod->coursemodule))) {
print_error('cannotupdatemod', '', '', $mod->coursemodule);
}
add_to_log($course->id, "course", "add mod",
"../mod/$mod->modulename/view.php?id=$mod->coursemodule",
"$mod->modulename $mod->instance");
Expand Down
4 changes: 1 addition & 3 deletions mod/hotpot/attempt.php
Expand Up @@ -111,9 +111,7 @@
$attempt->details = $attempt->details;

// update the attempt record
if (! $DB->update_record("hotpot_attempts", $attempt)) {
print_error('cannotupdateattempt', 'hotpot', $next_url, $DB->get_last_error());
}
$DB->update_record("hotpot_attempts", $attempt);

// update grades for this user
hotpot_update_grades($hotpot, $attempt->userid);
Expand Down
4 changes: 1 addition & 3 deletions mod/hotpot/index.php
Expand Up @@ -157,9 +157,7 @@
$attempt->details = $DB->get_field('hotpot_details', 'details', array('attempt'=>$attempt->id));
if ($attempt->details) {
hotpot_add_attempt_details($attempt);
if (! $DB->update_record('hotpot_attempts', $attempt)) {
print_error('cannotupdateattempt', 'hotpot', $next_url, $DB->get_last_error());
}
$DB->update_record('hotpot_attempts', $attempt);
}
$attemptcount++;
}
Expand Down
5 changes: 2 additions & 3 deletions mod/hotpot/lib.php
Expand Up @@ -939,9 +939,8 @@ function hotpot_update_chain(&$hotpot) {
}

// update $thishotpot, if required
if ($require_update && !$DB->update_record("hotpot", $thishotpot)) {
print_error('cannotupdatemod', '',
'view.php?id='.$hotpot->course, $hotpot->modulename);
if ($require_update) {
$DB->update_record("hotpot", $thishotpot);
}
}
} // end foreach $ids
Expand Down
4 changes: 1 addition & 3 deletions mod/lesson/action/continue.php
Expand Up @@ -40,9 +40,7 @@
}

$timer->lessontime = time();
if (!$DB->update_record("lesson_timer", $timer)) {
print_error("Error: could not update lesson_timer table");
}
$DB->update_record("lesson_timer", $timer);
}

// record answer (if necessary) and show response (if none say if answer is correct or not)
Expand Down
17 changes: 6 additions & 11 deletions mod/lesson/essay.php
Expand Up @@ -112,9 +112,7 @@

$attempt->useranswer = serialize($essayinfo);

if (!$DB->update_record('lesson_attempts', $attempt)) {
print_error('cannotupdateessayscore', 'lesson');
}
$DB->update_record('lesson_attempts', $attempt);

// Get grade information
$grade = current($grades);
Expand All @@ -123,14 +121,11 @@
// Set and update
$updategrade->id = $grade->id;
$updategrade->grade = $gradeinfo->grade;
if($DB->update_record('lesson_grades', $updategrade)) {
// Log it
add_to_log($course->id, 'lesson', 'update grade', "essay.php?id=$cm->id", $lesson->name, $cm->id);

lesson_set_message(get_string('changessaved'), 'notifysuccess');
} else {
lesson_set_message(get_string('updatefailed', 'lesson'));
}
$DB->update_record('lesson_grades', $updategrade);
// Log it
add_to_log($course->id, 'lesson', 'update grade', "essay.php?id=$cm->id", $lesson->name, $cm->id);

lesson_set_message(get_string('changessaved'), 'notifysuccess');

// update central gradebook
lesson_update_grades($lesson, $grade->userid);
Expand Down
20 changes: 4 additions & 16 deletions mod/lesson/locallib.php
Expand Up @@ -875,15 +875,9 @@ function lesson_save_question_options($question) {
$options->choose = $question->choose;
if ($existing = $DB->get_record("quiz_randomsamatch", array("question" => $options->question))) {
$options->id = $existing->id;
if (!$DB->update_record("quiz_randomsamatch", $options)) {
$result->error = "Could not update quiz randomsamatch options!";
return $result;
}
$DB->update_record("quiz_randomsamatch", $options);
} else {
if (!$DB->insert_record("quiz_randomsamatch", $options)) {
$result->error = "Could not insert quiz randomsamatch options!";
return $result;
}
$DB->insert_record("quiz_randomsamatch", $options);
}
break;

Expand All @@ -907,10 +901,7 @@ function lesson_save_question_options($question) {
$result->error = "Could not update multianswer alternatives! (id=$multianswer->id)";
return $result;
}
if (!$DB->update_record("quiz_multianswers", $multianswer)) {
$result->error = "Could not update quiz multianswer! (id=$multianswer->id)";
return $result;
}
$DB->update_record("quiz_multianswers", $multianswer);
} else { // This is a completely new answer
$multianswer = new stdClass;
$multianswer->question = $question->id;
Expand All @@ -925,10 +916,7 @@ function lesson_save_question_options($question) {
$result->error = "Could not insert multianswer alternatives! (questionid=$question->id)";
return $result;
}
if (!$DB->insert_record("quiz_multianswers", $multianswer)) {
$result->error = "Could not insert quiz multianswer!";
return $result;
}
$DB->insert_record("quiz_multianswers", $multianswer);
}
}
break;
Expand Down
10 changes: 2 additions & 8 deletions mod/quiz/locallib.php
Expand Up @@ -614,19 +614,13 @@ function quiz_save_best_grade($quiz, $userid = null, $attempts = array()) {
if ($grade = $DB->get_record('quiz_grades', array('quiz' => $quiz->id, 'userid' => $userid))) {
$grade->grade = $bestgrade;
$grade->timemodified = time();
if (!$DB->update_record('quiz_grades', $grade)) {
notify('Could not update best grade');
return false;
}
$DB->update_record('quiz_grades', $grade);
} else {
$grade->quiz = $quiz->id;
$grade->userid = $userid;
$grade->grade = $bestgrade;
$grade->timemodified = time();
if (!$DB->insert_record('quiz_grades', $grade)) {
notify('Could not insert new best grade');
return false;
}
$DB->insert_record('quiz_grades', $grade);
}

quiz_update_grades($quiz, $userid);
Expand Down
8 changes: 2 additions & 6 deletions mod/quiz/processattempt.php
Expand Up @@ -156,9 +156,7 @@
/// save the attempt and redirect to the next page.
if (!$finishattempt) {
$attempt->timemodified = $timenow;
if (!$DB->update_record('quiz_attempts', $attempt)) {
quiz_error($attemptobj->get_quiz(), 'saveattemptfailed');
}
$DB->update_record('quiz_attempts', $attempt);

redirect($nexturl);
}
Expand Down Expand Up @@ -199,9 +197,7 @@
/// Update the quiz attempt record.
$attempt->timemodified = $timenow;
$attempt->timefinish = $timenow;
if (!$DB->update_record('quiz_attempts', $attempt)) {
quiz_error($attemptobj->get_quiz(), 'saveattemptfailed');
}
$DB->update_record('quiz_attempts', $attempt);

if (!$attempt->preview) {
/// Record this user's best grade (if this is not a preview).
Expand Down
4 changes: 1 addition & 3 deletions mod/resource/lib.php
Expand Up @@ -733,9 +733,7 @@ function resource_renamefiles($course, $wdir, $oldname, $name) {
$updates = true;
$status .= "<li><a href=\"$CFG->wwwroot/mod/resource/view.php?id=$resource->cmid\" target=\"_blank\">$resource->name</a>: $resource->reference ==> $r->reference</li>";
if (!empty($CFG->resource_autofilerename)) {
if (!$DB->update_record('resource', $r)) {
print_error('cannotupdate', 'resource');
}
$DB->update_record('resource', $r);
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions mod/scorm/lib.php
Expand Up @@ -192,9 +192,7 @@ function scorm_update_instance($scorm, $mform=null) {
}
$scorm->grademethod = ($scorm->whatgrade * 10) + $scorm->grademethod;

if (!$DB->update_record('scorm', $scorm)) {
return false;
}
$DB->update_record('scorm', $scorm);

$scorm = $DB->get_record('scorm', array('id'=>$scorm->id));

Expand Down

0 comments on commit a8c31db

Please sign in to comment.