Skip to content

Commit

Permalink
MDL-72720 dataformat: 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 87baf79 commit 81556d8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
9 changes: 4 additions & 5 deletions admin/dataformats.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@
switch ($action) {
case 'disable':
if ($plugins[$name]->is_enabled()) {
set_config('disabled', 1, 'dataformat_'. $name);
core_plugin_manager::reset_caches();
$class = \core_plugin_manager::resolve_plugininfo_class('dataformat');
$class::enable_plugin($name, false);
}
break;
case 'enable':
if (!$plugins[$name]->is_enabled()) {
unset_config('disabled', 'dataformat_'. $name);
core_plugin_manager::reset_caches();
$class = \core_plugin_manager::resolve_plugininfo_class('dataformat');
$class::enable_plugin($name, true);
}
break;
case 'up':
Expand All @@ -78,4 +78,3 @@
break;
}
redirect($return);

24 changes: 23 additions & 1 deletion lib/classes/plugininfo/dataformat.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,29 @@ public static function get_enabled_plugins() {
return $enabled;
}

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

$plugin = 'dataformat_' . $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;
}

/**
* Returns the node name used in admin settings menu for this plugin settings (if applicable)
*
Expand Down Expand Up @@ -163,4 +186,3 @@ public static function get_manage_url() {
}

}

0 comments on commit 81556d8

Please sign in to comment.