Skip to content
Snippets Groups Projects
Commit 20f14550 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

FIX #4314

parent 3dafe76f
No related branches found
No related tags found
No related merge requests found
......@@ -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');
......
......@@ -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);
......
......@@ -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);
$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');
......
......@@ -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;
......
......@@ -121,6 +121,8 @@ 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();
......@@ -129,27 +131,34 @@ if(is_array($object->lines) && (count($object->lines)>0))
// 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))
{
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) {
if ($result<0)
{
echo "Error:".$cronjob->error;
dol_syslog("cron_run_jobs.php:: fetch Error".$cronjob->error, LOG_ERR);
exit(-1);
}
// execute methode
// Execute job
$result=$cronjob->run_jobs($userlogin);
if ($result<0) {
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) {
$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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment