From a8c31db2a32436c92c120bb292ec919a467e36cf Mon Sep 17 00:00:00 2001 From: skodak Date: Sat, 13 Jun 2009 17:47:18 +0000 Subject: [PATCH] MDL-18293 removed obsoleted checking of return values from insert and update_record + unused strings cleanup --- auth/mnet/auth.php | 7 +------ lang/en_utf8/error.php | 2 -- lang/en_utf8/forum.php | 1 - lang/en_utf8/hotpot.php | 1 - lang/en_utf8/lesson.php | 1 - lang/en_utf8/resource.php | 1 - login/forgot_password.php | 8 ++------ mod/chat/lib.php | 9 +++------ mod/data/import.php | 4 +--- mod/forum/lib.php | 4 +--- mod/glossary/import.php | 8 ++------ mod/hotpot/attempt.php | 4 +--- mod/hotpot/index.php | 4 +--- mod/hotpot/lib.php | 5 ++--- mod/lesson/action/continue.php | 4 +--- mod/lesson/essay.php | 17 ++++++----------- mod/lesson/locallib.php | 20 ++++---------------- mod/quiz/locallib.php | 10 ++-------- mod/quiz/processattempt.php | 8 ++------ mod/resource/lib.php | 4 +--- mod/scorm/lib.php | 4 +--- 21 files changed, 31 insertions(+), 95 deletions(-) diff --git a/auth/mnet/auth.php b/auth/mnet/auth.php index da5a9492e1..fb3e924f7f 100644 --- a/auth/mnet/auth.php +++ b/auth/mnet/auth.php @@ -373,12 +373,7 @@ class auth_plugin_mnet extends auth_plugin_base { $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', diff --git a/lang/en_utf8/error.php b/lang/en_utf8/error.php index af0f09d9ad..9582662c15 100644 --- a/lang/en_utf8/error.php +++ b/lang/en_utf8/error.php @@ -124,13 +124,11 @@ $string['cannotshowhidecoursesincategory'] = 'Cannot show/hide the courses in ca $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'; diff --git a/lang/en_utf8/forum.php b/lang/en_utf8/forum.php index 93869e4ec5..87848f4f77 100644 --- a/lang/en_utf8/forum.php +++ b/lang/en_utf8/forum.php @@ -44,7 +44,6 @@ $string['cannoteditposts'] = 'You can\'t edit other people\'s posts!'; $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'; diff --git a/lang/en_utf8/hotpot.php b/lang/en_utf8/hotpot.php index 78f9b073d9..5b0bb345ca 100644 --- a/lang/en_utf8/hotpot.php +++ b/lang/en_utf8/hotpot.php @@ -16,7 +16,6 @@ $string['cannotaddresprecord'] = 'Could not add response record'; $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'; diff --git a/lang/en_utf8/lesson.php b/lang/en_utf8/lesson.php index ed9355fdf5..0d84488a58 100644 --- a/lang/en_utf8/lesson.php +++ b/lang/en_utf8/lesson.php @@ -35,7 +35,6 @@ $string['branchtable'] = 'Branch Table'; $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'; diff --git a/lang/en_utf8/resource.php b/lang/en_utf8/resource.php index 04ec1c0e31..31feddfcda 100644 --- a/lang/en_utf8/resource.php +++ b/lang/en_utf8/resource.php @@ -9,7 +9,6 @@ $string['autofilerename'] = 'Update link if file renamed'; $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'; diff --git a/login/forgot_password.php b/login/forgot_password.php index 1598ca6d89..36441b2559 100644 --- a/login/forgot_password.php +++ b/login/forgot_password.php @@ -62,9 +62,7 @@ if ($p_secret !== false) { // 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(); @@ -118,9 +116,7 @@ if ($mform->is_cancelled()) { // 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'); diff --git a/mod/chat/lib.php b/mod/chat/lib.php index 883ab4b87c..530a92a059 100644 --- a/mod/chat/lib.php +++ b/mod/chat/lib.php @@ -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; @@ -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 diff --git a/mod/data/import.php b/mod/data/import.php index 5ebe3408d0..b665814ef3 100755 --- a/mod/data/import.php +++ b/mod/data/import.php @@ -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)
\n"; diff --git a/mod/forum/lib.php b/mod/forum/lib.php index ae707a68a3..990bc3ddf7 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -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)); } } diff --git a/mod/glossary/import.php b/mod/glossary/import.php index e47d60bf4c..89a22126ec 100644 --- a/mod/glossary/import.php +++ b/mod/glossary/import.php @@ -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"); diff --git a/mod/hotpot/attempt.php b/mod/hotpot/attempt.php index ab189ec293..8fab8e9678 100644 --- a/mod/hotpot/attempt.php +++ b/mod/hotpot/attempt.php @@ -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); diff --git a/mod/hotpot/index.php b/mod/hotpot/index.php index d5dfce79bd..8f7d04aebf 100644 --- a/mod/hotpot/index.php +++ b/mod/hotpot/index.php @@ -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++; } diff --git a/mod/hotpot/lib.php b/mod/hotpot/lib.php index a459a10d4c..1b37f5d210 100644 --- a/mod/hotpot/lib.php +++ b/mod/hotpot/lib.php @@ -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 diff --git a/mod/lesson/action/continue.php b/mod/lesson/action/continue.php index ee0b10e836..4b5bf4b190 100644 --- a/mod/lesson/action/continue.php +++ b/mod/lesson/action/continue.php @@ -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) diff --git a/mod/lesson/essay.php b/mod/lesson/essay.php index 0f4fcb7dc3..aa7f08c2b8 100644 --- a/mod/lesson/essay.php +++ b/mod/lesson/essay.php @@ -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); @@ -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); diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index cedadc60fe..d263d29510 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -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; @@ -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; @@ -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; diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php index 8ec712059b..b5510be11c 100644 --- a/mod/quiz/locallib.php +++ b/mod/quiz/locallib.php @@ -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); diff --git a/mod/quiz/processattempt.php b/mod/quiz/processattempt.php index e1a1d1e961..afd5df4028 100644 --- a/mod/quiz/processattempt.php +++ b/mod/quiz/processattempt.php @@ -156,9 +156,7 @@ if (!$success) { /// 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); } @@ -199,9 +197,7 @@ add_to_log($attemptobj->get_courseid(), 'quiz', 'close attempt', /// 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). diff --git a/mod/resource/lib.php b/mod/resource/lib.php index 7f35f1b84c..1feece9293 100644 --- a/mod/resource/lib.php +++ b/mod/resource/lib.php @@ -733,9 +733,7 @@ function resource_renamefiles($course, $wdir, $oldname, $name) { $updates = true; $status .= "
  • wwwroot/mod/resource/view.php?id=$resource->cmid\" target=\"_blank\">$resource->name: $resource->reference ==> $r->reference
  • "; if (!empty($CFG->resource_autofilerename)) { - if (!$DB->update_record('resource', $r)) { - print_error('cannotupdate', 'resource'); - } + $DB->update_record('resource', $r); } } } diff --git a/mod/scorm/lib.php b/mod/scorm/lib.php index 4d952c8193..a894d71932 100755 --- a/mod/scorm/lib.php +++ b/mod/scorm/lib.php @@ -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)); -- 2.39.5