1
0
mirror of https://github.com/moodle/moodle.git synced 2025-04-04 07:52:48 +02:00

MDL-60366 mod_feedback: fix deletion of valid anonymous duplicates

This commit is contained in:
Davo Smith 2017-10-06 12:46:05 +01:00
parent d8e9a23c48
commit 5ef66eaf7e

@ -146,17 +146,20 @@ function xmldb_feedback_upgrade($oldversion) {
// Related values in feedback_value won't be deleted (they won't be used and can be kept there as a backup).
$sql = "SELECT MAX(id) as maxid, userid, feedback, courseid
FROM {feedback_completed}
WHERE userid <> 0
WHERE userid <> 0 AND anonymous_response = :notanonymous
GROUP BY userid, feedback, courseid
HAVING COUNT(id) > 1";
$params = ['notanonymous' => 2]; // FEEDBACK_ANONYMOUS_NO.
$duplicatedrows = $DB->get_recordset_sql($sql);
$duplicatedrows = $DB->get_recordset_sql($sql, $params);
foreach ($duplicatedrows as $row) {
$DB->delete_records_select('feedback_completed', 'userid = ? AND feedback = ? AND courseid = ? AND id <> ?', array(
$row->userid,
$row->feedback,
$row->courseid,
$row->maxid,
$DB->delete_records_select('feedback_completed', 'userid = ? AND feedback = ? AND courseid = ? AND id <> ?'.
' AND anonymous_response = ?', array(
$row->userid,
$row->feedback,
$row->courseid,
$row->maxid,
2, // FEEDBACK_ANONYMOUS_NO.
));
}
$duplicatedrows->close();