mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
9fa49e22ab
Basically all the Database functions are in lib/datalib.php and the web functions are all in lib/weblib.php, so moodlelib.php is much thinner than it was. Data functions have been extended ... most old calls will still work, but now many more SQL commands can be performed using the datalib functions rather than using SQL. I'm currently moving through the whole tree replacing SQL calls or at least concentrating them in one section of mod/xxx/lib.php Still working on forums, quizzes, surveys, resources. The tree is currently not full working ... some things are half-completed ... will resume tomorrow.
70 lines
2.2 KiB
PHP
70 lines
2.2 KiB
PHP
<?PHP // $Id$
|
|
|
|
// This script looks through all the module directories for cron.php files
|
|
// and runs them. These files can contain cleanup functions, email functions
|
|
// or anything that needs to be run on a regular basis.
|
|
//
|
|
// This file is best run from cron on the host system (ie outside PHP).
|
|
// The script can either be invoked via the web server or via a standalone
|
|
// version of PHP compiled for CGI.
|
|
//
|
|
// eg wget -q -O /dev/null 'http://moodle.somewhere.edu/admin/cron.php'
|
|
// or php /web/moodle/admin/cron.php
|
|
|
|
$FULLME = "cron";
|
|
|
|
require("../config.php");
|
|
|
|
echo "<PRE>\n";
|
|
|
|
$timenow = time();
|
|
|
|
// Run all cron jobs for each module
|
|
|
|
if ($mods = get_records_select("modules", "cron > 0 AND (($timenow - lastcron) > cron)")) {
|
|
foreach ($mods as $mod) {
|
|
$libfile = "$CFG->dirroot/mod/$mod->name/lib.php";
|
|
if (file_exists($libfile)) {
|
|
include_once($libfile);
|
|
$cron_function = $mod->name."_cron";
|
|
if (function_exists($cron_function)) {
|
|
if ($cron_function()) {
|
|
if (! set_field("modules", "lastcron", $timenow, "id", $mod->id)) {
|
|
echo "Error: could not update timestamp for $mod->fullname\n";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// Unenrol users who haven't logged in for $CFG->longtimenosee
|
|
|
|
if ($CFG->longtimenosee) { // value in days
|
|
$longtime = $timenow - ($CFG->longtimenosee * 3600 * 24);
|
|
if ($users = get_users_longtimenosee($longtime)) {
|
|
foreach ($users as $user) {
|
|
if (unenrol_student($user->id)) {
|
|
echo "Deleted student enrolment for $user->firstname $user->lastname ($user->id)\n";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// Delete users who haven't confirmed within seven days
|
|
|
|
$oneweek = $timenow - (7 * 24 * 3600);
|
|
if ($users = get_users_unconfirmed($oneweek)) {
|
|
foreach ($users as $user) {
|
|
if (delete_records("user", "id", $user->id)) {
|
|
echo "Deleted unconfirmed user for $user->firstname $user->lastname ($user->id)\n";
|
|
}
|
|
}
|
|
}
|
|
|
|
echo "Cron script completed correctly\n";
|
|
|
|
?>
|