Failing to Create Groups Mdlv3.8.2 O365v3.8.1

Failing to Create Groups Mdlv3.8.2 O365v3.8.1

by Shane Hall -
Number of replies: 3

Hi All,
We are attempting to integrate our Moodle 3.8.2 with the latest production O365 package v3.8 for the first time. Authentication is working well. 
We are not creating class OneNote nor are we using the older Sharepoint. 
Our goal is to have Teams automatically created with the Moodle App and Moodle Bot functional. Our group creation task appears to be failing to create the O365 group and team. 
Has anyone seen this or do you have ideas on what might be wrong? We receive the following error:
Execute scheduled task: Create user groups in Office 365 (local_o365\task\groupcreate)
No groups waiting to have class notebook created.
Could not create class team for #1392. Reason: invalid team ID
Syncing group membership for course #1392
Could not find group object ID in local_o365_objects for course 1392. Please ensure group exists first.
Could not create class team for #2258. Reason: invalid team ID
Syncing group membership for course #2258
Could not find group object ID in local_o365_objects for course 2258. Please ensure group exists first.
Processed courses: 2
... used 30 dbqueries
... used 1.2063808441162 seconds
Scheduled task complete: Create user groups in Office 365 (local_o365\task\groupcreate)
Regards,

SH


-Moodle 3.8.2+ (Build: 20200312)
-Boost Office365 Teams 3.8.0.0 2020020200
-Microsoft Office 365 Integration 3.8.0.1 2020020301
-Office 365 Integration 3.8.0.1 2020020301
-Microsfot OneNote 3.8.0.0 2020020300
-PHP 7.2.26

Average of ratings: -
In reply to Shane Hall

Re: Failing to Create Groups Mdlv3.8.2 O365v3.8.1

by Infotech AAC -

Hi,

I have exactly this same error after on group created with succed:

Execute scheduled task: Créer des groupes d'utilisateurs dans Office 365 (local_o365\task\groupcreate)
Could not create class team for #6. Reason: invalid team ID
Syncing group membership for course #6
Could not find group object ID in local_o365_objects for course 6. Please ensure group exists first.
Processed courses: 1
... used 21 dbqueries
... used 41.884054899216 seconds
Scheduled task complete: Créer des groupes d'utilisateurs dans Office 365 (local_o365\task\groupcreate)

Did you find something aldready?

In reply to Infotech AAC

Re: Failing to Create Groups Mdlv3.8.2 O365v3.8.1

by Shane Hall -
Hi - we ended up having to write a patch to the PHP code directly. We've sent this to GitHub. Will paste our solution here but check the github post in case there are updates or additional suggestions: https://github.com/microsoft/o365-moodle/issues/1222

____________________________________________________________________
We've found a resolution to auto-populate the teams. Have to read on on how to suggest formal code changes but wanted to share our patch to help other Education organizations get up and running. Any suggestions on making this code patch better welcomed!

The function that finds groups without associated teams does not first create the o365 group and then the corresponding Team. By adding a o365 group creation step to the PHP code, it will create the missing groups. This happens almost instantly once the code change is made.

We've also used the prefix rule in the code so the o365 groups will all start with "M: Course Short Name" to differentiate them from other groups/teams.

PHP Code from Office 365 Integration 3.8.0.1 2020020301 Package local_o365
File Path: moodle\local\o365\classes\feature\usergroups\coursegroups.php

Function: public function create_groups_for_new_courses()

Updated/Added Group Naming Convention (exists currently line 62):
Original: $groupprefix = '';
New: $groupprefix = 'M';

After it runs the query to "Process courses without an associated group", there is a routine that tries to create the team then creates the group if that fails. Right now that isn't working and we didn't look at why but instead we try to always create the group first then try to create the team to hopefully always create both regardless.

The main patch is to replace the following code currently at line 135 quoted here with code that has an additional group create before trying to create the team.

OLD CODE:

if ($createclassteam) {
// Create class team directly.
try {
$objectrec = $this->create_class_team($course, $ownerids, $groupprefix);
} catch (\Exception $e) {
$this->mtrace('Could not create class team for course #' . $course->id . '. Reason: ' . $e->getMessage());
continue;
}
} else {
// Create group.
try {
$objectrec = $this->create_group($course, $groupprefix);
} catch (\Exception $e) {
$this->mtrace('Could not create group for course #'.$course->id.'. Reason: '.$e->getMessage());
continue;
}
}
NEW CODE:

// MANUAL CODE PATCH STARTS: First Create group
$this->mtrace('PATCHED: First trying to create group: '.$course->shortname);
try {
$objectrec = $this->create_group($course, $groupprefix);
} catch (\Exception $e) {
$this->mtrace('Could not create group for course #'.$course->shortname.'. Reason: '.$e->getMessage());
continue;
}
// MANUAL CODE PATCH ENDS

if ($createclassteam) {
// Create class team directly.
try {
$objectrec = $this->create_class_team($course, $ownerids, $groupprefix);
} catch (\Exception $e) {
$this->mtrace('Could not create class team for course #' . $course->id . '. Reason: ' . $e->getMessage());
continue;
}
} else {
// Create group.
try {
$objectrec = $this->create_group($course, $groupprefix);
} catch (\Exception $e) {
$this->mtrace('Could not create group for course #'.$course->id.'. Reason: '.$e->getMessage());
continue;
}
}