mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
slight modificaition to the function which updates from v1.2.0 or v1.2.1 to v1.2.2, so as to catch all incorrectly labelled "in progress" attempts
This commit is contained in:
parent
5c3706b27d
commit
e2f9f968cc
1 changed files with 24 additions and 21 deletions
|
@ -1,7 +1,7 @@
|
||||||
<?PHP
|
<?PHP
|
||||||
|
|
||||||
function hotpot_update_to_v2_1_2() {
|
function hotpot_update_to_v2_1_2() {
|
||||||
global $CFG;
|
global $CFG, $db;
|
||||||
$ok = true;
|
$ok = true;
|
||||||
|
|
||||||
// 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)
|
// 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)
|
||||||
|
@ -12,43 +12,45 @@ function hotpot_update_to_v2_1_2() {
|
||||||
// minstatus : minimum status in the group
|
// minstatus : minimum status in the group
|
||||||
// (groups with only one attempt, or no "in progess" attempt are ignored)
|
// (groups with only one attempt, or no "in progess" attempt are ignored)
|
||||||
$records = get_records_sql("
|
$records = get_records_sql("
|
||||||
SELECT userid, hotpot, COUNT(*) as countrecords, MAX(timestart) AS maxtimestart, MIN(status) as minstatus
|
SELECT id, userid, hotpot, COUNT(*) as countrecords, MAX(timestart) AS maxtimestart, MIN(status) as minstatus
|
||||||
FROM {$CFG->prefix}hotpot_attempts
|
FROM {$CFG->prefix}hotpot_attempts
|
||||||
GROUP BY userid, hotpot
|
GROUP BY userid, hotpot
|
||||||
HAVING countrecords > 1 AND minstatus=1
|
HAVING countrecords > 1 AND minstatus=1
|
||||||
");
|
");
|
||||||
|
|
||||||
// save and switch off SQL message echo
|
|
||||||
global $db;
|
|
||||||
$debug = $db->debug;
|
|
||||||
$db->debug = false;
|
|
||||||
|
|
||||||
if ($records) {
|
if ($records) {
|
||||||
|
|
||||||
|
// save and switch off SQL message echo
|
||||||
|
$debug = $db->debug;
|
||||||
|
$db->debug = false;
|
||||||
|
|
||||||
print "adjusting status of ".count($records)." "in progress" attempts ... ";
|
print "adjusting status of ".count($records)." "in progress" attempts ... ";
|
||||||
|
|
||||||
foreach ($records as $record) {
|
foreach ($records as $record) {
|
||||||
// get all attempts (except the most recent one) by this user at this hotpot
|
// get all attempts by this user at this hotpot
|
||||||
$attempts = get_records_sql("
|
$attempts = get_records_sql("
|
||||||
SELECT id, userid, hotpot, timestart, status
|
SELECT id, userid, hotpot, score, timestart, timefinish, status
|
||||||
FROM {$CFG->prefix}hotpot_attempts
|
FROM {$CFG->prefix}hotpot_attempts
|
||||||
WHERE userid = $record->userid AND hotpot=$record->hotpot AND timestart<$record->maxtimestart
|
WHERE userid = $record->userid AND hotpot=$record->hotpot
|
||||||
ORDER BY timestart DESC
|
ORDER BY timestart DESC, id DESC
|
||||||
");
|
");
|
||||||
|
|
||||||
$previous_timestart = $record->maxtimestart;
|
unset($previous_timestart);
|
||||||
|
|
||||||
// loop through the attempts and reset any "in progress" records to be "abandoned"
|
|
||||||
foreach ($attempts as $attempt) {
|
foreach ($attempts as $attempt) {
|
||||||
if ($attempt->status==1) { // in progress
|
|
||||||
$values = 'status=3'; // abandoned
|
// if this attempt has a status of "in progress" and is not
|
||||||
|
// the most recent one in the group, set the status to "abandoned"
|
||||||
|
if ($attempt->status==1 && isset($previous_timestart)) {
|
||||||
|
|
||||||
|
$values = 'status=3';
|
||||||
if (empty($attempt->score)) {
|
if (empty($attempt->score)) {
|
||||||
$values .= ',score=0';
|
$values .= ',score=0';
|
||||||
}
|
}
|
||||||
if (empty($attempt->timefinish)) {
|
if (empty($attempt->timefinish)) {
|
||||||
$values .= ",timefinish=$previous_timestart";
|
$values .= ",timefinish=$previous_timestart";
|
||||||
}
|
}
|
||||||
$ok = $ok && execute_sql("UPDATE {$CFG->prefix}hotpot_attempts SET $values WHERE id=$attempt->id", false);
|
execute_sql("UPDATE {$CFG->prefix}hotpot_attempts SET $values WHERE id=$attempt->id", false);
|
||||||
|
|
||||||
print ".";
|
print ".";
|
||||||
hotpot_flush(300);
|
hotpot_flush(300);
|
||||||
}
|
}
|
||||||
|
@ -58,10 +60,10 @@ function hotpot_update_to_v2_1_2() {
|
||||||
|
|
||||||
print $ok ? get_string('success') : 'failed';
|
print $ok ? get_string('success') : 'failed';
|
||||||
print "<br />\n";
|
print "<br />\n";
|
||||||
}
|
|
||||||
|
|
||||||
// restore SQL message echo setting
|
// restore SQL message echo setting
|
||||||
$db->debug = $debug;
|
$db->debug = $debug;
|
||||||
|
}
|
||||||
|
|
||||||
return $ok;
|
return $ok;
|
||||||
}
|
}
|
||||||
|
@ -1051,6 +1053,7 @@ function hotpot_db_update_field_type($table, $oldfield, $field, $type, $size, $u
|
||||||
$oldfield = $field;
|
$oldfield = $field;
|
||||||
}
|
}
|
||||||
if (is_string($unsigned)) {
|
if (is_string($unsigned)) {
|
||||||
|
|
||||||
$unsigned = (strtoupper($unsigned)=='UNSIGNED');
|
$unsigned = (strtoupper($unsigned)=='UNSIGNED');
|
||||||
}
|
}
|
||||||
if (is_string($notnull)) {
|
if (is_string($notnull)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue