Skip to content

Commit

Permalink
MDL-14679 fixed remaining old style set_field()s
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Sep 3, 2010
1 parent dd88de0 commit f685e83
Show file tree
Hide file tree
Showing 26 changed files with 82 additions and 167 deletions.
38 changes: 16 additions & 22 deletions admin/xmldb/actions/test/test.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1059,19 +1059,16 @@ function invoke() {
$rec->name = 'updatelobs';
/// Calculate its length
$textlen = $textlib->strlen($fulltext);
if ($DB->set_field('newnameforthetable', 'intro', $rec->intro, array('name'=>$rec->name))) {
if ($new = $DB->get_record('newnameforthetable', array('id'=>$rec->id))) {
$newtextlen = $textlib->strlen($new->intro);
if ($fulltext === $new->intro) {
$test->sql = array($newtextlen . ' cc. (text) sent and received ok');
$test->status = true;
} else {
$test->error = $DB->get_last_error();
$test->sql = array($newtextlen . ' cc. (text) transfer failed. Data changed!');
$test->status = false;
}
$DB->set_field('newnameforthetable', 'intro', $rec->intro, array('name'=>$rec->name));
if ($new = $DB->get_record('newnameforthetable', array('id'=>$rec->id))) {
$newtextlen = $textlib->strlen($new->intro);
if ($fulltext === $new->intro) {
$test->sql = array($newtextlen . ' cc. (text) sent and received ok');
$test->status = true;
} else {
$test->error = $DB->get_last_error();
$test->sql = array($newtextlen . ' cc. (text) transfer failed. Data changed!');
$test->status = false;
}
} else {
$test->error = $DB->get_last_error();
Expand All @@ -1089,19 +1086,16 @@ function invoke() {
$rec->name = 'updatelobs';
/// Calculate its length
$textlen = strlen($rec->avatar);
if ($DB->set_field('newnameforthetable', 'avatar', $rec->avatar, array('name'=>$rec->name))) {
if ($new = $DB->get_record('newnameforthetable', array('id'=>$rec->id))) {
$newtextlen = strlen($new->avatar);
if ($rec->avatar === $new->avatar) {
$test->sql = array($newtextlen . ' bytes (binary) sent and received ok');
$test->status = true;
} else {
$test->error = $DB->get_last_error();
$test->sql = array($newtextlen . ' bytes (binary) transfer failed. Data changed!');
$test->status = false;
}
$DB->set_field('newnameforthetable', 'avatar', $rec->avatar, array('name'=>$rec->name));
if ($new = $DB->get_record('newnameforthetable', array('id'=>$rec->id))) {
$newtextlen = strlen($new->avatar);
if ($rec->avatar === $new->avatar) {
$test->sql = array($newtextlen . ' bytes (binary) sent and received ok');
$test->status = true;
} else {
$test->error = $DB->get_last_error();
$test->sql = array($newtextlen . ' bytes (binary) transfer failed. Data changed!');
$test->status = false;
}
} else {
$test->error = $DB->get_last_error();
Expand Down
8 changes: 2 additions & 6 deletions auth/email/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,8 @@ function user_confirm($username, $confirmsecret) {
return AUTH_CONFIRM_ERROR;

} else if ($user->secret == $confirmsecret) { // They have provided the secret key to get in
if (!$DB->set_field("user", "confirmed", 1, array("id"=>$user->id))) {
return AUTH_CONFIRM_FAIL;
}
if (!$DB->set_field("user", "firstaccess", time(), array("id"=>$user->id))) {
return AUTH_CONFIRM_FAIL;
}
$DB->set_field("user", "confirmed", 1, array("id"=>$user->id));
$DB->set_field("user", "firstaccess", time(), array("id"=>$user->id));
return AUTH_CONFIRM_OK;
}
} else {
Expand Down
8 changes: 2 additions & 6 deletions auth/ldap/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,12 +549,8 @@ function user_confirm($username, $confirmsecret) {
if (!$this->user_activate($username)) {
return AUTH_CONFIRM_FAIL;
}
if (!$DB->set_field('user', 'confirmed', 1, array('id'=>$user->id))) {
return AUTH_CONFIRM_FAIL;
}
if (!$DB->set_field('user', 'firstaccess', time(), array('id'=>$user->id))) {
return AUTH_CONFIRM_FAIL;
}
$DB->set_field('user', 'confirmed', 1, array('id'=>$user->id));
$DB->set_field('user', 'firstaccess', time(), array('id'=>$user->id));
return AUTH_CONFIRM_OK;
}
} else {
Expand Down
8 changes: 2 additions & 6 deletions auth/manual/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,8 @@ function user_confirm($username, $confirmsecret = null) {
if ($user->confirmed) {
return AUTH_CONFIRM_ALREADY;
} else {
if (!$DB->set_field("user", "confirmed", 1, array("id"=>$user->id))) {
return AUTH_CONFIRM_FAIL;
}
if (!$DB->set_field("user", "firstaccess", time(), array("id"=>$user->id))) {
return AUTH_CONFIRM_FAIL;
}
$DB->set_field("user", "confirmed", 1, array("id"=>$user->id));
$DB->set_field("user", "firstaccess", time(), array("id"=>$user->id));
return AUTH_CONFIRM_OK;
}
} else {
Expand Down
4 changes: 1 addition & 3 deletions course/format/topics/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@

if (($marker >=0) && has_capability('moodle/course:setcurrentsection', $context) && confirm_sesskey()) {
$course->marker = $marker;
if (! $DB->set_field("course", "marker", $marker, array("id"=>$course->id))) {
print_error("cannotmarktopic");
}
$DB->set_field("course", "marker", $marker, array("id"=>$course->id));
}

$streditsummary = get_string('editsummary');
Expand Down
26 changes: 8 additions & 18 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1735,9 +1735,7 @@ function rebuild_course_cache($courseid=0, $clearonly=false) {
if ($rs = $DB->get_recordset("course", $select,'','id,fullname')) {
foreach ($rs as $course) {
$modinfo = serialize(get_array_of_activities($course->id));
if (!$DB->set_field("course", "modinfo", $modinfo, array("id"=>$course->id))) {
echo $OUTPUT->notification("Could not cache module information for course '" . format_string($course->fullname) . "'!");
}
$DB->set_field("course", "modinfo", $modinfo, array("id"=>$course->id));
// update cached global COURSE too ;-)
if ($course->id == $COURSE->id) {
$COURSE->modinfo = $modinfo;
Expand Down Expand Up @@ -2547,11 +2545,8 @@ function add_mod_to_section($mod, $beforemod=NULL) {
$newsequence = "$section->sequence,$mod->coursemodule";
}

if ($DB->set_field("course_sections", "sequence", $newsequence, array("id"=>$section->id))) {
return $section->id; // Return course_sections ID that was used.
} else {
return 0;
}
$DB->set_field("course_sections", "sequence", $newsequence, array("id"=>$section->id));
return $section->id; // Return course_sections ID that was used.

} else { // Insert a new record
$section->course = $mod->course;
Expand Down Expand Up @@ -2604,7 +2599,7 @@ function set_coursemodule_visible($id, $visible, $prevstateoverrides=false) {
if ($grade_item !== false) {
$grade_item->set_hidden(!$visible);
}

if ($prevstateoverrides) {
if ($visible == '0') {
// Remember the current visible state so we can toggle this back.
Expand Down Expand Up @@ -2703,12 +2698,9 @@ function move_section($course, $section, $move) {
return false;
}

if (!$DB->set_field("course_sections", "section", $sectiondest, array("id"=>$sectionrecord->id))) {
return false;
}
if (!$DB->set_field("course_sections", "section", $section, array("id"=>$sectiondestrecord->id))) {
return false;
}
$DB->set_field("course_sections", "section", $sectiondest, array("id"=>$sectionrecord->id));
$DB->set_field("course_sections", "section", $section, array("id"=>$sectiondestrecord->id));

// if the focus is on the section that is being moved, then move the focus along
if (isset($USER->display[$course->id]) and ($USER->display[$course->id] == $section)) {
course_set_display($course->id, $sectiondest);
Expand All @@ -2720,9 +2712,7 @@ function move_section($course, $section, $move) {
$n = 0;
foreach ($sections as $section) {
if ($section->section != $n) {
if (!$DB->set_field('course_sections', 'section', $n, array('id'=>$section->id))) {
return false;
}
$DB->set_field('course_sections', 'section', $n, array('id'=>$section->id));
}
$n++;
}
Expand Down
4 changes: 1 addition & 3 deletions course/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@
$visible = 1;
}
if ($course) {
if (! $DB->set_field("course", "visible", $visible, array("id"=>$course->id))) {
echo $OUTPUT->notification("Could not update that course!");
}
$DB->set_field("course", "visible", $visible, array("id"=>$course->id));
}
}
}
Expand Down
12 changes: 3 additions & 9 deletions lib/cronlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ function cron_run() {
$pre_dbqueries = $DB->perf_get_queries();
$pre_time = microtime(1);
if ($cron_function()) {
if (!$DB->set_field("modules", "lastcron", $timenow, array("id"=>$mod->id))) {
mtrace("Error: could not update timestamp for $mod->fullname");
}
$DB->set_field("modules", "lastcron", $timenow, array("id"=>$mod->id));
}
if (isset($pre_dbqueries)) {
mtrace("... used " . ($DB->perf_get_queries() - $pre_dbqueries) . " dbqueries");
Expand Down Expand Up @@ -106,9 +104,7 @@ function cron_run() {
if (method_exists($blockobj,'cron')) {
mtrace("Processing cron function for ".$block->name.'....','');
if ($blockobj->cron()) {
if (!$DB->set_field('block', 'lastcron', $timenow, array('id'=>$block->id))) {
mtrace('Error: could not update timestamp for '.$block->name);
}
$DB->set_field('block', 'lastcron', $timenow, array('id'=>$block->id));
}
/// Reset possible changes by blocks to time_limit. MDL-11597
@set_time_limit(0);
Expand All @@ -133,9 +129,7 @@ function cron_run() {
$pre_dbqueries = $DB->perf_get_queries();
$pre_time = microtime(1);
if ($cron_function()) {
if (!$DB->set_field('quiz_report', "lastcron", $timenow, array("id"=>$report->id))) {
mtrace("Error: could not update timestamp for $report->name");
}
$DB->set_field('quiz_report', "lastcron", $timenow, array("id"=>$report->id));
}
if (isset($pre_dbqueries)) {
mtrace("... used " . ($DB->perf_get_queries() - $pre_dbqueries) . " dbqueries");
Expand Down
7 changes: 3 additions & 4 deletions lib/grade/grade_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,9 @@ public function add_idnumber($idnumber) {
if (!empty($cm->idnumber)) {
return false;
}
if ($DB->set_field('course_modules', 'idnumber', $idnumber, array('id' => $cm->id))) {
$this->idnumber = $idnumber;
return $this->update();
}
$DB->set_field('course_modules', 'idnumber', $idnumber, array('id' => $cm->id));
$this->idnumber = $idnumber;
return $this->update();
} else {
$this->idnumber = $idnumber;
return $this->update();
Expand Down
34 changes: 13 additions & 21 deletions lib/listlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,7 @@ function move_item_up_down($direction, $id) {
function reorder_peers($peers) {
global $DB;
foreach ($peers as $key => $peer) {
if (!$DB->set_field($this->table, "sortorder", $key, array("id"=>$peer))) {
print_error('listupdatefail');
}
$DB->set_field($this->table, "sortorder", $key, array("id"=>$peer));
}
}

Expand All @@ -363,13 +361,10 @@ function move_item_left($id) {
} else {
$newparent = 0; // top level item
}
if (!$DB->set_field($this->table, "parent", $newparent, array("id"=>$item->id))) {
print_error('listupdatefail');
} else {
$oldparentkey = array_search($item->parentlist->parentitem->id, $newpeers);
$neworder = array_merge(array_slice($newpeers, 0, $oldparentkey+1), array($item->id), array_slice($newpeers, $oldparentkey+1));
$this->reorder_peers($neworder);
}
$DB->set_field($this->table, "parent", $newparent, array("id"=>$item->id));
$oldparentkey = array_search($item->parentlist->parentitem->id, $newpeers);
$neworder = array_merge(array_slice($newpeers, 0, $oldparentkey+1), array($item->id), array_slice($newpeers, $oldparentkey+1));
$this->reorder_peers($neworder);
}
return $item->parentlist->parentitem;
}
Expand All @@ -387,17 +382,14 @@ function move_item_right($id) {
if (!isset($peers[$itemkey-1])) {
print_error('listcantmoveright');
} else {
if (!$DB->set_field($this->table, "parent", $peers[$itemkey-1], array("id"=>$peers[$itemkey]))) {
print_error('listupdatefail');
} else {
$newparent = $this->find_item($peers[$itemkey-1]);
if (isset($newparent->children)) {
$newpeers = $newparent->children->get_child_ids();
}
if ($newpeers) {
$newpeers[] = $peers[$itemkey];
$this->reorder_peers($newpeers);
}
$DB->set_field($this->table, "parent", $peers[$itemkey-1], array("id"=>$peers[$itemkey]));
$newparent = $this->find_item($peers[$itemkey-1]);
if (isset($newparent->children)) {
$newpeers = $newparent->children->get_child_ids();
}
if ($newpeers) {
$newpeers[] = $peers[$itemkey];
$this->reorder_peers($newpeers);
}
}
}
Expand Down
16 changes: 6 additions & 10 deletions lib/questionlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -748,9 +748,7 @@ function question_delete_course_category($category, $newcategory, $feedback=true
if (!$newcontext = get_context_instance(CONTEXT_COURSECAT, $newcategory->id)) {
return false;
}
if (!$DB->set_field('question_categories', 'contextid', $newcontext->id, array('contextid'=>$context->id))) {
return false;
}
$DB->set_field('question_categories', 'contextid', $newcontext->id, array('contextid'=>$context->id));
if ($feedback) {
$a = new stdClass;
$a->oldplace = print_context_name($context);
Expand Down Expand Up @@ -855,7 +853,7 @@ function question_delete_activity($cm, $feedback=true) {
*/
function question_move_questions_to_category($questionids, $newcategoryid) {
global $DB, $QTYPES;
$result = true;

$ids = explode(',', $questionids);
foreach ($ids as $questionid) {
$questionid = (int)$questionid;
Expand All @@ -872,14 +870,14 @@ function question_move_questions_to_category($questionids, $newcategoryid) {


// Move the questions themselves.
$result = $result && $DB->set_field_select('question', 'category', $newcategoryid, "id IN ($questionids)");
$DB->set_field_select('question', 'category', $newcategoryid, "id IN ($questionids)");

// Move any subquestions belonging to them.
$result = $result && $DB->set_field_select('question', 'category', $newcategoryid, "parent IN ($questionids)");
$DB->set_field_select('question', 'category', $newcategoryid, "parent IN ($questionids)");

// TODO Deal with datasets.

return $result;
return true;
}

/**
Expand Down Expand Up @@ -1957,9 +1955,7 @@ function question_process_comment($question, &$state, &$attempt, $comment, $grad
$comment = trim($comment);
$state->manualcomment = $comment;
$state->newflaggedstate = $state->flagged;
if (!$DB->set_field('question_sessions', 'manualcomment', $comment, array('attemptid'=>$attempt->uniqueid, 'questionid'=>$question->id))) {
return get_string('errorsavingcomment', 'question', $question);
}
$DB->set_field('question_sessions', 'manualcomment', $comment, array('attemptid'=>$attempt->uniqueid, 'questionid'=>$question->id));

// Update the attempt if the score has changed.
if ($grade !== '' && (abs($state->last_graded->grade - $grade) > 0.002 || $state->last_graded->event != QUESTION_EVENTMANUALGRADE)) {
Expand Down
5 changes: 1 addition & 4 deletions mod/assignment/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2511,10 +2511,7 @@ function assignment_cron () {
$realuser = clone($USER);

foreach ($submissions as $key => $submission) {
if (! $DB->set_field("assignment_submissions", "mailed", "1", array("id"=>$submission->id))) {
echo "Could not update the mailed field for id $submission->id. Not mailed.\n";
unset($submissions[$key]);
}
$DB->set_field("assignment_submissions", "mailed", "1", array("id"=>$submission->id));
}

$timenow = time();
Expand Down
6 changes: 2 additions & 4 deletions mod/forum/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2944,10 +2944,8 @@ function forum_get_course_forum($courseid, $type) {
echo $OUTPUT->notification("Could not add the new course module to that section");
return false;
}
if (! $DB->set_field("course_modules", "section", $sectionid, array("id" => $mod->coursemodule))) {
echo $OUTPUT->notification("Could not update the course module with the correct section");
return false;
}
$DB->set_field("course_modules", "section", $sectionid, array("id" => $mod->coursemodule));

include_once("$CFG->dirroot/course/lib.php");
rebuild_course_cache($courseid);

Expand Down
4 changes: 1 addition & 3 deletions mod/quiz/editlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ function quiz_add_quiz_question($id, &$quiz, $page = 0) {

// Save new questionslist in database
$quiz->questions = implode(',', $questions);
if (!$DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id))) {
print_error('cannotsavequestion', 'quiz');
}
$DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));

// update question grades
$quiz->grades[$id] = $DB->get_field('question', 'defaultgrade', array('id' => $id));
Expand Down
4 changes: 1 addition & 3 deletions question/contextmove.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@
}
$sortorder = 0;
foreach ($peers as $peer) {
if (! $DB->set_field('question_categories', "sortorder", $sortorder, array("id" => $peer))) {
print_error('listupdatefail', '', $onerrorurl);
}
$DB->set_field('question_categories', "sortorder", $sortorder, array("id" => $peer));
$sortorder++;
}
//now move category
Expand Down
Loading

0 comments on commit f685e83

Please sign in to comment.