Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

cron MDL-25370 Added support for course report cron

- Adds support for course report cron
- Moves existing admin report cron support to end of cron function
- Adds new core API get_plugin_list_with_function

note: default shipping course and admin reports do not use cron
function, this is only to support plugins.
  • Loading branch information...
commit 546380244fdea5d224881694037ae97e90cddf5b 1 parent 8d9db9e
@sammarshallou sammarshallou authored
Showing with 67 additions and 25 deletions.
  1. +27 −25 lib/cronlib.php
  2. +40 −0 lib/moodlelib.php
View
52 lib/cronlib.php
@@ -156,31 +156,6 @@ function cron_run() {
}
mtrace("Finished quiz reports");
- mtrace('Starting admin reports');
- // Admin reports do not have a database table that lists them. Instead a
- // 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_plugin_list('report');
- foreach($reports as $report => $reportdir) {
- $cronfile = $reportdir.'/cron.php';
- if (file_exists($cronfile)) {
- require_once($cronfile);
- $cronfunction = 'report_'.$report.'_cron';
- mtrace('Processing cron function for '.$report.'...', '');
- $pre_dbqueries = null;
- $pre_dbqueries = $DB->perf_get_queries();
- $pre_time = microtime(true);
- $cronfunction();
- if (isset($pre_dbqueries)) {
- mtrace("... used " . ($DB->perf_get_queries() - $pre_dbqueries) . " dbqueries");
- mtrace("... used " . round(microtime(true) - $pre_time, 2) . " seconds");
- }
- mtrace('done.');
- }
- }
- mtrace('Finished admin reports');
-
mtrace('Starting main gradebook job ...');
grade_cron();
mtrace('done.');
@@ -496,6 +471,33 @@ function cron_run() {
mtrace('done.');
}
+ // NOTE: Other types of plugin could also be supported in this loop, which
+ // can handle generic cron function.
+ foreach (array('report', 'coursereport') as $plugintype) {
+ mtrace('Starting plugin type: ' . $plugintype);
+ // These reports do not have a database table that lists them. Instead
+ // a report has cron.php with function report_reportname_cron() if it
+ // wishes to be cronned. It is up to this function to handle e.g. if it
+ // only needs to actually do anything occasionally.
+ $reports = get_plugin_list_with_function(
+ $plugintype, 'cron', 'cron.php');
+ foreach($reports as $report => $cronfunction) {
+ mtrace('Processing cron function for ' . $report . '...', '');
+ $pre_dbqueries = null;
+ $pre_dbqueries = $DB->perf_get_queries();
+ $pre_time = microtime(true);
+ $cronfunction();
+ if (isset($pre_dbqueries)) {
+ mtrace("... used " .
+ ($DB->perf_get_queries() - $pre_dbqueries) .
+ " dbqueries");
+ mtrace("... used " . round(microtime(true) - $pre_time, 2) .
+ " seconds");
+ }
+ mtrace('done.');
+ }
+ mtrace('Finished plugin type: ' . $plugintype);
+ }
mtrace("Cron script completed correctly");
View
40 lib/moodlelib.php
@@ -7320,6 +7320,46 @@ function get_plugin_list($plugintype) {
}
/**
+ * Gets a list of all plugin API functions for given plugin type, function
+ * name, and filename.
+ * @param string $plugintype Plugin type, e.g. 'mod' or 'report'
+ * @param string $function Name of function after the frankenstyle prefix;
+ * e.g. if the function is called report_courselist_hook then this value
+ * would be 'hook'
+ * @param string $file Name of file that includes function within plugin,
+ * default 'lib.php'
+ * @return Array of plugin frankenstyle (e.g. 'report_courselist', 'mod_forum')
+ * to valid, existing plugin function name (e.g. 'report_courselist_hook',
+ * 'forum_hook')
+ */
+function get_plugin_list_with_function($plugintype, $function, $file='lib.php') {
+ $result = array();
+ // Loop through list of plugins with given type
+ $list = get_plugin_list($plugintype);
+ foreach($list as $plugin => $dir) {
+ $path = $dir . '/' . $file;
+ // If file exists, require it and look for function
+ if (file_exists($path)) {
+ require_once($path);
+ $fullfunction = $plugintype . '_' . $plugin . '_' . $function;
+ if (function_exists($fullfunction)) {
+ // Function exists with standard name. Store, indexed by
+ // frankenstyle name of plugin
+ $result[$plugintype . '_' . $plugin] = $fullfunction;
+ } else if($plugintype === 'mod') {
+ // For modules, we also allow plugin without full frankenstyle
+ // but just starting with the module name
+ $shortfunction = $plugin . '_' . $function;
+ if (function_exists($shortfunction)) {
+ $result[$plugintype . '_' . $plugin] = $shortfunction;
+ }
+ }
+ }
+ }
+ return $result;
+}
+
+/**
* Lists plugin-like directories within specified directory
*
* This function was originally used for standard Moodle plugins, please use
Please sign in to comment.
Something went wrong with that request. Please try again.