diff --git a/htdocs/cron/card.php b/htdocs/cron/card.php index b61ffb8da7fa000cd32729a739dc2728c7c36b56..569c85b2ce82591b96136396a16f45d9f5392af5 100644 --- a/htdocs/cron/card.php +++ b/htdocs/cron/card.php @@ -91,6 +91,8 @@ if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->cron->del // Execute jobs if ($action == 'confirm_execute' && $confirm == "yes" && $user->rights->cron->execute) { + $now = dol_now(); // Date we start + $result=$object->run_jobs($user->login); if ($result < 0) @@ -100,7 +102,7 @@ if ($action == 'confirm_execute' && $confirm == "yes" && $user->rights->cron->ex } else { - $res = $object->reprogram_jobs($user->login); + $res = $object->reprogram_jobs($user->login, $now); if ($res > 0) { if ($object->lastresult > 0) setEventMessages($langs->trans("JobFinished"), null, 'warnings'); diff --git a/htdocs/cron/class/cronjob.class.php b/htdocs/cron/class/cronjob.class.php index 5605cf1bfb2d5fb67cdea5d1dd2c1d3b4f4f04f0..39eaacd303fbf240754aef5e5e117bb191b032fc 100644 --- a/htdocs/cron/class/cronjob.class.php +++ b/htdocs/cron/class/cronjob.class.php @@ -1056,14 +1056,13 @@ class Cronjob extends CommonObject * Reprogram a job * * @param string $userlogin User login + * @param timestamp $now Date returned by dol_now() * @return int <0 if KO, >0 if OK */ - function reprogram_jobs($userlogin) + function reprogram_jobs($userlogin, $now) { dol_syslog(get_class($this)."::reprogram_jobs userlogin:$userlogin", LOG_DEBUG); - $now = dol_now(); - require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; $user=new User($this->db); $result=$user->fetch('',$userlogin); diff --git a/htdocs/cron/list.php b/htdocs/cron/list.php index d5331819ed21b9d34402ad9bc91a625e07dd431e..9645d42261ba7f1ec72ff71f4f4e50bddf48ad5b 100644 --- a/htdocs/cron/list.php +++ b/htdocs/cron/list.php @@ -93,17 +93,18 @@ if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->cron->del // Execute jobs if ($action == 'confirm_execute' && $confirm == "yes" && $user->rights->cron->execute){ - //Execute jobs $object = new Cronjob($db); $job = $object->fetch($id); - $result = $object->run_jobs($user->login); + $now = dol_now(); // Date we start + + $result = $object->run_jobs($user->login); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } else { - $res = $object->reprogram_jobs($user->login); + $res = $object->reprogram_jobs($user->login, $now); if ($res > 0) { if ($object->lastresult > 0) setEventMessages($langs->trans("JobFinished"), null, 'warnings'); diff --git a/htdocs/public/cron/cron_run_jobs.php b/htdocs/public/cron/cron_run_jobs.php index 5fd0ff949b48078a6362d0cb2fed520254b9509f..cfd4b28711dcad967ec864d3b03f5093aab949ad 100644 --- a/htdocs/public/cron/cron_run_jobs.php +++ b/htdocs/public/cron/cron_run_jobs.php @@ -119,6 +119,9 @@ if ($result<0) exit; } + +// TODO Duplicate code. This sequence of code must be shared with code into cron_run_jobs.php script. + // current date $now=dol_now(); $nbofjobs=count($object->lines); @@ -130,12 +133,11 @@ if (is_array($object->lines) && (count($object->lines)>0)) // Loop over job foreach($object->lines as $line) { - dol_syslog("cron_run_jobs.php fetch cronjobid: ".$line->id, LOG_WARNING); + dol_syslog("cron_run_jobs.php cronjobid: ".$line->id, LOG_WARNING); //If date_next_jobs is less of current dat, execute the program, and store the execution time of the next execution in database if (($line->datenextrun < $now) && (empty($line->datestart) || $line->datestart <= $now) && (empty($line->dateend) || $line->dateend >= $now)) { - dol_syslog("cron_run_jobs.php:: torun line->datenextrun:".dol_print_date($line->datenextrun,'dayhourtext')." line->dateend:".dol_print_date($line->dateend,'dayhourtext')." now:".dol_print_date($now,'dayhourtext')); $cronjob=new Cronjob($db); @@ -160,7 +162,7 @@ if (is_array($object->lines) && (count($object->lines)>0)) } // We re-program the next execution and stores the last execution time for this job - $result=$cronjob->reprogram_jobs($userlogin); + $result=$cronjob->reprogram_jobs($userlogin, $now); if ($result<0) { echo "Error:".$cronjob->error; diff --git a/scripts/cron/cron_run_jobs.php b/scripts/cron/cron_run_jobs.php index 20fb55bb2135416cac5f86119d1c4976955e73c3..df755a50b64c8610ca664dd36222c037ac2f42a2 100755 --- a/scripts/cron/cron_run_jobs.php +++ b/scripts/cron/cron_run_jobs.php @@ -121,42 +121,51 @@ if ($result<0) exit(-1); } +// TODO This sequence of code must be shared with code into cron_run_jobs.php php page. + // current date $now=dol_now(); if(is_array($object->lines) && (count($object->lines)>0)) { - // Loop over job - foreach($object->lines as $line) + // Loop over job + foreach($object->lines as $line) + { + dol_syslog("cron_run_jobs.php cronjobid: ".$line->id, LOG_WARNING); + + //If date_next_jobs is less of current date, execute the program, and store the execution time of the next execution in database + if (($line->datenextrun < $now) && (empty($line->datestart) || $line->datestart <= $now) && (empty($line->dateend) || $line->dateend >= $now)) { - //If date_next_jobs is less of current date, execute the program, and store the execution time of the next execution in database - if (($line->datenextrun < $now) && (empty($line->datestart) || $line->datestart <= $now) && (empty($line->dateend) || $line->dateend >= $now)) + dol_syslog("cron_run_jobs.php:: torun line->datenextrun:".dol_print_date($line->datenextrun,'dayhourtext')." line->dateend:".dol_print_date($line->dateend,'dayhourtext')." now:".dol_print_date($now,'dayhourtext')); + + $cronjob=new Cronjob($db); + $result=$cronjob->fetch($line->id); + if ($result<0) + { + echo "Error:".$cronjob->error; + dol_syslog("cron_run_jobs.php:: fetch Error".$cronjob->error, LOG_ERR); + exit(-1); + } + // Execute job + $result=$cronjob->run_jobs($userlogin); + if ($result<0) { - $cronjob=new Cronjob($db); - $result=$cronjob->fetch($line->id); - if ($result<0) { - echo "Error:".$cronjob->error; - dol_syslog("cron_run_jobs.php:: fetch Error".$cronjob->error, LOG_ERR); - exit(-1); - } - // execute methode - $result=$cronjob->run_jobs($userlogin); - if ($result<0) { - echo "Error:".$cronjob->error; - dol_syslog("cron_run_jobs.php:: run_jobs Error".$cronjob->error, LOG_ERR); - exit(-1); - } - - // we re-program the next execution and stores the last execution time for this job - $result=$cronjob->reprogram_jobs($userlogin); - if ($result<0) { - echo "Error:".$cronjob->error; - dol_syslog("cron_run_jobs.php:: reprogram_jobs Error".$cronjob->error, LOG_ERR); - exit(-1); - } + echo "Error:".$cronjob->error; + dol_syslog("cron_run_jobs.php:: run_jobs Error".$cronjob->error, LOG_ERR); + exit(-1); + } + // we re-program the next execution and stores the last execution time for this job + $result=$cronjob->reprogram_jobs($userlogin, $now); + if ($result<0) + { + echo "Error:".$cronjob->error; + dol_syslog("cron_run_jobs.php:: reprogram_jobs Error".$cronjob->error, LOG_ERR); + exit(-1); } + } + } } $db->close();