Merge branch 'wip-75494-m310' into MOODLE_310_STABLE

* wip-75494-m310:
  change upgrade.php to avoid upgrade script run multiple times
This commit is contained in:
Lai Wei 2021-06-09 10:45:55 +01:00
Родитель f0afca2bf2 c22cc9d8b7
Коммит 32f29c86e7
1 изменённых файлов: 29 добавлений и 10 удалений

Просмотреть файл

@ -180,22 +180,41 @@ function xmldb_auth_oidc_upgrade($oldversion) {
upgrade_plugin_savepoint($result, '2018051700.01', 'auth', 'oidc');
}
if ($result && $oldversion < 2020071503) {
$localo365singlesignoffsetting = get_config('local_o365', 'single_sign_off');
if ($localo365singlesignoffsetting) {
set_config('single_sign_off', true, 'auth_oidc');
if ($result && $oldversion < 2020020301) {
$oldgraphtokens = $DB->get_records('auth_oidc_token', ['resource' => 'https://graph.windows.net']);
foreach ($oldgraphtokens as $graphtoken) {
$graphtoken->resource = 'https://graph.microsoft.com';
$DB->update_record('auth_oidc_token', $graphtoken);
}
upgrade_plugin_savepoint($result, 2020071503, 'auth', 'oidc');
$oidcresource = get_config('auth_oidc', 'oidcresource');
if ($oidcresource !== false && strpos($oidcresource, 'windows') !== false) {
set_config('oidcresource', 'https://graph.microsoft.com', 'auth_oidc');
}
upgrade_plugin_savepoint(true, 2020020301, 'auth', 'oidc');
}
if ($result && $oldversion < 2020071503) {
$localo365singlesignoffsetting = get_config('local_o365', 'single_sign_off');
if ($localo365singlesignoffsetting !== false) {
set_config('single_sign_off', true, 'auth_oidc');
unset_config('single_sign_off', 'local_o365');
}
upgrade_plugin_savepoint(true, 2020071503, 'auth', 'oidc');
}
if ($result && $oldversion < 2020110901) {
// Rename field resource on table auth_oidc_token to tokenresource.
$table = new xmldb_table('auth_oidc_token');
$field = new xmldb_field('resource', XMLDB_TYPE_CHAR, '127', null, XMLDB_NOTNULL, null, null, 'scope');
if ($dbman->field_exists('auth_oidc_token', 'resource')) {
// Rename field resource on table auth_oidc_token to tokenresource.
$table = new xmldb_table('auth_oidc_token');
// Launch rename field resource.
$dbman->rename_field($table, $field, 'tokenresource');
$field = new xmldb_field('resource', XMLDB_TYPE_CHAR, '127', null, XMLDB_NOTNULL, null, null, 'scope');
// Launch rename field resource.
$dbman->rename_field($table, $field, 'tokenresource');
}
// Oidc savepoint reached.
upgrade_plugin_savepoint(true, 2020110901, 'auth', 'oidc');