Merge branch 'MDL-25708' of git://github.com/stronk7/moodle

This commit is contained in:
Petr Skoda 2011-01-31 14:21:53 +01:00
commit 8afc38bd39
53 changed files with 514 additions and 526 deletions

View file

@ -425,12 +425,11 @@ function get_role_access($roleid, $accessdata = null) {
if (!isset($ACCESSLIB_PRIVATE->croncache[$roleid])) {
$ACCESSLIB_PRIVATE->croncache[$roleid] = array();
if ($rs = $DB->get_recordset_sql($sql, $params)) {
foreach ($rs as $rd) {
$ACCESSLIB_PRIVATE->croncache[$roleid][] = $rd;
}
$rs->close();
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $rd) {
$ACCESSLIB_PRIVATE->croncache[$roleid][] = $rd;
}
$rs->close();
}
foreach ($ACCESSLIB_PRIVATE->croncache[$roleid] as $rd) {
@ -439,14 +438,15 @@ function get_role_access($roleid, $accessdata = null) {
}
} else {
if ($rs = $DB->get_recordset_sql($sql, $params)) {
$rs = $DB->get_recordset_sql($sql, $params);
if ($rs->valid()) {
foreach ($rs as $rd) {
$k = "{$rd->path}:{$roleid}";
$accessdata['rdef'][$k][$rd->capability] = $rd->permission;
}
unset($rd);
$rs->close();
}
$rs->close();
}
return $accessdata;
@ -480,14 +480,15 @@ function get_default_frontpage_role_access($roleid, $accessdata = null) {
ORDER BY ctx.depth, ctx.path";
$params = array($roleid, "$base/%");
if ($rs = $DB->get_recordset_sql($sql, $params)) {
$rs = $DB->get_recordset_sql($sql, $params);
if ($rs->valid()) {
foreach ($rs as $rd) {
$k = "{$rd->path}:{$roleid}";
$accessdata['rdef'][$k][$rd->capability] = $rd->permission;
}
unset($rd);
$rs->close();
}
$rs->close();
return $accessdata;
}
@ -1315,18 +1316,15 @@ function load_subcontext($userid, $context, &$accessdata) {
$params = array($context->id, $context->path."/%");
$newrdefs = array();
if ($rs = $DB->get_recordset_sql($sql, $params)) {
foreach ($rs as $rd) {
$k = "{$rd->path}:{$rd->roleid}";
if (!array_key_exists($k, $newrdefs)) {
$newrdefs[$k] = array();
}
$newrdefs[$k][$rd->capability] = $rd->permission;
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $rd) {
$k = "{$rd->path}:{$rd->roleid}";
if (!array_key_exists($k, $newrdefs)) {
$newrdefs[$k] = array();
}
$rs->close();
} else {
debugging('Bad SQL encountered!');
$newrdefs[$k][$rd->capability] = $rd->permission;
}
$rs->close();
compact_rdefs($newrdefs);
foreach ($newrdefs as $key=>$value) {
@ -1389,13 +1387,12 @@ function get_role_access_bycontext($roleid, $context, $accessdata = null) {
ORDER BY ctx.depth ASC, ctx.path DESC, rc.roleid ASC ";
$params = array($roleid, $context->path."/%");
if ($rs = $DB->get_recordset_sql($sql, $params)) {
foreach ($rs as $rd) {
$k = "{$rd->path}:{$roleid}";
$accessdata['rdef'][$k][$rd->capability] = $rd->permission;
}
$rs->close();
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $rd) {
$k = "{$rd->path}:{$roleid}";
$accessdata['rdef'][$k][$rd->capability] = $rd->permission;
}
$rs->close();
return $accessdata;
}
@ -1615,13 +1612,12 @@ function load_temp_role($context, $roleid, array $accessdata) {
AND rc.roleid = ?
ORDER BY ctx.depth, ctx.path";
$params = array($context->path."/%", $roleid);
if ($rs = $DB->get_recordset_sql($sql, $params)) {
foreach ($rs as $rd) {
$k = "{$rd->path}:{$roleid}";
$accessdata['rdef'][$k][$rd->capability] = $rd->permission;
}
$rs->close();
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $rd) {
$k = "{$rd->path}:{$roleid}";
$accessdata['rdef'][$k][$rd->capability] = $rd->permission;
}
$rs->close();
//
// Say we loaded everything for the course context
@ -2132,12 +2128,11 @@ function cleanup_contexts() {
// transactions used only for performance reasons here
$transaction = $DB->start_delegated_transaction();
if ($rs = $DB->get_recordset_sql($sql)) {
foreach ($rs as $ctx) {
delete_context($ctx->contextlevel, $ctx->instanceid);
}
$rs->close();
$rs = $DB->get_recordset_sql($sql);
foreach ($rs as $ctx) {
delete_context($ctx->contextlevel, $ctx->instanceid);
}
$rs->close();
$transaction->allow_commit();
return true;
@ -5335,16 +5330,13 @@ function get_user_capability_course($capability, $userid = null, $doanything = t
// Note the result can be used directly as a context (we are going to), the course
// fields are just appended.
if (!$rs = $DB->get_recordset_sql("SELECT x.*, c.id AS courseid $fieldlist
FROM {course} c
INNER JOIN {context} x
ON (c.id=x.instanceid AND x.contextlevel=".CONTEXT_COURSE.")
$orderby")) {
return false;
}
// Check capability for each course in turn
$courses = array();
$rs = $DB->get_recordset_sql("SELECT x.*, c.id AS courseid $fieldlist
FROM {course} c
INNER JOIN {context} x
ON (c.id=x.instanceid AND x.contextlevel=".CONTEXT_COURSE.")
$orderby");
// Check capability for each course in turn
foreach ($rs as $coursecontext) {
if (has_capability($capability, $coursecontext, $userid, $doanything)) {
// We've got the capability. Make the record look like a course record
@ -5357,7 +5349,7 @@ function get_user_capability_course($capability, $userid = null, $doanything = t
}
}
$rs->close();
return $courses;
return empty($courses) ? false : $courses;
}
/**

View file

@ -228,15 +228,13 @@ class completion_criteria_activity extends completion_criteria {
';
// Loop through completions, and mark as complete
if ($rs = $DB->get_recordset_sql($sql)) {
foreach ($rs as $record) {
$rs = $DB->get_recordset_sql($sql);
foreach ($rs as $record) {
$completion = new completion_criteria_completion((array)$record);
$completion->mark_complete($record->timecompleted);
}
$rs->close();
$completion = new completion_criteria_completion((array)$record);
$completion->mark_complete($record->timecompleted);
}
$rs->close();
}
/**

View file

@ -185,14 +185,12 @@ class completion_criteria_course extends completion_criteria {
";
// Loop through completions, and mark as complete
if ($rs = $DB->get_recordset_sql($sql)) {
foreach ($rs as $record) {
$completion = new completion_criteria_completion((array)$record);
$completion->mark_complete($record->timecompleted);
}
$rs->close();
$rs = $DB->get_recordset_sql($sql);
foreach ($rs as $record) {
$completion = new completion_criteria_completion((array)$record);
$completion->mark_complete($record->timecompleted);
}
$rs->close();
}
/**

View file

@ -178,15 +178,12 @@ class completion_criteria_date extends completion_criteria {
';
// Loop through completions, and mark as complete
if ($rs = $DB->get_recordset_sql($sql, array(time()))) {
foreach ($rs as $record) {
$completion = new completion_criteria_completion((array)$record);
$completion->mark_complete($record->timeend);
}
$rs->close();
$rs = $DB->get_recordset_sql($sql, array(time()));
foreach ($rs as $record) {
$completion = new completion_criteria_completion((array)$record);
$completion->mark_complete($record->timeend);
}
$rs->close();
}
/**

View file

@ -219,22 +219,19 @@ class completion_criteria_duration extends completion_criteria {
// Loop through completions, and mark as complete
$now = time();
if ($rs = $DB->get_recordset_sql($sql, array($now, $now))) {
foreach ($rs as $record) {
$rs = $DB->get_recordset_sql($sql, array($now, $now));
foreach ($rs as $record) {
$completion = new completion_criteria_completion((array)$record);
$completion = new completion_criteria_completion((array)$record);
// Use time start if not 0, otherwise use timeenrolled
if ($record->otimestart) {
$completion->mark_complete($record->ctimestart);
}
else {
$completion->mark_complete($record->ctimeenrolled);
}
// Use time start if not 0, otherwise use timeenrolled
if ($record->otimestart) {
$completion->mark_complete($record->ctimestart);
} else {
$completion->mark_complete($record->ctimeenrolled);
}
$rs->close();
}
$rs->close();
}
/**

View file

@ -214,15 +214,12 @@ class completion_criteria_grade extends completion_criteria {
';
// Loop through completions, and mark as complete
if ($rs = $DB->get_recordset_sql($sql)) {
foreach ($rs as $record) {
$completion = new completion_criteria_completion((array)$record);
$completion->mark_complete($record->timecompleted);
}
$rs->close();
$rs = $DB->get_recordset_sql($sql);
foreach ($rs as $record) {
$completion = new completion_criteria_completion((array)$record);
$completion->mark_complete($record->timecompleted);
}
$rs->close();
}
/**

View file

@ -118,9 +118,12 @@ function completion_cron_mark_started() {
userid
";
// Check if result is empty
$now = time();
if (!$rs = $DB->get_recordset_sql($sql, array($now, $now, $now, $now))) {
$rs = $DB->get_recordset_sql($sql, array($now, $now, $now, $now));
// Check if result is empty
if (!$rs->valid()) {
$rs->close(); // Not going to iterate (but exit), close rs
return;
}
@ -267,8 +270,11 @@ function completion_cron_completions() {
userid
';
$rs = $DB->get_recordset_sql($sql, array('timestarted' => $timestarted));
// Check if result is empty
if (!$rs = $DB->get_recordset_sql($sql, array('timestarted' => $timestarted))) {
if (!$rs->valid()) {
$rs->close(); // Not going to iterate (but exit), close rs
return;
}

View file

@ -438,6 +438,12 @@ function get_courses_page($categoryid="all", $sort="c.sortorder ASC", $fields="c
list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
$totalcount = 0;
if (!$limitfrom) {
$limitfrom = 0;
}
$visiblecourses = array();
$sql = "SELECT $fields $ccselect
FROM {course} c
$ccjoin
@ -445,17 +451,8 @@ function get_courses_page($categoryid="all", $sort="c.sortorder ASC", $fields="c
ORDER BY $sort";
// pull out all course matching the cat
if (!$rs = $DB->get_recordset_sql($sql, $params)) {
return array();
}
$totalcount = 0;
if (!$limitfrom) {
$limitfrom = 0;
}
$rs = $DB->get_recordset_sql($sql, $params);
// iteration will have to be done inside loop to keep track of the limitfrom and limitnum
$visiblecourses = array();
foreach($rs as $course) {
context_instance_preload($course);
if ($course->visible <= 0) {
@ -764,35 +761,35 @@ function get_courses_search($searchterms, $sort='fullname ASC', $page=0, $record
$searchcond = implode(" AND ", $searchcond);
$courses = array();
$c = 0; // counts how many visible courses we've seen
// Tiki pagination
$limitfrom = $page * $recordsperpage;
$limitto = $limitfrom + $recordsperpage;
list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
$sql = "SELECT c.* $ccselect
FROM {course} c
$ccjoin
WHERE $searchcond AND c.id <> ".SITEID."
ORDER BY $sort";
$courses = array();
$c = 0; // counts how many visible courses we've seen
if ($rs = $DB->get_recordset_sql($sql, $params)) {
// Tiki pagination
$limitfrom = $page * $recordsperpage;
$limitto = $limitfrom + $recordsperpage;
foreach($rs as $course) {
context_instance_preload($course);
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
if ($course->visible || has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
// Don't exit this loop till the end
// we need to count all the visible courses
// to update $totalcount
if ($c >= $limitfrom && $c < $limitto) {
$courses[$course->id] = $course;
}
$c++;
$rs = $DB->get_recordset_sql($sql, $params);
foreach($rs as $course) {
context_instance_preload($course);
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
if ($course->visible || has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
// Don't exit this loop till the end
// we need to count all the visible courses
// to update $totalcount
if ($c >= $limitfrom && $c < $limitto) {
$courses[$course->id] = $course;
}
$c++;
}
$rs->close();
}
$rs->close();
// our caller expects 2 bits of data - our return
// array, and an updated $totalcount
@ -857,16 +854,15 @@ function get_categories($parent='none', $sort=NULL, $shallow=true) {
}
$categories = array();
if( $rs = $DB->get_recordset_sql($sql, $params) ){
foreach($rs as $cat) {
context_instance_preload($cat);
$catcontext = get_context_instance(CONTEXT_COURSECAT, $cat->id);
if ($cat->visible || has_capability('moodle/category:viewhiddencategories', $catcontext)) {
$categories[$cat->id] = $cat;
}
$rs = $DB->get_recordset_sql($sql, $params);
foreach($rs as $cat) {
context_instance_preload($cat);
$catcontext = get_context_instance(CONTEXT_COURSECAT, $cat->id);
if ($cat->visible || has_capability('moodle/category:viewhiddencategories', $catcontext)) {
$categories[$cat->id] = $cat;
}
$rs->close();
}
$rs->close();
return $categories;
}

View file

@ -38,15 +38,14 @@ function upgrade_fix_category_depths() {
$sql = "SELECT c.id
FROM {course_categories} c
WHERE c.parent > 0 AND c.parent NOT IN (SELECT pc.id FROM {course_categories} pc)";
if ($rs = $DB->get_recordset_sql($sql)) {
foreach ($rs as $cat) {
$cat->depth = 1;
$cat->path = '/'.$cat->id;
$cat->parent = 0;
$DB->update_record('course_categories', $cat);
}
$rs->close();
$rs = $DB->get_recordset_sql($sql);
foreach ($rs as $cat) {
$cat->depth = 1;
$cat->path = '/'.$cat->id;
$cat->parent = 0;
$DB->update_record('course_categories', $cat);
}
$rs->close();
// now add path and depth to top level categories
$sql = "UPDATE {course_categories}
@ -60,14 +59,13 @@ function upgrade_fix_category_depths() {
$sql = "SELECT c.id, pc.path
FROM {course_categories} c, {course_categories} pc
WHERE c.parent=pc.id AND c.depth=0 AND pc.depth=?";
if ($rs = $DB->get_recordset_sql($sql, array($parentdepth))) {
foreach ($rs as $cat) {
$cat->depth = $parentdepth+1;
$cat->path = $cat->path.'/'.$cat->id;
$DB->update_record('course_categories', $cat);
}
$rs->close();
$rs = $DB->get_recordset_sql($sql, array($parentdepth));
foreach ($rs as $cat) {
$cat->depth = $parentdepth+1;
$cat->path = $cat->path.'/'.$cat->id;
$DB->update_record('course_categories', $cat);
}
$rs->close();
$parentdepth++;
if ($parentdepth > 100) {
//something must have gone wrong - nobody can have more than 100 levels of categories, right?
@ -378,7 +376,9 @@ function upgrade_migrate_files_blog() {
$count = $DB->count_records_select('post', "module='blog' AND attachment IS NOT NULL AND attachment <> '1'");
if ($rs = $DB->get_recordset_select('post', "module='blog' AND attachment IS NOT NULL AND attachment <> '1'")) {
$rs = $DB->get_recordset_select('post', "module='blog' AND attachment IS NOT NULL AND attachment <> '1'");
if ($rs->valid()) {
upgrade_set_timeout(60*20); // set up timeout, may also abort execution
@ -419,8 +419,8 @@ function upgrade_migrate_files_blog() {
$DB->update_record('post', $entry);
$pbar->update($i, $count, "Migrated blog attachments - $i/$count.");
}
$rs->close();
}
$rs->close();
@rmdir("$CFG->dataroot/blog/attachments/");
@rmdir("$CFG->dataroot/blog/");
@ -539,13 +539,12 @@ function upgrade_fix_incorrect_mnethostids() {
$params = array_merge($in_params, array($current_mnet_localhost_host->id));
if ($rs = $DB->get_recordset_sql($sql, $params)) {
foreach ($rs as $rec) {
$DB->set_field('user', 'mnethostid', $current_mnet_localhost_host->id, array('id' => $rec->id));
upgrade_set_timeout(60); /// Give upgrade at least 60 more seconds
}
$rs->close();
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $rec) {
$DB->set_field('user', 'mnethostid', $current_mnet_localhost_host->id, array('id' => $rec->id));
upgrade_set_timeout(60); /// Give upgrade at least 60 more seconds
}
$rs->close();
// fix up any host records that have incorrect ids
$DB->set_field_select('mnet_host', 'applicationid', $moodleapplicationid, 'id = ? or id = ?', array($current_mnet_localhost_host->id, $current_mnet_all_hosts_host->id));
@ -642,4 +641,4 @@ function update_fix_automated_backup_config() {
unset_config('backup_sche_gradebook_history');
unset_config('disablescheduleddbackups');
}
}

View file

@ -1550,12 +1550,10 @@ abstract class moodle_database {
* @throws dml_exception if error
*/
public function record_exists_sql($sql, array $params=null) {
if ($mrs = $this->get_recordset_sql($sql, $params, 0, 1)) {
$return = $mrs->valid();
$mrs->close();
return $return;
}
return false;
$mrs = $this->get_recordset_sql($sql, $params, 0, 1);
$return = $mrs->valid();
$mrs->close();
return $return;
}
/**

View file

@ -968,15 +968,14 @@ class oci_native_moodle_database extends moodle_database {
$strictness = (int)$strictness;
if ($strictness == IGNORE_MULTIPLE) {
// do not limit here - ORA does not like that
if (!$rs = $this->get_recordset_sql($sql, $params)) {
return false;
}
foreach ($rs as $result) {
$rs->close();
return $result;
$rs = $this->get_recordset_sql($sql, $params);
$result = false;
foreach ($rs as $rec) {
$result = $rec;
break;
}
$rs->close();
return false;
return $result;
}
return parent::get_record_sql($sql, $params, $strictness);
}

View file

@ -287,7 +287,9 @@ abstract class pdo_moodle_database extends moodle_database {
* @return array of values
*/
public function get_fieldset_sql($sql, array $params=null) {
if(!$rs = $this->get_recordset_sql($sql, $params)) {
$rs = $this->get_recordset_sql($sql, $params);
if (!$rs->valid()) {
$rs->close(); // Not going to iterate (but exit), close rs
return false;
}
$result = array();
@ -312,7 +314,9 @@ abstract class pdo_moodle_database extends moodle_database {
* @return array of objects, or empty array if no records were found, or false if an error occurred.
*/
public function get_records_sql($sql, array $params=null, $limitfrom=0, $limitnum=0) {
if(!$rs = $this->get_recordset_sql($sql, $params, $limitfrom, $limitnum)) {
$rs = $this->get_recordset_sql($sql, $params, $limitfrom, $limitnum);
if (!$rs->valid()) {
$rs->close(); // Not going to iterate (but exit), close rs
return false;
}
$objects = array();

View file

@ -435,25 +435,24 @@ function events_cron($eventname='') {
$params = array();
}
if ($rs = $DB->get_recordset_sql($sql, $params)) {
foreach ($rs as $qhandler) {
if (isset($failed[$qhandler->handlerid])) {
// do not try to dispatch any later events when one already asked for retry or ended with exception
continue;
}
$status = events_process_queued_handler($qhandler);
if ($status === false) {
// handler is asking for retry, do not send other events to this handler now
$failed[$qhandler->handlerid] = $qhandler->handlerid;
} else if ($status === NULL) {
// means completely broken handler, event data was purged
$failed[$qhandler->handlerid] = $qhandler->handlerid;
} else {
$processed++;
}
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $qhandler) {
if (isset($failed[$qhandler->handlerid])) {
// do not try to dispatch any later events when one already asked for retry or ended with exception
continue;
}
$status = events_process_queued_handler($qhandler);
if ($status === false) {
// handler is asking for retry, do not send other events to this handler now
$failed[$qhandler->handlerid] = $qhandler->handlerid;
} else if ($status === NULL) {
// means completely broken handler, event data was purged
$failed[$qhandler->handlerid] = $qhandler->handlerid;
} else {
$processed++;
}
$rs->close();
}
$rs->close();
// remove events that do not have any handlers waiting
$sql = "SELECT eq.id

View file

@ -1214,6 +1214,7 @@ class file_storage {
foreach ($rs as $dir) {
$this->delete_area_files($dir->contextid, $dir->component, $dir->filearea, $dir->itemid);
}
$rs->close();
mtrace('done.');
// remove trash pool files once a day
@ -1226,12 +1227,14 @@ class file_storage {
FROM {files} f
LEFT OUTER JOIN {context} c ON f.contextid = c.id
WHERE c.id IS NULL";
if ($rs = $DB->get_recordset_sql($sql)) {
$rs = $DB->get_recordset_sql($sql);
if ($rs->valid()) {
$fs = get_file_storage();
foreach ($rs as $ctx) {
$fs->delete_area_files($ctx->contextid);
}
}
$rs->close();
mtrace('done.');
mtrace('Deleting trash files... ', '');

View file

@ -481,7 +481,8 @@ class grade_category extends grade_object {
ORDER BY g.userid";
// group the results by userid and aggregate the grades for this user
if ($rs = $DB->get_recordset_sql($sql, $params)) {
$rs = $DB->get_recordset_sql($sql, $params);
if ($rs->valid()) {
$prevuser = 0;
$grade_values = array();
$excluded = array();
@ -506,9 +507,9 @@ class grade_category extends grade_object {
$oldgrade = $used;
}
}
$rs->close();
$this->aggregate_grades($prevuser, $items, $grade_values, $oldgrade, $excluded);//the last one
}
$rs->close();
return true;
}

View file

@ -390,14 +390,13 @@ class grade_grade extends grade_object {
$now = time(); // no rounding needed, this is not supposed to be called every 10 seconds
list($usql, $params) = $DB->get_in_or_equal($items);
$params[] = $now;
if ($rs = $DB->get_recordset_select('grade_grades', "itemid $usql AND locked = 0 AND locktime > 0 AND locktime < ?", $params)) {
foreach ($rs as $grade) {
$grade_grade = new grade_grade($grade, false);
$grade_grade->locked = time();
$grade_grade->update('locktime');
}
$rs->close();
$rs = $DB->get_recordset_select('grade_grades', "itemid $usql AND locked = 0 AND locktime > 0 AND locktime < ?", $params);
foreach ($rs as $grade) {
$grade_grade = new grade_grade($grade, false);
$grade_grade->locked = time();
$grade_grade->update('locktime');
}
$rs->close();
}
/**

View file

@ -1722,7 +1722,8 @@ class grade_item extends grade_object {
$return = true;
// group the grades by userid and use formula on the group
if ($rs = $DB->get_recordset_sql($sql, $params)) {
$rs = $DB->get_recordset_sql($sql, $params);
if ($rs->valid()) {
$prevuser = 0;
$grade_records = array();
$oldgrade = null;
@ -1740,11 +1741,11 @@ class grade_item extends grade_object {
}
$grade_records['gi'.$used->itemid] = $used->finalgrade;
}
$rs->close();
if (!$this->use_formula($prevuser, $grade_records, $useditems, $oldgrade)) {
$return = false;
}
}
$rs->close();
return $return;
}

View file

@ -1206,13 +1206,12 @@ function grade_uninstalled_module($modname) {
WHERE itemtype='mod' AND itemmodule=?";
// go all items for this module and delete them including the grades
if ($rs = $DB->get_recordset_sql($sql, array($modname))) {
foreach ($rs as $item) {
$grade_item = new grade_item($item, false);
$grade_item->delete('moduninstall');
}
$rs->close();
$rs = $DB->get_recordset_sql($sql, array($modname));
foreach ($rs as $item) {
$grade_item = new grade_item($item, false);
$grade_item->delete('moduninstall');
}
$rs->close();
}
/**
@ -1260,14 +1259,13 @@ function grade_cron() {
SELECT 'x' FROM {grade_items} c WHERE c.itemtype='course' AND c.needsupdate=0 AND c.courseid=i.courseid)";
// go through all courses that have proper final grades and lock them if needed
if ($rs = $DB->get_recordset_sql($sql, array($now))) {
foreach ($rs as $item) {
$grade_item = new grade_item($item, false);
$grade_item->locked = $now;
$grade_item->update('locktime');
}
$rs->close();
$rs = $DB->get_recordset_sql($sql, array($now));
foreach ($rs as $item) {
$grade_item = new grade_item($item, false);
$grade_item->locked = $now;
$grade_item->update('locktime');
}
$rs->close();
$grade_inst = new grade_grade();
$fields = 'g.'.implode(',g.', $grade_inst->required_fields);
@ -1278,14 +1276,13 @@ function grade_cron() {
SELECT 'x' FROM {grade_items} c WHERE c.itemtype='course' AND c.needsupdate=0 AND c.courseid=i.courseid)";
// go through all courses that have proper final grades and lock them if needed
if ($rs = $DB->get_recordset_sql($sql, array($now))) {
foreach ($rs as $grade) {
$grade_grade = new grade_grade($grade, false);
$grade_grade->locked = $now;
$grade_grade->update('locktime');
}
$rs->close();
$rs = $DB->get_recordset_sql($sql, array($now));
foreach ($rs as $grade) {
$grade_grade = new grade_grade($grade, false);
$grade_grade->locked = $now;
$grade_grade->update('locktime');
}
$rs->close();
//TODO: do not run this cleanup every cron invocation
// cleanup history tables

View file

@ -199,7 +199,10 @@ function groups_get_user_groups($courseid, $userid=0) {
WHERE gm.userid = ? AND g.courseid = ?";
$params = array($userid, $courseid);
if (!$rs = $DB->get_recordset_sql($sql, $params)) {
$rs = $DB->get_recordset_sql($sql, $params);
if (!$rs->valid()) {
$rs->close(); // Not going to iterate (but exit), close rs
return array('0' => array());
}

View file

@ -8012,14 +8012,13 @@ function notify_login_failures() {
GROUP BY ip
HAVING COUNT(*) >= ?";
$params = array($CFG->lastnotifyfailure, $CFG->notifyloginthreshold);
if ($rs = $DB->get_recordset_sql($sql, $params)) {
foreach ($rs as $iprec) {
if (!empty($iprec->ip)) {
set_cache_flag('login_failure_by_ip', $iprec->ip, '1', 0);
}
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $iprec) {
if (!empty($iprec->ip)) {
set_cache_flag('login_failure_by_ip', $iprec->ip, '1', 0);
}
$rs->close();
}
$rs->close();
/// Get all the INFOs with more than notifyloginthreshold failures since lastnotifyfailure
/// and insert them into the cache_flags temp table
@ -8030,14 +8029,13 @@ function notify_login_failures() {
GROUP BY info
HAVING count(*) >= ?";
$params = array($CFG->lastnotifyfailure, $CFG->notifyloginthreshold);
if ($rs = $DB->get_recordset_sql($sql, $params)) {
foreach ($rs as $inforec) {
if (!empty($inforec->info)) {
set_cache_flag('login_failure_by_info', $inforec->info, '1', 0);
}
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $inforec) {
if (!empty($inforec->info)) {
set_cache_flag('login_failure_by_info', $inforec->info, '1', 0);
}
$rs->close();
}
$rs->close();
/// Now, select all the login error logged records belonging to the ips and infos
/// since lastnotifyfailure, that we have stored in the cache_flags table
@ -8063,14 +8061,13 @@ function notify_login_failures() {
$count = 0;
$messages = '';
/// Iterate over the logs recordset
if ($rs = $DB->get_recordset_sql($sql, $params)) {
foreach ($rs as $log) {
$log->time = userdate($log->time);
$messages .= get_string('notifyloginfailuresmessage','',$log)."\n";
$count++;
}
$rs->close();
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $log) {
$log->time = userdate($log->time);
$messages .= get_string('notifyloginfailuresmessage','',$log)."\n";
$count++;
}
$rs->close();
/// If we haven't run in the last hour and
/// we have something useful to report and we