root/releases/0.8rc1/cron.php

Revision 297, 1.9 kB (checked in by carmartin, 2 years ago)

Includes should use full path given that we know where things are. Patch 2.

  • Property svn:eol-style set to native
Line 
1 <?php
2
3 // very basic cron functionality.
4 // later this will go through /mod
5 // and things like auth plugins
6 // but we don't have those yet, so...
7
8 $starttime = microtime();
9
10 require_once(dirname(__FILE__)."/includes.php");
11
12 $timenow  = time();
13
14 mtrace("<pre>");
15 mtrace("Server Time: ".date('r',$timenow)."\n\n");
16
17 $lastcron = $CFG->lastcron;
18 if (empty($lastcron)) {
19     $lastcron = 0;
20 }
21
22 // we only want to do this once a day because it could take awhile...
23 if ($timenow - (60*60*24) > $lastcron) {
24     mtrace('Cleaning up old incoming files... ','');
25     // clean up the lms incoming files
26     delete_records_select('files_incoming','intentiondate < ?',array(time()-60*60*24));
27
28     $dirtocheck = $CFG->dataroot.'temp/lms/';   
29     $cmd = "find $dirtocheck -type d -cmin 1440 -print0 | xargs -0 -r rm -rf";
30     exec($cmd);
31     
32     $dirtocheck = $CFG->dataroot.'lms/incoming';
33     // this is not going to work unless this script is running as either the owner of these files
34     // or root.
35     $cmd = "find $dirtocheck -type d -cmin 1440 -print0 | xargs -0 -r rm -rf";
36     exec($cmd);
37
38     mtrace('done');
39 }
40
41 // module cron
42 if ($mods = get_list_of_plugins()) {
43     foreach ($mods as $mod) {
44         $libfile = $CFG->dirroot.'mod/'.$mod.'/lib.php';
45         if (!file_exists($libfile)) {
46             continue;
47         }
48         require_once($libfile);
49         $cronfunction = $mod.'_cron';
50         if (!function_exists($cronfunction)) {
51             continue;
52         }
53         // each module is responsible for checking their last runtime and not running again if it's too soon.
54         mtrace('Running cron for '.$mod.'...','');
55         $cronfunction();
56         mtrace('Done');
57     }
58 }
59
60
61 if (!set_config('lastcron',$timenow)) {
62     mtrace('Could not update last cron time to now!');
63 }
64
65 mtrace("Cron script completed correctly");
66
67 $difftime = microtime_diff($starttime, microtime());
68 mtrace("Execution took ".$difftime." seconds");
69
70 ?>
Note: See TracBrowser for help on using the browser.