Added cron support for blocks - it was already there in the tables, now we just need to use it

This commit is contained in:
mjollnir_
2006-02-14 03:24:08 +00:00
parent d02cb0d006
commit f9648e77cf
3 changed files with 35 additions and 0 deletions
+25
View File
@@ -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();
+7
View File
@@ -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
+3
View File
@@ -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)