MDL-16438 separating subplugin detection from the plugin_supports code because it was running into infinite loops in get_string() which is often incorrectly used in lib.php files, but the get_string() itself needs to know about subplugins

This commit is contained in:
Petr Skoda
2010-04-04 19:58:03 +00:00
parent b9dd2a2e56
commit 846e4e177e
10 changed files with 37 additions and 40 deletions
+13 -9
View File
@@ -120,15 +120,19 @@ define('INSECURE_DATAROOT_ERROR', 2);
function uninstall_plugin($type, $name) {
global $CFG, $DB, $OUTPUT;
// recursively uninstall all the subplugins first
$subpluginlocations = plugin_supports($type, $name, FEATURE_MOD_SUBPLUGINS);
if (is_array($subpluginlocations)) {
foreach ($subpluginlocations as $subplugintype => $notusedlocationpath) {
$subplugins = get_plugin_list($subplugintype);
foreach ($subplugins as $subpluginname => $notusedpluginpath) {
uninstall_plugin($subplugintype, $subpluginname);
// recursively uninstall all module subplugins first
if ($type === 'mod') {
if (file_exists("$CFG->dirroot/$name/db/subplugins.php")) {
$subplugins = array();
include("$moddir/db/subplugins.php");
foreach ($subplugins as $subplugintype=>$dir) {
$instances = get_plugin_list($subplugintype);
foreach ($instances as $subpluginname => $notusedpluginpath) {
uninstall_plugin($subplugintype, $subpluginname);
}
}
}
}
$component = $type . '_' . $name; // eg. 'qtype_multichoice' or 'workshopgrading_accumulative' or 'mod_forum'
@@ -5078,10 +5082,10 @@ class admin_setting_managelicenses extends admin_setting {
$displayname = html_writer::link($value->source, get_string($value->shortname, 'license'), array('target'=>'_blank'));
if ($value->enabled == 1) {
$hideshow = html_writer::link($url.'&action=disable&license='.$value->shortname,
$hideshow = html_writer::link($url.'&action=disable&license='.$value->shortname,
html_writer::tag('img', '', array('src'=>$OUTPUT->pix_url('i/hide'), 'class'=>'icon', 'alt'=>'disable')));
} else {
$hideshow = html_writer::link($url.'&action=enable&license='.$value->shortname,
$hideshow = html_writer::link($url.'&action=enable&license='.$value->shortname,
html_writer::tag('img', '', array('src'=>$OUTPUT->pix_url('i/show'), 'class'=>'icon', 'alt'=>'enable')));
}
$enabled = true;
+7 -23
View File
@@ -357,8 +357,6 @@ define('FEATURE_GROUPMEMBERSONLY', 'groupmembersonly');
define('FEATURE_MOD_ARCHETYPE', 'mod_archetype');
/** True if module supports intro editor */
define('FEATURE_MOD_INTRO', 'mod_intro');
/** True if module supports subplugins */
define('FEATURE_MOD_SUBPLUGINS', 'mod_subplugins');
/** True if module has default completion */
define('FEATURE_MODEDIT_DEFAULT_COMPLETION', 'modedit_default_completion');
@@ -6223,7 +6221,7 @@ function get_string($identifier, $module='', $a=NULL, $extralocations=NULL) {
break;
}
}
return get_string_manager()->get_string($identifier, $module, $a);
}
@@ -6833,11 +6831,12 @@ function get_plugin_types($fullpaths=true) {
$mods = get_plugin_list('mod');
foreach ($mods as $mod => $moddir) {
if (!$subplugins = plugin_supports('mod', $mod, FEATURE_MOD_SUBPLUGINS, false)) {
continue;
}
foreach ($subplugins as $subtype=>$dir) {
$info[$subtype] = $dir;
if (file_exists("$moddir/db/subplugins.php")) {
$subplugins = array();
include("$moddir/db/subplugins.php");
foreach ($subplugins as $subtype=>$dir) {
$info[$subtype] = $dir;
}
}
}
@@ -7058,21 +7057,6 @@ function plugin_supports($type, $name, $feature, $default=null) {
$function = $name.'_supports';
} else {
if ($feature == FEATURE_MOD_SUBPLUGINS) {
//sorry only modules
return false;
}
if (!$dir = get_plugin_directory($type, $name)) {
throw new coding_exception("Unsupported plugin type or name ($type/$name)");
}
$libfile = $dir.'/lib.php';
if (file_exists($libfile)) {
include_once($libfile);
}
$function = $type.'_'.$name.'_supports';
}
if (function_exists($function)) {
+3
View File
@@ -0,0 +1,3 @@
<?php
$subplugins = array('assignment'=>'mod/assignment/type');
-1
View File
@@ -3339,7 +3339,6 @@ function assignment_supports($feature) {
case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
case FEATURE_GRADE_HAS_GRADE: return true;
case FEATURE_GRADE_OUTCOMES: return true;
case FEATURE_MOD_SUBPLUGINS: return array('assignment'=>'mod/assignment/type'); // to be hopefully removed in 2.0
case FEATURE_GRADE_HAS_GRADE: return true;
default: return null;
+4
View File
@@ -0,0 +1,4 @@
<?php
$subplugins = array('datafield' => 'mod/data/field',
'datapreset' => 'mod/data/preset');
-1
View File
@@ -2578,7 +2578,6 @@ function data_supports($feature) {
case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
case FEATURE_GRADE_HAS_GRADE: return true;
case FEATURE_GRADE_OUTCOMES: return true;
case FEATURE_MOD_SUBPLUGINS: return array('datafield'=>'mod/data/field', 'datapreset'=>'mod/data/preset');
case FEATURE_RATE: return true;
default: return null;
+3
View File
@@ -0,0 +1,3 @@
<?php
$subplugins = array('quiz'=>'mod/quiz/report');
-1
View File
@@ -1567,7 +1567,6 @@ function quiz_supports($feature) {
case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
case FEATURE_GRADE_HAS_GRADE: return true;
case FEATURE_GRADE_OUTCOMES: return true;
case FEATURE_MOD_SUBPLUGINS: return array('quiz'=>'mod/quiz/report');
default: return null;
}
+7
View File
@@ -0,0 +1,7 @@
<?php
$subplugins = array(
'workshopform' => 'mod/workshop/form',
'workshopallocation' => 'mod/workshop/allocation',
'workshopeval' => 'mod/workshop/eval',
);
-5
View File
@@ -46,11 +46,6 @@ function workshop_supports($feature) {
case FEATURE_GROUPINGS: return true;
case FEATURE_GROUPMEMBERSONLY: return true;
case FEATURE_MOD_INTRO: return true;
case FEATURE_MOD_SUBPLUGINS: return array(
'workshopform' => 'mod/workshop/form',
'workshopallocation' => 'mod/workshop/allocation',
'workshopeval' => 'mod/workshop/eval',
);
default: return null;
}
}