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

more stuff to do with blocktypes...

parent 31ba0c7f
......@@ -37,9 +37,12 @@ require('upgrade.php');
$plugins = array();
foreach (plugin_types() as $plugin) {
// this has to happen first because of broken artefact/blocktype ordering
$plugins[$plugin] = array();
$plugins[$plugin]['installed'] = array();
$plugins[$plugin]['notinstalled'] = array();
}
foreach (plugin_types() as $plugin) {
if ($installed = get_records_array($plugin . '_installed')) {
foreach ($installed as $i) {
$plugins[$plugin]['installed'][$i->name] = array();
......@@ -78,19 +81,46 @@ foreach (plugin_types() as $plugin) {
continue;
}
if (array_key_exists($dir, $plugins[$plugin]['installed'])) {
$installed = true;
}
if ($plugin != 'artefact' && empty($installed)) {
continue;
}
$plugins[$plugin]['notinstalled'][$dir] = array();
require_once('artefact.php');
$funname = $plugin . '_check_plugin_sanity';
if (function_exists($funname)) {
if (empty($installed)) {
$plugins[$plugin]['notinstalled'][$dir] = array();
try {
$funname($dir);
validate_plugin($plugin, $dir);
}
catch (InstallationException $e) {
$plugins[$plugin]['notinstalled'][$dir]['notinstallable'] = $e->GetMessage();
}
}
if ($plugin == 'artefact') { // go check it for blocks as well
$btlocation = get_config('docroot') . $plugin . '/' . $dir . '/blocktype';
if (!is_dir($btlocation)) {
continue;
}
$btdirhandle = opendir($btlocation);
while (false !== ($btdir = readdir($btdirhandle))) {
if (strpos($btdir, '.') === 0) {
continue;
}
if (!is_dir(get_config('docroot') . $plugin . '/' . $dir . '/blocktype/' . $btdir)) {
continue;
}
if (!array_key_exists($btdir, $plugins['blocktype']['installed'])) {
try {
validate_plugin('blocktype', $dir . '/' . $btdir,
get_config('docroot') . 'artefact/' . $dir . '/blocktype/' . $btdir);
$plugins['blocktype']['notinstalled'][$dir . '/' . $btdir] = array();
}
catch (InstallationException $_e) {
$plugins['blocktype']['notinstalled'][$dir . '/' . $btdir]['notinstallable'] = $_e->getMessage();
}
}
}
}
}
}
......
......@@ -37,7 +37,7 @@ class PluginArtefactFile extends PluginArtefact {
}
public static function get_block_types() {
return array();
return array('image');
}
public static function get_plugin_name() {
......
......@@ -65,6 +65,7 @@ $string['artefactpluginmethodmissing'] = "Artefact plugin %s must implement %s
$string['blocktypelibmissing'] = 'Missing lib.php for block %s in artefact plugin %s';
$string['blocktypemissingconfigform'] = 'Block type %s must implement config_form';
$string['blocktypemissingconfigsave'] = 'Block type %s must implement config_save';
$string['versionphpmissing'] = 'Plugin %s %s is missing version.php!';
// if you change these next two , be sure to change them in libroot/errors.php
// as they are duplicated there, in the case that get_string was not available.
......
......@@ -53,12 +53,12 @@ function artefact_check_plugin_sanity($pluginname) {
}
}
if (!class_exists($typeclassname)) {
throw new InstallationException(get_string('pluginclassmissing', 'error', $typeclassname, $type, $plugin));
throw new InstallationException(get_string('classmissing', 'error', $typeclassname, $type, $plugin));
}
}
$types = call_static_method($classname, 'get_block_types');
foreach ($types as $type) {
$typeclassname = generate_blocktype_class_name($type);
$pluginclassname = generate_class_name('blocktype', 'image');
if (get_config('installed')) {
if ($taken = get_record_select('blocktype_installed', 'name = ?', array($type))) {
throw new InstallationException(get_string('blocktypenametaken', 'error', $type,
......@@ -67,13 +67,13 @@ function artefact_check_plugin_sanity($pluginname) {
}
// go look for the lib file to include
try {
safe_require('blocktype', $type);
safe_require('blocktype', $pluginname . '/' . $type);
}
catch (Exception $_e) {
throw new InstallationException(get_string('blocktypelibmissing', 'error', $type, $pluginname));
}
if (!class_exists($typeclassname)) {
throw new InstallationException(get_string('pluginclassmissing', 'error', $typeclassname, $type, $pluginname));
if (!class_exists($pluginclassname)) {
throw new InstallationException(get_string('classmissing', 'error', $pluginclassname, $type, $pluginname));
}
}
}
......
......@@ -291,9 +291,16 @@ function get_string_location($identifier, $section, $variables, $replacefunc='fo
else {
$extras = plugin_types(); // more later..
foreach ($extras as $tocheck) {
if (strpos($section,$tocheck . '.') === 0) {
if (strpos($section, $tocheck . '.') === 0) {
$pluginname = substr($section ,strlen($tocheck) + 1);
$locations[] = $docroot . $tocheck . '/' . $pluginname . '/lang/';
if ($tocheck == 'blocktype' &&
strpos($pluginname, '/') !== false) { // it belongs to an artefact plugin
$bits = explode('/', $pluginname);
$locations[] = $docroot . 'artefact/ ' . $bits[0] . '/blocktype/' . $bits[1] . '/' . 'lang/';
}
else {
$locations[] = $docroot . $tocheck . '/' . $pluginname . '/lang/';
}
}
}
}
......
......@@ -93,7 +93,21 @@ function check_upgrades($name=null) {
$plugins = array();
if (!empty($name)) {
$plugins[] = explode('.', $name);
try {
$bits = explode('.', $name);
$pt = $bits[0];
$pn = $bits[1];
$pp = null;
if ($pt == 'blocktype' && strpos($pn, '/') !== false) {
$bits = explode('/', $name);
$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());
}
}
else {
foreach ($pluginstocheck as $plugin) {
......@@ -105,18 +119,30 @@ function check_upgrades($name=null) {
if (!is_dir(get_config('docroot') . $plugin . '/' . $dir)) {
continue;
}
require_once('artefact.php');
$funname = $plugin . '_check_plugin_sanity';
if (function_exists($funname)) {
try {
$funname($dir);
}
catch (InstallationException $e) {
log_warn("Plugin $plugin $dir is not installable: " . $e->GetMessage());
try {
validate_plugin($plugin, $dir);
$plugins[] = array($plugin, $dir);
}
catch (InstallationException $_e) {
log_warn("Plugin $plugin $dir is not installable: " . $e->GetMessage());
}
if ($plugin == 'artefact') { // go check it for blocks as well
$btlocation = get_config('docroot') . $plugin . '/blocktype';
if (!is_dir($btlocation)) {
continue;
}
$btdirhandle = opendir($btlocation);
while (false !== ($btdir = readdir($btdirhandle))) {
if (strpos($btdir, '.') === 0) {
continue;
}
if (!is_dir(get_config('docroot') . $plugin . '/blocktype/' . $btdir)) {
continue;
}
$plugins[] = array('blocktype', $dir . '/' . $btdir);
}
}
$plugins[] = array($plugin, $dir);
}
}
}
......@@ -127,7 +153,12 @@ function check_upgrades($name=null) {
$pluginpath = "$plugin[0]/$plugin[1]";
$pluginkey = "$plugin[0].$plugin[1]";
if ($plugintype == 'blocktype' && strpos($pluginname, '/') !== false) {
// sigh.. we're a bit special...
$bits = explode('/', $pluginname);
$pluginpath = 'artefact/' . $bits[0] . '/blocktype/' . $bits[1];
}
// Don't try to get the plugin info if we are installing - it will
// definitely fail
$pluginversion = 0;
......@@ -539,4 +570,25 @@ function local_xmldb_contents_sub(&$contents) {
$contents = str_replace($searchstring, $tosub, $contents);
}
/**
* validates a plugin for installation
* @throws InstallationException
*/
function validate_plugin($plugintype, $pluginname, $pluginpath='') {
if (empty($pluginpath)) {
$pluginpath = get_config('docroot') . $plugin . '/';
}
if (!file_exists($pluginpath . '/version.php')) {
throw new InstallationException(get_string('versionphpmissing', 'error', $plugintype, $pluginname));
}
require_once('artefact.php');
$funname = $plugintype . '_check_plugin_sanity';
if (function_exists($funname)) {
$funname($pluginname);
}
// @TODO more?
}
?>
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