Added cron support for blocks - it was already there in the tables, now we just need to use it
This commit is contained in:
@@ -72,6 +72,31 @@
|
||||
}
|
||||
mtrace("Finished activity modules");
|
||||
|
||||
mtrace("Starting blocks");
|
||||
if ($blocks = get_records_select("block", "cron > 0 AND (($timenow - lastcron) > cron)")) {
|
||||
// we will need the base class.
|
||||
require_once($CFG->dirroot.'/blocks/moodleblock.class.php');
|
||||
foreach ($blocks as $block) {
|
||||
$blockfile = $CFG->dirroot.'/blocks/'.$block->name.'/block_'.$block->name.'.php';
|
||||
if (file_exists($blockfile)) {
|
||||
require_once($blockfile);
|
||||
$classname = 'block_'.$block->name;
|
||||
$blockobj = new $classname;
|
||||
if (method_exists($blockobj,'cron')) {
|
||||
mtrace("Processing cron function for ".$block->name.'....','');
|
||||
if ($blockobj->cron()) {
|
||||
if (!set_field('block','lastcron',$timenow,'id',$block->id)) {
|
||||
mtrace('Error: could not update timestamp for '.$block->name);
|
||||
}
|
||||
}
|
||||
mtrace('done.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
mtrace("Finished blocks");
|
||||
|
||||
if (!empty($CFG->langcache)) {
|
||||
mtrace('Updating languages cache');
|
||||
get_list_of_languages();
|
||||
|
||||
@@ -83,6 +83,13 @@ class block_base {
|
||||
*/
|
||||
var $config = NULL;
|
||||
|
||||
/**
|
||||
* How often the cronjob should run, 0 if not at all.
|
||||
* @var int $cron
|
||||
*/
|
||||
|
||||
var $cron = NULL;
|
||||
|
||||
|
||||
/// Class Functions
|
||||
|
||||
|
||||
@@ -1071,6 +1071,9 @@ function upgrade_blocks_plugins($continueto) {
|
||||
|
||||
// If it allows multiples, start with it enabled
|
||||
$block->multiple = $blockobj->instance_allow_multiple();
|
||||
if (!empty($blockobj->cron)) {
|
||||
$block->cron = $blockobj->cron;
|
||||
}
|
||||
|
||||
// [pj] Normally this would be inline in the if, but we need to
|
||||
// check for NULL (necessary for 4.0.5 <= PHP < 4.2.0)
|
||||
|
||||
Reference in New Issue
Block a user