Merge branch 'ent-1436-opciones-avanzadas-cron-modulos-sinteticos-no-funciona-correctamente-4' into 'develop'

Ent 1436 opciones avanzadas cron modulos sinteticos no funciona correctamente 4

See merge request 
This commit is contained in:
vgilc 2018-01-12 08:49:22 +01:00
commit 8fcf3a7045
3 changed files with 23 additions and 43 deletions
pandora_console/include
pandora_server/lib/PandoraFMS

@ -90,15 +90,8 @@ function cron_next_execution_date ($cron, $cur_time = false, $module_interval =
// Get cron configuration
$cron_array = explode (" ", $cron);
// Months start from 0
if ($cron_array[3] != '*') {
$mon_s = cron_get_interval ($cron_array[3]);
if ($mon_s['up'] !== false) {
$cron_array[3] = $mon_s['down'] - 1 . "-" . $mon_s['up'] - 1;
} else {
$cron_array[3] = $mon_s['down'] - 1;
}
}
// REMARKS: Months start from 1 in php (different to server)
// Get current time
if ($cur_time === false) $cur_time = time();
@ -106,10 +99,6 @@ function cron_next_execution_date ($cron, $cur_time = false, $module_interval =
$nex_time = $cur_time + $module_interval;
$nex_time_array = explode (" ", date ("i H d m Y", $nex_time));
if (cron_is_in_cron($cron_array, $nex_time_array)) return $nex_time;
// Get first next date candidate from next cron configuration
// Initialize some vars
$prev_ovfl = false;
// Update minutes
$min_s = cron_get_interval ($cron_array[0]);
@ -128,7 +117,6 @@ function cron_next_execution_date ($cron, $cur_time = false, $module_interval =
if ($nex_time === false) {
// Update the month day if overflow
$prev_ovfl = true;
$nex_time_array[1] = 0;
$nex_time_array[2]++;
$nex_time = cron_valid_date($nex_time_array);
@ -139,7 +127,7 @@ function cron_next_execution_date ($cron, $cur_time = false, $module_interval =
$nex_time = cron_valid_date($nex_time_array);
if ($nex_time === false) {
#Update the year if overflow
$nex_time_array[3] = 0;
$nex_time_array[3] = 1;
$nex_time_array[4]++;
$nex_time = cron_valid_date($nex_time_array);
}
@ -155,26 +143,24 @@ function cron_next_execution_date ($cron, $cur_time = false, $module_interval =
$nex_time_array[1] = ($hour_s['down'] == '*') ? 0 : $hour_s['down'];
// When an overflow is passed check the hour update again
if ($prev_ovfl) {
$nex_time = cron_valid_date($nex_time_array);
$nex_time = cron_valid_date($nex_time_array);
if ($nex_time >= $cur_time) {
if (cron_is_in_cron($cron_array, $nex_time_array) && $nex_time) {
return $nex_time;
}
}
$prev_ovfl = false;
// Check if next day is in cron
$nex_time_array[2]++;
$nex_time = cron_valid_date($nex_time_array);
if ($nex_time === false) {
// Update the month if overflow
$prev_ovfl = true;
$nex_time_array[2] = 1;
$nex_time_array[3]++;
$nex_time = cron_valid_date($nex_time_array);
if ($nex_time === false) {
// Update the year if overflow
$nex_time_array[3] = 0;
$nex_time_array[3] = 1;
$nex_time_array[4]++;
$nex_time = cron_valid_date($nex_time_array);
}
@ -189,21 +175,20 @@ function cron_next_execution_date ($cron, $cur_time = false, $module_interval =
$nex_time_array[2] = ($mday_s['down'] == '*') ? 1 : $mday_s['down'];
// When an overflow is passed check the hour update in the next execution
if ($prev_ovfl) {
$nex_time = cron_valid_date($nex_time_array);
$nex_time = cron_valid_date($nex_time_array);
if ($nex_time >= $cur_time) {
if (cron_is_in_cron($cron_array, $nex_time_array) && $nex_time) {
return $nex_time;
}
}
$prev_ovfl = false;
// Check if next month is in cron
$nex_time_array[3]++;
$nex_time = cron_valid_date($nex_time_array);
if ($nex_time === false) {
#Update the year if overflow
$prev_ovfl = true;
$nex_time_array[3]++;
$nex_time_array[3] = 1;
$nex_time_array[4]++;
$nex_time = cron_valid_date($nex_time_array);
}
@ -214,11 +199,11 @@ function cron_next_execution_date ($cron, $cur_time = false, $module_interval =
// Update the month if fails
$mon_s = cron_get_interval ($cron_array[3]);
$nex_time_array[3] = ($mon_s['down'] == '*') ? 0 : $mon_s['down'];
$nex_time_array[3] = ($mon_s['down'] == '*') ? 1 : $mon_s['down'];
// When an overflow is passed check the hour update in the next execution
if ($prev_ovfl) {
$nex_time = cron_valid_date($nex_time_array);
$nex_time = cron_valid_date($nex_time_array);
if ($nex_time >= $cur_time) {
if (cron_is_in_cron($cron_array, $nex_time_array) && $nex_time) {
return $nex_time;
}

@ -929,7 +929,7 @@ function html_print_extended_select_for_cron ($hour = '*', $minute = '*', $mday
}
# Months
for ($i = 0; $i < 12; $i++) {
for ($i = 1; $i <= 12; $i++) {
$months[$i] = date('F', mktime (0, 0, 0, $i, 1));
}

@ -1373,7 +1373,7 @@ sub cron_next_execution_date {
if($mon ne '*') {
my ($mon_down, $mon_up) = cron_get_interval ($mon);
if (defined($mon_up)) {
$mon = $mon_down - 1 . "-" . $mon_up - 1;
$mon = ($mon_down - 1) . "-" . ($mon_up - 1);
} else {
$mon = $mon_down - 1;
}
@ -1395,7 +1395,6 @@ sub cron_next_execution_date {
# Get first next date candidate from next cron configuration
# Initialize some vars
my @nex_time_array = @curr_time_array;
my $prev_ovfl = 0;
# Update minutes
my ($min_down, undef) = cron_get_interval ($min);
@ -1412,7 +1411,6 @@ sub cron_next_execution_date {
if ($nex_time == 0) {
#Update the month day if overflow
$prev_ovfl = 1;
$nex_time_array[1] = 0;
$nex_time_array[2]++;
$nex_time = cron_valid_date(@nex_time_array, $cur_year);
@ -1437,18 +1435,16 @@ sub cron_next_execution_date {
$nex_time_array[1] = ($hour_down eq '*') ? 0 : $hour_down;
# When an overflow is passed check the hour update again
if ($prev_ovfl) {
$nex_time = cron_valid_date(@nex_time_array, $cur_year);
$nex_time = cron_valid_date(@nex_time_array, $cur_year);
if ($nex_time >= $cur_time) {
return $nex_time if cron_is_in_cron(\@cron_array, \@nex_time_array);
}
$prev_ovfl = 0;
# Check if next day is in cron
$nex_time_array[2]++;
$nex_time = cron_valid_date(@nex_time_array, $cur_year);
if ($nex_time == 0) {
#Update the month if overflow
$prev_ovfl = 1;
$nex_time_array[2] = 1;
$nex_time_array[3]++;
$nex_time = cron_valid_date(@nex_time_array, $cur_year);
@ -1467,18 +1463,17 @@ sub cron_next_execution_date {
$nex_time_array[2] = ($mday_down eq '*') ? 1 : $mday_down;
# When an overflow is passed check the hour update in the next execution
if ($prev_ovfl) {
$nex_time = cron_valid_date(@nex_time_array, $cur_year);
$nex_time = cron_valid_date(@nex_time_array, $cur_year);
if ($nex_time >= $cur_time) {
return $nex_time if cron_is_in_cron(\@cron_array, \@nex_time_array);
}
$prev_ovfl = 0;
# Check if next month is in cron
$nex_time_array[3]++;
$nex_time = cron_valid_date(@nex_time_array, $cur_year);
if ($nex_time == 0) {
#Update the year if overflow
$prev_ovfl = 1;
$nex_time_array[3] = 0;
$cur_year++;
$nex_time = cron_valid_date(@nex_time_array, $cur_year);
}
@ -1488,11 +1483,11 @@ sub cron_next_execution_date {
#Update the month if fails
my ($mon_down, undef) = cron_get_interval ($mon);
$nex_time_array[3] = ($mday_down eq '*') ? 0 : $mday_down;
$nex_time_array[3] = ($mon_down eq '*') ? 0 : $mon_down;
# When an overflow is passed check the hour update in the next execution
if ($prev_ovfl) {
$nex_time = cron_valid_date(@nex_time_array, $cur_year);
$nex_time = cron_valid_date(@nex_time_array, $cur_year);
if ($nex_time >= $cur_time) {
return $nex_time if cron_is_in_cron(\@cron_array, \@nex_time_array);
}