From f9648e77cf002067cd8a4c19bffbf06e8fe83fd3 Mon Sep 17 00:00:00 2001 From: mjollnir_ Date: Tue, 14 Feb 2006 03:24:08 +0000 Subject: [PATCH] Added cron support for blocks - it was already there in the tables, now we just need to use it --- admin/cron.php | 25 +++++++++++++++++++++++++ blocks/moodleblock.class.php | 7 +++++++ lib/blocklib.php | 3 +++ 3 files changed, 35 insertions(+) diff --git a/admin/cron.php b/admin/cron.php index b5172c97782..5932eec72b2 100644 --- a/admin/cron.php +++ b/admin/cron.php @@ -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(); diff --git a/blocks/moodleblock.class.php b/blocks/moodleblock.class.php index 0fab4a2b834..14bb583b273 100644 --- a/blocks/moodleblock.class.php +++ b/blocks/moodleblock.class.php @@ -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 diff --git a/lib/blocklib.php b/lib/blocklib.php index 4e639eb05e4..b69c18e38f1 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -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)