-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcron.php
executable file
·87 lines (69 loc) · 2.55 KB
/
cron.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* Copyright 2008, Jefferson González (JegoYalu.com)
* This file is part of Jaris CMS and licensed under the GPL,
* check the LICENSE.txt file for version and details or visit
* https://opensource.org/licenses/GPL-3.0.
*
* Script to run all cron jobs.
*
* @example To run cron job from system an example command is the following:
* /usr/bin/php-cgi /home/username/public_html/cron.php "HTTP_HOST=www.mysite.com" or
* /usr/bin/php-cgi /home/username/public_html/cron.php 'HTTP_HOST=www.mysite.com' or
* /usr/bin/php /home/username/public_html/cron.php www.mysite.com
*/
//Disables execution time and enables unlimited execution time for cron jobs
ini_set('max_execution_time', '0');
//If running in cli mode
if (php_sapi_name() == "cli") {
chdir(__DIR__);
if (isset($_SERVER["argv"][1])) {
$_REQUEST["HTTP_HOST"] = $_SERVER["argv"][1];
} else {
$_REQUEST["HTTP_HOST"] = "localhost";
}
}
//Register autoloader
require 'src/Autoloader.php';
Jaris\Autoloader::register();
//Shorthand functions commonly used on legacy templates
require 'src/Aliases.php';
//Include backward compatible functions if include dir exists
if (file_exists("include/forms.php")) {
require 'src/DeprecatedFunctions.php';
}
//Initialize settings.
Jaris\Site::init();
//Starts the main session for the user
if (isset($_SERVER["SERVER_NAME"])) {
Jaris\Session::startIfUserLogged();
}
//Initialize error handler
Jaris\System::initiateErrorCatchSystem();
//Check if cms is run for the first time and run the installer
Jaris\System::checkIfNotInstalled();
//Check if site status is online to continue
Jaris\Site::checkIfOffline();
//Check if cron is already running and if running exit cron script
$cron_file = fopen(Jaris\Site::dataDir() . "cron_running.lock", "w+");
$cron_lock = flock($cron_file, LOCK_EX | LOCK_NB, $cron_wouldblock);
if (!$cron_lock && $cron_wouldblock) {
exit;
}
//Load installed modules
Jaris\Site::loadModules();
//Calls the cron job function of each module that requires it
Jaris\Modules::hook("hook_cronjob");
//Save execution time
Jaris\Settings::save("last_cron_jobs_run", (string)time(), "main");
//Remove cron lock file
flock($cron_file, LOCK_UN);
fclose($cron_file);
unlink(Jaris\Site::dataDir() . "cron_running.lock");
//If script was executed from control panel return to it
if (isset($_REQUEST["return"])) {
Jaris\View::addMessage(t("All jobs successfully executed."));
Jaris\Uri::go($_REQUEST["return"]);
} elseif (!Jaris\Authentication::isAdminLogged() && isset($_SERVER["SERVER_NAME"])) {
Jaris\Uri::go("");
}