changed to get_recordset_sql because get_records forces the first element to be key

This commit is contained in:
toyomoyo 2007-11-19 01:44:26 +00:00
parent f7bd8c758f
commit 5bbf18cd6f

View File

@ -2594,22 +2594,25 @@ function xmldb_main_upgrade($oldversion=0) {
GROUP BY userid, itemid
HAVING COUNT( * ) >1";
// duplicates found
if ($dups = get_records_sql($SQL)) {
// for each set of userid, itemid
foreach ($dups as $dup) {
if ($thisdups = get_records_sql("SELECT id FROM {$CFG->prefix}grade_grades
WHERE itemid = $dup->itemid AND userid = $dup->userid
ORDER BY timemodified DESC")) {
$processed = 0; // keep the first one
foreach ($thisdups as $thisdup) {
if ($processed) {
// remove the duplicates
delete_records('grade_grades', 'id', $thisdup->id);
if ($rs = get_recordset_sql($SQL)) {
if ($rs && $rs->RecordCount() > 0) {
while ($dup = rs_fetch_next_record($rs)) {
if ($thisdups = get_records_sql("SELECT id FROM {$CFG->prefix}grade_grades
WHERE itemid = $dup->itemid AND userid = $dup->userid
ORDER BY timemodified DESC")) {
$processed = 0; // keep the first one
foreach ($thisdups as $thisdup) {
if ($processed) {
// remove the duplicates
delete_records('grade_grades', 'id', $thisdup->id);
}
$processed++;
}
$processed++;
}
}
rs_close($rs);
}
}