function hotpot_update_to_v2_1_2() {\r
global $CFG, $db;\r
$ok = true;\r
- // hotpot_attempts: make sure there is only one "in progress" attempt by each user on each hotpot (and it must be the most recent attempt)\r
- // get info about attempts (grouped by user and hotpot)\r
- // countrecords : number of attempts in the group\r
- // maxtimestart : most recent timestart in the group\r
- // minstatus : minimum status in the group\r
- // (groups with only one attempt, or no "in progess" attempt are ignored)\r
- $records = get_records_sql("\r
- SELECT id, userid, hotpot, COUNT(*) as countrecords, MAX(timestart) AS maxtimestart, MIN(status) as minstatus\r
+\r
+ // save and switch off SQL message echo\r
+ $debug = $db->debug;\r
+ $db->debug = false;\r
+\r
+ // extract info about attempts by each user on each hotpot (cases where \r
+ // the user has only one attempt, or no "in progess" attempt are ignored)\r
+ $rs = $db->Execute("\r
+ SELECT userid, hotpot, COUNT(*), MIN(status)\r
FROM {$CFG->prefix}hotpot_attempts\r
GROUP BY userid, hotpot\r
- HAVING countrecords > 1 AND minstatus=1\r
+ HAVING COUNT(*)>1 AND MIN(status)=1\r
");\r
- if ($records) {\r
- // save and switch off SQL message echo\r
- $debug = $db->debug;\r
- $db->debug = false;\r
+ if ($rs && $rs->RecordCount()) {\r
+ $records = $rs->GetArray();\r
+\r
+ // start message to browser\r
print "adjusting status of ".count($records)." "in progress" attempts ... ";\r
+\r
+ // loop through records\r
foreach ($records as $record) {\r
+\r
// get all attempts by this user at this hotpot\r
$attempts = get_records_sql("\r
SELECT id, userid, hotpot, score, timestart, timefinish, status \r
FROM {$CFG->prefix}hotpot_attempts \r
- WHERE userid = $record->userid AND hotpot=$record->hotpot\r
+ WHERE userid = ".$record['userid']." AND hotpot=".$record['hotpot']."\r
ORDER BY timestart DESC, id DESC\r
");\r
+\r
unset($previous_timestart);\r
+\r
foreach ($attempts as $attempt) {\r
// if this attempt has a status of "in progress" and is not \r
// the most recent one in the group, set the status to "abandoned"\r
$previous_timestart = $attempt->timestart;\r
} // end foreach $attempts\r
} // end foreach $records\r
+\r
+ // finish message to browser\r
print $ok ? get_string('success') : 'failed';\r
print "<br />\n";\r
- // restore SQL message echo setting\r
- $db->debug = $debug;\r
}\r
+\r
+ // restore SQL message echo setting\r
+ $db->debug = $debug;\r
+\r
return $ok;\r
}\r
function hotpot_update_to_v2_1() {\r