From 7e66e9468bc60fb7a96d507cf7270833289438f4 Mon Sep 17 00:00:00 2001 From: Lai Wei Date: Wed, 11 May 2022 15:27:09 +0100 Subject: [PATCH] Update SDS feature to work with incomplete Graph API response --- local/o365/classes/feature/sds/task/sync.php | 33 ++++++++++++++------ local/o365/lang/en/local_o365.php | 3 +- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/local/o365/classes/feature/sds/task/sync.php b/local/o365/classes/feature/sds/task/sync.php index a602465a8..1ad9569f9 100644 --- a/local/o365/classes/feature/sds/task/sync.php +++ b/local/o365/classes/feature/sds/task/sync.php @@ -128,15 +128,30 @@ public static function runsync(unified $apiclient) : bool { $studentstudentnumber = ''; $teacherexternalid = ''; $teacherteachernumber = ''; - if (array_key_exists('student', $processedschooluser)) { - $studentexternalid = $processedschooluser['student']['externalId']; - $studentbirthdate = $processedschooluser['student']['birthDate']; - $studentgrade = $processedschooluser['student']['grade']; - $studentgraduationyear = $processedschooluser['student']['graduationYear']; - $studentstudentnumber = $processedschooluser['student']['studentNumber']; - } else if (array_key_exists('teacher', $processedschooluser)) { - $teacherexternalid = $processedschooluser['teacher']['externalId']; - $teacherteachernumber = $processedschooluser['teacher']['teacherNumber']; + if ($primaryrole == 'student' && isset($processedschooluser['student'])) { + if (isset($processedschooluser['student']['externalId'])) { + $studentexternalid = $processedschooluser['student']['externalId']; + } + if (isset($processedschooluser['student']['birthDate'])) { + $studentbirthdate = $processedschooluser['student']['birthDate']; + } + if (isset($processedschooluser['student']['grade'])) { + $studentgrade = $processedschooluser['student']['grade']; + } + if (isset($processedschooluser['student']['graduationYear'])) { + $studentgraduationyear = $processedschooluser['student']['graduationYear']; + } + if (isset($processedschooluser['student']['studentNumber'])) { + $studentstudentnumber = $processedschooluser['student']['studentNumber']; + } + } + if ($primaryrole == 'teacher' && isset($processedschooluser['teacher'])) { + if (isset($processedschooluser['teacher']['externalId'])) { + $teacherexternalid = $processedschooluser['teacher']['externalId']; + } + if (isset($processedschooluser['teacher']['teacherNumber'])) { + $teacherteachernumber = $processedschooluser['teacher']['teacherNumber']; + } } foreach ($additionalprofilemappings as $remotefield => $localfield) { diff --git a/local/o365/lang/en/local_o365.php b/local/o365/lang/en/local_o365.php index d07770bb7..26cb6aa7b 100644 --- a/local/o365/lang/en/local_o365.php +++ b/local/o365/lang/en/local_o365.php @@ -553,7 +553,8 @@ $string['settings_sds_profilesync_disabled'] = 'Disabled'; $string['settings_sds_profilesync'] = 'Sync profile data from school'; $string['settings_sds_profilesync_desc'] = 'Select the SDS school from which Moodle synchronises SDS specific profile data.
-Note synchronisation of SDS fields will only happen when running the "Sync with SDS" scheduled task, and will not happen when running the "Sync users with Azure AD" scheduled task, nor when user logs in.'; +Note synchronisation of SDS fields will only happen when running the "Sync with SDS" scheduled task, and will not happen when running the "Sync users with Azure AD" scheduled task, nor when user logs in.
+Note there is a known issue in Microsoft Graph API used by this feature that certain student and teacher school profile fields are not returned, therefore are unavilable to sync even when configured.'; $string['settings_sds_noschools'] = '
You do not have any schools available in School data sync.
'; $string['settings_sds_get_schools_error'] = '
Failed to get SDS schools. Check the Azure app has required permission.
'; $string['settings_sds_school_disabled_action'] = 'School sync disabled action';