MDL-73394 admin_presets: New setting to store last preset applied

A new setting has been added to config_plugins to store the last
preset identifier applied.
This commit is contained in:
Sara Arjona 2021-12-23 16:07:53 +01:00
parent 58a729f088
commit bfa24ae53a
2 changed files with 13 additions and 0 deletions

View File

@ -399,6 +399,11 @@ class manager {
$applied = array_merge($settingsapplied, $pluginsapplied);
$skipped = array_merge($settingsskipped, $pluginsskipped);
if (!$simulate) {
// Store it in a config setting as the last preset applied.
set_config('lastpresetapplied', $presetid, 'tool_admin_presets');
}
return [$applied, $skipped];
}

View File

@ -236,6 +236,14 @@ class manager_test extends \advanced_testcase {
$this->assertArrayHasKey('assign', $enabledplugins);
$enabledplugins = \core\plugininfo\qtype::get_enabled_plugins();
$this->assertArrayHasKey('truefalse', $enabledplugins);
// Check the presetid has been also stored in the lastpresetapplied config setting.
$this->assertEquals($presetid, get_config('tool_admin_presets', 'lastpresetapplied'));
// Call apply_preset as a simulation, so it shouldn't be applied and lastpresetapplied should still be $presetid.
$presetid2 = $generator->create_preset();
$manager->apply_preset($presetid2, true);
$this->assertEquals($presetid, get_config('tool_admin_presets', 'lastpresetapplied'));
}