Commit c0c549b5 authored by Penny Leach's avatar Penny Leach Committed by Nigel McNie
Browse files

changed the blocktype base class to differentiate between instance & plugin wide config

parent 532c1157
......@@ -45,18 +45,22 @@ foreach (plugin_types() as $plugin) {
foreach (plugin_types() as $plugin) {
if ($installed = get_records_array($plugin . '_installed')) {
foreach ($installed as $i) {
$plugins[$plugin]['installed'][$i->name] = array();
$key = $i->name;
if ($plugin == 'blocktype' && !empty($i->artefactplugin)) {
$key = $i->artefactplugin . '/' . $i->name;
}
$plugins[$plugin]['installed'][$key] = array();
if ($plugin == 'artefact') {
$plugins[$plugin]['installed'][$i->name]['types'] = array();
safe_require('artefact',$i->name);
$plugins[$plugin]['installed'][$key]['types'] = array();
safe_require('artefact', $key);
if ($types = call_static_method(generate_class_name('artefact', $i->name), 'get_artefact_types')) {
foreach ($types as $t) {
$classname = generate_artefact_class_name($t);
if ($collapseto = call_static_method($classname, 'collapse_config')) {
$plugins[$plugin]['installed'][$i->name]['types'][$collapseto] = true;
$plugins[$plugin]['installed'][$key]['types'][$collapseto] = true;
}
else {
$plugins[$plugin]['installed'][$i->name]['types'][$t] =
$plugins[$plugin]['installed'][$key]['types'][$t] =
call_static_method($classname, 'has_config');
}
}
......@@ -66,7 +70,7 @@ foreach (plugin_types() as $plugin) {
$classname = generate_class_name($plugin, $i->name);
safe_require($plugin, $i->name);
if (call_static_method($classname, 'has_config')) {
$plugins[$plugin]['installed'][$i->name]['config'] = true;
$plugins[$plugin]['installed'][$key]['config'] = true;
}
}
}
......@@ -109,7 +113,7 @@ foreach (plugin_types() as $plugin) {
if (!is_dir(get_config('docroot') . $plugin . '/' . $dir . '/blocktype/' . $btdir)) {
continue;
}
if (!array_key_exists($btdir, $plugins['blocktype']['installed'])) {
if (!array_key_exists($dir . '/' . $btdir, $plugins['blocktype']['installed'])) {
try {
validate_plugin('blocktype', $dir . '/' . $btdir,
get_config('docroot') . 'artefact/' . $dir . '/blocktype/' . $btdir);
......
......@@ -86,7 +86,7 @@ if (!empty($upgrade)) {
}
else {
json_reply(false, array('error' => false,
'message' => string('nothingtoupgrade','admin')));
'message' => get_string('nothingtoupgrade','admin')));
exit;
}
?>
......@@ -36,7 +36,7 @@ abstract class PluginBlocktype extends Plugin {
public static function extra_xmldb_substitution($xml) {
return str_replace(
'<!-- PLUGINTYPE_INSTALLED_EXTRAFIELDS -->',
' <FIELD NAME="artefactplugin" TYPE="int" LENGTH="10" NOTNULL="false" />',
' <FIELD NAME="artefactplugin" TYPE="char" LENGTH="255" NOTNULL="false" />',
str_replace(
'<!-- PLUGINTYPE_INSTALLED_EXTRAKEYS -->',
'<KEY NAME="artefactpluginfk" TYPE="foreign" FIELDS="artefactplugin" REFTABLE="artefact_installed" REFFIELDS="name" />',
......
......@@ -769,6 +769,13 @@ function safe_require($plugintype, $pluginname, $filename='lib.php', $function='
if (count($bits) == 2) {
$fullpath = get_config('docroot') . 'artefact/' . $bits[0] . '/blocktype/' . $bits[1] . '/' . $filename;
}
else {
if (get_config('installed')) {
if ($artefactplugin = get_field('blocktype_installed', 'artefactplugin', 'name', $pluginname)) {
$fullpath = get_config('docroot') . 'artefact/' . $artefactplugin . '/blocktype/' . $pluginname . '/'. $filename;
}
}
}
}
if (empty($fullpath)) {
$fullpath = get_config('docroot') . $plugintype . '/' . $pluginname . '/' . $filename;
......@@ -802,7 +809,7 @@ function safe_require($plugintype, $pluginname, $filename='lib.php', $function='
function plugin_types() {
static $pluginstocheck;
if (empty($pluginstocheck)) {
$pluginstocheck = array('artefact', 'auth', 'notification', 'search', 'blocktype');
$pluginstocheck = array('blocktype', 'artefact', 'auth', 'notification', 'search');
}
return $pluginstocheck;
}
......
......@@ -99,14 +99,14 @@ function check_upgrades($name=null) {
$pn = $bits[1];
$pp = null;
if ($pt == 'blocktype' && strpos($pn, '/') !== false) {
$bits = explode('/', $name);
$bits = explode('/', $pn);
$pp = get_config('docroot') . 'artefact/' . $bits[0] . '/blocktype/' . $bits[1];
}
validate_plugin($pt, $pn, $pp);
$plugins[] = explode('.', $name);
}
catch (InstallationException $_e) {
log_warn("Plugin $plugin $dir is not installable: " . $e->GetMessage());
log_warn("Plugin $pt $pn is not installable: " . $_e->GetMessage());
}
}
else {
......@@ -124,7 +124,7 @@ function check_upgrades($name=null) {
$plugins[] = array($plugin, $dir);
}
catch (InstallationException $_e) {
log_warn("Plugin $plugin $dir is not installable: " . $e->GetMessage());
log_warn("Plugin $plugin $dir is not installable: " . $_e->GetMessage());
}
if ($plugin == 'artefact') { // go check it for blocks as well
......@@ -281,6 +281,10 @@ function upgrade_plugin($upgrade) {
list($plugintype, $pluginname) = explode('.', $upgrade->name);
if ($plugintype == 'blocktype' && strpos($pluginname, '/') !== false) {
list($artefactplugin, $blocktypename) = explode('/', $pluginname);
}
$location = get_config('docroot') . $plugintype . '/' . $pluginname . '/db/';
$db->StartTrans();
......@@ -311,6 +315,14 @@ function upgrade_plugin($upgrade) {
$installed->name = $pluginname;
$installed->version = $upgrade->to;
$installed->release = $upgrade->torelease;
if ($plugintype == 'blocktype') {
if (!empty($blocktypename)) {
$installed->name = $blocktypename;
}
if (!empty($artefactplugin)) { // blocks come from artefactplugins.
$installed->artefactplugin = $artefactplugin;
}
}
if (property_exists($upgrade, 'requires_config')) {
$installed->requires_config = $upgrade->requires_config;
}
......@@ -328,7 +340,7 @@ function upgrade_plugin($upgrade) {
// postinst stuff...
safe_require($plugintype, $pluginname);
$pcname = generate_class_name($plugintype, $pluginname);
$pcname = generate_class_name($plugintype, $installed->name);
if ($crons = call_static_method($pcname, 'get_cron')) {
foreach ($crons as $cron) {
......@@ -578,9 +590,9 @@ function local_xmldb_contents_sub(&$contents) {
function validate_plugin($plugintype, $pluginname, $pluginpath='') {
if (empty($pluginpath)) {
$pluginpath = get_config('docroot') . $plugin . '/';
$pluginpath = get_config('docroot') . $plugintype . '/' . $pluginname;
}
error_log("looking for $pluginpath/version.php");
if (!file_exists($pluginpath . '/version.php')) {
throw new InstallationException(get_string('versionphpmissing', 'error', $plugintype, $pluginname));
}
......@@ -590,5 +602,6 @@ function validate_plugin($plugintype, $pluginname, $pluginpath='') {
$funname($pluginname);
}
// @TODO more?
// validate the plugin class
}
?>
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