MDL-58256 group: prevents users to be added to a group twice
This commit is contained in:
committed by
Sara Arjona
parent
7d4a9008fa
commit
8516febdd7
+3
-2
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="lib/db" VERSION="20190111" COMMENT="XMLDB file for core Moodle tables"
|
||||
<XMLDB PATH="lib/db" VERSION="20190122" COMMENT="XMLDB file for core Moodle tables"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
@@ -2282,6 +2282,7 @@
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
<KEY NAME="groupid" TYPE="foreign" FIELDS="groupid" REFTABLE="groups" REFFIELDS="id"/>
|
||||
<KEY NAME="userid" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id"/>
|
||||
<KEY NAME="useridgroupid" TYPE="unique" FIELDS="userid, groupid" COMMENT="Unique key"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
<TABLE NAME="groupings_groups" COMMENT="Link a grouping to a group (note, groups can be in multiple groupings ONLY in a course). WAS: groups_groupings_groups">
|
||||
@@ -4096,4 +4097,4 @@
|
||||
</INDEXES>
|
||||
</TABLE>
|
||||
</TABLES>
|
||||
</XMLDB>
|
||||
</XMLDB>
|
||||
|
||||
@@ -2692,5 +2692,32 @@ function xmldb_main_upgrade($oldversion) {
|
||||
upgrade_main_savepoint(true, 2019011801.02);
|
||||
}
|
||||
|
||||
if ($oldversion < 2019011801.03) {
|
||||
// Remove duplicate entries from group memberships.
|
||||
// Find records with multiple userid/groupid combinations and find the highest ID.
|
||||
// Later we will remove all those entries.
|
||||
$sql = "
|
||||
SELECT MIN(id) as minid, userid, groupid
|
||||
FROM {groups_members}
|
||||
GROUP BY userid, groupid
|
||||
HAVING COUNT(id) > 1";
|
||||
if ($duplicatedrows = $DB->get_recordset_sql($sql)) {
|
||||
foreach ($duplicatedrows as $row) {
|
||||
$DB->delete_records_select('groups_members',
|
||||
'userid = :userid AND groupid = :groupid AND id <> :minid', (array)$row);
|
||||
}
|
||||
}
|
||||
$duplicatedrows->close();
|
||||
|
||||
// Define key useridgroupid (unique) to be added to group_members.
|
||||
$table = new xmldb_table('groups_members');
|
||||
$key = new xmldb_key('useridgroupid', XMLDB_KEY_UNIQUE, array('userid', 'groupid'));
|
||||
// Launch add key useridgroupid.
|
||||
$dbman->add_key($table, $key);
|
||||
|
||||
// Main savepoint reached.
|
||||
upgrade_main_savepoint(true, 2019011801.03);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2019011801.02; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
$version = 2019011801.03; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
// RR = release increments - 00 in DEV branches.
|
||||
// .XX = incremental changes.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user