forked from fengoffice/fengoffice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cron.php
66 lines (57 loc) · 1.89 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
<?php
chdir(dirname(__FILE__));
define("CONSOLE_MODE", true);
define('PUBLIC_FOLDER', 'public');
include "init.php";
include APPLICATION_PATH . "/cron_functions.php";
header("Content-type: text/plain");
$type = array_var($_GET, "type");
session_commit(); // we don't need sessions
@set_time_limit(0); // don't limit execution of cron, if possible
$fast_functions = array(
"send_reminders" => 1,
"send_password_expiration_reminders" => 1,
"send_notifications_through_cron"=> 1
);
$events = CronEvents::getDueEvents();
foreach ($events as $event) {
if ($event->getEnabled()) {
$function = $event->getName();
if ( $type=="fast" && array_var($fast_functions, $function) ||
$type=="slow" && !array_var($fast_functions, $function) ||
!$type ) {
/* @var $event CronEvent */
$event = CronEvents::findById($event->getId());
if (!$event instanceof CronEvent || $event->getDate() instanceof DateTimeValue && $event->getDate()->getTimestamp() > DateTimeValueLib::now()->getTimestamp()) {
continue;
}
$errordate = DateTimeValueLib::now()->add("m", 30);
/* setting this date allows to rerun the event in 30 minutes if a fatal error occurs
during its execution, which would prevent the event from being rescheduled */
$event->setDate($errordate);
$event->save();
$function = $event->getName();
try {
if (function_exists($function)) {
$function();
} else {
echo "Could not execute $function - function does not exists\n";
}
} catch (Error $e) {
echo $e->getMessage();
}
if ($event->getRecursive()) {
try {
DB::beginWork();
$nextdate = DateTimeValueLib::now()->add("m", $event->getDelay());
$event->setDate($nextdate);
$event->save();
DB::commit();
} catch (Exception $e) {
echo $e->getMessage();
DB::rollback();
}
}
}
}
}