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