From 846e4e177efd947dcd883b262616acb0885c6c84 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sun, 4 Apr 2010 19:58:03 +0000 Subject: [PATCH] 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 --- lib/adminlib.php | 22 +++++++++++++--------- lib/moodlelib.php | 30 +++++++----------------------- mod/assignment/db/subplugins.php | 3 +++ mod/assignment/lib.php | 1 - mod/data/db/subplugins.php | 4 ++++ mod/data/lib.php | 1 - mod/quiz/db/subplugins.php | 3 +++ mod/quiz/lib.php | 1 - mod/workshop/db/subplugins.php | 7 +++++++ mod/workshop/lib.php | 5 ----- 10 files changed, 37 insertions(+), 40 deletions(-) create mode 100644 mod/assignment/db/subplugins.php create mode 100644 mod/data/db/subplugins.php create mode 100644 mod/quiz/db/subplugins.php create mode 100644 mod/workshop/db/subplugins.php diff --git a/lib/adminlib.php b/lib/adminlib.php index 2ad04970fe3..0c3d2d984d1 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -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; diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 32c3f00d173..87744ebf7cf 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -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)) { diff --git a/mod/assignment/db/subplugins.php b/mod/assignment/db/subplugins.php new file mode 100644 index 00000000000..52e3b41db5b --- /dev/null +++ b/mod/assignment/db/subplugins.php @@ -0,0 +1,3 @@ +'mod/assignment/type'); diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index 1a9df93af74..e93365be9ce 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -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; diff --git a/mod/data/db/subplugins.php b/mod/data/db/subplugins.php new file mode 100644 index 00000000000..2c1a7e92136 --- /dev/null +++ b/mod/data/db/subplugins.php @@ -0,0 +1,4 @@ + 'mod/data/field', + 'datapreset' => 'mod/data/preset'); diff --git a/mod/data/lib.php b/mod/data/lib.php index 5d954b3ff7f..f91b280d41b 100755 --- a/mod/data/lib.php +++ b/mod/data/lib.php @@ -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; diff --git a/mod/quiz/db/subplugins.php b/mod/quiz/db/subplugins.php new file mode 100644 index 00000000000..06f8ac16bf4 --- /dev/null +++ b/mod/quiz/db/subplugins.php @@ -0,0 +1,3 @@ +'mod/quiz/report'); diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index c166ab76ae7..eaf151b51cf 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -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; } diff --git a/mod/workshop/db/subplugins.php b/mod/workshop/db/subplugins.php new file mode 100644 index 00000000000..3186096a69a --- /dev/null +++ b/mod/workshop/db/subplugins.php @@ -0,0 +1,7 @@ + 'mod/workshop/form', + 'workshopallocation' => 'mod/workshop/allocation', + 'workshopeval' => 'mod/workshop/eval', + ); diff --git a/mod/workshop/lib.php b/mod/workshop/lib.php index b160939f3d5..8327f1e0b9f 100644 --- a/mod/workshop/lib.php +++ b/mod/workshop/lib.php @@ -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; } }