mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 00:16:46 +02:00
Merge branch 'MDL-25708' of git://github.com/stronk7/moodle
This commit is contained in:
commit
8afc38bd39
53 changed files with 514 additions and 526 deletions
|
@ -56,7 +56,7 @@ foreach ($tables as $table) {
|
|||
if (in_array($data->type, array('text','mediumtext','longtext','varchar'))) { // Text stuff only
|
||||
// first find candidate records
|
||||
$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) {
|
||||
$text = $data->$column;
|
||||
$id = $data->id;
|
||||
|
@ -88,7 +88,6 @@ foreach ($tables as $table) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set conversion flag - switches to new plugin automatically
|
||||
set_config('filter_multilang_converted', 1);
|
||||
|
|
|
@ -11,7 +11,7 @@ function add_selection_all($ufiltering) {
|
|||
|
||||
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) {
|
||||
if (!isset($SESSION->bulk_users[$user->id])) {
|
||||
$SESSION->bulk_users[$user->id] = $user->id;
|
||||
|
@ -19,7 +19,6 @@ function add_selection_all($ufiltering) {
|
|||
}
|
||||
$rs->close();
|
||||
}
|
||||
}
|
||||
|
||||
function get_selection_data($ufiltering) {
|
||||
global $SESSION, $DB, $CFG;
|
||||
|
|
|
@ -24,7 +24,7 @@ echo $OUTPUT->header();
|
|||
|
||||
if ($confirm and confirm_sesskey()) {
|
||||
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) {
|
||||
if ($user->confirmed) {
|
||||
continue;
|
||||
|
@ -36,7 +36,6 @@ if ($confirm and confirm_sesskey()) {
|
|||
}
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
redirect($return, get_string('changessaved'));
|
||||
|
||||
} else {
|
||||
|
|
|
@ -25,7 +25,7 @@ echo $OUTPUT->header();
|
|||
if ($confirm and confirm_sesskey()) {
|
||||
|
||||
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) {
|
||||
if (!is_siteadmin($user) and $USER->id != $user->id and delete_user($user)) {
|
||||
unset($SESSION->bulk_users[$user->id]);
|
||||
|
@ -34,7 +34,6 @@ if ($confirm and confirm_sesskey()) {
|
|||
}
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
session_gc(); // remove stale sessions
|
||||
redirect($return, get_string('changessaved'));
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ if ($confirm and confirm_sesskey()) {
|
|||
$parts = array_chunk($SESSION->bulk_users, 300);
|
||||
foreach ($parts as $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) {
|
||||
if (!empty($changeable[$user->auth])) {
|
||||
set_user_preference('auth_forcepasswordchange', 1, $user->id);
|
||||
|
@ -49,7 +49,6 @@ if ($confirm and confirm_sesskey()) {
|
|||
}
|
||||
$rs->close();
|
||||
}
|
||||
}
|
||||
echo $OUTPUT->notification(get_string('changessaved'), 'notifysuccess');
|
||||
echo $OUTPUT->continue_button($return);
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ if (empty($CFG->messaging)) {
|
|||
|
||||
if ($confirm and !empty($msg) and confirm_sesskey()) {
|
||||
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) {
|
||||
//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
|
||||
|
@ -33,7 +33,6 @@ if ($confirm and !empty($msg) and confirm_sesskey()) {
|
|||
message_post_message($USER, $user, $msg, FORMAT_HTML, 'direct');
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
redirect($return);
|
||||
}
|
||||
|
||||
|
|
|
@ -1757,7 +1757,7 @@ function rebuild_course_cache($courseid=0, $clearonly=false) {
|
|||
@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) {
|
||||
$modinfo = serialize(get_array_of_activities($course->id));
|
||||
$DB->set_field("course", "modinfo", $modinfo, array("id"=>$course->id));
|
||||
|
@ -1767,7 +1767,6 @@ function rebuild_course_cache($courseid=0, $clearonly=false) {
|
|||
}
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
// reset the fast modinfo cache
|
||||
$reset = 'reset';
|
||||
get_fast_modinfo($reset);
|
||||
|
|
|
@ -400,7 +400,8 @@ switch ($mode) {
|
|||
}
|
||||
|
||||
// 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) {
|
||||
$error = get_string('nocompletions', 'coursereport_completion');
|
||||
|
@ -409,6 +410,7 @@ switch ($mode) {
|
|||
}
|
||||
|
||||
echo $OUTPUT->notification($error);
|
||||
$rs->close(); // not going to loop (but break), close rs
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -437,8 +439,7 @@ switch ($mode) {
|
|||
$courses['unstarted'][] = $c_info;
|
||||
}
|
||||
}
|
||||
|
||||
$rs->close();
|
||||
$rs->close(); // after loop, close rs
|
||||
|
||||
// Loop through course status groups
|
||||
foreach ($courses as $type => $infos) {
|
||||
|
|
|
@ -194,7 +194,9 @@ function send_welcome_messages($orderdata) {
|
|||
WHERE e.id IN(" . implode(',', $orderdata) . ")
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -247,7 +249,7 @@ function send_welcome_messages($orderdata) {
|
|||
}
|
||||
while ($ei);
|
||||
|
||||
$rs->close();
|
||||
$rs->close(); // end of iteration, close rs
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -634,12 +634,11 @@ class grade_report_user extends grade_report {
|
|||
GROUP BY gg.itemid";
|
||||
|
||||
$sum_array = array();
|
||||
if ($sums = $DB->get_recordset_sql($sql, $params)) {
|
||||
$sums = $DB->get_recordset_sql($sql, $params);
|
||||
foreach ($sums as $itemid => $csum) {
|
||||
$sum_array[$itemid] = $csum->sum;
|
||||
}
|
||||
$sums->close();
|
||||
}
|
||||
|
||||
$columncount=0;
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ $sql = "SELECT g.id AS groupid, gg.groupingid, u.id AS userid, u.firstname, u.la
|
|||
WHERE g.courseid = :courseid $groupwhere $groupingwhere
|
||||
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) {
|
||||
$user = new stdClass();
|
||||
$user->id = $row->userid;
|
||||
|
@ -99,7 +99,6 @@ if ($rs = $DB->get_recordset_sql($sql, $params)) {
|
|||
}
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
navigation_node::override_active_url(new moodle_url('/group/index.php', array('id'=>$courseid)));
|
||||
$PAGE->navbar->add(get_string('overview', 'group'));
|
||||
|
|
|
@ -425,13 +425,12 @@ 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)) {
|
||||
$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) {
|
||||
$k = "{$rd->path}:{$roleid}";
|
||||
|
@ -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,7 +1316,7 @@ function load_subcontext($userid, $context, &$accessdata) {
|
|||
$params = array($context->id, $context->path."/%");
|
||||
|
||||
$newrdefs = array();
|
||||
if ($rs = $DB->get_recordset_sql($sql, $params)) {
|
||||
$rs = $DB->get_recordset_sql($sql, $params);
|
||||
foreach ($rs as $rd) {
|
||||
$k = "{$rd->path}:{$rd->roleid}";
|
||||
if (!array_key_exists($k, $newrdefs)) {
|
||||
|
@ -1324,9 +1325,6 @@ function load_subcontext($userid, $context, &$accessdata) {
|
|||
$newrdefs[$k][$rd->capability] = $rd->permission;
|
||||
}
|
||||
$rs->close();
|
||||
} else {
|
||||
debugging('Bad SQL encountered!');
|
||||
}
|
||||
|
||||
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)) {
|
||||
$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)) {
|
||||
$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)) {
|
||||
$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
|
||||
$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")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$orderby");
|
||||
// Check capability for each course in turn
|
||||
$courses = array();
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -228,16 +228,14 @@ class completion_criteria_activity extends completion_criteria {
|
|||
';
|
||||
|
||||
// Loop through completions, and mark as complete
|
||||
if ($rs = $DB->get_recordset_sql($sql)) {
|
||||
$rs = $DB->get_recordset_sql($sql);
|
||||
foreach ($rs as $record) {
|
||||
|
||||
$completion = new completion_criteria_completion((array)$record);
|
||||
$completion->mark_complete($record->timecompleted);
|
||||
}
|
||||
|
||||
$rs->close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return criteria progress details for display in reports
|
||||
|
|
|
@ -185,15 +185,13 @@ class completion_criteria_course extends completion_criteria {
|
|||
";
|
||||
|
||||
// Loop through completions, and mark as complete
|
||||
if ($rs = $DB->get_recordset_sql($sql)) {
|
||||
$rs = $DB->get_recordset_sql($sql);
|
||||
foreach ($rs as $record) {
|
||||
$completion = new completion_criteria_completion((array)$record);
|
||||
$completion->mark_complete($record->timecompleted);
|
||||
}
|
||||
|
||||
$rs->close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return criteria progress details for display in reports
|
||||
|
|
|
@ -178,16 +178,13 @@ class completion_criteria_date extends completion_criteria {
|
|||
';
|
||||
|
||||
// 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) {
|
||||
|
||||
$completion = new completion_criteria_completion((array)$record);
|
||||
$completion->mark_complete($record->timeend);
|
||||
}
|
||||
|
||||
$rs->close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return criteria progress details for display in reports
|
||||
|
|
|
@ -219,7 +219,7 @@ 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))) {
|
||||
$rs = $DB->get_recordset_sql($sql, array($now, $now));
|
||||
foreach ($rs as $record) {
|
||||
|
||||
$completion = new completion_criteria_completion((array)$record);
|
||||
|
@ -227,15 +227,12 @@ class completion_criteria_duration extends completion_criteria {
|
|||
// Use time start if not 0, otherwise use timeenrolled
|
||||
if ($record->otimestart) {
|
||||
$completion->mark_complete($record->ctimestart);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$completion->mark_complete($record->ctimeenrolled);
|
||||
}
|
||||
}
|
||||
|
||||
$rs->close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return criteria progress details for display in reports
|
||||
|
|
|
@ -214,16 +214,13 @@ class completion_criteria_grade extends completion_criteria {
|
|||
';
|
||||
|
||||
// Loop through completions, and mark as complete
|
||||
if ($rs = $DB->get_recordset_sql($sql)) {
|
||||
$rs = $DB->get_recordset_sql($sql);
|
||||
foreach ($rs as $record) {
|
||||
|
||||
$completion = new completion_criteria_completion((array)$record);
|
||||
$completion->mark_complete($record->timecompleted);
|
||||
}
|
||||
|
||||
$rs->close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return criteria progress details for display in reports
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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,20 +761,21 @@ 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;
|
||||
|
||||
$rs = $DB->get_recordset_sql($sql, $params);
|
||||
foreach($rs as $course) {
|
||||
context_instance_preload($course);
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
|
@ -792,7 +790,6 @@ function get_courses_search($searchterms, $sort='fullname ASC', $page=0, $record
|
|||
}
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
// our caller expects 2 bits of data - our return
|
||||
// array, and an updated $totalcount
|
||||
|
@ -857,7 +854,7 @@ function get_categories($parent='none', $sort=NULL, $shallow=true) {
|
|||
}
|
||||
$categories = array();
|
||||
|
||||
if( $rs = $DB->get_recordset_sql($sql, $params) ){
|
||||
$rs = $DB->get_recordset_sql($sql, $params);
|
||||
foreach($rs as $cat) {
|
||||
context_instance_preload($cat);
|
||||
$catcontext = get_context_instance(CONTEXT_COURSECAT, $cat->id);
|
||||
|
@ -866,7 +863,6 @@ function get_categories($parent='none', $sort=NULL, $shallow=true) {
|
|||
}
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
return $categories;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ 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)) {
|
||||
$rs = $DB->get_recordset_sql($sql);
|
||||
foreach ($rs as $cat) {
|
||||
$cat->depth = 1;
|
||||
$cat->path = '/'.$cat->id;
|
||||
|
@ -46,7 +46,6 @@ function upgrade_fix_category_depths() {
|
|||
$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))) {
|
||||
$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)) {
|
||||
$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));
|
||||
|
|
|
@ -1550,13 +1550,11 @@ 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)) {
|
||||
$mrs = $this->get_recordset_sql($sql, $params, 0, 1);
|
||||
$return = $mrs->valid();
|
||||
$mrs->close();
|
||||
return $return;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the records from a table where all the given conditions met.
|
||||
|
|
|
@ -968,16 +968,15 @@ 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;
|
||||
$rs = $this->get_recordset_sql($sql, $params);
|
||||
$result = false;
|
||||
foreach ($rs as $rec) {
|
||||
$result = $rec;
|
||||
break;
|
||||
}
|
||||
foreach ($rs as $result) {
|
||||
$rs->close();
|
||||
return $result;
|
||||
}
|
||||
$rs->close();
|
||||
return false;
|
||||
}
|
||||
return parent::get_record_sql($sql, $params, $strictness);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -435,7 +435,7 @@ function events_cron($eventname='') {
|
|||
$params = array();
|
||||
}
|
||||
|
||||
if ($rs = $DB->get_recordset_sql($sql, $params)) {
|
||||
$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
|
||||
|
@ -453,7 +453,6 @@ function events_cron($eventname='') {
|
|||
}
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
// remove events that do not have any handlers waiting
|
||||
$sql = "SELECT eq.id
|
||||
|
|
|
@ -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... ', '');
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -390,7 +390,7 @@ 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)) {
|
||||
$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();
|
||||
|
@ -398,7 +398,6 @@ class grade_grade extends grade_object {
|
|||
}
|
||||
$rs->close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the locktime for this grade.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -1206,14 +1206,13 @@ 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))) {
|
||||
$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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all user data from gradebook.
|
||||
|
@ -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))) {
|
||||
$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))) {
|
||||
$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
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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)) {
|
||||
$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();
|
||||
}
|
||||
|
||||
/// 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)) {
|
||||
$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();
|
||||
}
|
||||
|
||||
/// 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)) {
|
||||
$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
|
||||
|
|
|
@ -269,9 +269,8 @@ function message_get_contacts($user1=null, &$user2=null) {
|
|||
GROUP BY $userfields
|
||||
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) {
|
||||
|
||||
if ($rd->lastaccess >= $timefrom) {
|
||||
// they have been active recently, so are counted online
|
||||
$onlinecontacts[] = $rd;
|
||||
|
@ -284,9 +283,7 @@ function message_get_contacts($user1=null, &$user2=null) {
|
|||
$user2->iscontact = true;
|
||||
}
|
||||
}
|
||||
unset($rd);
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
// get messages from anyone who isn't in our contact list and count the number
|
||||
// of messages we have from each of them
|
||||
|
@ -298,13 +295,11 @@ function message_get_contacts($user1=null, &$user2=null) {
|
|||
GROUP BY $userfields
|
||||
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) {
|
||||
$strangers[] = $rd;
|
||||
}
|
||||
unset($rd);
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
return array($onlinecontacts, $offlinecontacts, $strangers);
|
||||
}
|
||||
|
|
|
@ -49,10 +49,10 @@ function xmldb_assignment_upgrade($oldversion) {
|
|||
|
||||
$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);
|
||||
|
||||
$i = 0;
|
||||
foreach ($rs as $submission) {
|
||||
$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");
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
upgrade_mod_savepoint(true, 2008081900, 'assignment');
|
||||
}
|
||||
|
|
|
@ -2688,7 +2688,8 @@ function assignment_upgrade_grades() {
|
|||
$sql = "SELECT a.*, cm.idnumber AS cmidnumber, a.course AS courseid
|
||||
FROM {assignment} a, {course_modules} cm, {modules} m
|
||||
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
|
||||
$pbar = new progress_bar('assignmentupgradegrades', 500, true);
|
||||
$i=0;
|
||||
|
@ -2698,9 +2699,9 @@ function assignment_upgrade_grades() {
|
|||
assignment_update_grades($assignment);
|
||||
$pbar->update($i, $count, "Updating Assignment grades ($i/$count).");
|
||||
}
|
||||
$rs->close();
|
||||
upgrade_set_timeout(); // reset to default timeout
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -55,16 +55,16 @@ function xmldb_data_upgrade($oldversion) {
|
|||
}
|
||||
|
||||
if ($oldversion < 2008081400) {
|
||||
if ($rs = $DB->get_recordset('data')) {
|
||||
$pattern = '/\#\#delete\#\#(\s+)\#\#approve\#\#/';
|
||||
$replacement = '##delete##$1##approve##$1##export##';
|
||||
$rs = $DB->get_recordset('data');
|
||||
foreach ($rs as $data) {
|
||||
$data->listtemplate = preg_replace($pattern, $replacement, $data->listtemplate);
|
||||
$data->singletemplate = preg_replace($pattern, $replacement, $data->singletemplate);
|
||||
$DB->update_record('data', $data);
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
upgrade_mod_savepoint(true, 2008081400, 'data');
|
||||
}
|
||||
|
||||
|
@ -89,8 +89,9 @@ function xmldb_data_upgrade($oldversion) {
|
|||
|
||||
$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);
|
||||
|
||||
$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");
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
upgrade_mod_savepoint(true, 2008091400, 'data');
|
||||
}
|
||||
|
||||
|
@ -218,7 +220,7 @@ function xmldb_data_upgrade($oldversion) {
|
|||
$lastdataid = null;
|
||||
$lastcourseid = null;
|
||||
$modcontext = null;
|
||||
if ($rs = $DB->get_recordset_sql($sql)) {
|
||||
$rs = $DB->get_recordset_sql($sql);
|
||||
foreach($rs as $res) {
|
||||
if ($res->dataid != $lastdataid || $res->courseid != $lastcourseid) {
|
||||
$cm = get_coursemodule_from_instance('data', $res->dataid, $res->courseid);
|
||||
|
@ -242,7 +244,7 @@ function xmldb_data_upgrade($oldversion) {
|
|||
$DB->delete_records('data_comments', array('id'=>$res->commentid));
|
||||
}
|
||||
}
|
||||
}
|
||||
$rs->close();
|
||||
// the default exception handler will stop the script if error occurs before
|
||||
$dbman->drop_table($table);
|
||||
}
|
||||
|
|
|
@ -361,13 +361,14 @@ class data_field_base { // Base class for Database Field Types (see field/*/
|
|||
$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();
|
||||
foreach ($rs as $content) {
|
||||
$fs->delete_area_files($this->context->id, 'mod_data', 'content', $content->id);
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
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
|
||||
FROM {data} d, {course_modules} cm, {modules} m
|
||||
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
|
||||
$pbar = new progress_bar('dataupgradegrades', 500, true);
|
||||
$i=0;
|
||||
|
@ -1081,8 +1083,8 @@ function data_upgrade_grades() {
|
|||
data_update_grades($data, 0, false);
|
||||
$pbar->update($i, $count, "Updating Database grades ($i/$count).");
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2448,7 +2450,7 @@ function data_reset_userdata($data) {
|
|||
$course_context = get_context_instance(CONTEXT_COURSE, $data->courseid);
|
||||
$notenrolled = 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) {
|
||||
if (array_key_exists($record->userid, $notenrolled) or !$record->userexists or $record->userdeleted
|
||||
or !is_enrolled($course_context, $record->userid)) {
|
||||
|
@ -2481,7 +2483,6 @@ function data_reset_userdata($data) {
|
|||
$rs->close();
|
||||
$status[] = array('component'=>$componentstr, 'item'=>get_string('deletenotenrolled', 'data'), 'error'=>false);
|
||||
}
|
||||
}
|
||||
|
||||
// remove all ratings
|
||||
if (!empty($data->reset_data_ratings)) {
|
||||
|
|
|
@ -48,7 +48,10 @@ function folder_20_migrate() {
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -104,7 +104,8 @@ function xmldb_forum_upgrade($oldversion) {
|
|||
|
||||
$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);
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
upgrade_mod_savepoint(true, 2008081900, 'forum');
|
||||
}
|
||||
|
|
|
@ -1504,7 +1504,8 @@ function forum_upgrade_grades() {
|
|||
$sql = "SELECT f.*, cm.idnumber AS cmidnumber, f.course AS courseid
|
||||
FROM {forum} f, {course_modules} cm, {modules} m
|
||||
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);
|
||||
$i=0;
|
||||
foreach ($rs as $forum) {
|
||||
|
@ -1513,8 +1514,8 @@ function forum_upgrade_grades() {
|
|||
forum_update_grades($forum, 0, false);
|
||||
$pbar->update($i, $count, "Updating Forum grades ($i/$count).");
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -45,7 +45,8 @@ function xmldb_glossary_upgrade($oldversion) {
|
|||
|
||||
$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);
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
upgrade_mod_savepoint(true, 2008081900, 'glossary');
|
||||
}
|
||||
|
@ -240,7 +241,7 @@ function xmldb_glossary_upgrade($oldversion) {
|
|||
$modcontext = null;
|
||||
|
||||
/// move glossary comments to comments table
|
||||
if ($rs = $DB->get_recordset_sql($sql)) {
|
||||
$rs = $DB->get_recordset_sql($sql);
|
||||
foreach($rs as $res) {
|
||||
if ($res->glossaryid != $lastglossaryid || $res->courseid != $lastcourseid) {
|
||||
$cm = get_coursemodule_from_instance('glossary', $res->glossaryid, $res->courseid);
|
||||
|
@ -263,7 +264,7 @@ function xmldb_glossary_upgrade($oldversion) {
|
|||
$DB->delete_records('glossary_comments', array('id'=>$res->old_id));
|
||||
}
|
||||
}
|
||||
}
|
||||
$rs->close();
|
||||
$dbman->drop_table($table);
|
||||
}
|
||||
|
||||
|
|
|
@ -506,7 +506,8 @@ function glossary_upgrade_grades() {
|
|||
$sql = "SELECT g.*, cm.idnumber AS cmidnumber, g.course AS courseid
|
||||
FROM {glossary} g, {course_modules} cm, {modules} m
|
||||
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);
|
||||
$i=0;
|
||||
foreach ($rs as $glossary) {
|
||||
|
@ -515,8 +516,8 @@ function glossary_upgrade_grades() {
|
|||
glossary_update_grades($glossary, 0, false);
|
||||
$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);
|
||||
$notenrolled = array();
|
||||
if ($rs = $DB->get_recordset_sql($entriessql, $params)) {
|
||||
$rs = $DB->get_recordset_sql($entriessql, $params);
|
||||
if ($rs->valid()) {
|
||||
foreach ($rs as $entry) {
|
||||
if (array_key_exists($entry->userid, $notenrolled) or !$entry->userexists or $entry->userdeleted
|
||||
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);
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
// remove all ratings
|
||||
|
|
|
@ -49,7 +49,9 @@ function imscp_20_migrate() {
|
|||
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;
|
||||
}
|
||||
|
||||
|
@ -133,7 +135,6 @@ function imscp_20_migrate() {
|
|||
fulldelete($root);
|
||||
}
|
||||
}
|
||||
|
||||
$candidates->close();
|
||||
|
||||
// clear all course modinfo caches
|
||||
|
|
|
@ -429,7 +429,8 @@ function lesson_upgrade_grades() {
|
|||
$sql = "SELECT l.*, cm.idnumber AS cmidnumber, l.course AS courseid
|
||||
FROM {lesson} l, {course_modules} cm, {modules} m
|
||||
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);
|
||||
$i=0;
|
||||
foreach ($rs as $lesson) {
|
||||
|
@ -438,8 +439,8 @@ function lesson_upgrade_grades() {
|
|||
lesson_update_grades($lesson, 0, false);
|
||||
$pbar->update($i, $count, "Updating Lesson grades ($i/$count).");
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -51,14 +51,13 @@ function page_20_migrate() {
|
|||
|
||||
$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) {
|
||||
page_20_migrate_candidate($candidate, $fs, FORMAT_HTML);
|
||||
}
|
||||
$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) {
|
||||
//there might be some rubbish instead of format int value
|
||||
$format = (int)$candidate->reference;
|
||||
|
@ -68,7 +67,6 @@ function page_20_migrate() {
|
|||
page_20_migrate_candidate($candidate, $fs, $format);
|
||||
}
|
||||
$candidates->close();
|
||||
}
|
||||
|
||||
// clear all course modinfo caches
|
||||
rebuild_course_cache(0, true);
|
||||
|
|
|
@ -604,7 +604,8 @@ function quiz_upgrade_grades() {
|
|||
$sql = "SELECT a.*, cm.idnumber AS cmidnumber, a.course AS courseid
|
||||
FROM {quiz} a, {course_modules} cm, {modules} m
|
||||
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);
|
||||
$i=0;
|
||||
foreach ($rs as $quiz) {
|
||||
|
@ -613,8 +614,8 @@ function quiz_upgrade_grades() {
|
|||
quiz_update_grades($quiz, 0, false);
|
||||
$pbar->update($i, $count, "Updating Quiz grades ($i/$count).");
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -226,7 +226,7 @@ function xmldb_resource_upgrade($oldversion) {
|
|||
JOIN {modules} m ON m.name='resource'
|
||||
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) {
|
||||
$context = get_context_instance(CONTEXT_MODULE, $instance->cmid);
|
||||
$component = 'mod_resource';
|
||||
|
@ -236,7 +236,7 @@ function xmldb_resource_upgrade($oldversion) {
|
|||
$filename = basename($instance->mainfile);
|
||||
file_set_sortorder($context->id, $component, $filearea, $itemid, $filepath, $filename, 1);
|
||||
}
|
||||
}
|
||||
$instances->close();
|
||||
|
||||
/// Define field mainfile to be dropped from resource
|
||||
$table = new xmldb_table('resource');
|
||||
|
|
|
@ -42,7 +42,9 @@ function resource_20_migrate() {
|
|||
$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
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -140,7 +140,8 @@ function xmldb_scorm_upgrade($oldversion) {
|
|||
|
||||
$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);
|
||||
|
||||
|
@ -213,8 +214,8 @@ function xmldb_scorm_upgrade($oldversion) {
|
|||
@rmdir("$CFG->dataroot/$scorm->course/$CFG->moddata/scorm/");
|
||||
@rmdir("$CFG->dataroot/$scorm->course/$CFG->moddata/");
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
/// scorm savepoint reached
|
||||
upgrade_mod_savepoint(true, 2008090304, 'scorm');
|
||||
|
|
|
@ -575,7 +575,8 @@ function scorm_upgrade_grades() {
|
|||
$sql = "SELECT s.*, cm.idnumber AS cmidnumber, s.course AS courseid
|
||||
FROM {scorm} s, {course_modules} cm, {modules} m
|
||||
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);
|
||||
$i=0;
|
||||
foreach ($rs as $scorm) {
|
||||
|
@ -584,8 +585,8 @@ function scorm_upgrade_grades() {
|
|||
scorm_update_grades($scorm, 0, false);
|
||||
$pbar->update($i, $count, "Updating Scorm grades ($i/$count).");
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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?
|
||||
|
||||
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
|
||||
FROM {survey_answers} sa
|
||||
JOIN {user} u ON u.id = sa.userid
|
||||
WHERE sa.survey IN ($slist) AND sa.time > ?
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,9 @@ function url_20_migrate() {
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -409,7 +409,7 @@ function tag_get_id($tags, $return_value=null) {
|
|||
|
||||
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) {
|
||||
if ($return_value == TAG_RETURN_OBJECT) {
|
||||
$result[$record->name] = $record;
|
||||
|
@ -418,7 +418,6 @@ function tag_get_id($tags, $return_value=null) {
|
|||
}
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
if ($return_an_int) {
|
||||
return array_pop($result);
|
||||
|
|
|
@ -763,12 +763,11 @@ class group_non_members_selector extends groups_user_selector_base {
|
|||
JOIN {groups} g ON gm.groupid = g.id
|
||||
WHERE u.id $membersidsclause AND g.courseid = :courseid ";
|
||||
$params['courseid'] = $courseid;
|
||||
if ($rs = $DB->get_recordset_sql($sql, $params)) {
|
||||
$rs = $DB->get_recordset_sql($sql, $params);
|
||||
foreach ($rs as $usergroup) {
|
||||
$usergroups[$usergroup->userid][$usergroup->id] = $usergroup;
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
foreach ($potentialmembersids as $userid) {
|
||||
if (isset($usergroups[$userid])) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue