Skip to content

Commit

Permalink
MDL-67458 tool_cohortroles: remove role mapping for deleted roles
Browse files Browse the repository at this point in the history
Before syncing anything, clean up records pointing to deleted roles.
  • Loading branch information
snake committed Dec 11, 2019
1 parent 8cf4c97 commit 94eabe3
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions admin/tool/cohortroles/classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ public static function sync_all_cohort_roles() {
$rolesadded = array();
$rolesremoved = array();

// Remove any cohort role mappings for roles which have been deleted.
// The role assignments are not a consideration because these will have been removed when the role was.
$DB->delete_records_select('tool_cohortroles', "roleid NOT IN (SELECT id FROM {role})");

// Get all cohort role assignments and group them by user and role.
$all = cohort_role_assignment::get_records(array(), 'userid, roleid');
// We build an better structure to loop on.
Expand Down

0 comments on commit 94eabe3

Please sign in to comment.