Skip to content

Commit

Permalink
MDL-16438 centralise information about plugins to avoid duplication, …
Browse files Browse the repository at this point in the history
…includes local customisation conversion to standard plugin structure + fixes for some recent regressions; see tracker for more details and links to docs and forums discussions
  • Loading branch information
skodak committed Jun 19, 2009
1 parent 5085a59 commit 17da2e6
Show file tree
Hide file tree
Showing 60 changed files with 726 additions and 829 deletions.
3 changes: 0 additions & 3 deletions admin/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
41 changes: 22 additions & 19 deletions admin/cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 ...", '');
Expand All @@ -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 ...", '');
Expand All @@ -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 ...", '');
Expand All @@ -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.');
}

Expand Down
9 changes: 4 additions & 5 deletions admin/enrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions admin/enrol_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 2 additions & 8 deletions admin/report/unittest/test_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,9 @@


/// upgrade all plugins types
$upgradedplugins = false;
$plugintypes = get_plugin_types();
foreach ($plugintypes as $type=>$location) {
$upgradedplugins = upgrade_plugins($type, $location) || $upgradedplugins;
foreach ($plugintypes as $type => $location) {
upgrade_plugins($type);
}

/// Check for changes to RPC functions
Expand All @@ -95,11 +94,6 @@
upgrade_RPC_functions($return_url); // Return here afterwards
}

/// Check for local database customisations
/// first old *.php update and then the new upgrade.php script
require_once("$CFG->dirroot/lib/locallib.php");
upgrade_local_db($return_url); // Return here afterwards

/// just make sure upgrade logging is properly terminated
upgrade_finished();

Expand Down
4 changes: 2 additions & 2 deletions admin/settings/courses.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
19 changes: 9 additions & 10 deletions admin/settings/grades.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,26 +173,26 @@

// 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);
}
}

// 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);
}
Expand All @@ -201,17 +201,16 @@

// 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);
}
}

} // end of speedup

?>
18 changes: 14 additions & 4 deletions admin/settings/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
8 changes: 4 additions & 4 deletions admin/settings/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion admin/uploaduser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions admin/xmldb/actions/XMLDBAction.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,23 +201,23 @@ function launch($action) {
* @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);
}

Expand Down
4 changes: 2 additions & 2 deletions blocks/admin/block_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ function get_content() {
if (has_capability('moodle/grade:viewall', $context)) {
$reportavailable = true;
} else if (!empty($course->showgrades)) {
if ($reports = get_list_of_plugins('grade/report')) { // Get all installed reports
if ($reports = get_plugin_list('gradereport')) { // Get all installed reports
arsort($reports); // user is last, we want to test it first
foreach ($reports as $plugin) {
foreach ($reports as $plugin => $plugindir) {
if (has_capability('gradereport/'.$plugin.':view', $context)) {
//stop when the first visible plugin is found
$reportavailable = true;
Expand Down
6 changes: 3 additions & 3 deletions course/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ function definition() {
$mform->setHelpButton('summary', array('text2', get_string('helptext')), true);
$mform->setType('summary', PARAM_RAW);

$courseformats = get_list_of_plugins('course/format');
$courseformats = get_plugin_list('format');
$formcourseformats = array();
foreach ($courseformats as $courseformat) {
$formcourseformats["$courseformat"] = get_string("format$courseformat","format_$courseformat");
foreach ($courseformats as $courseformat => $formatdir) {
$formcourseformats["$courseformat"] = get_string("format$courseformat", "format_$courseformat");
if($formcourseformats["$courseformat"]=="[[format$courseformat]]") {
$formcourseformats["$courseformat"] = get_string("format$courseformat");
}
Expand Down
6 changes: 3 additions & 3 deletions course/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@

print_header($course->fullname.': '.$strimport, $course->fullname.': '.$strimport, $navigation);

$directories = get_list_of_plugins('course/import');
$imports = get_plugin_list('import');

foreach ($directories as $directory) {
foreach ($imports as $import => $importdir) {
echo '<div class="plugin">';
include_once($CFG->dirroot.'/course/import/'.$directory.'/mod.php');
include($importdir.'/mod.php');
echo '</div>';
}

Expand Down
6 changes: 3 additions & 3 deletions course/report.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
$navigation = build_navigation($navlinks);
print_header($course->fullname.': '.$strreports, $course->fullname.': '.$strreports, $navigation);

$directories = get_list_of_plugins('course/report');
$reports = get_plugin_list('report');

foreach ($directories as $directory) {
$pluginfile = $CFG->dirroot.'/course/report/'.$directory.'/mod.php';
foreach ($reports as $report => $reportdirectory) {
$pluginfile = $reportdirectory.'/mod.php';
if (file_exists($pluginfile)) {
ob_start();
include($pluginfile); // Fragment for listing
Expand Down
6 changes: 3 additions & 3 deletions grade/edit/settings/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ function definition() {
$types = array('report', 'export', 'import');

foreach($types as $type) {
foreach (get_list_of_plugins('grade/'.$type) as $plugin) {
foreach (get_plugin_list('grade'.$type) as $plugin => $plugindir) {
// Include all the settings commands for this plugin if there are any
if (file_exists($CFG->dirroot.'/grade/'.$type.'/'.$plugin.'/lib.php')) {
require_once($CFG->dirroot.'/grade/'.$type.'/'.$plugin.'/lib.php');
if (file_exists($plugindir.'/lib.php')) {
require_once($plugindir.'/lib.php');
$functionname = 'grade_'.$type.'_'.$plugin.'_settings_definition';
if (function_exists($functionname)) {
$mform->addElement('header', 'grade_'.$type.$plugin, get_string('modulename', 'grade'.$type.'_'.$plugin, NULL));
Expand Down
Loading

0 comments on commit 17da2e6

Please sign in to comment.