Skip to content

Commit

Permalink
MDL-72720 customfield: Implement enable_plugin() method
Browse files Browse the repository at this point in the history
  • Loading branch information
sarjona committed Oct 14, 2021
1 parent fc59c10 commit 87baf79
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
8 changes: 4 additions & 4 deletions admin/customfields.php
Expand Up @@ -47,14 +47,14 @@
switch ($action) {
case 'disable':
if ($customfieldplugins[$customfieldname]->is_enabled()) {
set_config('disabled', 1, 'customfield_'. $customfieldname);
core_plugin_manager::reset_caches();
$class = \core_plugin_manager::resolve_plugininfo_class('customfield');
$class::enable_plugin($customfieldname, false);
}
break;
case 'enable':
if (!$customfieldplugins[$customfieldname]->is_enabled()) {
unset_config('disabled', 'customfield_'. $customfieldname);
core_plugin_manager::reset_caches();
$class = \core_plugin_manager::resolve_plugininfo_class('customfield');
$class::enable_plugin($customfieldname, true);
}
break;
}
Expand Down
23 changes: 23 additions & 0 deletions lib/classes/plugininfo/customfield.php
Expand Up @@ -78,6 +78,29 @@ public static function get_enabled_plugins() {
return $enabled;
}

public static function enable_plugin(string $pluginname, int $enabled): bool {
$haschanged = false;

$plugin = 'customfield_' . $pluginname;
$oldvalue = get_config($plugin, 'disabled');
$disabled = !$enabled;
// Only set value if there is no config setting or if the value is different from the previous one.
if ($oldvalue == false && $disabled) {
set_config('disabled', $disabled, $plugin);
$haschanged = true;
} else if ($oldvalue != false && !$disabled) {
unset_config('disabled', $plugin);
$haschanged = true;
}

if ($haschanged) {
add_to_config_log('disabled', $oldvalue, $disabled, $plugin);
\core_plugin_manager::reset_caches();
}

return $haschanged;
}

/**
* Pre-uninstall hook.
*
Expand Down

0 comments on commit 87baf79

Please sign in to comment.