| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
define('context','external'); |
|---|
| 9 |
|
|---|
| 10 |
$starttime = microtime(); |
|---|
| 11 |
|
|---|
| 12 |
require_once(dirname(__FILE__)."/includes.php"); |
|---|
| 13 |
|
|---|
| 14 |
$timenow = time(); |
|---|
| 15 |
|
|---|
| 16 |
mtrace("<pre>"); |
|---|
| 17 |
mtrace("Server Time: ".date('r',$timenow)."\n\n"); |
|---|
| 18 |
|
|---|
| 19 |
$lastcron = $CFG->lastcron; |
|---|
| 20 |
if (empty($lastcron)) { |
|---|
| 21 |
$lastcron = 0; |
|---|
| 22 |
} |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
if ($timenow - (60*60*24) > $lastcron) { |
|---|
| 26 |
mtrace('Cleaning up old incoming files... ',''); |
|---|
| 27 |
|
|---|
| 28 |
delete_records_select('files_incoming','intentiondate < ?',array(time()-60*60*24)); |
|---|
| 29 |
|
|---|
| 30 |
$dirtocheck = $CFG->dataroot.'temp/lms/'; |
|---|
| 31 |
$cmd = "find $dirtocheck -type d -cmin 1440 -print0 | xargs -0 -r rm -rf"; |
|---|
| 32 |
exec($cmd); |
|---|
| 33 |
|
|---|
| 34 |
$dirtocheck = $CFG->dataroot.'lms/incoming'; |
|---|
| 35 |
|
|---|
| 36 |
// or root. |
|---|
| 37 |
$cmd = "find $dirtocheck -type d -cmin 1440 -print0 | xargs -0 -r rm -rf"; |
|---|
| 38 |
exec($cmd); |
|---|
| 39 |
|
|---|
| 40 |
mtrace('done'); |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
if ($mods = get_list_of_plugins()) { |
|---|
| 45 |
foreach ($mods as $mod) { |
|---|
| 46 |
$libfile = $CFG->dirroot.'mod/'.$mod.'/lib.php'; |
|---|
| 47 |
if (!file_exists($libfile)) { |
|---|
| 48 |
continue; |
|---|
| 49 |
} |
|---|
| 50 |
require_once($libfile); |
|---|
| 51 |
$cronfunction = $mod.'_cron'; |
|---|
| 52 |
if (!function_exists($cronfunction)) { |
|---|
| 53 |
continue; |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
mtrace('Running cron for '.$mod.'...',''); |
|---|
| 57 |
$cronfunction(); |
|---|
| 58 |
mtrace('Done'); |
|---|
| 59 |
} |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
if (!set_config('lastcron',$timenow)) { |
|---|
| 64 |
mtrace('Could not update last cron time to now!'); |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
mtrace("Cron script completed correctly"); |
|---|
| 68 |
|
|---|
| 69 |
$difftime = microtime_diff($starttime, microtime()); |
|---|
| 70 |
mtrace("Execution took ".$difftime." seconds"); |
|---|
| 71 |
|
|---|
| 72 |
?> |
|---|