MDL-65809 upgrade: remove upgrade_fix_config_auth_plugin_names
These functions were used only by deleted upgrade steps so it's safe to proceed with straight deletion, considering them internal. Deletion has been documented in corresponding upgrade.txt files: - upgrade_fix_config_auth_plugin_names() - upgrade_fix_config_auth_plugin_defaults()
This commit is contained in:
@@ -32,13 +32,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
function xmldb_auth_cas_upgrade($oldversion) {
|
||||
global $CFG;
|
||||
|
||||
if ($oldversion < 2017020700) {
|
||||
// Convert info in config plugins from auth/cas to auth_cas.
|
||||
upgrade_fix_config_auth_plugin_names('cas');
|
||||
upgrade_fix_config_auth_plugin_defaults('cas');
|
||||
upgrade_plugin_savepoint(true, 2017020700, 'auth', 'cas');
|
||||
}
|
||||
|
||||
// Automatically generated Moodle v3.3.0 release upgrade line.
|
||||
// Put any upgrade step following this.
|
||||
|
||||
|
||||
@@ -32,13 +32,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
function xmldb_auth_db_upgrade($oldversion) {
|
||||
global $CFG, $DB;
|
||||
|
||||
if ($oldversion < 2017032800) {
|
||||
// Convert info in config plugins from auth/db to auth_db
|
||||
upgrade_fix_config_auth_plugin_names('db');
|
||||
upgrade_fix_config_auth_plugin_defaults('db');
|
||||
upgrade_plugin_savepoint(true, 2017032800, 'auth', 'db');
|
||||
}
|
||||
|
||||
// Automatically generated Moodle v3.3.0 release upgrade line.
|
||||
// Put any upgrade step following this.
|
||||
|
||||
|
||||
@@ -32,13 +32,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
function xmldb_auth_email_upgrade($oldversion) {
|
||||
global $CFG, $DB;
|
||||
|
||||
if ($oldversion < 2017020700) {
|
||||
// Convert info in config plugins from auth/email to auth_email.
|
||||
upgrade_fix_config_auth_plugin_names('email');
|
||||
upgrade_fix_config_auth_plugin_defaults('email');
|
||||
upgrade_plugin_savepoint(true, 2017020700, 'auth', 'email');
|
||||
}
|
||||
|
||||
// Automatically generated Moodle v3.3.0 release upgrade line.
|
||||
// Put any upgrade step following this.
|
||||
|
||||
|
||||
@@ -32,13 +32,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
function xmldb_auth_ldap_upgrade($oldversion) {
|
||||
global $CFG;
|
||||
|
||||
if ($oldversion < 2017020700) {
|
||||
// Convert info in config plugins from auth/ldap to auth_ldap.
|
||||
upgrade_fix_config_auth_plugin_names('ldap');
|
||||
upgrade_fix_config_auth_plugin_defaults('ldap');
|
||||
upgrade_plugin_savepoint(true, 2017020700, 'auth', 'ldap');
|
||||
}
|
||||
|
||||
// Automatically generated Moodle v3.3.0 release upgrade line.
|
||||
// Put any upgrade step following this.
|
||||
|
||||
|
||||
@@ -32,13 +32,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
function xmldb_auth_manual_upgrade($oldversion) {
|
||||
global $CFG;
|
||||
|
||||
if ($oldversion < 2017020700) {
|
||||
// Convert info in config plugins from auth/manual to auth_manual.
|
||||
upgrade_fix_config_auth_plugin_names('manual');
|
||||
upgrade_fix_config_auth_plugin_defaults('manual');
|
||||
upgrade_plugin_savepoint(true, 2017020700, 'auth', 'manual');
|
||||
}
|
||||
|
||||
// Automatically generated Moodle v3.3.0 release upgrade line.
|
||||
// Put any upgrade step following this.
|
||||
|
||||
|
||||
@@ -32,13 +32,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
function xmldb_auth_mnet_upgrade($oldversion) {
|
||||
global $CFG;
|
||||
|
||||
if ($oldversion < 2017020700) {
|
||||
// Convert info in config plugins from auth/mnet to auth_mnet.
|
||||
upgrade_fix_config_auth_plugin_names('mnet');
|
||||
upgrade_fix_config_auth_plugin_defaults('mnet');
|
||||
upgrade_plugin_savepoint(true, 2017020700, 'auth', 'mnet');
|
||||
}
|
||||
|
||||
// Automatically generated Moodle v3.3.0 release upgrade line.
|
||||
// Put any upgrade step following this.
|
||||
|
||||
|
||||
@@ -32,13 +32,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
function xmldb_auth_none_upgrade($oldversion) {
|
||||
global $CFG, $DB;
|
||||
|
||||
if ($oldversion < 2017020700) {
|
||||
// Convert info in config plugins from auth/none to auth_none.
|
||||
upgrade_fix_config_auth_plugin_names('none');
|
||||
upgrade_fix_config_auth_plugin_defaults('none');
|
||||
upgrade_plugin_savepoint(true, 2017020700, 'auth', 'none');
|
||||
}
|
||||
|
||||
// Automatically generated Moodle v3.3.0 release upgrade line.
|
||||
// Put any upgrade step following this.
|
||||
|
||||
|
||||
@@ -32,13 +32,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
function xmldb_auth_shibboleth_upgrade($oldversion) {
|
||||
global $CFG, $DB;
|
||||
|
||||
if ($oldversion < 2017020700) {
|
||||
// Convert info in config plugins from auth/shibboleth to auth_shibboleth.
|
||||
upgrade_fix_config_auth_plugin_names('shibboleth');
|
||||
upgrade_fix_config_auth_plugin_defaults('shibboleth');
|
||||
upgrade_plugin_savepoint(true, 2017020700, 'auth', 'shibboleth');
|
||||
}
|
||||
|
||||
// Automatically generated Moodle v3.3.0 release upgrade line.
|
||||
// Put any upgrade step following this.
|
||||
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
This files describes API changes in /auth/* - plugins,
|
||||
information provided here is intended especially for developers.
|
||||
|
||||
=== 3.9 ===
|
||||
|
||||
* The following functions, previously used (exclusively) by upgrade steps are not available anymore because of the upgrade cleanup performed for this version. See MDL-65809 for more info:
|
||||
- upgrade_fix_config_auth_plugin_names()
|
||||
- upgrade_fix_config_auth_plugin_defaults()
|
||||
|
||||
=== 3.7 ===
|
||||
|
||||
* get_password_change_info() method is added to the base class and returns an array containing the subject and body of the message
|
||||
|
||||
@@ -650,57 +650,6 @@ class core_upgradelib_testcase extends advanced_testcase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the conversion of auth plugin settings names.
|
||||
*/
|
||||
public function test_upgrade_fix_config_auth_plugin_names() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Let the plugin auth_foo use legacy format only.
|
||||
set_config('name1', 'val1', 'auth/foo');
|
||||
set_config('name2', 'val2', 'auth/foo');
|
||||
|
||||
// Let the plugin auth_bar use new format only.
|
||||
set_config('name1', 'val1', 'auth_bar');
|
||||
set_config('name2', 'val2', 'auth_bar');
|
||||
|
||||
// Let the plugin auth_baz use a mix of legacy and new format, with no conflicts.
|
||||
set_config('name1', 'val1', 'auth_baz');
|
||||
set_config('name1', 'val1', 'auth/baz');
|
||||
set_config('name2', 'val2', 'auth/baz');
|
||||
set_config('name3', 'val3', 'auth_baz');
|
||||
|
||||
// Let the plugin auth_qux use a mix of legacy and new format, with conflicts.
|
||||
set_config('name1', 'val1', 'auth_qux');
|
||||
set_config('name1', 'val2', 'auth/qux');
|
||||
|
||||
// Execute the migration.
|
||||
upgrade_fix_config_auth_plugin_names('foo');
|
||||
upgrade_fix_config_auth_plugin_names('bar');
|
||||
upgrade_fix_config_auth_plugin_names('baz');
|
||||
upgrade_fix_config_auth_plugin_names('qux');
|
||||
|
||||
// Assert that legacy settings are gone and no new were introduced.
|
||||
$this->assertEmpty((array) get_config('auth/foo'));
|
||||
$this->assertEmpty((array) get_config('auth/bar'));
|
||||
$this->assertEmpty((array) get_config('auth/baz'));
|
||||
$this->assertEmpty((array) get_config('auth/qux'));
|
||||
|
||||
// Assert values were simply kept where there was no conflict.
|
||||
$this->assertSame('val1', get_config('auth_foo', 'name1'));
|
||||
$this->assertSame('val2', get_config('auth_foo', 'name2'));
|
||||
|
||||
$this->assertSame('val1', get_config('auth_bar', 'name1'));
|
||||
$this->assertSame('val2', get_config('auth_bar', 'name2'));
|
||||
|
||||
$this->assertSame('val1', get_config('auth_baz', 'name1'));
|
||||
$this->assertSame('val2', get_config('auth_baz', 'name2'));
|
||||
$this->assertSame('val3', get_config('auth_baz', 'name3'));
|
||||
|
||||
// Assert the new format took precedence in case of conflict.
|
||||
$this->assertSame('val1', get_config('auth_qux', 'name1'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a collection of test themes to test determining parent themes.
|
||||
*
|
||||
|
||||
@@ -2571,103 +2571,3 @@ function check_libcurl_version(environment_results $result) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix how auth plugins are called in the 'config_plugins' table.
|
||||
*
|
||||
* For legacy reasons, the auth plugins did not always use their frankenstyle
|
||||
* component name in the 'plugin' column of the 'config_plugins' table. This is
|
||||
* a helper function to correctly migrate the legacy settings into the expected
|
||||
* and consistent way.
|
||||
*
|
||||
* @param string $plugin the auth plugin name such as 'cas', 'manual' or 'mnet'
|
||||
*/
|
||||
function upgrade_fix_config_auth_plugin_names($plugin) {
|
||||
global $CFG, $DB, $OUTPUT;
|
||||
|
||||
$legacy = (array) get_config('auth/'.$plugin);
|
||||
$current = (array) get_config('auth_'.$plugin);
|
||||
|
||||
// I don't want to rely on array_merge() and friends here just in case
|
||||
// there was some crazy setting with a numerical name.
|
||||
|
||||
if ($legacy) {
|
||||
$new = $legacy;
|
||||
} else {
|
||||
$new = [];
|
||||
}
|
||||
|
||||
if ($current) {
|
||||
foreach ($current as $name => $value) {
|
||||
if (isset($legacy[$name]) && ($legacy[$name] !== $value)) {
|
||||
// No need to pollute the output during unit tests.
|
||||
if (!empty($CFG->upgraderunning)) {
|
||||
$message = get_string('settingmigrationmismatch', 'core_auth', [
|
||||
'plugin' => 'auth_'.$plugin,
|
||||
'setting' => s($name),
|
||||
'legacy' => s($legacy[$name]),
|
||||
'current' => s($value),
|
||||
]);
|
||||
echo $OUTPUT->notification($message, \core\output\notification::NOTIFY_ERROR);
|
||||
|
||||
upgrade_log(UPGRADE_LOG_NOTICE, 'auth_'.$plugin, 'Setting values mismatch detected',
|
||||
'SETTING: '.$name. ' LEGACY: '.$legacy[$name].' CURRENT: '.$value);
|
||||
}
|
||||
}
|
||||
|
||||
$new[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($new as $name => $value) {
|
||||
set_config($name, $value, 'auth_'.$plugin);
|
||||
unset_config($name, 'auth/'.$plugin);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate the auth plugin settings with defaults if needed.
|
||||
*
|
||||
* As a result of fixing the auth plugins config storage, many settings would
|
||||
* be falsely reported as new ones by admin/upgradesettings.php. We do not want
|
||||
* to confuse admins so we try to reduce the bewilderment by pre-populating the
|
||||
* config_plugins table with default values. This should be done only for
|
||||
* disabled auth methods. The enabled methods have their settings already
|
||||
* stored, so reporting actual new settings for them is valid.
|
||||
*
|
||||
* @param string $plugin the auth plugin name such as 'cas', 'manual' or 'mnet'
|
||||
*/
|
||||
function upgrade_fix_config_auth_plugin_defaults($plugin) {
|
||||
global $CFG;
|
||||
|
||||
$pluginman = core_plugin_manager::instance();
|
||||
$enabled = $pluginman->get_enabled_plugins('auth');
|
||||
|
||||
if (isset($enabled[$plugin])) {
|
||||
// Do not touch settings of enabled auth methods.
|
||||
return;
|
||||
}
|
||||
|
||||
// We can't directly use {@link core\plugininfo\auth::load_settings()} here
|
||||
// because the plugins are not fully upgraded yet. Instead, we emulate what
|
||||
// that method does. We fetch a temporary instance of the plugin's settings
|
||||
// page to get access to the settings and their defaults. Note we are not
|
||||
// adding that temporary instance into the admin tree. Yes, this is a hack.
|
||||
|
||||
$plugininfo = $pluginman->get_plugin_info('auth_'.$plugin);
|
||||
$adminroot = admin_get_root();
|
||||
$ADMIN = $adminroot;
|
||||
$auth = $plugininfo;
|
||||
|
||||
$section = $plugininfo->get_settings_section_name();
|
||||
$settingspath = $plugininfo->full_path('settings.php');
|
||||
|
||||
if (file_exists($settingspath)) {
|
||||
$settings = new admin_settingpage($section, 'Emulated settings page for auth_'.$plugin, 'moodle/site:config');
|
||||
include($settingspath);
|
||||
|
||||
if ($settings) {
|
||||
admin_apply_default_settings($settings, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user