Commit 75a9f3d0 authored by Tobias Zeuch's avatar Tobias Zeuch Committed by Robert Lyon
Browse files

Bug 1298855: new method Plugin::sanity_check() that is called upon install or


update of the plugin. Caught exception InstallException results in the
error-message being presented to the user and the plugin not being installed
while the installation process continues

Change-Id: Iba04bbfebe7b192409cd2e943d7449f0ec258eca
Signed-off-by: default avatarTobias Zeuch <tobias.zeuch@kit.edu>
parent 5735898e
......@@ -99,6 +99,8 @@ foreach (array_keys($plugins) as $plugin) {
$plugins[$plugin]['notinstalled'][$dir] = array();
try {
validate_plugin($plugin, $dir);
$classname = generate_class_name($plugin, $dir);
$classname::sanity_check();
}
catch (InstallationException $e) {
$plugins[$plugin]['notinstalled'][$dir]['notinstallable'] = $e->GetMessage();
......
......@@ -64,6 +64,13 @@ if ($install) {
}
if (!empty($upgrade)) {
if (!empty($upgrade->errormsg)) {
$data['newversion'] = $upgrade->torelease . ' (' . $upgrade->to . ')' ;
$data['install'] = false;
$data['error'] = false;
$data['message'] = get_string('notinstalled', 'admin') . ': ' . $upgrade->errormsg;
json_reply('local', $data);
}
$data['newversion'] = $upgrade->torelease . ' (' . $upgrade->to . ')' ;
if ($name == 'core') {
$funname = 'upgrade_core';
......
......@@ -145,11 +145,13 @@ $js = <<< EOJS
var message;
if (data.coredata) {
message = {$coresuccess};
}
$(data.key).innerHTML = '<img src="{$successicon}" alt=":)" /> ' + message;
}
else if (data.localdata) {
message = {$localsuccess};
$(data.key).innerHTML = '<img src="{$successicon}" alt=":)" /> ' + message;
}
else {
else if (data.install || data.upgrade) {
if (data.install) {
message = {$installsuccessstring};
}
......@@ -162,8 +164,12 @@ $js = <<< EOJS
}
}
message += data.newversion ? data.newversion : '';
$(data.key).innerHTML = '<img src="{$successicon}" alt=":)" /> ' + message;
}
else {
message = data.message;
$(data.key).innerHTML = '<img src="{$failureicon}" alt=":(" /> ' + message;
}
$(data.key).innerHTML = '<img src="{$successicon}" alt=":)" /> ' + message;
if (data.feedback) {
var feedback_element = DIV();
feedback_element.innerHTML = data.feedback;
......
......@@ -1801,6 +1801,15 @@ class Plugin {
public static function can_be_disabled() {
return true;
}
/**
* Can this plugin be installed?
* Override to implement individual dependencies, for example special
* php extensions or artefact types installed by other plugins.
* To disable installation, throw an InstallationException
*/
public static function sanity_check() {
}
}
/**
......
......@@ -230,6 +230,21 @@ function check_upgrades($name=null) {
if (property_exists($config, 'requires_parent')) {
$plugininfo->requires_parent = $config->requires_parent;
}
$classname = generate_class_name($plugintype, $pluginname);
safe_require($plugintype, $pluginname);
try {
$classname::sanity_check();
}
catch (InstallationException $exc) {
$plugininfo->to = get_string('notinstalled', 'admin');
$plugininfo->torelease = get_string('notinstalled', 'admin');
$plugininfo->errormsg = $exc->getMessage();
$toupgrade[$pluginkey] = $plugininfo;
continue;
}
$toupgrade[$pluginkey] = $plugininfo;
}
else if ($config->version > $pluginversion) {
......@@ -251,6 +266,21 @@ function check_upgrades($name=null) {
if (property_exists($config, 'requires_parent')) {
$plugininfo->requires_parent = $config->requires_parent;
}
$classname = generate_class_name($plugintype, $pluginname);
safe_require($plugintype, $pluginname);
try {
$classname::sanity_check();
}
catch (InstallationException $exc) {
$plugininfo->to = $config->version;
$plugininfo->torelease = $pluginrelease;
$plugininfo->errormsg = $exc->getMessage();
$toupgrade[$pluginkey] = $plugininfo;
continue;
}
$toupgrade[$pluginkey] = $plugininfo;
}
}
......
{include file='header.tpl'}
<div id="adminplugin">
<b>{str tag='pluginexplainaddremove'}
<br/><br/>{str tag='pluginexplainartefactblocktypes'}<br/><br/></b>
<ul class="adminpluginstypes">
{foreach from=$plugins key='plugintype' item='plugins'}
<li><h4>{str tag='plugintype'}: {$plugintype}</h4>
{assign var="installed" value=$plugins.installed}
{assign var="notinstalled" value=$plugins.notinstalled}
<ul>
<li><b>{str tag='installedplugins'}</b>
<ul id="{$plugintype}.installed">
{foreach from=$installed key='plugin' item='data'}
<li id="{$plugintype}.{$plugin}">{$plugin}
{if $data.activateform}
[ {$data.activateform|safe}
{/if}
{if $data.config}
{if !$data.activateform} [ {else} | {/if}
<a href="pluginconfig.php?plugintype={$plugintype}&amp;pluginname={$plugin}">{str tag='config'}</a>
{/if} {if $data.config || $data.activateform} ] {/if} </li>
{if $data.types}
<li><ul>
{foreach from=$data.types key='type' item='config'}
<li>{$type}
{if $config} [ <a href="pluginconfig.php?plugintype={$plugintype}&amp;pluginname={$plugin}&amp;type={$type}">{str tag='config'}</a> ]{/if}</li>
{/foreach}
</ul></li>
{/if}
<b>{str tag='pluginexplainaddremove'}
<br/><br/>{str tag='pluginexplainartefactblocktypes'}<br/><br/></b>
<ul class="adminpluginstypes">
{foreach from=$plugins key='plugintype' item='plugins'}
<li><h4>{str tag='plugintype'}: {$plugintype}</h4>
{assign var="installed" value=$plugins.installed}
{assign var="notinstalled" value=$plugins.notinstalled}
<ul>
<li><b>{str tag='installedplugins'}</b>
<ul id="{$plugintype}.installed">
{foreach from=$installed key='plugin' item='data'}
<li id="{$plugintype}.{$plugin}">{$plugin}
{if $data.activateform}
[ {$data.activateform|safe}
{/if}
{if $data.config}
{if !$data.activateform} [ {else} | {/if}
<a href="pluginconfig.php?plugintype={$plugintype}&amp;pluginname={$plugin}">{str tag='config'}</a>
{/if}
{if $data.config || $data.activateform} ] {/if}
</li>
{if $data.types}
<li>
<ul>
{foreach from=$data.types key='type' item='config'}
<li>{$type}
{if $config} [ <a href="pluginconfig.php?plugintype={$plugintype}&amp;pluginname={$plugin}&amp;type={$type}">{str tag='config'}</a> ]{/if}</li>
{/foreach}
</ul>
</li>
{/if}
{/foreach}
</ul>
</li>
{if $notinstalled}
<li><b>{str tag='notinstalledplugins'}</b>
<ul id="{$plugintype}.notinstalled">
{foreach from=$notinstalled key='plugin' item='data'}
<li id="{$plugintype}.{$plugin}">{$plugin}
{if $data.notinstallable}
{str tag='notinstallable'}: {$data.notinstallable}
{else}
<span id="{$plugintype}.{$plugin}.install">(<a href="" onClick="{$installlink}('{$plugintype}.{$plugin}'); return false;">{str tag='install' section='admin'}</a>)</span>
{/if}
<span id="{$plugintype}.{$plugin}.message"></span>
</li>
{/foreach}
</ul>
</li>
{/if}
</ul>
</li>
{/foreach}
</ul></li>
{if $notinstalled}
<li><b>{str tag='notinstalledplugins'}</b>
<ul id="{$plugintype}.notinstalled">
{foreach from=$notinstalled key='plugin' item='data'}
<li id="{$plugintype}.{$plugin}">{$plugin} {if $data.notinstallable} {str tag='notinstallable'} {$data.notinstallable}
{else} <span id="{$plugintype}.{$plugin}.install">(<a href="" onClick="{$installlink}('{$plugintype}.{$plugin}'); return false;">{str tag='install' section='admin'}</a>)</span>
{/if}
<span id="{$plugintype}.{$plugin}.message"></span>
</li>
{/foreach}</li>
</ul>
{/if}
</ul></li>
{/foreach}
</ul>
<div class="cb"></div>
</ul>
<div class="cb"></div>
</div>
{include file='footer.tpl'}
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