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

@ -56,35 +56,34 @@ foreach ($tables as $table) {
if (in_array($data->type, array('text','mediumtext','longtext','varchar'))) { // Text stuff only if (in_array($data->type, array('text','mediumtext','longtext','varchar'))) { // Text stuff only
// first find candidate records // first find candidate records
$sql = "SELECT id, $column FROM $fulltable WHERE $column LIKE '%</lang>%' OR $column LIKE '%<span lang=%'"; $sql = "SELECT id, $column FROM $fulltable WHERE $column LIKE '%</lang>%' OR $column LIKE '%<span lang=%'";
if ($rs = $DB->get_recordset_sql($sql)) { $rs = $DB->get_recordset_sql($sql);
foreach ($rs as $data) { foreach ($rs as $data) {
$text = $data->$column; $text = $data->$column;
$id = $data->id; $id = $data->id;
if ($i % 600 == 0) { if ($i % 600 == 0) {
echo '<br />'; echo '<br />';
} }
if ($i % 10 == 0) { if ($i % 10 == 0) {
echo '.'; echo '.';
} }
$i++; $i++;
if (empty($text) or is_numeric($text)) { if (empty($text) or is_numeric($text)) {
continue; // nothing to do continue; // nothing to do
} }
$search = '/(<(?:lang|span) lang="[a-zA-Z0-9_-]*".*?>.+?<\/(?:lang|span)>)(\s*<(?:lang|span) lang="[a-zA-Z0-9_-]*".*?>.+?<\/(?:lang|span)>)+/is'; $search = '/(<(?:lang|span) lang="[a-zA-Z0-9_-]*".*?>.+?<\/(?:lang|span)>)(\s*<(?:lang|span) lang="[a-zA-Z0-9_-]*".*?>.+?<\/(?:lang|span)>)+/is';
$newtext = preg_replace_callback($search, 'multilangupgrade_impl', $text); $newtext = preg_replace_callback($search, 'multilangupgrade_impl', $text);
if (is_null($newtext)) { if (is_null($newtext)) {
continue; // regex error continue; // regex error
} }
if ($newtext != $text) { if ($newtext != $text) {
$DB->execute("UPDATE $fulltable SET $column=? WHERE id=?", array($newtext, $id)); $DB->execute("UPDATE $fulltable SET $column=? WHERE id=?", array($newtext, $id));
}
} }
$rs->close();
} }
$rs->close();
} }
} }
} }

View file

@ -11,14 +11,13 @@ function add_selection_all($ufiltering) {
list($sqlwhere, $params) = $ufiltering->get_sql_filter("id<>:exguest AND deleted <> 1", array('exguest'=>$CFG->siteguest)); list($sqlwhere, $params) = $ufiltering->get_sql_filter("id<>:exguest AND deleted <> 1", array('exguest'=>$CFG->siteguest));
if ($rs = $DB->get_recordset_select('user', $sqlwhere, $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname')) { $rs = $DB->get_recordset_select('user', $sqlwhere, $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname');
foreach ($rs as $user) { foreach ($rs as $user) {
if (!isset($SESSION->bulk_users[$user->id])) { if (!isset($SESSION->bulk_users[$user->id])) {
$SESSION->bulk_users[$user->id] = $user->id; $SESSION->bulk_users[$user->id] = $user->id;
}
} }
$rs->close();
} }
$rs->close();
} }
function get_selection_data($ufiltering) { function get_selection_data($ufiltering) {

View file

@ -24,19 +24,18 @@ echo $OUTPUT->header();
if ($confirm and confirm_sesskey()) { if ($confirm and confirm_sesskey()) {
list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users); list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users);
if ($rs = $DB->get_recordset_select('user', "id $in", $params, '', 'id, username, secret, confirmed, auth, firstname, lastname')) { $rs = $DB->get_recordset_select('user', "id $in", $params, '', 'id, username, secret, confirmed, auth, firstname, lastname');
foreach ($rs as $user) { foreach ($rs as $user) {
if ($user->confirmed) { if ($user->confirmed) {
continue; continue;
} }
$auth = get_auth_plugin($user->auth); $auth = get_auth_plugin($user->auth);
$result = $auth->user_confirm($user->username, $user->secret); $result = $auth->user_confirm($user->username, $user->secret);
if ($result != AUTH_CONFIRM_OK && $result != AUTH_CONFIRM_ALREADY) { if ($result != AUTH_CONFIRM_OK && $result != AUTH_CONFIRM_ALREADY) {
echo $OUTPUT->notification(get_string('usernotconfirmed', '', fullname($user, true))); echo $OUTPUT->notification(get_string('usernotconfirmed', '', fullname($user, true)));
}
} }
$rs->close();
} }
$rs->close();
redirect($return, get_string('changessaved')); redirect($return, get_string('changessaved'));
} else { } else {

View file

@ -25,16 +25,15 @@ echo $OUTPUT->header();
if ($confirm and confirm_sesskey()) { if ($confirm and confirm_sesskey()) {
list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users); list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users);
if ($rs = $DB->get_recordset_select('user', "id $in", $params)) { $rs = $DB->get_recordset_select('user', "id $in", $params);
foreach ($rs as $user) { foreach ($rs as $user) {
if (!is_siteadmin($user) and $USER->id != $user->id and delete_user($user)) { if (!is_siteadmin($user) and $USER->id != $user->id and delete_user($user)) {
unset($SESSION->bulk_users[$user->id]); unset($SESSION->bulk_users[$user->id]);
} else { } else {
echo $OUTPUT->notification(get_string('deletednot', '', fullname($user, true))); echo $OUTPUT->notification(get_string('deletednot', '', fullname($user, true)));
}
} }
$rs->close();
} }
$rs->close();
session_gc(); // remove stale sessions session_gc(); // remove stale sessions
redirect($return, get_string('changessaved')); redirect($return, get_string('changessaved'));

View file

@ -38,17 +38,16 @@ if ($confirm and confirm_sesskey()) {
$parts = array_chunk($SESSION->bulk_users, 300); $parts = array_chunk($SESSION->bulk_users, 300);
foreach ($parts as $users) { foreach ($parts as $users) {
list($in, $params) = $DB->get_in_or_equal($users); list($in, $params) = $DB->get_in_or_equal($users);
if ($rs = $DB->get_recordset_select('user', "id $in", $params)) { $rs = $DB->get_recordset_select('user', "id $in", $params);
foreach ($rs as $user) { foreach ($rs as $user) {
if (!empty($changeable[$user->auth])) { if (!empty($changeable[$user->auth])) {
set_user_preference('auth_forcepasswordchange', 1, $user->id); set_user_preference('auth_forcepasswordchange', 1, $user->id);
unset($SESSION->bulk_users[$user->id]); unset($SESSION->bulk_users[$user->id]);
} else { } else {
echo $OUTPUT->notification(get_string('forcepasswordchangenot', '', fullname($user, true))); echo $OUTPUT->notification(get_string('forcepasswordchangenot', '', fullname($user, true)));
}
} }
$rs->close();
} }
$rs->close();
} }
echo $OUTPUT->notification(get_string('changessaved'), 'notifysuccess'); echo $OUTPUT->notification(get_string('changessaved'), 'notifysuccess');
echo $OUTPUT->continue_button($return); echo $OUTPUT->continue_button($return);

View file

@ -25,15 +25,14 @@ if (empty($CFG->messaging)) {
if ($confirm and !empty($msg) and confirm_sesskey()) { if ($confirm and !empty($msg) and confirm_sesskey()) {
list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users); list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users);
if ($rs = $DB->get_recordset_select('user', "id $in", $params)) { $rs = $DB->get_recordset_select('user', "id $in", $params);
foreach ($rs as $user) { foreach ($rs as $user) {
//TODO we should probably support all text formats here or only FORMAT_MOODLE //TODO we should probably support all text formats here or only FORMAT_MOODLE
//For now bulk messaging is still using the html editor and its supplying html //For now bulk messaging is still using the html editor and its supplying html
//so we have to use html format for it to be displayed correctly //so we have to use html format for it to be displayed correctly
message_post_message($USER, $user, $msg, FORMAT_HTML, 'direct'); message_post_message($USER, $user, $msg, FORMAT_HTML, 'direct');
}
$rs->close();
} }
$rs->close();
redirect($return); redirect($return);
} }

View file

@ -1757,17 +1757,16 @@ function rebuild_course_cache($courseid=0, $clearonly=false) {
@set_time_limit(0); // this could take a while! MDL-10954 @set_time_limit(0); // this could take a while! MDL-10954
} }
if ($rs = $DB->get_recordset("course", $select,'','id,fullname')) { $rs = $DB->get_recordset("course", $select,'','id,fullname');
foreach ($rs as $course) { foreach ($rs as $course) {
$modinfo = serialize(get_array_of_activities($course->id)); $modinfo = serialize(get_array_of_activities($course->id));
$DB->set_field("course", "modinfo", $modinfo, array("id"=>$course->id)); $DB->set_field("course", "modinfo", $modinfo, array("id"=>$course->id));
// update cached global COURSE too ;-) // update cached global COURSE too ;-)
if ($course->id == $COURSE->id) { if ($course->id == $COURSE->id) {
$COURSE->modinfo = $modinfo; $COURSE->modinfo = $modinfo;
}
} }
$rs->close();
} }
$rs->close();
// reset the fast modinfo cache // reset the fast modinfo cache
$reset = 'reset'; $reset = 'reset';
get_fast_modinfo($reset); get_fast_modinfo($reset);

View file

@ -400,7 +400,8 @@ switch ($mode) {
} }
// Check if result is empty // Check if result is empty
if (!$rs = $DB->get_recordset_sql($sql)) { $rs = $DB->get_recordset_sql($sql);
if (!$rs->valid()) {
if ($course->id != 1) { if ($course->id != 1) {
$error = get_string('nocompletions', 'coursereport_completion'); $error = get_string('nocompletions', 'coursereport_completion');
@ -409,6 +410,7 @@ switch ($mode) {
} }
echo $OUTPUT->notification($error); echo $OUTPUT->notification($error);
$rs->close(); // not going to loop (but break), close rs
break; break;
} }
@ -437,8 +439,7 @@ switch ($mode) {
$courses['unstarted'][] = $c_info; $courses['unstarted'][] = $c_info;
} }
} }
$rs->close(); // after loop, close rs
$rs->close();
// Loop through course status groups // Loop through course status groups
foreach ($courses as $type => $infos) { foreach ($courses as $type => $infos) {

View file

@ -194,7 +194,9 @@ function send_welcome_messages($orderdata) {
WHERE e.id IN(" . implode(',', $orderdata) . ") WHERE e.id IN(" . implode(',', $orderdata) . ")
ORDER BY e.userid"; ORDER BY e.userid";
if (!$rs = $DB->get_recordset_sql($sql)) { $rs = $DB->get_recordset_sql($sql);
if (!$rs->valid()) {
$rs->close(); // Not going to iterate (but exit), close rs
return; return;
} }
@ -247,7 +249,7 @@ function send_welcome_messages($orderdata) {
} }
while ($ei); while ($ei);
$rs->close(); $rs->close(); // end of iteration, close rs
} }
} }

View file

@ -634,12 +634,11 @@ class grade_report_user extends grade_report {
GROUP BY gg.itemid"; GROUP BY gg.itemid";
$sum_array = array(); $sum_array = array();
if ($sums = $DB->get_recordset_sql($sql, $params)) { $sums = $DB->get_recordset_sql($sql, $params);
foreach ($sums as $itemid => $csum) { foreach ($sums as $itemid => $csum) {
$sum_array[$itemid] = $csum->sum; $sum_array[$itemid] = $csum->sum;
}
$sums->close();
} }
$sums->close();
$columncount=0; $columncount=0;

View file

@ -80,26 +80,25 @@ $sql = "SELECT g.id AS groupid, gg.groupingid, u.id AS userid, u.firstname, u.la
WHERE g.courseid = :courseid $groupwhere $groupingwhere WHERE g.courseid = :courseid $groupwhere $groupingwhere
ORDER BY g.name, u.lastname, u.firstname"; ORDER BY g.name, u.lastname, u.firstname";
if ($rs = $DB->get_recordset_sql($sql, $params)) { $rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $row) { foreach ($rs as $row) {
$user = new stdClass(); $user = new stdClass();
$user->id = $row->userid; $user->id = $row->userid;
$user->firstname = $row->firstname; $user->firstname = $row->firstname;
$user->lastname = $row->lastname; $user->lastname = $row->lastname;
$user->username = $row->username; $user->username = $row->username;
$user->idnumber = $row->idnumber; $user->idnumber = $row->idnumber;
if (!$row->groupingid) { if (!$row->groupingid) {
$row->groupingid = -1; $row->groupingid = -1;
} }
if (!array_key_exists($row->groupid, $members[$row->groupingid])) { if (!array_key_exists($row->groupid, $members[$row->groupingid])) {
$members[$row->groupingid][$row->groupid] = array(); $members[$row->groupingid][$row->groupid] = array();
} }
if(isset($user->id)){ if(isset($user->id)){
$members[$row->groupingid][$row->groupid][] = $user; $members[$row->groupingid][$row->groupid][] = $user;
}
} }
$rs->close();
} }
$rs->close();
navigation_node::override_active_url(new moodle_url('/group/index.php', array('id'=>$courseid))); navigation_node::override_active_url(new moodle_url('/group/index.php', array('id'=>$courseid)));
$PAGE->navbar->add(get_string('overview', 'group')); $PAGE->navbar->add(get_string('overview', 'group'));

View file

@ -425,12 +425,11 @@ function get_role_access($roleid, $accessdata = null) {
if (!isset($ACCESSLIB_PRIVATE->croncache[$roleid])) { if (!isset($ACCESSLIB_PRIVATE->croncache[$roleid])) {
$ACCESSLIB_PRIVATE->croncache[$roleid] = array(); $ACCESSLIB_PRIVATE->croncache[$roleid] = array();
if ($rs = $DB->get_recordset_sql($sql, $params)) { $rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $rd) { foreach ($rs as $rd) {
$ACCESSLIB_PRIVATE->croncache[$roleid][] = $rd; $ACCESSLIB_PRIVATE->croncache[$roleid][] = $rd;
}
$rs->close();
} }
$rs->close();
} }
foreach ($ACCESSLIB_PRIVATE->croncache[$roleid] as $rd) { foreach ($ACCESSLIB_PRIVATE->croncache[$roleid] as $rd) {
@ -439,14 +438,15 @@ function get_role_access($roleid, $accessdata = null) {
} }
} else { } else {
if ($rs = $DB->get_recordset_sql($sql, $params)) { $rs = $DB->get_recordset_sql($sql, $params);
if ($rs->valid()) {
foreach ($rs as $rd) { foreach ($rs as $rd) {
$k = "{$rd->path}:{$roleid}"; $k = "{$rd->path}:{$roleid}";
$accessdata['rdef'][$k][$rd->capability] = $rd->permission; $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
} }
unset($rd); unset($rd);
$rs->close();
} }
$rs->close();
} }
return $accessdata; return $accessdata;
@ -480,14 +480,15 @@ function get_default_frontpage_role_access($roleid, $accessdata = null) {
ORDER BY ctx.depth, ctx.path"; ORDER BY ctx.depth, ctx.path";
$params = array($roleid, "$base/%"); $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) { foreach ($rs as $rd) {
$k = "{$rd->path}:{$roleid}"; $k = "{$rd->path}:{$roleid}";
$accessdata['rdef'][$k][$rd->capability] = $rd->permission; $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
} }
unset($rd); unset($rd);
$rs->close();
} }
$rs->close();
return $accessdata; return $accessdata;
} }
@ -1315,18 +1316,15 @@ function load_subcontext($userid, $context, &$accessdata) {
$params = array($context->id, $context->path."/%"); $params = array($context->id, $context->path."/%");
$newrdefs = array(); $newrdefs = array();
if ($rs = $DB->get_recordset_sql($sql, $params)) { $rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $rd) { foreach ($rs as $rd) {
$k = "{$rd->path}:{$rd->roleid}"; $k = "{$rd->path}:{$rd->roleid}";
if (!array_key_exists($k, $newrdefs)) { if (!array_key_exists($k, $newrdefs)) {
$newrdefs[$k] = array(); $newrdefs[$k] = array();
}
$newrdefs[$k][$rd->capability] = $rd->permission;
} }
$rs->close(); $newrdefs[$k][$rd->capability] = $rd->permission;
} else {
debugging('Bad SQL encountered!');
} }
$rs->close();
compact_rdefs($newrdefs); compact_rdefs($newrdefs);
foreach ($newrdefs as $key=>$value) { 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 "; ORDER BY ctx.depth ASC, ctx.path DESC, rc.roleid ASC ";
$params = array($roleid, $context->path."/%"); $params = array($roleid, $context->path."/%");
if ($rs = $DB->get_recordset_sql($sql, $params)) { $rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $rd) { foreach ($rs as $rd) {
$k = "{$rd->path}:{$roleid}"; $k = "{$rd->path}:{$roleid}";
$accessdata['rdef'][$k][$rd->capability] = $rd->permission; $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
}
$rs->close();
} }
$rs->close();
return $accessdata; return $accessdata;
} }
@ -1615,13 +1612,12 @@ function load_temp_role($context, $roleid, array $accessdata) {
AND rc.roleid = ? AND rc.roleid = ?
ORDER BY ctx.depth, ctx.path"; ORDER BY ctx.depth, ctx.path";
$params = array($context->path."/%", $roleid); $params = array($context->path."/%", $roleid);
if ($rs = $DB->get_recordset_sql($sql, $params)) { $rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $rd) { foreach ($rs as $rd) {
$k = "{$rd->path}:{$roleid}"; $k = "{$rd->path}:{$roleid}";
$accessdata['rdef'][$k][$rd->capability] = $rd->permission; $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
}
$rs->close();
} }
$rs->close();
// //
// Say we loaded everything for the course context // Say we loaded everything for the course context
@ -2132,12 +2128,11 @@ function cleanup_contexts() {
// transactions used only for performance reasons here // transactions used only for performance reasons here
$transaction = $DB->start_delegated_transaction(); $transaction = $DB->start_delegated_transaction();
if ($rs = $DB->get_recordset_sql($sql)) { $rs = $DB->get_recordset_sql($sql);
foreach ($rs as $ctx) { foreach ($rs as $ctx) {
delete_context($ctx->contextlevel, $ctx->instanceid); delete_context($ctx->contextlevel, $ctx->instanceid);
}
$rs->close();
} }
$rs->close();
$transaction->allow_commit(); $transaction->allow_commit();
return true; 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 // Note the result can be used directly as a context (we are going to), the course
// fields are just appended. // 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(); $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) { foreach ($rs as $coursecontext) {
if (has_capability($capability, $coursecontext, $userid, $doanything)) { if (has_capability($capability, $coursecontext, $userid, $doanything)) {
// We've got the capability. Make the record look like a course record // 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(); $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 // Loop through completions, and mark as complete
if ($rs = $DB->get_recordset_sql($sql)) { $rs = $DB->get_recordset_sql($sql);
foreach ($rs as $record) { foreach ($rs as $record) {
$completion = new completion_criteria_completion((array)$record); $completion = new completion_criteria_completion((array)$record);
$completion->mark_complete($record->timecompleted); $completion->mark_complete($record->timecompleted);
}
$rs->close();
} }
$rs->close();
} }
/** /**

View file

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

View file

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

View file

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

View file

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

View file

@ -38,15 +38,14 @@ function upgrade_fix_category_depths() {
$sql = "SELECT c.id $sql = "SELECT c.id
FROM {course_categories} c FROM {course_categories} c
WHERE c.parent > 0 AND c.parent NOT IN (SELECT pc.id FROM {course_categories} pc)"; WHERE c.parent > 0 AND c.parent NOT IN (SELECT pc.id FROM {course_categories} pc)";
if ($rs = $DB->get_recordset_sql($sql)) { $rs = $DB->get_recordset_sql($sql);
foreach ($rs as $cat) { foreach ($rs as $cat) {
$cat->depth = 1; $cat->depth = 1;
$cat->path = '/'.$cat->id; $cat->path = '/'.$cat->id;
$cat->parent = 0; $cat->parent = 0;
$DB->update_record('course_categories', $cat); $DB->update_record('course_categories', $cat);
}
$rs->close();
} }
$rs->close();
// now add path and depth to top level categories // now add path and depth to top level categories
$sql = "UPDATE {course_categories} $sql = "UPDATE {course_categories}
@ -60,14 +59,13 @@ function upgrade_fix_category_depths() {
$sql = "SELECT c.id, pc.path $sql = "SELECT c.id, pc.path
FROM {course_categories} c, {course_categories} pc FROM {course_categories} c, {course_categories} pc
WHERE c.parent=pc.id AND c.depth=0 AND pc.depth=?"; WHERE c.parent=pc.id AND c.depth=0 AND pc.depth=?";
if ($rs = $DB->get_recordset_sql($sql, array($parentdepth))) { $rs = $DB->get_recordset_sql($sql, array($parentdepth));
foreach ($rs as $cat) { foreach ($rs as $cat) {
$cat->depth = $parentdepth+1; $cat->depth = $parentdepth+1;
$cat->path = $cat->path.'/'.$cat->id; $cat->path = $cat->path.'/'.$cat->id;
$DB->update_record('course_categories', $cat); $DB->update_record('course_categories', $cat);
}
$rs->close();
} }
$rs->close();
$parentdepth++; $parentdepth++;
if ($parentdepth > 100) { if ($parentdepth > 100) {
//something must have gone wrong - nobody can have more than 100 levels of categories, right? //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'"); $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 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); $DB->update_record('post', $entry);
$pbar->update($i, $count, "Migrated blog attachments - $i/$count."); $pbar->update($i, $count, "Migrated blog attachments - $i/$count.");
} }
$rs->close();
} }
$rs->close();
@rmdir("$CFG->dataroot/blog/attachments/"); @rmdir("$CFG->dataroot/blog/attachments/");
@rmdir("$CFG->dataroot/blog/"); @rmdir("$CFG->dataroot/blog/");
@ -539,13 +539,12 @@ function upgrade_fix_incorrect_mnethostids() {
$params = array_merge($in_params, array($current_mnet_localhost_host->id)); $params = array_merge($in_params, array($current_mnet_localhost_host->id));
if ($rs = $DB->get_recordset_sql($sql, $params)) { $rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $rec) { foreach ($rs as $rec) {
$DB->set_field('user', 'mnethostid', $current_mnet_localhost_host->id, array('id' => $rec->id)); $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 upgrade_set_timeout(60); /// Give upgrade at least 60 more seconds
}
$rs->close();
} }
$rs->close();
// fix up any host records that have incorrect ids // 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)); $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('backup_sche_gradebook_history');
unset_config('disablescheduleddbackups'); unset_config('disablescheduleddbackups');
} }

View file

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

View file

@ -968,15 +968,14 @@ class oci_native_moodle_database extends moodle_database {
$strictness = (int)$strictness; $strictness = (int)$strictness;
if ($strictness == IGNORE_MULTIPLE) { if ($strictness == IGNORE_MULTIPLE) {
// do not limit here - ORA does not like that // do not limit here - ORA does not like that
if (!$rs = $this->get_recordset_sql($sql, $params)) { $rs = $this->get_recordset_sql($sql, $params);
return false; $result = false;
} foreach ($rs as $rec) {
foreach ($rs as $result) { $result = $rec;
$rs->close(); break;
return $result;
} }
$rs->close(); $rs->close();
return false; return $result;
} }
return parent::get_record_sql($sql, $params, $strictness); 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 * @return array of values
*/ */
public function get_fieldset_sql($sql, array $params=null) { 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; return false;
} }
$result = array(); $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. * @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) { 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; return false;
} }
$objects = array(); $objects = array();

View file

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

View file

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

View file

@ -481,7 +481,8 @@ class grade_category extends grade_object {
ORDER BY g.userid"; ORDER BY g.userid";
// group the results by userid and aggregate the grades for this user // 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; $prevuser = 0;
$grade_values = array(); $grade_values = array();
$excluded = array(); $excluded = array();
@ -506,9 +507,9 @@ class grade_category extends grade_object {
$oldgrade = $used; $oldgrade = $used;
} }
} }
$rs->close();
$this->aggregate_grades($prevuser, $items, $grade_values, $oldgrade, $excluded);//the last one $this->aggregate_grades($prevuser, $items, $grade_values, $oldgrade, $excluded);//the last one
} }
$rs->close();
return true; 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 $now = time(); // no rounding needed, this is not supposed to be called every 10 seconds
list($usql, $params) = $DB->get_in_or_equal($items); list($usql, $params) = $DB->get_in_or_equal($items);
$params[] = $now; $params[] = $now;
if ($rs = $DB->get_recordset_select('grade_grades', "itemid $usql AND locked = 0 AND locktime > 0 AND locktime < ?", $params)) { $rs = $DB->get_recordset_select('grade_grades', "itemid $usql AND locked = 0 AND locktime > 0 AND locktime < ?", $params);
foreach ($rs as $grade) { foreach ($rs as $grade) {
$grade_grade = new grade_grade($grade, false); $grade_grade = new grade_grade($grade, false);
$grade_grade->locked = time(); $grade_grade->locked = time();
$grade_grade->update('locktime'); $grade_grade->update('locktime');
}
$rs->close();
} }
$rs->close();
} }
/** /**

View file

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

View file

@ -1206,13 +1206,12 @@ function grade_uninstalled_module($modname) {
WHERE itemtype='mod' AND itemmodule=?"; WHERE itemtype='mod' AND itemmodule=?";
// go all items for this module and delete them including the grades // go all items for this module and delete them including the grades
if ($rs = $DB->get_recordset_sql($sql, array($modname))) { $rs = $DB->get_recordset_sql($sql, array($modname));
foreach ($rs as $item) { foreach ($rs as $item) {
$grade_item = new grade_item($item, false); $grade_item = new grade_item($item, false);
$grade_item->delete('moduninstall'); $grade_item->delete('moduninstall');
}
$rs->close();
} }
$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)"; 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 // go through all courses that have proper final grades and lock them if needed
if ($rs = $DB->get_recordset_sql($sql, array($now))) { $rs = $DB->get_recordset_sql($sql, array($now));
foreach ($rs as $item) { foreach ($rs as $item) {
$grade_item = new grade_item($item, false); $grade_item = new grade_item($item, false);
$grade_item->locked = $now; $grade_item->locked = $now;
$grade_item->update('locktime'); $grade_item->update('locktime');
}
$rs->close();
} }
$rs->close();
$grade_inst = new grade_grade(); $grade_inst = new grade_grade();
$fields = 'g.'.implode(',g.', $grade_inst->required_fields); $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)"; 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 // go through all courses that have proper final grades and lock them if needed
if ($rs = $DB->get_recordset_sql($sql, array($now))) { $rs = $DB->get_recordset_sql($sql, array($now));
foreach ($rs as $grade) { foreach ($rs as $grade) {
$grade_grade = new grade_grade($grade, false); $grade_grade = new grade_grade($grade, false);
$grade_grade->locked = $now; $grade_grade->locked = $now;
$grade_grade->update('locktime'); $grade_grade->update('locktime');
}
$rs->close();
} }
$rs->close();
//TODO: do not run this cleanup every cron invocation //TODO: do not run this cleanup every cron invocation
// cleanup history tables // cleanup history tables

View file

@ -199,7 +199,10 @@ function groups_get_user_groups($courseid, $userid=0) {
WHERE gm.userid = ? AND g.courseid = ?"; WHERE gm.userid = ? AND g.courseid = ?";
$params = array($userid, $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()); return array('0' => array());
} }

View file

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

View file

@ -269,24 +269,21 @@ function message_get_contacts($user1=null, &$user2=null) {
GROUP BY $userfields GROUP BY $userfields
ORDER BY u.firstname ASC"; ORDER BY u.firstname ASC";
if ($rs = $DB->get_recordset_sql($contactsql, array($user1->id, $user1->id))){ $rs = $DB->get_recordset_sql($contactsql, array($user1->id, $user1->id));
foreach($rs as $rd){ foreach ($rs as $rd) {
if ($rd->lastaccess >= $timefrom) {
// they have been active recently, so are counted online
$onlinecontacts[] = $rd;
if($rd->lastaccess >= $timefrom){ } else {
// they have been active recently, so are counted online $offlinecontacts[] = $rd;
$onlinecontacts[] = $rd; }
}else{ if (!empty($user2) && $user2->id==$rd->id) {
$offlinecontacts[] = $rd; $user2->iscontact = true;
}
if (!empty($user2) && $user2->id==$rd->id) {
$user2->iscontact = true;
}
} }
unset($rd);
$rs->close();
} }
$rs->close();
// get messages from anyone who isn't in our contact list and count the number // get messages from anyone who isn't in our contact list and count the number
// of messages we have from each of them // of messages we have from each of them
@ -298,13 +295,11 @@ function message_get_contacts($user1=null, &$user2=null) {
GROUP BY $userfields GROUP BY $userfields
ORDER BY u.firstname ASC"; ORDER BY u.firstname ASC";
if($rs = $DB->get_recordset_sql($strangersql, array($USER->id))){ $rs = $DB->get_recordset_sql($strangersql, array($USER->id));
foreach($rs as $rd){ foreach ($rs as $rd) {
$strangers[] = $rd; $strangers[] = $rd;
}
unset($rd);
$rs->close();
} }
$rs->close();
return array($onlinecontacts, $offlinecontacts, $strangers); return array($onlinecontacts, $offlinecontacts, $strangers);
} }

View file

@ -49,10 +49,10 @@ function xmldb_assignment_upgrade($oldversion) {
$count = $DB->count_records_sql("SELECT COUNT('x') $sqlfrom"); $count = $DB->count_records_sql("SELECT COUNT('x') $sqlfrom");
if ($rs = $DB->get_recordset_sql("SELECT s.id, s.userid, s.teacher, s.assignment, a.course, cm.id AS cmid $sqlfrom ORDER BY a.course, s.assignment")) { $rs = $DB->get_recordset_sql("SELECT s.id, s.userid, s.teacher, s.assignment, a.course, cm.id AS cmid $sqlfrom ORDER BY a.course, s.assignment");
if ($rs->valid()) {
$pbar = new progress_bar('migrateassignmentfiles', 500, true); $pbar = new progress_bar('migrateassignmentfiles', 500, true);
$i = 0; $i = 0;
foreach ($rs as $submission) { foreach ($rs as $submission) {
$i++; $i++;
@ -122,9 +122,8 @@ function xmldb_assignment_upgrade($oldversion) {
@rmdir("$CFG->dataroot/$submission->course/$CFG->moddata/assignment/$submission->assignment"); @rmdir("$CFG->dataroot/$submission->course/$CFG->moddata/assignment/$submission->assignment");
@rmdir("$CFG->dataroot/$submission->course/$CFG->moddata/assignment"); @rmdir("$CFG->dataroot/$submission->course/$CFG->moddata/assignment");
} }
$rs->close();
} }
$rs->close();
upgrade_mod_savepoint(true, 2008081900, 'assignment'); upgrade_mod_savepoint(true, 2008081900, 'assignment');
} }

View file

@ -2688,7 +2688,8 @@ function assignment_upgrade_grades() {
$sql = "SELECT a.*, cm.idnumber AS cmidnumber, a.course AS courseid $sql = "SELECT a.*, cm.idnumber AS cmidnumber, a.course AS courseid
FROM {assignment} a, {course_modules} cm, {modules} m FROM {assignment} a, {course_modules} cm, {modules} m
WHERE m.name='assignment' AND m.id=cm.module AND cm.instance=a.id"; WHERE m.name='assignment' AND m.id=cm.module AND cm.instance=a.id";
if ($rs = $DB->get_recordset_sql($sql)) { $rs = $DB->get_recordset_sql($sql);
if ($rs->valid()) {
// too much debug output // too much debug output
$pbar = new progress_bar('assignmentupgradegrades', 500, true); $pbar = new progress_bar('assignmentupgradegrades', 500, true);
$i=0; $i=0;
@ -2698,9 +2699,9 @@ function assignment_upgrade_grades() {
assignment_update_grades($assignment); assignment_update_grades($assignment);
$pbar->update($i, $count, "Updating Assignment grades ($i/$count)."); $pbar->update($i, $count, "Updating Assignment grades ($i/$count).");
} }
$rs->close();
upgrade_set_timeout(); // reset to default timeout upgrade_set_timeout(); // reset to default timeout
} }
$rs->close();
} }
/** /**

View file

@ -55,16 +55,16 @@ function xmldb_data_upgrade($oldversion) {
} }
if ($oldversion < 2008081400) { if ($oldversion < 2008081400) {
if ($rs = $DB->get_recordset('data')) { $pattern = '/\#\#delete\#\#(\s+)\#\#approve\#\#/';
$pattern = '/\#\#delete\#\#(\s+)\#\#approve\#\#/'; $replacement = '##delete##$1##approve##$1##export##';
$replacement = '##delete##$1##approve##$1##export##'; $rs = $DB->get_recordset('data');
foreach ($rs as $data) { foreach ($rs as $data) {
$data->listtemplate = preg_replace($pattern, $replacement, $data->listtemplate); $data->listtemplate = preg_replace($pattern, $replacement, $data->listtemplate);
$data->singletemplate = preg_replace($pattern, $replacement, $data->singletemplate); $data->singletemplate = preg_replace($pattern, $replacement, $data->singletemplate);
$DB->update_record('data', $data); $DB->update_record('data', $data);
}
$rs->close();
} }
$rs->close();
upgrade_mod_savepoint(true, 2008081400, 'data'); upgrade_mod_savepoint(true, 2008081400, 'data');
} }
@ -89,8 +89,9 @@ function xmldb_data_upgrade($oldversion) {
$count = $DB->count_records_sql("SELECT COUNT('x') $sqlfrom"); $count = $DB->count_records_sql("SELECT COUNT('x') $sqlfrom");
if ($rs = $DB->get_recordset_sql("SELECT c.id, f.type, r.dataid, c.recordid, f.id AS fieldid, r.userid, c.content, c.content1, d.course, r.userid, cm.id AS cmid $sqlfrom ORDER BY d.course, d.id")) { $rs = $DB->get_recordset_sql("SELECT c.id, f.type, r.dataid, c.recordid, f.id AS fieldid, r.userid, c.content, c.content1, d.course, r.userid, cm.id AS cmid $sqlfrom ORDER BY d.course, d.id");
if ($rs->valid()) {
$pbar = new progress_bar('migratedatafiles', 500, true); $pbar = new progress_bar('migratedatafiles', 500, true);
$i = 0; $i = 0;
@ -142,8 +143,9 @@ function xmldb_data_upgrade($oldversion) {
@rmdir("$CFG->dataroot/$content->course/$CFG->moddata/data"); @rmdir("$CFG->dataroot/$content->course/$CFG->moddata/data");
@rmdir("$CFG->dataroot/$content->course/$CFG->moddata"); @rmdir("$CFG->dataroot/$content->course/$CFG->moddata");
} }
$rs->close();
} }
$rs->close();
upgrade_mod_savepoint(true, 2008091400, 'data'); upgrade_mod_savepoint(true, 2008091400, 'data');
} }
@ -218,31 +220,31 @@ function xmldb_data_upgrade($oldversion) {
$lastdataid = null; $lastdataid = null;
$lastcourseid = null; $lastcourseid = null;
$modcontext = null; $modcontext = null;
if ($rs = $DB->get_recordset_sql($sql)) { $rs = $DB->get_recordset_sql($sql);
foreach($rs as $res) { foreach($rs as $res) {
if ($res->dataid != $lastdataid || $res->courseid != $lastcourseid) { if ($res->dataid != $lastdataid || $res->courseid != $lastcourseid) {
$cm = get_coursemodule_from_instance('data', $res->dataid, $res->courseid); $cm = get_coursemodule_from_instance('data', $res->dataid, $res->courseid);
if ($cm) { if ($cm) {
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
}
$lastdataid = $res->dataid;
$lastcourseid = $res->courseid;
}
$cmt = new stdClass();
$cmt->contextid = $modcontext->id;
$cmt->commentarea = 'database_entry';
$cmt->itemid = $res->itemid;
$cmt->content = $res->commentcontent;
$cmt->format = $res->format;
$cmt->userid = $res->userid;
$cmt->timecreated = $res->timecreated;
// comments class will throw an exception if error occurs
$cmt_id = $DB->insert_record('comments', $cmt);
if (!empty($cmt_id)) {
$DB->delete_records('data_comments', array('id'=>$res->commentid));
} }
$lastdataid = $res->dataid;
$lastcourseid = $res->courseid;
}
$cmt = new stdClass();
$cmt->contextid = $modcontext->id;
$cmt->commentarea = 'database_entry';
$cmt->itemid = $res->itemid;
$cmt->content = $res->commentcontent;
$cmt->format = $res->format;
$cmt->userid = $res->userid;
$cmt->timecreated = $res->timecreated;
// comments class will throw an exception if error occurs
$cmt_id = $DB->insert_record('comments', $cmt);
if (!empty($cmt_id)) {
$DB->delete_records('data_comments', array('id'=>$res->commentid));
} }
} }
$rs->close();
// the default exception handler will stop the script if error occurs before // the default exception handler will stop the script if error occurs before
$dbman->drop_table($table); $dbman->drop_table($table);
} }

View file

@ -361,13 +361,14 @@ class data_field_base { // Base class for Database Field Types (see field/*/
$conditions = array('fieldid'=>$this->field->id); $conditions = array('fieldid'=>$this->field->id);
} }
if ($rs = $DB->get_recordset('data_content', $conditions)) { $rs = $DB->get_recordset('data_content', $conditions);
if ($rs->valid()) {
$fs = get_file_storage(); $fs = get_file_storage();
foreach ($rs as $content) { foreach ($rs as $content) {
$fs->delete_area_files($this->context->id, 'mod_data', 'content', $content->id); $fs->delete_area_files($this->context->id, 'mod_data', 'content', $content->id);
} }
$rs->close();
} }
$rs->close();
return $DB->delete_records('data_content', $conditions); return $DB->delete_records('data_content', $conditions);
} }
@ -1071,7 +1072,8 @@ function data_upgrade_grades() {
$sql = "SELECT d.*, cm.idnumber AS cmidnumber, d.course AS courseid $sql = "SELECT d.*, cm.idnumber AS cmidnumber, d.course AS courseid
FROM {data} d, {course_modules} cm, {modules} m FROM {data} d, {course_modules} cm, {modules} m
WHERE m.name='data' AND m.id=cm.module AND cm.instance=d.id"; WHERE m.name='data' AND m.id=cm.module AND cm.instance=d.id";
if ($rs = $DB->get_recordset_sql($sql)) { $rs = $DB->get_recordset_sql($sql);
if ($rs->valid()) {
// too much debug output // too much debug output
$pbar = new progress_bar('dataupgradegrades', 500, true); $pbar = new progress_bar('dataupgradegrades', 500, true);
$i=0; $i=0;
@ -1081,8 +1083,8 @@ function data_upgrade_grades() {
data_update_grades($data, 0, false); data_update_grades($data, 0, false);
$pbar->update($i, $count, "Updating Database grades ($i/$count)."); $pbar->update($i, $count, "Updating Database grades ($i/$count).");
} }
$rs->close();
} }
$rs->close();
} }
/** /**
@ -2448,39 +2450,38 @@ function data_reset_userdata($data) {
$course_context = get_context_instance(CONTEXT_COURSE, $data->courseid); $course_context = get_context_instance(CONTEXT_COURSE, $data->courseid);
$notenrolled = array(); $notenrolled = array();
$fields = array(); $fields = array();
if ($rs = $DB->get_recordset_sql($recordssql, array($data->courseid))) { $rs = $DB->get_recordset_sql($recordssql, array($data->courseid));
foreach ($rs as $record) { foreach ($rs as $record) {
if (array_key_exists($record->userid, $notenrolled) or !$record->userexists or $record->userdeleted if (array_key_exists($record->userid, $notenrolled) or !$record->userexists or $record->userdeleted
or !is_enrolled($course_context, $record->userid)) { or !is_enrolled($course_context, $record->userid)) {
//delete ratings //delete ratings
if (!$cm = get_coursemodule_from_instance('data', $record->dataid)) { if (!$cm = get_coursemodule_from_instance('data', $record->dataid)) {
continue; continue;
}
$datacontext = get_context_instance(CONTEXT_MODULE, $cm->id);
$ratingdeloptions->contextid = $datacontext->id;
$ratingdeloptions->itemid = $record->id;
$rm->delete_ratings($ratingdeloptions);
$DB->delete_records('comments', array('itemid'=>$record->id, 'commentarea'=>'database_entry'));
$DB->delete_records('data_content', array('recordid'=>$record->id));
$DB->delete_records('data_records', array('id'=>$record->id));
// HACK: this is ugly - the recordid should be before the fieldid!
if (!array_key_exists($record->dataid, $fields)) {
if ($fs = $DB->get_records('data_fields', array('dataid'=>$record->dataid))) {
$fields[$record->dataid] = array_keys($fs);
} else {
$fields[$record->dataid] = array();
}
}
foreach($fields[$record->dataid] as $fieldid) {
fulldelete("$CFG->dataroot/$data->courseid/moddata/data/$record->dataid/$fieldid/$record->id");
}
$notenrolled[$record->userid] = true;
} }
$datacontext = get_context_instance(CONTEXT_MODULE, $cm->id);
$ratingdeloptions->contextid = $datacontext->id;
$ratingdeloptions->itemid = $record->id;
$rm->delete_ratings($ratingdeloptions);
$DB->delete_records('comments', array('itemid'=>$record->id, 'commentarea'=>'database_entry'));
$DB->delete_records('data_content', array('recordid'=>$record->id));
$DB->delete_records('data_records', array('id'=>$record->id));
// HACK: this is ugly - the recordid should be before the fieldid!
if (!array_key_exists($record->dataid, $fields)) {
if ($fs = $DB->get_records('data_fields', array('dataid'=>$record->dataid))) {
$fields[$record->dataid] = array_keys($fs);
} else {
$fields[$record->dataid] = array();
}
}
foreach($fields[$record->dataid] as $fieldid) {
fulldelete("$CFG->dataroot/$data->courseid/moddata/data/$record->dataid/$fieldid/$record->id");
}
$notenrolled[$record->userid] = true;
} }
$rs->close();
$status[] = array('component'=>$componentstr, 'item'=>get_string('deletenotenrolled', 'data'), 'error'=>false);
} }
$rs->close();
$status[] = array('component'=>$componentstr, 'item'=>get_string('deletenotenrolled', 'data'), 'error'=>false);
} }
// remove all ratings // remove all ratings

View file

@ -48,7 +48,10 @@ function folder_20_migrate() {
return; return;
} }
if (!$candidates = $DB->get_recordset('resource_old', array('type'=>'directory', 'migrated'=>0))) { $candidates = $DB->get_recordset('resource_old', array('type'=>'directory', 'migrated'=>0));
if (!$candidates->valid()) {
$candidates->close(); // Not going to iterate (but exit), close rs
return; return;
} }
@ -101,4 +104,4 @@ function folder_20_migrate() {
// clear all course modinfo caches // clear all course modinfo caches
rebuild_course_cache(0, true); rebuild_course_cache(0, true);
} }

View file

@ -104,7 +104,8 @@ function xmldb_forum_upgrade($oldversion) {
$count = $DB->count_records_sql("SELECT COUNT('x') $sqlfrom"); $count = $DB->count_records_sql("SELECT COUNT('x') $sqlfrom");
if ($rs = $DB->get_recordset_sql("SELECT p.id, p.attachment, p.userid, d.forum, f.course, cm.id AS cmid $sqlfrom ORDER BY f.course, f.id, d.id")) { $rs = $DB->get_recordset_sql("SELECT p.id, p.attachment, p.userid, d.forum, f.course, cm.id AS cmid $sqlfrom ORDER BY f.course, f.id, d.id");
if ($rs->valid()) {
$pbar = new progress_bar('migrateforumfiles', 500, true); $pbar = new progress_bar('migrateforumfiles', 500, true);
@ -146,8 +147,8 @@ function xmldb_forum_upgrade($oldversion) {
@rmdir("$CFG->dataroot/$post->course/$CFG->moddata/forum/$post->forum"); @rmdir("$CFG->dataroot/$post->course/$CFG->moddata/forum/$post->forum");
@rmdir("$CFG->dataroot/$post->course/$CFG->moddata/forum"); @rmdir("$CFG->dataroot/$post->course/$CFG->moddata/forum");
} }
$rs->close();
} }
$rs->close();
upgrade_mod_savepoint(true, 2008081900, 'forum'); upgrade_mod_savepoint(true, 2008081900, 'forum');
} }

View file

@ -1504,7 +1504,8 @@ function forum_upgrade_grades() {
$sql = "SELECT f.*, cm.idnumber AS cmidnumber, f.course AS courseid $sql = "SELECT f.*, cm.idnumber AS cmidnumber, f.course AS courseid
FROM {forum} f, {course_modules} cm, {modules} m FROM {forum} f, {course_modules} cm, {modules} m
WHERE m.name='forum' AND m.id=cm.module AND cm.instance=f.id"; WHERE m.name='forum' AND m.id=cm.module AND cm.instance=f.id";
if ($rs = $DB->get_recordset_sql($sql)) { $rs = $DB->get_recordset_sql($sql);
if ($rs->valid()) {
$pbar = new progress_bar('forumupgradegrades', 500, true); $pbar = new progress_bar('forumupgradegrades', 500, true);
$i=0; $i=0;
foreach ($rs as $forum) { foreach ($rs as $forum) {
@ -1513,8 +1514,8 @@ function forum_upgrade_grades() {
forum_update_grades($forum, 0, false); forum_update_grades($forum, 0, false);
$pbar->update($i, $count, "Updating Forum grades ($i/$count)."); $pbar->update($i, $count, "Updating Forum grades ($i/$count).");
} }
$rs->close();
} }
$rs->close();
} }
/** /**

View file

@ -45,7 +45,8 @@ function xmldb_glossary_upgrade($oldversion) {
$count = $DB->count_records_sql("SELECT COUNT('x') $sqlfrom"); $count = $DB->count_records_sql("SELECT COUNT('x') $sqlfrom");
if ($rs = $DB->get_recordset_sql("SELECT ge.id, ge.userid, ge.attachment, ge.glossaryid, ge.sourceglossaryid, g.course, cm.id AS cmid $sqlfrom ORDER BY g.course, g.id")) { $rs = $DB->get_recordset_sql("SELECT ge.id, ge.userid, ge.attachment, ge.glossaryid, ge.sourceglossaryid, g.course, cm.id AS cmid $sqlfrom ORDER BY g.course, g.id");
if ($rs->valid()) {
$pbar = new progress_bar('migrateglossaryfiles', 500, true); $pbar = new progress_bar('migrateglossaryfiles', 500, true);
@ -92,8 +93,8 @@ function xmldb_glossary_upgrade($oldversion) {
@rmdir("$CFG->dataroot/$entry->course/$CFG->moddata/glossary/$entry->glossaryid"); @rmdir("$CFG->dataroot/$entry->course/$CFG->moddata/glossary/$entry->glossaryid");
@rmdir("$CFG->dataroot/$entry->course/$CFG->moddata/glossary"); @rmdir("$CFG->dataroot/$entry->course/$CFG->moddata/glossary");
} }
$rs->close();
} }
$rs->close();
upgrade_mod_savepoint(true, 2008081900, 'glossary'); upgrade_mod_savepoint(true, 2008081900, 'glossary');
} }
@ -240,30 +241,30 @@ function xmldb_glossary_upgrade($oldversion) {
$modcontext = null; $modcontext = null;
/// move glossary comments to comments table /// move glossary comments to comments table
if ($rs = $DB->get_recordset_sql($sql)) { $rs = $DB->get_recordset_sql($sql);
foreach($rs as $res) { foreach($rs as $res) {
if ($res->glossaryid != $lastglossaryid || $res->courseid != $lastcourseid) { if ($res->glossaryid != $lastglossaryid || $res->courseid != $lastcourseid) {
$cm = get_coursemodule_from_instance('glossary', $res->glossaryid, $res->courseid); $cm = get_coursemodule_from_instance('glossary', $res->glossaryid, $res->courseid);
if ($cm) { if ($cm) {
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
}
$lastglossaryid = $res->glossaryid;
$lastcourseid = $res->courseid;
}
$cmt = new stdClass();
$cmt->contextid = $modcontext->id;
$cmt->commentarea = 'glossary_entry';
$cmt->itemid = $res->itemid;
$cmt->content = $res->commentcontent;
$cmt->format = $res->format;
$cmt->userid = $res->userid;
$cmt->timecreated = $res->timemodified;
$cmt_id = $DB->insert_record('comments', $cmt);
if (!empty($cmt_id)) {
$DB->delete_records('glossary_comments', array('id'=>$res->old_id));
} }
$lastglossaryid = $res->glossaryid;
$lastcourseid = $res->courseid;
}
$cmt = new stdClass();
$cmt->contextid = $modcontext->id;
$cmt->commentarea = 'glossary_entry';
$cmt->itemid = $res->itemid;
$cmt->content = $res->commentcontent;
$cmt->format = $res->format;
$cmt->userid = $res->userid;
$cmt->timecreated = $res->timemodified;
$cmt_id = $DB->insert_record('comments', $cmt);
if (!empty($cmt_id)) {
$DB->delete_records('glossary_comments', array('id'=>$res->old_id));
} }
} }
$rs->close();
$dbman->drop_table($table); $dbman->drop_table($table);
} }

View file

@ -506,7 +506,8 @@ function glossary_upgrade_grades() {
$sql = "SELECT g.*, cm.idnumber AS cmidnumber, g.course AS courseid $sql = "SELECT g.*, cm.idnumber AS cmidnumber, g.course AS courseid
FROM {glossary} g, {course_modules} cm, {modules} m FROM {glossary} g, {course_modules} cm, {modules} m
WHERE m.name='glossary' AND m.id=cm.module AND cm.instance=g.id"; WHERE m.name='glossary' AND m.id=cm.module AND cm.instance=g.id";
if ($rs = $DB->get_recordset_sql($sql)) { $rs = $DB->get_recordset_sql($sql);
if ($rs->valid()) {
$pbar = new progress_bar('glossaryupgradegrades', 500, true); $pbar = new progress_bar('glossaryupgradegrades', 500, true);
$i=0; $i=0;
foreach ($rs as $glossary) { foreach ($rs as $glossary) {
@ -515,8 +516,8 @@ function glossary_upgrade_grades() {
glossary_update_grades($glossary, 0, false); glossary_update_grades($glossary, 0, false);
$pbar->update($i, $count, "Updating Glossary grades ($i/$count)."); $pbar->update($i, $count, "Updating Glossary grades ($i/$count).");
} }
$rs->close();
} }
$rs->close();
} }
/** /**
@ -2462,7 +2463,8 @@ function glossary_reset_userdata($data) {
$course_context = get_context_instance(CONTEXT_COURSE, $data->courseid); $course_context = get_context_instance(CONTEXT_COURSE, $data->courseid);
$notenrolled = array(); $notenrolled = array();
if ($rs = $DB->get_recordset_sql($entriessql, $params)) { $rs = $DB->get_recordset_sql($entriessql, $params);
if ($rs->valid()) {
foreach ($rs as $entry) { foreach ($rs as $entry) {
if (array_key_exists($entry->userid, $notenrolled) or !$entry->userexists or $entry->userdeleted if (array_key_exists($entry->userid, $notenrolled) or !$entry->userexists or $entry->userdeleted
or !is_enrolled($course_context , $entry->userid)) { or !is_enrolled($course_context , $entry->userid)) {
@ -2479,9 +2481,9 @@ function glossary_reset_userdata($data) {
} }
} }
} }
$rs->close();
$status[] = array('component'=>$componentstr, 'item'=>get_string('deletenotenrolled', 'glossary'), 'error'=>false); $status[] = array('component'=>$componentstr, 'item'=>get_string('deletenotenrolled', 'glossary'), 'error'=>false);
} }
$rs->close();
} }
// remove all ratings // remove all ratings

View file

@ -49,7 +49,9 @@ function imscp_20_migrate() {
return; return;
} }
if (!$candidates = $DB->get_recordset('resource_old', array('type'=>'ims', 'migrated'=>0))) { $candidates = $DB->get_recordset('resource_old', array('type'=>'ims', 'migrated'=>0));
if (!$candidates->valid()) {
$candidates->close(); // Not going to iterate (but exit), close rs
return; return;
} }
@ -133,7 +135,6 @@ function imscp_20_migrate() {
fulldelete($root); fulldelete($root);
} }
} }
$candidates->close(); $candidates->close();
// clear all course modinfo caches // clear all course modinfo caches

View file

@ -429,7 +429,8 @@ function lesson_upgrade_grades() {
$sql = "SELECT l.*, cm.idnumber AS cmidnumber, l.course AS courseid $sql = "SELECT l.*, cm.idnumber AS cmidnumber, l.course AS courseid
FROM {lesson} l, {course_modules} cm, {modules} m FROM {lesson} l, {course_modules} cm, {modules} m
WHERE m.name='lesson' AND m.id=cm.module AND cm.instance=l.id"; WHERE m.name='lesson' AND m.id=cm.module AND cm.instance=l.id";
if ($rs = $DB->get_recordset_sql($sql)) { $rs = $DB->get_recordset_sql($sql);
if ($rs->valid()) {
$pbar = new progress_bar('lessonupgradegrades', 500, true); $pbar = new progress_bar('lessonupgradegrades', 500, true);
$i=0; $i=0;
foreach ($rs as $lesson) { foreach ($rs as $lesson) {
@ -438,8 +439,8 @@ function lesson_upgrade_grades() {
lesson_update_grades($lesson, 0, false); lesson_update_grades($lesson, 0, false);
$pbar->update($i, $count, "Updating Lesson grades ($i/$count)."); $pbar->update($i, $count, "Updating Lesson grades ($i/$count).");
} }
$rs->close();
} }
$rs->close();
} }
/** /**

View file

@ -51,24 +51,22 @@ function page_20_migrate() {
$fs = get_file_storage(); $fs = get_file_storage();
if ($candidates = $DB->get_recordset('resource_old', array('type'=>'html', 'migrated'=>0))) { $candidates = $DB->get_recordset('resource_old', array('type'=>'html', 'migrated'=>0));
foreach ($candidates as $candidate) { foreach ($candidates as $candidate) {
page_20_migrate_candidate($candidate, $fs, FORMAT_HTML); page_20_migrate_candidate($candidate, $fs, FORMAT_HTML);
}
$candidates->close();
} }
$candidates->close();
if ($candidates = $DB->get_recordset('resource_old', array('type'=>'text', 'migrated'=>0))) { $candidates = $DB->get_recordset('resource_old', array('type'=>'text', 'migrated'=>0));
foreach ($candidates as $candidate) { foreach ($candidates as $candidate) {
//there might be some rubbish instead of format int value //there might be some rubbish instead of format int value
$format = (int)$candidate->reference; $format = (int)$candidate->reference;
if ($format < 0 or $format > 4) { if ($format < 0 or $format > 4) {
$format = FORMAT_MOODLE; $format = FORMAT_MOODLE;
}
page_20_migrate_candidate($candidate, $fs, $format);
} }
$candidates->close(); page_20_migrate_candidate($candidate, $fs, $format);
} }
$candidates->close();
// clear all course modinfo caches // clear all course modinfo caches
rebuild_course_cache(0, true); rebuild_course_cache(0, true);

View file

@ -604,7 +604,8 @@ function quiz_upgrade_grades() {
$sql = "SELECT a.*, cm.idnumber AS cmidnumber, a.course AS courseid $sql = "SELECT a.*, cm.idnumber AS cmidnumber, a.course AS courseid
FROM {quiz} a, {course_modules} cm, {modules} m FROM {quiz} a, {course_modules} cm, {modules} m
WHERE m.name='quiz' AND m.id=cm.module AND cm.instance=a.id"; WHERE m.name='quiz' AND m.id=cm.module AND cm.instance=a.id";
if ($rs = $DB->get_recordset_sql($sql)) { $rs = $DB->get_recordset_sql($sql);
if ($rs->valid()) {
$pbar = new progress_bar('quizupgradegrades', 500, true); $pbar = new progress_bar('quizupgradegrades', 500, true);
$i=0; $i=0;
foreach ($rs as $quiz) { foreach ($rs as $quiz) {
@ -613,8 +614,8 @@ function quiz_upgrade_grades() {
quiz_update_grades($quiz, 0, false); quiz_update_grades($quiz, 0, false);
$pbar->update($i, $count, "Updating Quiz grades ($i/$count)."); $pbar->update($i, $count, "Updating Quiz grades ($i/$count).");
} }
$rs->close();
} }
$rs->close();
} }
/** /**

View file

@ -226,17 +226,17 @@ function xmldb_resource_upgrade($oldversion) {
JOIN {modules} m ON m.name='resource' JOIN {modules} m ON m.name='resource'
JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = r.id)"; JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = r.id)";
if ($instances = $DB->get_recordset_sql($sql)) { $instances = $DB->get_recordset_sql($sql);
foreach ($instances as $instance) { foreach ($instances as $instance) {
$context = get_context_instance(CONTEXT_MODULE, $instance->cmid); $context = get_context_instance(CONTEXT_MODULE, $instance->cmid);
$component = 'mod_resource'; $component = 'mod_resource';
$filearea = 'content'; $filearea = 'content';
$itemid = 0; $itemid = 0;
$filepath = file_correct_filepath(dirname($instance->mainfile)); $filepath = file_correct_filepath(dirname($instance->mainfile));
$filename = basename($instance->mainfile); $filename = basename($instance->mainfile);
file_set_sortorder($context->id, $component, $filearea, $itemid, $filepath, $filename, 1); file_set_sortorder($context->id, $component, $filearea, $itemid, $filepath, $filename, 1);
}
} }
$instances->close();
/// Define field mainfile to be dropped from resource /// Define field mainfile to be dropped from resource
$table = new xmldb_table('resource'); $table = new xmldb_table('resource');

View file

@ -42,7 +42,9 @@ function resource_20_migrate() {
$withrelativelinks = array('text/html', 'text/xml', 'application/xhtml+xml', 'application/x-shockwave-flash'); $withrelativelinks = array('text/html', 'text/xml', 'application/xhtml+xml', 'application/x-shockwave-flash');
// note: pdf doc and other types may contain links too, but we do not support relative links there // note: pdf doc and other types may contain links too, but we do not support relative links there
if (!$candidates = $DB->get_recordset('resource_old', array('type'=>'file', 'migrated'=>0))) { $candidates = $DB->get_recordset('resource_old', array('type'=>'file', 'migrated'=>0));
if (!$candidates->valid()) {
$candidates->close(); // Not going to iterate (but exit), close rs
return; return;
} }

View file

@ -140,7 +140,8 @@ function xmldb_scorm_upgrade($oldversion) {
$count = $DB->count_records_sql("SELECT COUNT('x') $sqlfrom"); $count = $DB->count_records_sql("SELECT COUNT('x') $sqlfrom");
if ($rs = $DB->get_recordset_sql("SELECT s.id, s.scormtype, s.reference, s.course, cm.id AS cmid $sqlfrom ORDER BY s.course, s.id")) { $rs = $DB->get_recordset_sql("SELECT s.id, s.scormtype, s.reference, s.course, cm.id AS cmid $sqlfrom ORDER BY s.course, s.id");
if ($rs->valid()) {
$pbar = new progress_bar('migratescormfiles', 500, true); $pbar = new progress_bar('migratescormfiles', 500, true);
@ -213,8 +214,8 @@ function xmldb_scorm_upgrade($oldversion) {
@rmdir("$CFG->dataroot/$scorm->course/$CFG->moddata/scorm/"); @rmdir("$CFG->dataroot/$scorm->course/$CFG->moddata/scorm/");
@rmdir("$CFG->dataroot/$scorm->course/$CFG->moddata/"); @rmdir("$CFG->dataroot/$scorm->course/$CFG->moddata/");
} }
$rs->close();
} }
$rs->close();
/// scorm savepoint reached /// scorm savepoint reached
upgrade_mod_savepoint(true, 2008090304, 'scorm'); upgrade_mod_savepoint(true, 2008090304, 'scorm');

View file

@ -575,7 +575,8 @@ function scorm_upgrade_grades() {
$sql = "SELECT s.*, cm.idnumber AS cmidnumber, s.course AS courseid $sql = "SELECT s.*, cm.idnumber AS cmidnumber, s.course AS courseid
FROM {scorm} s, {course_modules} cm, {modules} m FROM {scorm} s, {course_modules} cm, {modules} m
WHERE m.name='scorm' AND m.id=cm.module AND cm.instance=s.id"; WHERE m.name='scorm' AND m.id=cm.module AND cm.instance=s.id";
if ($rs = $DB->get_recordset_sql($sql)) { $rs = $DB->get_recordset_sql($sql);
if ($rs->valid()) {
$pbar = new progress_bar('scormupgradegrades', 500, true); $pbar = new progress_bar('scormupgradegrades', 500, true);
$i=0; $i=0;
foreach ($rs as $scorm) { foreach ($rs as $scorm) {
@ -584,8 +585,8 @@ function scorm_upgrade_grades() {
scorm_update_grades($scorm, 0, false); scorm_update_grades($scorm, 0, false);
$pbar->update($i, $count, "Updating Scorm grades ($i/$count)."); $pbar->update($i, $count, "Updating Scorm grades ($i/$count).");
} }
$rs->close();
} }
$rs->close();
} }
/** /**

View file

@ -232,13 +232,15 @@ function survey_print_recent_activity($course, $viewfullnames, $timestart) {
$slist = implode(',', $ids); // there should not be hundreds of glossaries in one course, right? $slist = implode(',', $ids); // there should not be hundreds of glossaries in one course, right?
if (!$rs = $DB->get_recordset_sql("SELECT sa.userid, sa.survey, MAX(sa.time) AS time, $rs = $DB->get_recordset_sql("SELECT sa.userid, sa.survey, MAX(sa.time) AS time,
u.firstname, u.lastname, u.email, u.picture u.firstname, u.lastname, u.email, u.picture
FROM {survey_answers} sa FROM {survey_answers} sa
JOIN {user} u ON u.id = sa.userid JOIN {user} u ON u.id = sa.userid
WHERE sa.survey IN ($slist) AND sa.time > ? WHERE sa.survey IN ($slist) AND sa.time > ?
GROUP BY sa.userid, sa.survey, u.firstname, u.lastname, u.email, u.picture GROUP BY sa.userid, sa.survey, u.firstname, u.lastname, u.email, u.picture
ORDER BY time ASC", array($timestart))) { ORDER BY time ASC", array($timestart));
if (!$rs->valid()) {
$rs->close(); // Not going to iterate (but exit), close rs
return false; return false;
} }

View file

@ -50,7 +50,9 @@ function url_20_migrate() {
return; return;
} }
if (!$candidates = $DB->get_recordset('resource_old', array('type'=>'file', 'migrated'=>0))) { $candidates = $DB->get_recordset('resource_old', array('type'=>'file', 'migrated'=>0));
if (!$candidates->valid()) {
$candidates->close(); // Not going to iterate (but exit), close rs
return; return;
} }
@ -135,4 +137,4 @@ function url_20_migrate() {
// clear all course modinfo caches // clear all course modinfo caches
rebuild_course_cache(0, true); rebuild_course_cache(0, true);
} }

View file

@ -409,16 +409,15 @@ function tag_get_id($tags, $return_value=null) {
list($tag_string, $params) = $DB->get_in_or_equal($tags); list($tag_string, $params) = $DB->get_in_or_equal($tags);
if ($rs = $DB->get_recordset_sql("SELECT * FROM {tag} WHERE name $tag_string ORDER BY name", $params)) { $rs = $DB->get_recordset_sql("SELECT * FROM {tag} WHERE name $tag_string ORDER BY name", $params);
foreach ($rs as $record) { foreach ($rs as $record) {
if ($return_value == TAG_RETURN_OBJECT) { if ($return_value == TAG_RETURN_OBJECT) {
$result[$record->name] = $record; $result[$record->name] = $record;
} else { // TAG_RETURN_ARRAY } else { // TAG_RETURN_ARRAY
$result[$record->name] = $record->id; $result[$record->name] = $record->id;
}
} }
$rs->close();
} }
$rs->close();
if ($return_an_int) { if ($return_an_int) {
return array_pop($result); return array_pop($result);

View file

@ -763,12 +763,11 @@ class group_non_members_selector extends groups_user_selector_base {
JOIN {groups} g ON gm.groupid = g.id JOIN {groups} g ON gm.groupid = g.id
WHERE u.id $membersidsclause AND g.courseid = :courseid "; WHERE u.id $membersidsclause AND g.courseid = :courseid ";
$params['courseid'] = $courseid; $params['courseid'] = $courseid;
if ($rs = $DB->get_recordset_sql($sql, $params)) { $rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $usergroup) { foreach ($rs as $usergroup) {
$usergroups[$usergroup->userid][$usergroup->id] = $usergroup; $usergroups[$usergroup->userid][$usergroup->id] = $usergroup;
}
$rs->close();
} }
$rs->close();
foreach ($potentialmembersids as $userid) { foreach ($potentialmembersids as $userid) {
if (isset($usergroups[$userid])) { if (isset($usergroups[$userid])) {