The handlers now throw moodle1_convert_exception instead of convert_exception
[moodle.git] / admin / cron.php
blobe131e9bbf057a3cfb3f1ff034abe63cc46cf78c1
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * Web cron
21 * This script looks through all the module directories for cron.php files
22 * and runs them. These files can contain cleanup functions, email functions
23 * or anything that needs to be run on a regular basis.
25 * This file is best run from cron on the host system (ie outside PHP).
26 * It is strongly recommended to add password protection via admin settings.
28 * eg wget -q -O /dev/null 'http: *moodle.somewhere.edu/admin/cron.php?password=SeCreT666'
30 * It is also possible to use CLI script admin/cli/cron.php instead,
31 * you can not call this script from command line any more.
33 * @package core
34 * @subpackage admin
35 * @copyright 1999 onwards Martin Dougiamas http://dougiamas.com
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39 // This is a fake CLI script, it is a really ugly hack which emulates
40 // CLI via web interface, please do not use this hack elsewhere
41 define('CLI_SCRIPT', true);
42 define('WEB_CRON_EMULATED_CLI', 'defined'); // ugly ugly hack, do not use elsewhere please
43 define('NO_OUTPUT_BUFFERING', true);
45 require('../config.php');
46 require_once($CFG->libdir.'/clilib.php');
47 require_once($CFG->libdir.'/cronlib.php');
49 // extra safety
50 session_get_instance()->write_close();
52 // check if execution allowed
53 if (!empty($CFG->cronclionly)) {
54 // This script can only be run via the cli.
55 print_error('cronerrorclionly', 'admin');
56 exit;
58 // This script is being called via the web, so check the password if there is one.
59 if (!empty($CFG->cronremotepassword)) {
60 $pass = optional_param('password', '', PARAM_RAW);
61 if ($pass != $CFG->cronremotepassword) {
62 // wrong password.
63 print_error('cronerrorpassword', 'admin');
64 exit;
68 // send mime type and encoding
69 if (check_browser_version('MSIE')) {
70 //ugly IE hack to work around downloading instead of viewing
71 @header('Content-Type: text/html; charset=utf-8');
72 echo "<xmp>"; //<pre> is not good enough for us here
73 } else {
74 //send proper plaintext header
75 @header('Content-Type: text/plain; charset=utf-8');
78 // execute the cron
79 cron_run();
81 // finish the IE hack
82 if (check_browser_version('MSIE')) {
83 echo "</xmp>";