MDL-86679 core: Fix MS field mappings in upgrade script
This commit is contained in:
@@ -1894,5 +1894,38 @@ function xmldb_main_upgrade($oldversion) {
|
||||
upgrade_main_savepoint(true, 2025041403.11);
|
||||
}
|
||||
|
||||
if ($oldversion < 2025041403.13) {
|
||||
// Fix Microsoft OAuth2 user field mappings to use OpenID Connect standard field names.
|
||||
// This corrects the mappings introduced in MDL-84432 which used non-standard field names
|
||||
// that only work with personal Microsoft accounts but not work/school (Entra ID) accounts.
|
||||
$userfieldmappings = [
|
||||
'firstname' => 'given_name',
|
||||
'lastname' => 'family_name',
|
||||
];
|
||||
$admin = get_admin();
|
||||
$adminid = $admin ? $admin->id : '0';
|
||||
$microsoftservices = $DB->get_records('oauth2_issuer', ['servicetype' => 'microsoft']);
|
||||
foreach ($microsoftservices as $microsoftservice) {
|
||||
$time = time();
|
||||
// Update user field mappings to use OpenID Connect standard field names.
|
||||
foreach ($userfieldmappings as $internalfieldname => $externalfieldname) {
|
||||
$fieldmap = ['issuerid' => $microsoftservice->id, 'internalfield' => $internalfieldname];
|
||||
$fieldmapid = $DB->get_field('oauth2_user_field_mapping', 'id', $fieldmap);
|
||||
if ($fieldmapid) {
|
||||
$fieldmap = array_merge($fieldmap, [
|
||||
'id' => $fieldmapid,
|
||||
'externalfield' => $externalfieldname,
|
||||
'timemodified' => $time,
|
||||
'usermodified' => $adminid,
|
||||
]);
|
||||
$DB->update_record('oauth2_user_field_mapping', $fieldmap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Main savepoint reached.
|
||||
upgrade_main_savepoint(true, 2025041403.13);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2025041403.12; // 20250414 = branching date YYYYMMDD - do not modify!
|
||||
$version = 2025041403.13; // 20250414 = branching date YYYYMMDD - do not modify!
|
||||
// RR = release increments - 00 in DEV branches.
|
||||
// .XX = incremental changes.
|
||||
$release = '5.0.3+ (Build: 20251205)'; // Human-friendly version name
|
||||
|
||||
Reference in New Issue
Block a user