MDL-51110 badges: prevent duplicate award of badges
authorDan Poltawski <dan@moodle.com>
Thu, 13 Aug 2015 12:12:52 +0000 (13:12 +0100)
committerDan Poltawski <dan@moodle.com>
Thu, 13 Aug 2015 12:21:03 +0000 (13:21 +0100)
Previously duplicate users could be returned when they had
done duplicate badge criteria - this would lead to a duplicate
constraint being hit as they were attempted to be awarded twice.

lib/badgeslib.php

index c8af3f8..8e3d7e5 100644 (file)
@@ -472,7 +472,7 @@ class badge {
                     $wheresql = ' WHERE u.id ' . $earnedsql;
                 }
                 list($enrolledsql, $enrolledparams) = get_enrolled_sql($this->get_context(), 'moodle/badges:earnbadge', 0, true);
-                $sql = "SELECT u.id
+                $sql = "SELECT DISTINCT u.id
                         FROM {user} u
                         {$extrajoin}
                         JOIN ({$enrolledsql}) je ON je.id = u.id " . $wheresql . $extrawhere;