MDL-16438 separating subplugin detection from the plugin_supports code because it...
authorPetr Skoda <skodak@moodle.org>
Sun, 4 Apr 2010 19:58:03 +0000 (19:58 +0000)
committerPetr Skoda <skodak@moodle.org>
Sun, 4 Apr 2010 19:58:03 +0000 (19:58 +0000)
lib/adminlib.php
lib/moodlelib.php
mod/assignment/db/subplugins.php [new file with mode: 0644]
mod/assignment/lib.php
mod/data/db/subplugins.php [new file with mode: 0644]
mod/data/lib.php
mod/quiz/db/subplugins.php [new file with mode: 0644]
mod/quiz/lib.php
mod/workshop/db/subplugins.php [new file with mode: 0644]
mod/workshop/lib.php

index 2ad0497..0c3d2d9 100644 (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;
index 32c3f00..87744eb 100644 (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)) {
diff --git a/mod/assignment/db/subplugins.php b/mod/assignment/db/subplugins.php
new file mode 100644 (file)
index 0000000..52e3b41
--- /dev/null
@@ -0,0 +1,3 @@
+<?php
+
+$subplugins = array('assignment'=>'mod/assignment/type');
index 1a9df93..e93365b 100644 (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;
diff --git a/mod/data/db/subplugins.php b/mod/data/db/subplugins.php
new file mode 100644 (file)
index 0000000..2c1a7e9
--- /dev/null
@@ -0,0 +1,4 @@
+<?php
+
+$subplugins = array('datafield'  => 'mod/data/field',
+                    'datapreset' => 'mod/data/preset');
index 5d954b3..f91b280 100755 (executable)
@@ -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 (file)
index 0000000..06f8ac1
--- /dev/null
@@ -0,0 +1,3 @@
+<?php
+
+$subplugins = array('quiz'=>'mod/quiz/report');
index c166ab7..eaf151b 100644 (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;
     }
diff --git a/mod/workshop/db/subplugins.php b/mod/workshop/db/subplugins.php
new file mode 100644 (file)
index 0000000..3186096
--- /dev/null
@@ -0,0 +1,7 @@
+<?php
+
+$subplugins = array(
+                    'workshopform'       => 'mod/workshop/form',
+                    'workshopallocation' => 'mod/workshop/allocation',
+                    'workshopeval'       => 'mod/workshop/eval',
+                    );
index b160939..8327f1e 100644 (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;
     }
 }