Skip to content

Commit

Permalink
Issue #3003448 by Xenza, kala4ek: PHP has reserved all method names w…
Browse files Browse the repository at this point in the history
…ith a double underscore prefix for future use
  • Loading branch information
git authored and Dmitry Kiselev committed Oct 1, 2018
1 parent bb119f4 commit 45a3663
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions elysia_cron_scheduler.inc
Expand Up @@ -51,17 +51,17 @@ function _elysia_cron_next_run($conf) {

$rule = array($rules[1], $rules[2], array($rules[3], $rules[5]), $rules[4]);
$ruledec = array();
$date = __cronDecodeDate($conf['last_run'], 1);
$expected_date = __cronDecodeDate(!empty($conf['last_run_expected']) ? $conf['last_run_expected'] : 0);
$date = _cronDecodeDate($conf['last_run'], 1);
$expected_date = _cronDecodeDate(!empty($conf['last_run_expected']) ? $conf['last_run_expected'] : 0);

for ($i = 0; $i < 4; $i++) {
if ($i != 2) {
// Standard scheme for mins, hours, month.
$ruledec[$i] = __cronDecodeRule($rule[$i], $ranges[$i][0], $ranges[$i][1]);
$ruledec[$i] = _cronDecodeRule($rule[$i], $ranges[$i][0], $ranges[$i][1]);
}
else {
// For mday+week we follow another scheme.
$ruledec[$i] = __cronDecodeRuleMday($rule[2], $date[3], $date[4]);
$ruledec[$i] = _cronDecodeRuleMday($rule[2], $date[3], $date[4]);
}
$r = $ruledec[$i];
$new = $date[$i];
Expand All @@ -72,7 +72,7 @@ function _elysia_cron_next_run($conf) {
$new = $expected_date[$i] + ceil(($date[$i] - $expected_date[$i]) / $r['d']) * $r['d'];
}
elseif ($r['n']) {
$new = __cronNextOrEqual($date[$i], $r['n'], $ranges[$i][0], $ranges[$i][1]);
$new = _cronNextOrEqual($date[$i], $r['n'], $ranges[$i][0], $ranges[$i][1]);
}
if ($new != $date[$i]) {
$date[$i] = $new;
Expand All @@ -83,21 +83,21 @@ function _elysia_cron_next_run($conf) {
for ($j = 0; $j < $i; $j++) {
if ($j == 2) {
// For mday+week decoded rule could be changed (by month+year)
$ruledec[$j] = __cronDecodeRuleMday($rule[2], $date[3], $date[4]);
$ruledec[$j] = _cronDecodeRuleMday($rule[2], $date[3], $date[4]);
}
$date[$j] = $ruledec[$j]['d'] ? ($ranges[$j][0] == 0 ? 0 : $ruledec[$j]['d']) : ($ruledec[$j]['n'] ? reset($ruledec[$j]['n']) : $ranges[$j][0]);
$expected_date[$j] = 0;
}
}
}

return __cronEncodeDate($date);
return _cronEncodeDate($date);
}

/**
* Helper function for _elysia_cron_next_run().
*/
function __cronDecodeDate($timestamp, $min_diff = 0) {
function _cronDecodeDate($timestamp, $min_diff = 0) {
$time = floor($timestamp / 60);
$time += $min_diff;

Expand All @@ -115,14 +115,14 @@ function __cronDecodeDate($timestamp, $min_diff = 0) {
/**
* Helper function for _elysia_cron_next_run().
*/
function __cronEncodeDate($date) {
function _cronEncodeDate($date) {
return mktime($date[1], $date[0], 0, $date[3], $date[2], $date[4]);
}

/**
* Helper function for _elysia_cron_next_run().
*/
function __cronNextOrEqual($el, $arr, $range_start, $range_end) {
function _cronNextOrEqual($el, $arr, $range_start, $range_end) {
if (empty($arr)) {
return $el;
}
Expand All @@ -137,7 +137,7 @@ function __cronNextOrEqual($el, $arr, $range_start, $range_end) {
/**
* Helper function for _elysia_cron_next_run().
*/
function __cronDecodeRule($rule, $min, $max) {
function _cronDecodeRule($rule, $min, $max) {
if ($rule == '*') {
return array('n' => array(), 'd' => 0);
}
Expand All @@ -161,11 +161,11 @@ function __cronDecodeRule($rule, $min, $max) {
/**
* Helper function for _elysia_cron_next_run().
*/
function __cronDecodeRuleMday($rule, $month, $year) {
function _cronDecodeRuleMday($rule, $month, $year) {
$range_from = 1;
$range_to = $month != 2 ? (in_array($month, array(4, 6, 9, 11)) ? 30 : 31) : ($year % 4 == 0 ? 29 : 28);
$r1 = __cronDecodeRule($rule[0], $range_from, $range_to);
$r2 = __cronDecodeRule($rule[1], $range_from, $range_to);
$r1 = _cronDecodeRule($rule[0], $range_from, $range_to);
$r2 = _cronDecodeRule($rule[1], $range_from, $range_to);
if ($r2['d']) {
for ($i = 0; $i < 7; $i++) {
if ($i % $r2['d'] == 0) {
Expand All @@ -176,15 +176,15 @@ function __cronDecodeRuleMday($rule, $month, $year) {
if ($r2['n']) {
$r2['n'] = array_unique($r2['n']);
// Use always "31" and not $range_to, see http://drupal.org/node/1668302.
$r1['n'] = array_merge($r1['n'], __cronMonDaysFromWeekDays($year, $month, $r2['n']), __cronMonDaysFromWeekDays($year, $month + 1, $r2['n'], 31));
$r1['n'] = array_merge($r1['n'], _cronMonDaysFromWeekDays($year, $month, $r2['n']), _cronMonDaysFromWeekDays($year, $month + 1, $r2['n'], 31));
}
return $r1;
}

/**
* Helper function for _elysia_cron_next_run().
*/
function __cronMonDaysFromWeekDays($year, $mon, $weekdays, $offset = 0) {
function _cronMonDaysFromWeekDays($year, $mon, $weekdays, $offset = 0) {
if ($mon > 12) {
$year++;
$mon = $mon - 12;
Expand Down

0 comments on commit 45a3663

Please sign in to comment.