MDL-14679 fixed remaining old style set_field()s

This commit is contained in:
Petr Skoda 2010-09-03 18:14:55 +00:00
parent dd88de0ebd
commit f685e83030
26 changed files with 82 additions and 167 deletions

View file

@ -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");
@ -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);
@ -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");

View file

@ -431,10 +431,9 @@ class grade_item extends grade_object {
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();

View file

@ -340,9 +340,7 @@ class moodle_list {
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));
}
}
@ -363,13 +361,10 @@ class moodle_list {
} 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;
}
@ -387,17 +382,14 @@ class moodle_list {
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);
}
}
}

View file

@ -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);
@ -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;
@ -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;
}
/**
@ -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)) {