From a9cf661f4da09628bbe4198fb1f18177f961982a Mon Sep 17 00:00:00 2001 From: rylon Date: Thu, 9 Oct 2014 22:05:44 +0200 Subject: [PATCH] cron fix, next func for cron, next in cronsaimod --- cron/cron.php | 21 ++++++++-- cron/crontime.php | 39 +++++++++---------- dbd/qq/SYS_CRON_GET.php | 11 ++++++ sai/autoload.inc.php | 2 +- .../{autoload_modules.php => autoload.inc} | 0 .../saimod_sys_cron/saimod_sys_cron.php | 3 +- .../saimod_sys_cron/tpl/list_entry.tpl | 1 + sai/modules/saimod_sys_cron/tpl/tabs.tpl | 1 + 8 files changed, 52 insertions(+), 26 deletions(-) create mode 100644 dbd/qq/SYS_CRON_GET.php rename sai/modules/{autoload_modules.php => autoload.inc} (100%) diff --git a/cron/cron.php b/cron/cron.php index 9a26f6b..54303f0 100644 --- a/cron/cron.php +++ b/cron/cron.php @@ -2,9 +2,9 @@ namespace SYSTEM\CRON; class cron { - private static function check($cron){ - if( !\class_exists($cron) || - !\is_array($parents = \class_parents($cron)) || + public static function check($class){ + if( !\class_exists($class) || + !\is_array($parents = \class_parents($class)) || !\array_search('SYSTEM\CRON\cronjob', $parents)){ return false;} return true;} @@ -17,7 +17,7 @@ class cron { self::status($cron[\SYSTEM\DBD\system_cron::FIELD_CLASS], \SYSTEM\CRON\cronstatus::CRON_STATUS_FAIL_CLASS); continue;} //time to execute? - if(!\SYSTEM\CRON\crontime::check_now( time($cron[\SYSTEM\DBD\system_cron::FIELD_LAST_RUN]), + if(!\SYSTEM\CRON\crontime::check_now( strtotime($cron[\SYSTEM\DBD\system_cron::FIELD_LAST_RUN]), $cron[\SYSTEM\DBD\system_cron::FIELD_MIN], $cron[\SYSTEM\DBD\system_cron::FIELD_HOUR], $cron[\SYSTEM\DBD\system_cron::FIELD_DAY], @@ -35,6 +35,19 @@ class cron { return \SYSTEM\LOG\JsonResult::ok(); } + public static function next($class){ + $cron = \SYSTEM\DBD\SYS_CRON_GET::Q1(array($class)); + //check module + if(!self::check($cron[\SYSTEM\DBD\system_cron::FIELD_CLASS])){ + throw new \SYSTEM\LOG\ERROR("Given class is not a cronjob");} + //time + return \SYSTEM\CRON\crontime::next_now( $cron[\SYSTEM\DBD\system_cron::FIELD_MIN], + $cron[\SYSTEM\DBD\system_cron::FIELD_HOUR], + $cron[\SYSTEM\DBD\system_cron::FIELD_DAY], + $cron[\SYSTEM\DBD\system_cron::FIELD_DAY_WEEK], + $cron[\SYSTEM\DBD\system_cron::FIELD_MONTH]); + } + private static function status($class, $status){ new \SYSTEM\LOG\CRON('Cron Status for Class '.$class.' updated to: '. \SYSTEM\CRON\cronstatus::decode($status)); return \SYSTEM\DBD\SYS_CRON_UPD::QI(array($status,time(),$class));} diff --git a/cron/crontime.php b/cron/crontime.php index 6a58616..03f9dda 100644 --- a/cron/crontime.php +++ b/cron/crontime.php @@ -1,23 +1,21 @@ 12){ $next_year += 1;} + $next_month = ($now_month+$month)%12;} if($day){ - if($day < $now_day){ $next_month += 1;} - $next_day = $day;} + if($day + $now_day> 31){ $next_month += 1;} + $next_day = ($now_day+$day)%31;} if($hour){ - if($hour < $now_hour){ $next_day += 1;} - $next_hour = $hour;} + if(($hour + $now_hour)> 24){ $next_day += 1;} + $next_hour = ($now_hour+$hour)%24;} if($min){ - if($min < $now_min){ $next_hour += 1;} - $next_min = $min;} + if(($min + $now_min)> 60){ $next_hour += 1;} + $next_min = ($now_min+$min)%60;} if($day_week){ $day_week = $day_week % 6; // 7 and 0 both mean Sunday $now_day_week = $now_day_week % 6; // 7 and 0 both mean Sunday @@ -28,17 +26,17 @@ class crontime { list( $now_min, $now_hour, $now_day, $now_month, $now_day_week ) = preg_split( "/ /", date("i H d n N", $base_time ) ); list( $last_min, $last_hour, $last_day, $last_month, $last_year) = preg_split( "/ /", date("i H d n Y", $base_time ) ); if($month){ - if($month > $now_month){ $last_year -= 1;} - $last_month = $month;} + if(($now_month - $month)< 12){ $last_year -= 1;} + $last_month = ($now_month-$month)%12;} if($day){ - if($day > $now_day){ $last_month -= 1;} - $last_day = $day;} + if(($now_day - $day)> 31){ $last_month -= 1;} + $last_day = ($now_day-$day)%31;} if($hour){ - if($hour > $now_hour){ $last_day -= 1;} - $last_hour = $hour;} + if(($now_hour - $hour)> 24){ $last_day -= 1;} + $last_hour = ($now_hour-$hour)%24;} if($min){ - if($min > $now_min){ $last_hour -= 1;} - $last_min = $min;} + if(($now_min - $min)> 60){ $last_hour -= 1;} + $last_min = ($now_min-$min)%60;} if($day_week){ $day_week = $day_week % 6; // 7 and 0 both mean Sunday $now_day_week = $now_day_week % 6; // 7 and 0 both mean Sunday @@ -46,9 +44,10 @@ class crontime { return mktime($last_hour, $last_min, 0, $last_month, $last_day, $last_year); } public static function check($base_time,$last_run,$min,$hour,$day,$day_week,$month){ - return self::next($last_run, $min, $hour, $day, $day_week, $month) < $base_time ? true : false;} + //new \SYSTEM\LOG\INFO('next:'.self::next($last_run, $min, $hour, $day, $day_week, $month).' bt:'.$base_time.' last:'.$last_run.' dif:'.(self::next($last_run, $min, $hour, $day, $day_week, $month) - time($base_time)).' run:'.(self::next($last_run, $min, $hour, $day, $day_week, $month) <= time($base_time) ? 'run' : 'not run')); + return self::next($last_run, $min, $hour, $day, $day_week, $month) <= $base_time ? true : false;} public static function next_now($min,$hour,$day,$day_week,$month){ - self::next(time(),$min,$hour,$day,$day_week,$month);} + return self::next(time(),$min,$hour,$day,$day_week,$month);} public static function last_now($min,$hour,$day,$day_week,$month){ return self::last(time(),$min,$hour,$day,$day_week,$month);} public static function check_now($last_run,$min,$hour,$day,$day_week,$month){ diff --git a/dbd/qq/SYS_CRON_GET.php b/dbd/qq/SYS_CRON_GET.php new file mode 100644 index 0000000..c9a4083 --- /dev/null +++ b/dbd/qq/SYS_CRON_GET.php @@ -0,0 +1,11 @@ +next()){ + $r['next'] = date('Y-m-d H:i:s',\SYSTEM\CRON\cron::next($r['class'])); $vars['content'] .= \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_cron/tpl/list_entry.tpl'), $r);} return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_cron/tpl/tabs.tpl'), $vars); } diff --git a/sai/modules/saimod_sys_cron/tpl/list_entry.tpl b/sai/modules/saimod_sys_cron/tpl/list_entry.tpl index 017fc0d..75fd5a4 100644 --- a/sai/modules/saimod_sys_cron/tpl/list_entry.tpl +++ b/sai/modules/saimod_sys_cron/tpl/list_entry.tpl @@ -6,5 +6,6 @@ ${day_week} ${month} ${last_run} + ${next} ${status} \ No newline at end of file diff --git a/sai/modules/saimod_sys_cron/tpl/tabs.tpl b/sai/modules/saimod_sys_cron/tpl/tabs.tpl index 0319acd..912ac79 100644 --- a/sai/modules/saimod_sys_cron/tpl/tabs.tpl +++ b/sai/modules/saimod_sys_cron/tpl/tabs.tpl @@ -11,6 +11,7 @@ day_week month last_run + next_run status ${content}