FIX #4314
This commit is contained in:
parent
3dafe76f5e
commit
20f1455090
@ -91,6 +91,8 @@ if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->cron->del
|
|||||||
// Execute jobs
|
// Execute jobs
|
||||||
if ($action == 'confirm_execute' && $confirm == "yes" && $user->rights->cron->execute)
|
if ($action == 'confirm_execute' && $confirm == "yes" && $user->rights->cron->execute)
|
||||||
{
|
{
|
||||||
|
$now = dol_now(); // Date we start
|
||||||
|
|
||||||
$result=$object->run_jobs($user->login);
|
$result=$object->run_jobs($user->login);
|
||||||
|
|
||||||
if ($result < 0)
|
if ($result < 0)
|
||||||
@ -100,7 +102,7 @@ if ($action == 'confirm_execute' && $confirm == "yes" && $user->rights->cron->ex
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$res = $object->reprogram_jobs($user->login);
|
$res = $object->reprogram_jobs($user->login, $now);
|
||||||
if ($res > 0)
|
if ($res > 0)
|
||||||
{
|
{
|
||||||
if ($object->lastresult > 0) setEventMessages($langs->trans("JobFinished"), null, 'warnings');
|
if ($object->lastresult > 0) setEventMessages($langs->trans("JobFinished"), null, 'warnings');
|
||||||
|
|||||||
@ -1056,14 +1056,13 @@ class Cronjob extends CommonObject
|
|||||||
* Reprogram a job
|
* Reprogram a job
|
||||||
*
|
*
|
||||||
* @param string $userlogin User login
|
* @param string $userlogin User login
|
||||||
|
* @param timestamp $now Date returned by dol_now()
|
||||||
* @return int <0 if KO, >0 if OK
|
* @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);
|
dol_syslog(get_class($this)."::reprogram_jobs userlogin:$userlogin", LOG_DEBUG);
|
||||||
|
|
||||||
$now = dol_now();
|
|
||||||
|
|
||||||
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
|
||||||
$user=new User($this->db);
|
$user=new User($this->db);
|
||||||
$result=$user->fetch('',$userlogin);
|
$result=$user->fetch('',$userlogin);
|
||||||
|
|||||||
@ -93,17 +93,18 @@ if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->cron->del
|
|||||||
// Execute jobs
|
// Execute jobs
|
||||||
if ($action == 'confirm_execute' && $confirm == "yes" && $user->rights->cron->execute){
|
if ($action == 'confirm_execute' && $confirm == "yes" && $user->rights->cron->execute){
|
||||||
|
|
||||||
//Execute jobs
|
|
||||||
$object = new Cronjob($db);
|
$object = new Cronjob($db);
|
||||||
$job = $object->fetch($id);
|
$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) {
|
if ($result < 0) {
|
||||||
setEventMessages($object->error, $object->errors, 'errors');
|
setEventMessages($object->error, $object->errors, 'errors');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$res = $object->reprogram_jobs($user->login);
|
$res = $object->reprogram_jobs($user->login, $now);
|
||||||
if ($res > 0)
|
if ($res > 0)
|
||||||
{
|
{
|
||||||
if ($object->lastresult > 0) setEventMessages($langs->trans("JobFinished"), null, 'warnings');
|
if ($object->lastresult > 0) setEventMessages($langs->trans("JobFinished"), null, 'warnings');
|
||||||
|
|||||||
@ -119,6 +119,9 @@ if ($result<0)
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO Duplicate code. This sequence of code must be shared with code into cron_run_jobs.php script.
|
||||||
|
|
||||||
// current date
|
// current date
|
||||||
$now=dol_now();
|
$now=dol_now();
|
||||||
$nbofjobs=count($object->lines);
|
$nbofjobs=count($object->lines);
|
||||||
@ -130,12 +133,11 @@ if (is_array($object->lines) && (count($object->lines)>0))
|
|||||||
// Loop over job
|
// Loop over job
|
||||||
foreach($object->lines as $line)
|
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 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))
|
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'));
|
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);
|
$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
|
// 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)
|
if ($result<0)
|
||||||
{
|
{
|
||||||
echo "Error:".$cronjob->error;
|
echo "Error:".$cronjob->error;
|
||||||
|
|||||||
@ -121,42 +121,51 @@ if ($result<0)
|
|||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO This sequence of code must be shared with code into cron_run_jobs.php php page.
|
||||||
|
|
||||||
// current date
|
// current date
|
||||||
$now=dol_now();
|
$now=dol_now();
|
||||||
|
|
||||||
if(is_array($object->lines) && (count($object->lines)>0))
|
if(is_array($object->lines) && (count($object->lines)>0))
|
||||||
{
|
{
|
||||||
// Loop over job
|
// Loop over job
|
||||||
foreach($object->lines as $line)
|
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
|
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'));
|
||||||
if (($line->datenextrun < $now) && (empty($line->datestart) || $line->datestart <= $now) && (empty($line->dateend) || $line->dateend >= $now))
|
|
||||||
|
$cronjob=new Cronjob($db);
|
||||||
|
$result=$cronjob->fetch($line->id);
|
||||||
|
if ($result<0)
|
||||||
{
|
{
|
||||||
$cronjob=new Cronjob($db);
|
echo "Error:".$cronjob->error;
|
||||||
$result=$cronjob->fetch($line->id);
|
dol_syslog("cron_run_jobs.php:: fetch Error".$cronjob->error, LOG_ERR);
|
||||||
if ($result<0) {
|
exit(-1);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// Execute job
|
||||||
|
$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, $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();
|
$db->close();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user