### Eclipse Workspace Patch 1.0 #P moodle20 Index: admin/enrol.php =================================================================== RCS file: /cvsroot/moodle/moodle/admin/enrol.php,v retrieving revision 1.34 diff -u -r1.34 enrol.php --- admin/enrol.php 6 May 2009 08:43:51 -0000 1.34 +++ admin/enrol.php 17 Jun 2009 06:48:51 -0000 @@ -51,9 +51,9 @@ admin_externalpage_print_header(); - $modules = get_list_of_plugins("enrol"); + $modules = get_plugin_list('enrol'); $options = array(); - foreach ($modules as $module) { + foreach ($modules as $module=>$moduledir) { $options[$module] = get_string("enrolname", "enrol_$module"); } asort($options); @@ -71,12 +71,11 @@ $table->width = '700'; $table->data = array(); - $modules = get_list_of_plugins("enrol"); $enabledplugins = explode(',', $CFG->enrol_plugins_enabled); - foreach ($modules as $module) { + foreach ($modules as $module=>$moduledir) { // skip if directory is empty - if (!file_exists("$CFG->dirroot/enrol/$module/enrol.php")) { + if (!file_exists("$moduledir/enrol.php")) { continue; } Index: admin/uploaduser.php =================================================================== RCS file: /cvsroot/moodle/moodle/admin/uploaduser.php,v retrieving revision 1.93 diff -u -r1.93 uploaduser.php --- admin/uploaduser.php 14 May 2009 07:03:27 -0000 1.93 +++ admin/uploaduser.php 17 Jun 2009 06:48:52 -0000 @@ -159,7 +159,8 @@ $allowedauths = uu_allowed_auths(); $allowedauths = array_keys($allowedauths); - $availableauths = get_list_of_plugins('auth'); + $availableauths = get_plugin_list('auth'); + $availableauths = array_keys($availableauths); $allowedroles = uu_allowed_roles(true); foreach ($allowedroles as $rid=>$rname) { Index: admin/cron.php =================================================================== RCS file: /cvsroot/moodle/moodle/admin/cron.php,v retrieving revision 1.163 diff -u -r1.163 cron.php --- admin/cron.php 3 Jun 2009 08:10:22 -0000 1.163 +++ admin/cron.php 17 Jun 2009 06:48:51 -0000 @@ -183,9 +183,9 @@ // report includes cron.php with function report_reportname_cron() if it wishes // to be cronned. It is up to cron.php to handle e.g. if it only needs to // actually do anything occasionally. - $reports = get_list_of_plugins($CFG->admin.'/report'); - foreach($reports as $report) { - $cronfile = $CFG->dirroot.'/'.$CFG->admin.'/report/'.$report.'/cron.php'; + $reports = get_plugin_list('report'); + foreach($reports as $report=>$reportdir) { + $cronfile = $reportdir.'/cron.php'; if (file_exists($cronfile)) { require_once($cronfile); $cronfunction = 'report_'.$report.'_cron'; @@ -506,10 +506,10 @@ } // run gradebook import/export/report cron - if ($gradeimports = get_list_of_plugins('grade/import')) { - foreach ($gradeimports as $gradeimport) { - if (file_exists($CFG->dirroot.'/grade/import/'.$gradeimport.'/lib.php')) { - require_once($CFG->dirroot.'/grade/import/'.$gradeimport.'/lib.php'); + if ($gradeimports = get_plugin_list('gradeimport')) { + foreach ($gradeimports as $gradeimport=>$plugindir) { + if (file_exists($plugindir.'/lib.php')) { + require_once($plugindir.'/lib.php'); $cron_function = 'grade_import_'.$gradeimport.'_cron'; if (function_exists($cron_function)) { mtrace("Processing gradebook import function $cron_function ...", ''); @@ -519,10 +519,10 @@ } } - if ($gradeexports = get_list_of_plugins('grade/export')) { - foreach ($gradeexports as $gradeexport) { - if (file_exists($CFG->dirroot.'/grade/export/'.$gradeexport.'/lib.php')) { - require_once($CFG->dirroot.'/grade/export/'.$gradeexport.'/lib.php'); + if ($gradeexports = get_plugin_list('gradeexport')) { + foreach ($gradeexports as $gradeexport=>$plugindir) { + if (file_exists($plugindir.'/lib.php')) { + require_once($plugindir.'/lib.php'); $cron_function = 'grade_export_'.$gradeexport.'_cron'; if (function_exists($cron_function)) { mtrace("Processing gradebook export function $cron_function ...", ''); @@ -532,10 +532,10 @@ } } - if ($gradereports = get_list_of_plugins('grade/report')) { - foreach ($gradereports as $gradereport) { - if (file_exists($CFG->dirroot.'/grade/report/'.$gradereport.'/lib.php')) { - require_once($CFG->dirroot.'/grade/report/'.$gradereport.'/lib.php'); + if ($gradereports = get_plugin_list('gradereport')) { + foreach ($gradereports as $gradereport=>$plugindir) { + if (file_exists($plugindir.'/lib.php')) { + require_once($plugindir.'/lib.php'); $cron_function = 'grade_report_'.$gradereport.'_cron'; if (function_exists($cron_function)) { mtrace("Processing gradebook report function $cron_function ...", ''); @@ -550,10 +550,13 @@ $fs->cron(); // run any customized cronjobs, if any - // looking for functions in lib/local/cron.php - if (file_exists($CFG->dirroot.'/local/cron.php')) { - mtrace('Processing customized cron script ...', ''); - include_once($CFG->dirroot.'/local/cron.php'); + if ($locals = get_plugin_list('local')) { + mtrace('Processing customized cron scripts ...', ''); + foreach ($locals as $local=>$localdir) { + if (file_exists("$localdir/cron.php")) { + include("$localdir/cron.php"); + } + } mtrace('done.'); } Index: admin/enrol_config.php =================================================================== RCS file: /cvsroot/moodle/moodle/admin/enrol_config.php,v retrieving revision 1.21 diff -u -r1.21 enrol_config.php --- admin/enrol_config.php 6 May 2009 08:43:51 -0000 1.21 +++ admin/enrol_config.php 17 Jun 2009 06:48:51 -0000 @@ -34,8 +34,8 @@ unset($options); - $modules = get_list_of_plugins("enrol"); - foreach ($modules as $module) { + $modules = get_plugin_list('enrol'); + foreach ($modules as $module=>$enroldir) { $options[$module] = get_string("enrolname", "enrol_$module"); } asort($options); Index: admin/auth.php =================================================================== RCS file: /cvsroot/moodle/moodle/admin/auth.php,v retrieving revision 1.68 diff -u -r1.68 auth.php --- admin/auth.php 18 Jan 2009 18:00:45 -0000 1.68 +++ admin/auth.php 17 Jun 2009 06:48:51 -0000 @@ -19,9 +19,6 @@ $action = optional_param('action', '', PARAM_ACTION); $auth = optional_param('auth', '', PARAM_SAFEDIR); -// get currently installed and enabled auth plugins -$authsavailable = get_list_of_plugins('auth'); - get_enabled_auth_plugins(true); // fix the list of enabled auths if (empty($CFG->auth)) { $authsenabled = array(); Index: rss/file.php =================================================================== RCS file: /cvsroot/moodle/moodle/rss/file.php,v retrieving revision 1.24 diff -u -r1.24 file.php --- rss/file.php 5 Jan 2009 21:37:21 -0000 1.24 +++ rss/file.php 17 Jun 2009 06:49:29 -0000 @@ -65,7 +65,8 @@ //Check name of module if (!$isblog) { - $mods = get_list_of_plugins('mod'); + $mods = get_plugin_list('mod'); + $mods = array_keys($mods); if (!in_array(strtolower($modulename), $mods)) { rss_not_found(); } Index: mod/quiz/settingstree.php =================================================================== RCS file: /cvsroot/moodle/moodle/mod/quiz/settingstree.php,v retrieving revision 1.4 diff -u -r1.4 settingstree.php --- mod/quiz/settingstree.php 10 Mar 2009 08:39:55 -0000 1.4 +++ mod/quiz/settingstree.php 17 Jun 2009 06:49:28 -0000 @@ -13,9 +13,9 @@ // First get a list of quiz reports with there own settings pages. If there none, // we use a simpler overall menu structure. $reportsbyname = array(); -if ($reports = get_list_of_plugins('mod/quiz/report')) { - foreach ($reports as $report) { - if (file_exists($CFG->dirroot . "/mod/quiz/report/$report/settings.php")) { +if ($reports = get_plugin_list('quiz')) { + foreach ($reports as $report=>$reportdir) { + if (file_exists("$reportdir/settings.php")) { $strreportname = get_string($report . 'report', 'quiz_'.$report); // Deal with reports which are lacking the language string if ($strreportname[0] == '[') { Index: mod/quiz/lib.php =================================================================== RCS file: /cvsroot/moodle/moodle/mod/quiz/lib.php,v retrieving revision 1.339 diff -u -r1.339 lib.php --- mod/quiz/lib.php 13 Jun 2009 18:34:45 -0000 1.339 +++ mod/quiz/lib.php 17 Jun 2009 06:49:28 -0000 @@ -1386,6 +1386,7 @@ 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; } Index: message/db/messages.php =================================================================== RCS file: message/db/messages.php diff -N message/db/messages.php --- message/db/messages.php 25 Sep 2008 14:19:42 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,37 +0,0 @@ - array ( - ) - -); - - -?> Index: mod/quiz/report/reportlib.php =================================================================== RCS file: /cvsroot/moodle/moodle/mod/quiz/report/reportlib.php,v retrieving revision 1.38 diff -u -r1.38 reportlib.php --- mod/quiz/report/reportlib.php 10 Mar 2009 08:39:55 -0000 1.38 +++ mod/quiz/report/reportlib.php 17 Jun 2009 06:49:28 -0000 @@ -355,7 +355,7 @@ } $reports = $DB->get_records('quiz_report', null, 'displayorder DESC', 'name, capability'); - $reportdirs = get_list_of_plugins("mod/quiz/report"); + $reportdirs = get_plugin_list("quiz"); //order the reports tab in descending order of displayorder $reportcaps = array(); if ($reports){ @@ -367,7 +367,7 @@ } //add any other reports on the end - foreach ($reportdirs as $reportname) { + foreach ($reportdirs as $reportname=>$reportdir) { if (!isset($reportcaps[$reportname])) { $reportcaps[$reportname]= null; } Index: admin/xmldb/actions/XMLDBAction.class.php =================================================================== RCS file: /cvsroot/moodle/moodle/admin/xmldb/actions/XMLDBAction.class.php,v retrieving revision 1.6 diff -u -r1.6 XMLDBAction.class.php --- admin/xmldb/actions/XMLDBAction.class.php 30 May 2009 18:57:00 -0000 1.6 +++ admin/xmldb/actions/XMLDBAction.class.php 17 Jun 2009 06:48:53 -0000 @@ -201,23 +201,23 @@ * @param xmldb_structure structure object containing all the info * @return string PHP code to be used to stabilish a savepoint */ - function upgrade_savepoint_php ($structure) { + function upgrade_savepoint_php($structure) { $path = $structure->getPath(); /// Trim "db" from path $path = dirname($path); - /// Get all the available plugin types - $plugintypes = get_plugin_types(); - /// Get pluginname, plugindir and plugintype $pluginname = basename($path); if ($path == 'lib') { /// exception for lib (not proper plugin) $plugindir = 'lib'; $plugintype = 'lib'; } else { /// rest of plugins + //TODO: this is not nice and may fail, plugintype should be passed around somehow instead + $plugintypes = get_plugin_types(false); $plugindir = dirname($path); + $plugindir = str_replace('\\', '/', $plugindir); $plugintype = array_search($plugindir, $plugintypes); } Index: grade/lib.php =================================================================== RCS file: /cvsroot/moodle/moodle/grade/lib.php,v retrieving revision 1.173 diff -u -r1.173 lib.php --- grade/lib.php 15 Jun 2009 02:45:26 -0000 1.173 +++ grade/lib.php 17 Jun 2009 06:48:55 -0000 @@ -494,10 +494,10 @@ // report plugins with its special structure // Get all installed reports - if ($reports = get_list_of_plugins('grade/report', 'CVS')) { + if ($reports = get_plugin_list('gradereport')) { // Remove ones we can't see - foreach ($reports as $key => $plugin) { + foreach ($reports as $plugin=>$unused) { if (!has_capability('gradereport/'.$plugin.':view', $context)) { unset($reports[$key]); } @@ -507,7 +507,7 @@ $reportnames = array(); if (!empty($reports)) { - foreach ($reports as $plugin) { + foreach ($reports as $plugin=>$plugindir) { $pluginstr = get_string('modulename', 'gradereport_'.$plugin); $url = $url_prefix.'report/'.$plugin.'/index.php?id='.$courseid; if ($active_type == 'report' and $active_plugin == $plugin ) { @@ -516,7 +516,7 @@ $reportnames[$plugin] = new grade_plugin_info($plugin, $url, $pluginstr); // Add link to preferences tab if such a page exists - if (file_exists($CFG->dirroot . '/grade/report/'.$plugin.'/preferences.php')) { + if (file_exists($plugindir.'/preferences.php')) { $pref_url = $url_prefix.'report/'.$plugin.'/preferences.php?id='.$courseid; $plugin_info['preferences'][$plugin] = new grade_plugin_info($plugin, $pref_url, $pluginstr); } @@ -631,8 +631,8 @@ } // standard import plugins - if ($imports = get_list_of_plugins('grade/import', 'CVS')) { // Get all installed import plugins - foreach ($imports as $key => $plugin) { // Remove ones we can't see + if ($imports = get_plugin_list('gradeimport')) { // Get all installed import plugins + foreach ($imports as $plugin=>$plugindir) { // Remove ones we can't see if (!has_capability('gradeimport/'.$plugin.':view', $context)) { unset($imports[$key]); } @@ -656,7 +656,7 @@ } // standard export plugins - if ($exports = get_list_of_plugins('grade/export', 'CVS')) { // Get all installed export plugins + if ($exports = get_plugin_list('gradeexport')) { // Get all installed export plugins foreach ($exports as $key => $plugin) { // Remove ones we can't see if (!has_capability('gradeexport/'.$plugin.':view', $context)) { unset($exports[$key]); @@ -665,7 +665,7 @@ } $exportnames = array(); if (!empty($exports)) { - foreach ($exports as $plugin) { + foreach ($exports as $plugin=>$plugindir) { $pluginstr = get_string('modulename', 'gradeexport_'.$plugin); $url = $url_prefix.'export/'.$plugin.'/index.php?id='.$courseid; if ($active_type == 'export' and $active_plugin == $plugin ) { Index: admin/settings/grades.php =================================================================== RCS file: /cvsroot/moodle/moodle/admin/settings/grades.php,v retrieving revision 1.39 diff -u -r1.39 grades.php --- admin/settings/grades.php 24 Apr 2009 17:59:28 -0000 1.39 +++ admin/settings/grades.php 17 Jun 2009 06:48:52 -0000 @@ -173,12 +173,12 @@ // Reports $ADMIN->add('grades', new admin_category('gradereports', get_string('reportsettings', 'grades'))); - foreach (get_list_of_plugins('grade/report') as $plugin) { + foreach (get_plugin_list('gradereport') as $plugin=>$plugindir) { // Include all the settings commands for this plugin if there are any - if (file_exists($CFG->dirroot.'/grade/report/'.$plugin.'/settings.php')) { + if (file_exists($plugindir.'/settings.php')) { $settings = new admin_settingpage('gradereport'.$plugin, get_string('modulename', 'gradereport_'.$plugin), 'moodle/grade:manage'); if ($ADMIN->fulltree) { - include($CFG->dirroot.'/grade/report/'.$plugin.'/settings.php'); + include($plugindir.'/settings.php'); } $ADMIN->add('gradereports', $settings); } @@ -186,13 +186,13 @@ // Imports $ADMIN->add('grades', new admin_category('gradeimports', get_string('importsettings', 'grades'))); - foreach (get_list_of_plugins('grade/import') as $plugin) { + foreach (get_plugin_list('gradeimport') as $plugin=>$plugindir) { // Include all the settings commands for this plugin if there are any - if (file_exists($CFG->dirroot.'/grade/import/'.$plugin.'/settings.php')) { + if (file_exists($plugindir.'/settings.php')) { $settings = new admin_settingpage('gradeimport'.$plugin, get_string('modulename', 'gradeimport_'.$plugin), 'moodle/grade:manage'); if ($ADMIN->fulltree) { - include($CFG->dirroot.'/grade/import/'.$plugin.'/settings.php'); + include($plugindir.'/settings.php'); } $ADMIN->add('gradeimports', $settings); } @@ -201,12 +201,12 @@ // Exports $ADMIN->add('grades', new admin_category('gradeexports', get_string('exportsettings', 'grades'))); - foreach (get_list_of_plugins('grade/export') as $plugin) { + foreach (get_plugin_list('gradeexport') as $plugin=>$plugindir) { // Include all the settings commands for this plugin if there are any - if (file_exists($CFG->dirroot.'/grade/export/'.$plugin.'/settings.php')) { + if (file_exists($plugindir.'/settings.php')) { $settings = new admin_settingpage('gradeexport'.$plugin, get_string('modulename', 'gradeexport_'.$plugin), 'moodle/grade:manage'); if ($ADMIN->fulltree) { - include($CFG->dirroot.'/grade/export/'.$plugin.'/settings.php'); + include($plugindir.'/settings.php'); } $ADMIN->add('gradeexports', $settings); } @@ -214,4 +214,3 @@ } // end of speedup -?> Index: admin/settings/courses.php =================================================================== RCS file: /cvsroot/moodle/moodle/admin/settings/courses.php,v retrieving revision 1.35 diff -u -r1.35 courses.php --- admin/settings/courses.php 30 Apr 2009 04:16:35 -0000 1.35 +++ admin/settings/courses.php 17 Jun 2009 06:48:52 -0000 @@ -17,9 +17,9 @@ /// NOTE: these settings must be applied after all other settings because they depend on them ///main course settings $temp = new admin_settingpage('coursesettings', get_string('coursesettings')); - $courseformats = get_list_of_plugins('course/format'); + $courseformats = get_plugin_list('format'); $formcourseformats = array(); - foreach ($courseformats as $courseformat) { + foreach ($courseformats as $courseformat=>$courseformatdir) { $formcourseformats["$courseformat"] = get_string("format$courseformat","format_$courseformat"); if ($formcourseformats["$courseformat"]=="[[format$courseformat]]") { $formcourseformats["$courseformat"] = get_string("format$courseformat"); Index: admin/settings/plugins.php =================================================================== RCS file: /cvsroot/moodle/moodle/admin/settings/plugins.php,v retrieving revision 1.41 diff -u -r1.41 plugins.php --- admin/settings/plugins.php 17 May 2009 21:10:07 -0000 1.41 +++ admin/settings/plugins.php 17 Jun 2009 06:48:52 -0000 @@ -258,20 +258,30 @@ /// Now add reports -foreach (get_list_of_plugins($CFG->admin.'/report') as $plugin) { - $settings_path = "$CFG->dirroot/$CFG->admin/report/$plugin/settings.php"; +foreach (get_plugin_list('report') as $plugin=>$plugindir) { + $settings_path = "$plugindir/settings.php"; if (file_exists($settings_path)) { include($settings_path); continue; } - $index_path = "$CFG->dirroot/$CFG->admin/report/$plugin/index.php"; + $index_path = "$plugindir/index.php"; if (!file_exists($index_path)) { continue; } // old style 3rd party plugin without settings.php - $www_path = "$CFG->dirroot/$CFG->admin/report/$plugin/index.php"; + $www_path = "$CFG->wwwroot/$CFG->admin/report/$plugin/index.php"; $reportname = get_string($plugin, 'report_' . $plugin); $ADMIN->add('reports', new admin_externalpage('report'.$plugin, $reportname, $www_path, 'moodle/site:viewreports')); } + +/// Add all local plugins - must be always last! + +foreach (get_plugin_list('local') as $plugin=>$plugindir) { + $settings_path = "$plugindir/settings.php"; + if (file_exists($settings_path)) { + include($settings_path); + continue; + } +} \ No newline at end of file Index: admin/settings/users.php =================================================================== RCS file: /cvsroot/moodle/moodle/admin/settings/users.php,v retrieving revision 1.49 diff -u -r1.49 users.php --- admin/settings/users.php 14 May 2009 07:03:28 -0000 1.49 +++ admin/settings/users.php 17 Jun 2009 06:48:52 -0000 @@ -36,22 +36,22 @@ $ADMIN->add('authsettings', $temp); - if ($auths = get_list_of_plugins('auth')) { + if ($auths = get_plugin_list('auth')) { $authsenabled = get_enabled_auth_plugins(); $authbyname = array(); - foreach ($auths as $auth) { + foreach ($auths as $auth=>$authdir) { $strauthname = auth_get_plugin_title($auth); $authbyname[$strauthname] = $auth; } ksort($authbyname); foreach ($authbyname as $strauthname=>$authname) { - if (file_exists($CFG->dirroot.'/auth/'.$authname.'/settings.php')) { + if (file_exists($authdir.'/settings.php')) { // do not show disabled auths in tree, keep only settings link on manage page $settings = new admin_settingpage('authsetting'.$authname, $strauthname, 'moodle/site:config', !in_array($authname, $authsenabled)); if ($ADMIN->fulltree) { - include($CFG->dirroot.'/auth/'.$authname.'/settings.php'); + include($authdir.'/settings.php'); } // TODO: finish implementation of common settings - locking, etc. $ADMIN->add('authsettings', $settings); Index: lib/accesslib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/accesslib.php,v retrieving revision 1.600 diff -u -r1.600 accesslib.php --- lib/accesslib.php 16 Jun 2009 15:34:55 -0000 1.600 +++ lib/accesslib.php 17 Jun 2009 06:49:00 -0000 @@ -3025,9 +3025,9 @@ } /// Ask all the modules if anything needs to be done for this user - if ($mods = get_list_of_plugins('mod')) { - foreach ($mods as $mod) { - include_once($CFG->dirroot.'/mod/'.$mod.'/lib.php'); + if ($mods = get_plugin_list('mod')) { + foreach ($mods as $mod=>$moddir) { + include_once($moddir.'/lib.php'); $functionname = $mod.'_role_assign'; if (function_exists($functionname)) { $functionname($userid, $context, $roleid); @@ -3087,7 +3087,7 @@ if ($select) { if ($ras = $DB->get_records_select('role_assignments', implode(' AND ', $select), $params)) { - $mods = get_list_of_plugins('mod'); + $mods = get_plugin_list('mod'); foreach($ras as $ra) { $fireevent = false; /// infinite loop protection when deleting recursively @@ -3117,8 +3117,8 @@ } /// Ask all the modules if anything needs to be done for this user - foreach ($mods as $mod) { - include_once($CFG->dirroot.'/mod/'.$mod.'/lib.php'); + foreach ($mods as $mod=>$moddir) { + include_once($moddir.'/lib.php'); $functionname = $mod.'_role_unassign'; if (function_exists($functionname)) { $functionname($ra->userid, $context); // watch out, $context might be NULL if something goes wrong @@ -3208,7 +3208,7 @@ * capabilities are defined for the component, we simply return an empty array. * * @global object - * @param string $component examples: 'moodle', 'mod/forum', 'block/quiz_results' + * @param string $component full plugin name, examples: 'moodle', 'mod_forum' * @return array array of capabilities */ function load_capability_def($component) { @@ -3218,91 +3218,33 @@ $defpath = $CFG->libdir.'/db/access.php'; $varprefix = 'moodle'; } else { - $compparts = explode('/', $component); - - if ($compparts[0] == 'report') { - $defpath = $CFG->dirroot.'/'.$CFG->admin.'/report/'.$compparts[1].'/db/access.php'; - $varprefix = $compparts[0].'_'.$compparts[1]; - - } else if ($compparts[0] == 'block') { - // Blocks are an exception. Blocks directory is 'blocks', and not - // 'block'. So we need to jump through hoops. - $defpath = $CFG->dirroot.'/'.$compparts[0]. - 's/'.$compparts[1].'/db/access.php'; - $varprefix = $compparts[0].'_'.$compparts[1]; - - } else if ($compparts[0] == 'format') { - // Similar to the above, course formats are 'format' while they - // are stored in 'course/format'. - $defpath = $CFG->dirroot.'/course/'.$component.'/db/access.php'; - $varprefix = $compparts[0].'_'.$compparts[1]; - - } else if ($compparts[0] == 'editor') { - $defpath = $CFG->dirroot.'/lib/editor/'.$compparts[1].'/db/access.php'; - $varprefix = $compparts[0].'_'.$compparts[1]; - - } else if ($compparts[0] == 'gradeimport') { - $defpath = $CFG->dirroot.'/grade/import/'.$compparts[1].'/db/access.php'; - $varprefix = $compparts[0].'_'.$compparts[1]; - - } else if ($compparts[0] == 'gradeexport') { - $defpath = $CFG->dirroot.'/grade/export/'.$compparts[1].'/db/access.php'; - $varprefix = $compparts[0].'_'.$compparts[1]; - - } else if ($compparts[0] == 'gradereport') { - $defpath = $CFG->dirroot.'/grade/report/'.$compparts[1].'/db/access.php'; - $varprefix = $compparts[0].'_'.$compparts[1]; - - } else if ($compparts[0] == 'quizreport') { - $defpath = $CFG->dirroot.'/mod/quiz/report/'.$compparts[1].'/db/access.php'; - $varprefix = $compparts[0].'_'.$compparts[1]; - - } else if ($compparts[0] == 'coursereport') { - $defpath = $CFG->dirroot.'/course/report/'.$compparts[1].'/db/access.php'; - $varprefix = $compparts[0].'_'.$compparts[1]; - - } else { - $defpath = $CFG->dirroot.'/'.$component.'/db/access.php'; - $varprefix = str_replace('/', '_', $component); - } + list($type, $plugin) = explode('_', $component, 2); + $defpath = get_plugin_directory($type, $plugin).'/db/access.php'; + $varprefix = $component; } - $capabilities = array(); + $capabilities = array(); if (file_exists($defpath)) { require($defpath); $capabilities = ${$varprefix.'_capabilities'}; } + return $capabilities; } /** * Gets the capabilities that have been cached in the database for this component. - * - * @global object - * @param string $component - examples: 'moodle', 'mod/forum', 'block/quiz_results' + * @param string $component - examples: 'moodle', 'mod_forum' * @return array array of capabilities */ function get_cached_capabilities($component='moodle') { global $DB; - - if ($component == 'moodle') { - $storedcaps = $DB->get_records_select('capabilities', "name LIKE ?", array('moodle/%:%')); - - } else if ($component == 'local') { - $storedcaps = $DB->get_records_select('capabilities', "name LIKE ?", array('moodle/local:%')); - - } else { - $storedcaps = $DB->get_records_select('capabilities', "name LIKE ?", array("$component:%")); - } - - return $storedcaps; + return $DB->get_records('capabilities', array('component'=>$component)); } /** * Returns default capabilities for given legacy role type. - * - * @global object * @param string $legacyrole legacy role name * @return array */ @@ -3336,8 +3278,6 @@ * Reset role capabilitites to default according to selected legacy capability. * If several legacy caps selected, use the first from get_default_capabilities. * If no legacy selected, removes all capabilities. - * - * @global object * @param int @roleid */ function reset_role_capabilities($roleid) { Index: lib/moodlelib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/moodlelib.php,v retrieving revision 1.1215 diff -u -r1.1215 moodlelib.php --- lib/moodlelib.php 15 Jun 2009 05:37:58 -0000 1.1215 +++ lib/moodlelib.php 17 Jun 2009 06:49:11 -0000 @@ -314,6 +314,8 @@ /** 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'); @@ -3882,10 +3884,10 @@ $strdeleted = get_string('deleted'); /// Clean up course formats (iterate through all formats in the even the course format was ever changed) - $formats = get_list_of_plugins('course/format'); - foreach ($formats as $format) { + $formats = get_plugin_list('format'); + foreach ($formats as $format=>$formatdir) { $formatdelete = $format.'_course_format_delete_course'; - $formatlib = "$CFG->dirroot/course/format/$format/lib.php"; + $formatlib = "$formatdir/lib.php"; if (file_exists($formatlib)) { include_once($formatlib); if (function_exists($formatdelete)) { @@ -3946,10 +3948,6 @@ print_error('nomodules', 'debug'); } -/// Give local code a chance to delete its references to this course. - require_once($CFG->libdir.'/locallib.php'); - notify_local_delete_course($courseid, $showfeedback); - /// Delete course blocks blocks_delete_all_for_context($context->id); @@ -5692,29 +5690,12 @@ $dirroot . '/lang/' => '', $dataroot . '/lang/' => '', ); - $this->searchplacesbyplugintype = array( - 'assignment_' => array('mod/assignment/type'), - 'auth_' => array('auth'), - 'block_' => array('blocks'), - 'datafield_' => array('mod/data/field'), - 'datapreset_' => array('mod/data/preset'), - 'enrol_' => array('enrol'), - 'filter_' => array('filter'), - 'format_' => array('course/format'), - 'editor_' => array('lib/editor'), - 'quiz_' => array('mod/quiz/report'), - 'qtype_' => array('question/type'), - 'qformat_' => array('question/format'), - 'report_' => array($admin.'/report', 'course/report'), - 'repository_'=>array('repository'), - 'resource_' => array('mod/resource/type'), - 'gradereport_' => array('grade/report'), - 'gradeimport_' => array('grade/import'), - 'gradeexport_' => array('grade/export'), - 'profilefield_' => array('user/profile/field'), - 'portfolio_' => array('portfolio/type'), - '' => array('mod') - ); + $this->searchplacesbyplugintype = array(''=>array('mod')); + $plugintypes = get_plugin_types(false); + foreach ($plugintypes as $plugintype=>$dir) { + $this->searchplacesbyplugintype[$plugintype.'_'] = array($dir); + } + unset($this->searchplacesbyplugintype['mod_']); $this->restore_extra_locations_from_session(); if ($runninginstaller) { $stringnames = file($dirroot . '/install/stringnames.txt'); @@ -5822,14 +5803,10 @@ foreach ($locations as $location => $ignored) { $locations[$location] = $module . '/'; } - if ($module == 'local') { - $locations[$this->dirroot . '/local/lang/'] = 'local/'; - } else { - list($type, $plugin) = $this->parse_module_name($module); - if (isset($this->searchplacesbyplugintype[$type])) { - foreach ($this->searchplacesbyplugintype[$type] as $location) { - $locations[$this->dirroot . "/$location/$plugin/lang/"] = $plugin . '/'; - } + list($type, $plugin) = $this->parse_module_name($module); + if (isset($this->searchplacesbyplugintype[$type])) { + foreach ($this->searchplacesbyplugintype[$type] as $location) { + $locations[$this->dirroot . "/$location/$plugin/lang/"] = $plugin . '/'; } } } @@ -6371,7 +6348,7 @@ if (!empty($CFG->themelist)) { // use admin's list of themes $themelist = explode(',', $CFG->themelist); } else { - $themelist = get_list_of_plugins("theme"); + $themelist = array_keys(get_plugin_list("theme")); } foreach ($themelist as $key => $theme) { @@ -6759,6 +6736,142 @@ /// ENVIRONMENT CHECKING //////////////////////////////////////////////////////////// /** + * Return exactl path to plugin directory in dirroot + * @param string $plugintype type of plugin + * @param string $name name of the plugin + * @param bool $fullpaths false means relative paths from dirroot + * @return full directory path + */ +function get_plugin_directory($plugintype, $name, $fullpaths=true) { + if ($plugintype === '') { + $plugintype = 'mod'; + } + + $types = get_plugin_types($fullpaths); + if (!array_key_exists($plugintype, $types)) { + return null; + } + $name = clean_param($name, PARAM_SAFEDIR); // just in case ;-) + + return $types[$plugintype].'/'.$name; +} + +/** + * Lists all plugin types + * @param bool $fullpaths false means relative paths from dirroot + * @return array Array of strings - name=>location + */ +function get_plugin_types($fullpaths=true) { + global $CFG; + + static $info = null; + static $fullinfo = null; + + if (!$info) { + $info = array('mod' => 'mod', + 'auth' => 'auth', + 'enrol' => 'enrol', + 'message' => 'message/output', + 'block' => 'blocks', + 'filter' => 'filter', + 'editor' => 'lib/editor', + 'format' => 'course/format', + 'import' => 'course/import', + 'profilefield' => 'user/profile/field', + 'report' => $CFG->admin.'/report', + 'coursereport' => 'course/report', // must be after system reports + 'gradeexport' => 'grade/export', + 'gradeimport' => 'grade/import', + 'gradereport' => 'grade/report', + 'repository' => 'repository', + 'portfolio' => 'portfolio/type', + 'qtype' => 'question/type', + 'qformat' => 'question/format'); + + $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; + } + } + + // do not include themes if in non-standard location + if ($CFG->themedir === $CFG->dirroot.'/theme') { + $info['theme'] = 'theme'; + } + + // local is always last + $info['local'] = 'local'; + + $fullinfo = array(); + foreach ($info as $type=>$dir) { + $fullinfo[$type] = $CFG->dirroot.'/'.$dir; + } + $fullinfo['theme'] = $CFG->themedir; + } + + return $fullpaths ? $fullinfo : $info; +} + +/** + * Simplified version of get_list_of_plugins() + * @param string $plugintype type of plugin + * @param bool $fullpaths false means relative paths from dirroot + * @return array name=>fulllocation pairs of plugins of given type + */ +function get_plugin_list($plugintype, $fullpaths=true) { + global $CFG; + + $ignored = array('CVS', '_vti_cnf', 'simpletest', 'db'); + + if ($plugintype === '') { + $plugintype = 'mod'; + } + + if ($plugintype === 'mod') { + // mod is eán exception because we have to call this function from get_plugin_types() + $fulldir = $CFG->dirroot.'/mod'; + $dir = $fullpaths ? $fulldir : 'mod'; + + } else { + $fulltypes = get_plugin_types(true); + $types = get_plugin_types($fullpaths); + if (!array_key_exists($plugintype, $types)) { + return array(); + } + $fulldir = $fulltypes[$plugintype]; + $dir = $types[$plugintype]; + if (!file_exists($fulldir)) { + return array(); + } + } + + $result = array(); + + $items = new DirectoryIterator($fulldir); + foreach ($items as $item) { + if ($item->isDot() or !$item->isDir()) { + continue; + } + $pluginname = $item->getFilename(); + if (in_array($pluginname, $ignored)) { + continue; + } + if ($pluginname !== clean_param($pluginname, PARAM_SAFEDIR)) { + // better ignore plugins with problematic names here + continue; + } + $result[$pluginname] = $dir.'/'.$pluginname; + } + + ksort($result); + return $result; +} + +/** * Lists plugin directories within some directory * * @global object @@ -7121,9 +7234,8 @@ if ($version > $CFG->version) { return true; } - if ($mods = get_list_of_plugins('mod')) { - foreach ($mods as $mod) { - $fullmod = $CFG->dirroot .'/mod/'. $mod; + if ($mods = get_plugin_list('mod')) { + foreach ($mods as $mod=>$fullmod) { $module = new object(); if (!is_readable($fullmod .'/version.php')) { notify('Module "'. $mod .'" is not readable - check permissions'); Index: lib/portfoliolib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/portfoliolib.php,v retrieving revision 1.69 diff -u -r1.69 portfoliolib.php --- lib/portfoliolib.php 1 Jun 2009 17:06:28 -0000 1.69 +++ lib/portfoliolib.php 17 Jun 2009 06:49:11 -0000 @@ -669,11 +669,11 @@ if (is_string($plugins)) { $plugins = array($plugins); } else if (empty($plugins)) { - $plugins = get_list_of_plugins('portfolio/type'); + $plugins = get_plugin_list('portfolio'); } $insane = array(); - foreach ($plugins as $plugin) { + foreach ($plugins as $plugin=>$dir) { if ($result = portfolio_static_function($plugin, 'plugin_sanity_check')) { $insane[$plugin] = $result; } Index: lib/messagelib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/messagelib.php,v retrieving revision 1.7 diff -u -r1.7 messagelib.php --- lib/messagelib.php 26 May 2009 02:46:09 -0000 1.7 +++ lib/messagelib.php 17 Jun 2009 06:49:05 -0000 @@ -118,7 +118,7 @@ /** * This code updates the message_providers table with the current set of providers - * @param $component - examples: 'moodle', 'mod/forum', 'block/quiz_results' + * @param $component - examples: 'moodle', 'mod_forum', 'block_quiz_results' * @return boolean */ function message_update_providers($component='moodle') { @@ -210,7 +210,7 @@ /** * Loads the messages definitions for the component (from file). If no * messages are defined for the component, we simply return an empty array. - * @param $component - examples: 'moodle', 'mod/forum', 'block/quiz_results' + * @param $component - examples: 'moodle', 'mod_forum', 'block_quiz_results' * @return array of message providerss or empty array if not exists * * INTERNAL - to be used from messagelib only @@ -220,36 +220,10 @@ if ($component == 'moodle') { $defpath = $CFG->libdir.'/db/messages.php'; - - } else if ($component == 'unittest') { - $defpath = $CFG->libdir.'/simpletest/fixtures/messages.php'; - } else { - $compparts = explode('/', $component); - - if ($compparts[0] == 'block') { - // Blocks are an exception. Blocks directory is 'blocks', and not - // 'block'. So we need to jump through hoops. - $defpath = $CFG->dirroot.'/blocks/'.$compparts[1].'/db/messages.php'; - - } else if ($compparts[0] == 'format') { - // Similar to the above, course formats are 'format' while they - // are stored in 'course/format'. - $defpath = $CFG->dirroot.'/course/format/'.$compparts[1].'/db/messages.php'; - - } else if ($compparts[0] == 'gradeimport') { - $defpath = $CFG->dirroot.'/grade/import/'.$compparts[1].'/db/messages.php'; - - } else if ($compparts[0] == 'gradeexport') { - $defpath = $CFG->dirroot.'/grade/export/'.$compparts[1].'/db/messages.php'; - - } else if ($compparts[0] == 'gradereport') { - $defpath = $CFG->dirroot.'/grade/report/'.$compparts[1].'/db/messages.php'; - - } else { - $defpath = $CFG->dirroot.'/'.$component.'/db/messages.php'; - } - } + list($type, $plugin) = explode('_', $component, 2); + $defpath = get_plugin_directory($type, $plugin).'/db/messages.php'; + } $messageproviders = array(); Index: lib/eventslib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/eventslib.php,v retrieving revision 1.24 diff -u -r1.24 eventslib.php --- lib/eventslib.php 22 May 2009 08:43:14 -0000 1.24 +++ lib/eventslib.php 17 Jun 2009 06:49:04 -0000 @@ -40,40 +40,10 @@ if ($component == 'moodle') { $defpath = $CFG->libdir.'/db/events.php'; - - } else if ($component == 'unittest') { - $defpath = $CFG->libdir.'/simpletest/fixtures/events.php'; - } else { - $compparts = explode('/', $component); - - if ($compparts[0] == 'block') { - // Blocks are an exception. Blocks directory is 'blocks', and not - // 'block'. So we need to jump through hoops. - $defpath = $CFG->dirroot.'/blocks/'.$compparts[1].'/db/events.php'; - - } else if ($compparts[0] == 'format') { - // Similar to the above, course formats are 'format' while they - // are stored in 'course/format'. - $defpath = $CFG->dirroot.'/course/format/'.$compparts[1].'/db/events.php'; - - } else if ($compparts[0] == 'editor') { - $defpath = $CFG->dirroot.'/lib/editor/'.$compparts[1].'/db/events.php'; - - } else if ($compparts[0] == 'gradeimport') { - $defpath = $CFG->dirroot.'/grade/import/'.$compparts[1].'/db/events.php'; - - } else if ($compparts[0] == 'gradeexport') { - $defpath = $CFG->dirroot.'/grade/export/'.$compparts[1].'/db/events.php'; - - } else if ($compparts[0] == 'gradereport') { - $defpath = $CFG->dirroot.'/grade/report/'.$compparts[1].'/db/events.php'; - } else if ($compparts[0] == 'portfolio'){ - $defpath = $CFG->dirroot.'/portfolio/type/'.$compparts[1].'/db/events.php'; - } else { - $defpath = $CFG->dirroot.'/'.$component.'/db/events.php'; - } - } + list($type, $plugin) = explode('_', $component, 2); + $defpath = get_plugin_directory($type, $plugin).'/db/events.php'; + } $handlers = array(); @@ -121,7 +91,7 @@ * the database. * * @global object - * @param string $component examples: 'moodle', 'mod/forum', 'block/quiz_results' + * @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results' * @return boolean */ function events_update_definition($component='moodle') { Index: lib/locallib.php =================================================================== RCS file: lib/locallib.php diff -N lib/locallib.php --- lib/locallib.php 2 Jun 2009 04:13:05 -0000 1.29 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,175 +0,0 @@ -. - -/** - * This file provides hooks from moodle core into custom code. - * - * Important note - * -------------- - * - * If at all possible, the facilities provided here should not be used. - * Wherever possible, customisations should be written using one of the - * standard plug-in points like modules, blocks, auth plugins, themes, ... - * - * However, sometimes that is just not possible, because of the nature - * of the change you want to make. In which case the second best plan is - * to implement your feature in a generally useful way, which can - * be contributed back to the moodle project so that everyone benefits. - * - * But supposing you are forced to implement some nasty hack that only - * you will ever want, then the local folder is for you. The idea is that - * instead of scattering your changes throughout the code base, you - * put them all in a folder called 'local'. Then you won't have to - * deal with merging problems when you upgrade the rest of your moodle - * installation. - * - * - * Available hooks - * =============== - * - * These are similar to the module interface, however, not all the the - * facilities that are available to modules are available to local code (yet). - * See also http://docs.moodle.org/en/Development:Local_customisation for more - * information. - * - * - * Local database customisations - * ----------------------------- - * - * If your local customisations require changes to the database, use the files: - * - * local/version.php - * local/db/upgrade.php - * local/db/install.php - * - * In the file version.php, set the variable $local_version to a versionstamp - * value like 2006030300 (a concatenation of year, month, day, serial). - * - * In the file upgrade.php, implement the - * function xmldb_local_upgrade($oldversion) to make the database changes. - * - * Note that you don't need to have an install.xml file. Instead, - * when your moodle instance is first installed, xmldb_local_install() will be called. - * - * Please note that modifying of core tables is NOT supported at all! - * - * Local capabilities - * ------------------ - * - * If your local customisations require their own capabilities, use - * - * local/db/access.php - * - * You should create an array called $local_capabilities, which looks like: - * - * $local_capabilities = array( - * 'moodle/local:capability' => array( - * 'captype' => 'read', - * 'contextlevel' => CONTEXT_SYSTEM, - * ), - * ); - * - * Note that for all local capabilities you add, you'll need to add language strings. - * Moodle will expect to find them in local/lang/en_utf8/local.php (eg for English) - * with a key (following the above example) of local:capability - * See the next section for local language support. - * - * - * Local language support - * ---------------------- - * - * Moodle already supports local overriding of any language strings, or the - * creation of new strings. Just create a folder lang/XX_utf8_local where XX is - * a language code. Any language files you put in there will be used before - * the standard files. So, for example, can can create a file - * lang/en_utf8_local/moodle.php containing - * $strings['login'] = 'Sign in'; - * and that will change the string 'Login' to 'Sign in'. (See also - * http://docs.moodle.org/en/Language_editing for another way to achieve this.) - * - * This mechanism can also be used to create completely new language files. For - * example, suppose you have created some code in local/myfeature.php that needs - * some language strings. You can put those strings in the file - * lang/en_utf8_local/local_myfeature.php, and then access then using - * get_string('mystring', 'local_myfeature'). (Note that you do not have to call - * the file local_myfeature.php, you can call it anything you like, however, - * the convention of calling lang files for local/ code local_somthing is recommended.) - * - * In addition, there is one other mechanism that is available. Strings from the - * 'local' langauge file (for example get_string('mystring', 'local') will be - * found if the string is found in the file local/lang/en_utf8/local.php. Since - * the lang file 'local' is used for a lot of things like capability names, you - * can use this file for things like that. - * - * - * Local admin menu items - * ---------------------- - * - * It is possible to add new items to the admin_tree block. - * To do this, create a file, local/settings.php - * which can access the $ADMIN variable directly and add things to it. - * You might do something like: - * $ADMIN->add('root', new admin_category($name, $title); - * $ADMIN->add('foo', new admin_externalpage($name, $title, $url, $cap); - * - * - * Course deletion - * --------------- - * - * To have your local customisations notified when a course is deleted, - * make a file called - * - * local/lib.php - * - * In there, implement the function local_delete_course($courseid). This - * function will then be called whenever the functions remove_course_contents() - * or delete_course() from moodlelib are called. - * - * @package moodlecore - * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -/** - * Notify local code that a course is being deleted. - * Look for a function local_delete_course() in a file called - * local/lib.php andn call it if it is there. - * - * @global object - * @param int $courseid the course that is being deleted. - * @param bool $showfeedback Whether to display notifications on success. - * @return bool false if local_delete_course failed, or true if - * there was noting to do or local_delete_course succeeded. - */ -function notify_local_delete_course($courseid, $showfeedback) { - global $CFG; - $localfile = $CFG->dirroot .'/local/lib.php'; - if (file_exists($localfile)) { - require_once($localfile); - if (function_exists('local_delete_course')) { - if (local_delete_course($courseid)) { - if ($showfeedback) { - notify(get_string('deleted') . ' local data'); - } - } else { - return false; - } - } - } - return true; -} -?> Index: lib/gradelib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/gradelib.php,v retrieving revision 1.158 diff -u -r1.158 gradelib.php --- lib/gradelib.php 25 May 2009 08:27:25 -0000 1.158 +++ lib/gradelib.php 17 Jun 2009 06:49:05 -0000 @@ -1044,17 +1044,15 @@ return; } - if (!$mods = get_list_of_plugins('mod') ) { + if (!$mods = get_plugin_list('mod') ) { print_error('nomodules', 'debug'); } - foreach ($mods as $mod) { + foreach ($mods as $mod=>$fullmod) { if ($mod == 'NEWMODULE') { // Someone has unzipped the template, ignore it continue; } - $fullmod = $CFG->dirroot.'/mod/'.$mod; - // include the module lib once if (file_exists($fullmod.'/lib.php')) { // get all instance of the activity Index: lib/upgradelib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/upgradelib.php,v retrieving revision 1.20 diff -u -r1.20 upgradelib.php --- lib/upgradelib.php 13 Jun 2009 15:59:56 -0000 1.20 +++ lib/upgradelib.php 17 Jun 2009 06:49:14 -0000 @@ -256,18 +256,14 @@ * @param bool $allowabort allow user to abort script execution here * @return void */ -function upgrade_plugin_savepoint($result, $version, $type, $dir, $allowabort=true) { +function upgrade_plugin_savepoint($result, $version, $type, $plugin, $allowabort=true) { if (!$result) { - throw new upgrade_exception("$type/$dir", $version); + throw new upgrade_exception($type.'_'.$plugin, $version); } - /// TODO: Check that $type is a correct type - based on get_plugin_types() - /// TODO: Check that $dir (that perhaps should be named $name) is an existing plugin + $component = $type.'_'.$plugin; - $fullname = $type.'_'.$dir; - $component = $type.'/'.$dir; - - $installedversion = get_config($fullname, 'version'); + $installedversion = get_config($component, 'version'); if ($installedversion >= $version) { // Something really wrong is going on in the upgrade script throw new downgrade_exception($component, $installedversion, $version); @@ -287,14 +283,10 @@ /** * Upgrade plugins - * - * @global object - * @global object * @param string $type The type of plugins that should be updated (e.g. 'enrol', 'qtype') - * @param string $dir The directory where the plugins are located (e.g. 'question/questiontypes') - * @param string $return The url to prompt the user to continue to + * return void */ -function upgrade_plugins($type, $dir, $startcallback, $endcallback, $verbose) { +function upgrade_plugins($type, $startcallback, $endcallback, $verbose) { global $CFG, $DB; /// special cases @@ -304,12 +296,10 @@ return upgrade_plugins_blocks($startcallback, $endcallback, $verbose); } - $plugs = get_list_of_plugins($dir); - - foreach ($plugs as $plug) { + $plugs = get_plugin_list($type); - $fullplug = $CFG->dirroot.'/'.$dir.'/'.$plug; - $component = $type.'/'.$plug; // standardised plugin name + foreach ($plugs as $plug=>$fullplug) { + $component = $type.'_'.$plug; // standardised plugin name if (!is_readable($fullplug.'/version.php')) { continue; @@ -322,8 +312,8 @@ throw new plugin_defective_exception($component, 'Missing version value in version.php'); } - $plugin->name = $plug; // The name MUST match the directory - $plugin->fullname = $type.'_'.$plug; // The name MUST match the directory + $plugin->name = $plug; + $plugin->fullname = $component; if (!empty($plugin->requires)) { @@ -399,16 +389,15 @@ function upgrade_plugins_modules($startcallback, $endcallback, $verbose) { global $CFG, $DB; - $mods = get_list_of_plugins('mod'); + $mods = get_plugin_list('mod'); - foreach ($mods as $mod) { + foreach ($mods as $mod=>$fullmod) { if ($mod == 'NEWMODULE') { // Someone has unzipped the template, ignore it continue; } - $fullmod = $CFG->dirroot.'/mod/'.$mod; - $component = 'mod/'.$mod; + $component = 'mod_'.$mod; if (!is_readable($fullmod.'/version.php')) { throw new plugin_defective_exception($component, 'Missing version.php'); @@ -510,9 +499,9 @@ //Is this a first install $first_install = null; - $blocks = get_list_of_plugins('blocks'); + $blocks = get_plugin_list('block'); - foreach ($blocks as $blockname) { + foreach ($blocks as $blockname=>$fullblock) { if (is_null($first_install)) { $first_install = ($DB->count_records('block') == 0); @@ -522,8 +511,7 @@ continue; } - $fullblock = $CFG->dirroot.'/blocks/'.$blockname; - $component = 'block/'.$blockname; + $component = 'block_'.$blockname; if (!is_readable($fullblock.'/block_'.$blockname.'.php')) { throw new plugin_defective_exception('block/'.$blockname, 'Missing main block class file.'); @@ -611,8 +599,8 @@ } // Upgrade various componebts - events_update_definition($component); update_capabilities($component); + events_update_definition($component); message_update_providers($component); $endcallback($component, false, $verbose); @@ -637,70 +625,8 @@ } /** - * This function checks to see whether local database customisations are up-to-date - * by comparing $CFG->local_version to the variable $local_version defined in - * local/version.php. If not, it looks for a function called 'xmldb_local_upgrade' - * in a file called 'local/db/upgrade.php', and if it's there calls it with the - * appropiate $oldversion parameter. Then it updates $CFG->local_version. - * - * @global object - * @global object - */ -function upgrade_local_db($startcallback, $endcallback) { - global $CFG, $DB; - - // if we don't have code version, just return false - if (!file_exists($CFG->dirroot.'/local/version.php')) { - return; - } - - $local_version = null; - require($CFG->dirroot.'/local/version.php'); // Get code versions - - if (empty($CFG->local_version)) { // install - $startcallback('local', true); - - if (file_exists($CFG->dirroot.'/local/db/install.php')) { - require_once($CFG->dirroot.'/local/db/install.php'); - xmldb_local_install(); - } - set_config('local_version', $local_version); - - /// Install various components - events_update_definition('local'); - update_capabilities('local'); - message_update_providers('local'); - - $endcallback('local', true); - - } else if ($local_version > $CFG->local_version) { // upgrade! - $startcallback('local', false); - - if (file_exists($CFG->dirroot.'/local/db/upgrade.php')) { - require_once($CFG->dirroot.'/local/db/upgrade.php'); - xmldb_local_upgrade($CFG->local_version); - } - set_config('local_version', $local_version); - - /// Upgrade various components - events_update_definition('local'); - update_capabilities('local'); - message_update_providers('local'); - - $endcallback('local', false); - - } else if ($local_version < $CFG->local_version) { - throw new downgrade_exception('local', $CFG->local_version, $local_version); - } -} - - -/** * upgrade logging functions - * - * @global object */ - function upgrade_handle_exception($ex, $plugin=null) { global $CFG; @@ -1040,7 +966,6 @@ // Continue with the instalation events_update_definition('moodle'); message_update_providers('moodle'); - message_update_providers('message'); // Write default settings unconditionlly admin_apply_default_settings(NULL, true); @@ -1080,7 +1005,6 @@ update_capabilities('moodle'); events_update_definition('moodle'); message_update_providers('moodle'); - message_update_providers('message'); remove_dir($CFG->dataroot . '/cache', true); // flush cache @@ -1102,7 +1026,7 @@ try { $plugintypes = get_plugin_types(); foreach ($plugintypes as $type=>$location) { - upgrade_plugins($type, $location, 'print_upgrade_part_start', 'print_upgrade_part_end', $verbose); + upgrade_plugins($type, 'print_upgrade_part_start', 'print_upgrade_part_end', $verbose); } } catch (Exception $ex) { upgrade_handle_exception($ex); @@ -1119,14 +1043,6 @@ upgrade_handle_exception($ex); } } - - // Check for local database customisations - try { - require_once("$CFG->dirroot/lib/locallib.php"); - upgrade_local_db('print_upgrade_part_start', 'print_upgrade_part_end', $verbose); - } catch (Exception $ex) { - upgrade_handle_exception($ex); - } } /** Index: lib/adminlib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/adminlib.php,v retrieving revision 1.363 diff -u -r1.363 adminlib.php --- lib/adminlib.php 14 Jun 2009 21:35:08 -0000 1.363 +++ lib/adminlib.php 17 Jun 2009 06:49:03 -0000 @@ -199,38 +199,6 @@ } /** - * Lists all plugin types - * - * @global object - * @return array Array of strings - name=>location - */ -function get_plugin_types() { - global $CFG; - - return array('mod' => 'mod', - 'qtype' => 'question/type', - 'block' => 'blocks', - 'auth' => 'auth', - 'enrol' => 'enrol', - 'format' => 'course/format', - 'editor' => 'lib/editor', - 'gradeexport' => 'grade/export', - 'gradeimport' => 'grade/import', - 'gradereport' => 'grade/report', - 'message' => 'message/output', - 'coursereport' => 'course/report', - 'report' => $CFG->admin.'/report', - 'portfolio' => 'portfolio/type', - 'repository' => 'repository', - - // following types a very ugly hacks - we should not make exceptions like this - all plugins should be equal; - // these plugins may cause problems such as when wanting to uninstall them - 'quizreport' => 'mod/quiz/report', - 'assignment_type' => 'mod/assignment/type', - ); -} - -/** * Returns list of all directories where we expect install.xml files * * @global object @@ -245,21 +213,15 @@ $dbdirs[] = $CFG->libdir.'/db'; /// Then, all the ones defined by get_plugin_types() - if ($plugintypes = get_plugin_types()) { - foreach ($plugintypes as $plugintype => $pluginbasedir) { - if ($plugins = get_list_of_plugins($pluginbasedir, 'db')) { - foreach ($plugins as $plugin) { - $dbdirs[] = $CFG->dirroot . '/' . $pluginbasedir . '/' . $plugin . '/db'; - } + $plugintypes = get_plugin_types(); + foreach ($plugintypes as $plugintype => $pluginbasedir) { + if ($plugins = get_plugin_list($plugintype)) { + foreach ($plugins as $plugin=>$plugindir) { + $dbdirs[] = $plugindir.'/db'; } } } -/// Local database changes, if the local folder exists. - if (file_exists($CFG->dirroot . '/local')) { - $dbdirs[] = $CFG->dirroot.'/local/db'; - } - return $dbdirs; } @@ -4125,8 +4087,8 @@ } $this->choices = array(); - if ($plugins = get_list_of_plugins('grade/export')) { - foreach($plugins as $plugin) { + if ($plugins = get_plugin_list('gradeexport')) { + foreach($plugins as $plugin=>$unused) { $this->choices[$plugin] = get_string('modulename', 'gradeexport_'.$plugin); } } @@ -4301,9 +4263,9 @@ global $CFG; require_once($CFG->libdir.'/gradelib.php'); - foreach (get_list_of_plugins('grade/report') as $plugin) { - if (file_exists($CFG->dirroot.'/grade/report/'.$plugin.'/lib.php')) { - require_once($CFG->dirroot.'/grade/report/'.$plugin.'/lib.php'); + foreach (get_plugin_list('gradereport') as $plugin=>$plugindir) { + if (file_exists($plugindir.'/lib.php')) { + require_once($plugindir.'/lib.php'); $functionname = 'grade_report_'.$plugin.'_profilereport'; if (function_exists($functionname)) { $this->choices[$plugin] = get_string('modulename', 'gradereport_'.$plugin); @@ -4457,9 +4419,9 @@ $found = false; - if ($modules = get_list_of_plugins('enrol')) { + if ($modules = get_plugin_list('enrol')) { $textlib = textlib_get_instance(); - foreach ($modules as $plugin) { + foreach ($modules as $plugin=>$dir) { if (strpos($plugin, $query) !== false) { $found = true; break; @@ -4655,8 +4617,8 @@ } $textlib = textlib_get_instance(); - $authsavailable = get_list_of_plugins('auth'); - foreach ($authsavailable as $auth) { + $authsavailable = get_plugin_list('auth'); + foreach ($authsavailable as $auth=>$dir) { if (strpos($auth, $query) !== false) { return true; } @@ -4687,7 +4649,7 @@ 'up', 'down', 'none')); $txt->updown = "$txt->up/$txt->down"; - $authsavailable = get_list_of_plugins('auth'); + $authsavailable = get_plugin_list('auth'); get_enabled_auth_plugins(true); // fix the list of enabled auths if (empty($CFG->auth)) { $authsenabled = array(); @@ -4710,7 +4672,7 @@ } } - foreach ($authsavailable as $auth) { + foreach ($authsavailable as $auth=>$dir) { if (array_key_exists($auth, $displayauths)) { continue; //already in the list } @@ -5081,8 +5043,8 @@ } $textlib = textlib_get_instance(); - $portfolios= get_list_of_plugins('portfolio/type'); - foreach ($portfolios as $p) { + $portfolios = get_plugin_list('portfolio'); + foreach ($portfolios as $p=>$dir) { if (strpos($p, $query) !== false) { return true; } @@ -5112,7 +5074,8 @@ $namestr = get_string('name'); $pluginstr = get_string('plugin', 'portfolio'); - $plugins = get_list_of_plugins('portfolio/type'); + $plugins = get_plugin_list('portfolio'); + $plugins = array_keys($plugins); $instances = portfolio_instances(false, false); $alreadyplugins = array(); @@ -5418,10 +5381,6 @@ } require($CFG->dirroot.'/'.$CFG->admin.'/settings/plugins.php'); - if (file_exists($CFG->dirroot.'/local/settings.php')) { - require($CFG->dirroot.'/local/settings.php'); - } - $ADMIN->loaded = true; } @@ -5882,9 +5841,9 @@ $plugins_installed['filter'] = array(); $plugins_ondisk = array(); - $plugins_ondisk['mod'] = get_list_of_plugins('mod', 'db'); - $plugins_ondisk['blocks'] = get_list_of_plugins('blocks', 'db'); - $plugins_ondisk['filter'] = get_list_of_plugins('filter', 'db'); + $plugins_ondisk['mod'] = array_keys(get_plugin_list('mod')); + $plugins_ondisk['blocks'] = array_keys(get_plugin_list('block')); + $plugins_ondisk['filter'] = array_keys(get_plugin_list('filter')); $strstandard = get_string('standard'); $strnonstandard = get_string('nonstandard'); @@ -6048,8 +6007,8 @@ } $textlib = textlib_get_instance(); - $repositories= get_list_of_plugins('repository'); - foreach ($repositories as $p) { + $repositories= get_plugin_list('repository'); + foreach ($repositories as $p=>$dir) { if (strpos($p, $query) !== false) { return true; } @@ -6080,7 +6039,7 @@ $updownstr = get_string('updown', 'repository'); $hiddenstr = get_string('hiddenshow', 'repository'); $deletestr = get_string('delete'); - $plugins = get_list_of_plugins('repository'); + $plugins = get_plugin_list('repository'); $instances = repository::get_types(); $instancesnumber = count($instances); $alreadyplugins = array(); @@ -6161,7 +6120,7 @@ $instancehtml .= get_string('addplugin', 'repository'); $instancehtml .= '