Commit 108bfa68 authored by Penny Leach's avatar Penny Leach Committed by Richard Mansfield
Browse files

replaced reliance on 'internal' with a new plugin contract method

now each plugin can say whether it can be disabled or not. defaults to true
parent aa9619cb
......@@ -47,6 +47,10 @@ if ($sesskey = param_alphanum('sesskey', '')) {
$enable = param_integer('enable', 0);
$disable = param_integer('disable', 0);
if ($disable && !call_static_method(generate_class_name($plugintype, $pluginname), 'can_be_disabled')) {
throw new UserException("Plugin $plugintype $pluginname cannot be disabled");
}
if ($enable || $disable) {
if ($plugintype == 'blocktype') {
$pluginname = blocktype_namespaced_to_single($pluginname);
......
......@@ -54,7 +54,11 @@ foreach (array_keys($plugins) as $plugin) {
if ($plugin == 'blocktype') {
$key = blocktype_single_to_namespaced($i->name, $i->artefactplugin);
}
$plugins[$plugin]['installed'][$key] = array('active' => $i->active);
safe_require($plugin, $key);
$plugins[$plugin]['installed'][$key] = array(
'active' => $i->active,
'disableable' => call_static_method(generate_class_name($plugin, $key), 'can_be_disabled'),
);
if ($plugin == 'artefact') {
$plugins[$plugin]['installed'][$key]['types'] = array();
safe_require('artefact', $key);
......
......@@ -123,6 +123,10 @@ class PluginArtefactInternal extends PluginArtefact {
public static function sort_child_data($a, $b) {
return strnatcasecmp($a->text, $b->text);
}
public static function can_be_disabled() {
return false;
}
}
class ArtefactTypeProfile extends ArtefactType {
......
......@@ -206,6 +206,10 @@ class PluginAuthInternal extends PluginAuth {
public static function get_instance_config_options() {
return array();
}
public static function can_be_disabled() {
return false;
}
}
?>
......@@ -34,6 +34,10 @@ class PluginGrouptypeStandard extends PluginGrouptype {
}
}
public static function can_be_disabled() {
return false;
}
}
class GroupTypeStandard extends GroupType {
......
......@@ -337,6 +337,10 @@ class PluginInteractionForum extends PluginInteraction {
'ctime < ? AND deleted = 0 AND sent = 0', array(db_format_timestamp($minpostdelay)));
}
}
public static function can_be_disabled() {
return false; //TODO until it either becomes an artefact plugin or stops being hardcoded everywhere
}
}
class InteractionForumInstance extends InteractionInstance {
......
......@@ -1180,6 +1180,15 @@ class Plugin {
public static function get_activity_types() {
return array();
}
/**
* Can this plugin be disabled?
* All internal type plugins, and ones in which Mahara won't work should override this.
* Probably at least one plugin per plugin-type should override this.
*/
public static function can_be_disabled() {
return true;
}
}
/**
......
......@@ -97,6 +97,9 @@ class PluginNotificationInternal extends PluginNotification {
delete_records('notification_internal_activity', 'usr', $user['id']);
}
public static function can_be_disabled() {
return false;
}
}
?>
......@@ -32,6 +32,10 @@ defined('INTERNAL') || die();
*/
class PluginSearchInternal extends PluginSearch {
public static function can_be_disabled() {
return false;
}
/**
* Implement user searching with SQL
*
......
......@@ -13,7 +13,7 @@
<ul id="{$plugintype}.installed">
{foreach from=$installed key='plugin' item='data'}
<li id="{$plugintype}.{$plugin}">{$plugin}
{if $plugin != 'internal'}
{if $data.disableable}
{if $data.active}
[ <a href="pluginconfig.php?plugintype={$plugintype}&amp;pluginname={$plugin}&amp;disable=1&amp;sesskey={$SESSKEY}">{str tag='disable'}</a>
{else}
......@@ -21,9 +21,9 @@
{/if}
{/if}
{if $data.config}
{if $plugin == 'internal'} [ {else} | {/if}
{if !$data.disableable} [ {else} | {/if}
<a href="pluginconfig.php?plugintype={$plugintype}&amp;pluginname={$plugin}">{str tag='config'}</a>
{/if} {if $data.config || $plugin != 'internal'} ] {/if} </li>
{/if} {if $data.config || $data.disableable} ] {/if} </li>
{if $data.types}
<ul>
{foreach from=$data.types key='type' item='config'}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment