function elysia_cron_should_run in Elysia Cron 7
Same name in this branch
- 7 elysia_cron_scheduler.inc \elysia_cron_should_run()
- 7 elysia_cron_scheduler_old.inc \elysia_cron_should_run()
Same name and namespace in other branches
- 5.2 elysia_cron_scheduler.inc \elysia_cron_should_run()
- 5.2 elysia_cron_scheduler_old.inc \elysia_cron_should_run()
- 5 elysia_cron_scheduler.inc \elysia_cron_should_run()
- 5 elysia_cron_scheduler_old.inc \elysia_cron_should_run()
- 6.2 elysia_cron_scheduler.inc \elysia_cron_should_run()
- 6.2 elysia_cron_scheduler_old.inc \elysia_cron_should_run()
- 6 elysia_cron_scheduler.inc \elysia_cron_should_run()
- 6 elysia_cron_scheduler_old.inc \elysia_cron_should_run()
- 7.2 elysia_cron_scheduler.inc \elysia_cron_should_run()
4 calls to elysia_cron_should_run()
- elysia_cron_active_jobs in ./
elysia_cron.module - Get all jobs that needs to be executed in a channel
- elysia_cron_admin_page in ./
elysia_cron.admin.inc - test_elysia_cron_should_run in ./
elysia_cron_scheduler.inc - test_elysia_cron_should_run in ./
elysia_cron_scheduler_old.inc
File
- ./
elysia_cron_scheduler_old.inc, line 3
Code
function elysia_cron_should_run($conf, $now = -1) {
if ($conf['disabled']) {
return false;
}
if ($now < 0) {
$now = time();
}
if (!$conf['last_run'] || $now - $conf['last_run'] > 365 * 86400) {
return true;
}
if (!preg_match('/^([0-9*,\\/-]+)[ ]+([0-9*,\\/-]+)[ ]+([0-9*,\\/-]+)[ ]+([0-9*,\\/-]+)[ ]+([0-9*,\\/-]+)$/', $conf['rule'], $rules)) {
_dco_watchdog('cron', 'Invalid rule found: %rule', array(
'%rule' => $conf['rule'],
));
return false;
}
$weekdayspec = $rules[5] != '*';
$mondayspec = $rules[3] != '*';
$rules[5] = _cronDecodeRule($rules[5], 0, 6);
$rules[4] = _cronDecodeRule($rules[4], 1, 12);
$rules[3] = _cronDecodeRule($rules[3], 1, 31);
$rules[2] = _cronDecodeRule($rules[2], 0, 23);
$rules[1] = _cronDecodeRule($rules[1], 0, 59);
$lastT = _cronT($conf['last_run'] + 30);
$nowT = _cronT($now);
$nowTDelta = $nowT - $lastT + ($lastT > $nowT ? 12 * 31 * 24 * 60 : 0);
$year = date('Y', $conf['last_run']);
if ($mondayspec || !$mondayspec && !$weekdayspec) {
$first = -1;
foreach ($rules[4] as $mon) {
foreach ($rules[3] as $d) {
if (checkdate($mon, $d, $year)) {
foreach ($rules[2] as $h) {
foreach ($rules[1] as $m) {
$t = _cronT($mon, $d, $h, $m);
//dprint("* ".$t." L:".$lastT);
if ($first < 0) {
$first = $t;
}
if ($t > $lastT) {
$nextT = $t;
break 4;
}
}
}
}
}
}
//dprint("R: ".$nextT);
if (!$nextT) {
$nextT = $first;
}
$nextTDelta = $nextT - $lastT + ($lastT > $nextT ? 12 * 31 * 24 * 60 : 0);
//dprint($nowT.' '.$nowTDelta.' '.$nextT.' '.$nextTDelta);
if ($nowTDelta >= $nextTDelta) {
return true;
}
}
if ($weekdayspec) {
foreach ($rules[4] as $mon) {
foreach (_cronMonDaysFromWeekDays($year, $mon, $rules[5]) as $d) {
foreach ($rules[2] as $h) {
foreach ($rules[1] as $m) {
$t = _cronT($mon, $d, $h, $m);
//dprint("* ".$t." L:".$lastT);
if ($t > $lastT) {
$nextT = $t;
break 4;
}
}
}
}
}
//dprint("R: ".$nextT);
if (!$nextT) {
//Must get the first of following year (if day_of_week is specified it's not the same of previous one)
foreach ($rules[4] as $mon) {
foreach (_cronMonDaysFromWeekDays($year + 1, $mon, $rules[5]) as $d) {
foreach ($rules[2] as $h) {
foreach ($rules[1] as $m) {
$nextT = _cronT($mon, $d, $h, $m);
break 4;
}
}
}
}
}
$nextTDelta = $nextT - $lastT + ($lastT > $nextT ? 12 * 31 * 24 * 60 : 0);
//dprint($nowT.' '.$nowTDelta.' '.$nextT.' '.$nextTDelta);
if ($nowTDelta >= $nextTDelta) {
return true;
}
}
return false;
}