Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix in function to clean up teams connections on invalid or deleted teams #2755

Open
wants to merge 1 commit into
base: MOODLE_405_STABLE
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions local/o365/classes/feature/coursesync/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -1130,11 +1130,31 @@ public function cleanup_teams_connections() {
if ($teamobjectids) {
// If there are records in teams cache, delete teams connection records with object IDs not in the cache.
[$teamobjectidsql, $params] = $DB->get_in_or_equal($teamobjectids, SQL_PARAMS_QM, 'param', false);
$DB->delete_records_select('local_o365_objects',
"type = 'group' AND subtype IN ('classteam', 'teamfromgroup') AND objectid {$teamobjectidsql}", $params);

if (count($params) < 65535) {
$DB->delete_records_select('local_o365_objects',
"type = 'group' AND subtype IN ('courseteam', 'teamfromgroup') AND objectid {$teamobjectidsql}", $params);
} else {
// PostgreSQL can't handle more than 65535 parameters in a query. Special care is needed.
$groupobjectids = $DB->get_records_select_menu('local_o365_objects',
"type = 'group' AND subtype IN ('courseteam', 'teamfromgroup')", [], '', 'objectid, id');
$objectrecordidstodelete = [];
foreach ($groupobjectids as $objectid => $objectrecordid) {
if (!in_array($objectid, $teamobjectids)) {
$objectrecordidstodelete[] = $objectrecordid;
}
}
if ($objectrecordidstodelete) {
$objectrecordidstodeletechunk = array_chunk($objectrecordidstodelete, 10000);
foreach ($objectrecordidstodeletechunk as $objectrecordidstodelete) {
[$teamsobjectidsql, $params] = $DB->get_in_or_equal($objectrecordidstodelete);
$DB->delete_records_select('local_o365_objects', "id {$teamsobjectidsql}", $params);
}
}
}
} else {
// If there are no records in teams cache, delete all teams connection records.
$DB->delete_records_select('local_o365_objects', "type = 'group' AND subtype IN ('classteam', 'teamfromgroup')");
$DB->delete_records_select('local_o365_objects', "type = 'group' AND subtype IN ('courseteam', 'teamfromgroup')");
}
$this->mtrace('Finished cleaning up teams connection records.');
$this->mtrace('');
Expand Down
Loading