This commit is contained in:
Laurent Destailleur 2016-01-08 15:45:23 +01:00
parent 3dafe76f5e
commit 20f1455090
5 changed files with 50 additions and 37 deletions

View File

@ -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');

View File

@ -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);

View File

@ -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');

View File

@ -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;

View File

@ -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)
{
$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:: fetch 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();