diff --git a/htdocs/cron/card.php b/htdocs/cron/card.php index 60513588ef8..b61ffb8da7f 100644 --- a/htdocs/cron/card.php +++ b/htdocs/cron/card.php @@ -317,7 +317,7 @@ if (($action=="create") || ($action=="edit")) print "\n"; print "
| '; print $langs->trans('CronDtLastLaunch')." | "; - if(!empty($object->datelastrun)) {print dol_print_date($object->datelastrun,'dayhourtext');} else {print $langs->trans('CronNone');} - print " | |||||||||||||
| '; - print $langs->trans('CronDtNextLaunch'); - print ' ('.$langs->trans('CronFrom').')'; - print " | "; - if(!empty($object->datenextrun)) {print dol_print_date($object->datenextrun,'dayhourtext');} else {print $langs->trans('CronNone');} + if(!empty($object->datelastrun)) {print dol_print_date($object->datelastrun,'dayhoursec');} else {print $langs->trans('CronNone');} print " | |||||||||||||
| '; print $langs->trans('CronDtLastResult')." | "; - if(!empty($object->datelastresult)) {print dol_print_date($object->datelastresult,'dayhourtext');} else {print $langs->trans('CronNone');} + if(!empty($object->datelastresult)) {print dol_print_date($object->datelastresult,'dayhoursec');} else {print $langs->trans('CronNone');} print " | |||||||||||||
';
diff --git a/htdocs/cron/class/cronjob.class.php b/htdocs/cron/class/cronjob.class.php
index 742db0cb461..5605cf1bfb2 100644
--- a/htdocs/cron/class/cronjob.class.php
+++ b/htdocs/cron/class/cronjob.class.php
@@ -521,9 +521,6 @@ class Cronjob extends CommonObject
// Check parameters
// Put here code to add a control on parameters values
- if (empty($this->status)) {
- $this->dateend=dol_now();
- }
if (dol_strlen($this->datestart)==0) {
$this->errors[]=$langs->trans('CronFieldMandatory',$langs->trans('CronDtStart'));
$error++;
@@ -830,7 +827,9 @@ class Cronjob extends CommonObject
/**
- * Run a job
+ * Run a job.
+ * Once job is finished, status and nb of of run is updated.
+ * This function does not plan the next run. This is done by function ->reprogram_jobs
*
* @param string $userlogin User login
* @return int <0 if KO, >0 if OK
@@ -843,7 +842,8 @@ class Cronjob extends CommonObject
$langs->load('cron');
- if (empty($userlogin)) {
+ if (empty($userlogin))
+ {
$this->error="User login is mandatory";
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
return -1;
@@ -891,7 +891,7 @@ class Cronjob extends CommonObject
$this->datelastrun=$now;
$this->lastoutput='';
$this->lastresult='';
- $this->nbrun=$this->nbrun+1;
+ $this->nbrun=$this->nbrun + 1;
$result = $this->update($user);
if ($result<0) {
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
@@ -1055,23 +1055,28 @@ class Cronjob extends CommonObject
/**
* Reprogram a job
*
- * @param string $userlogin User login
- * @return int <0 if KO, >0 if OK
- *
+ * @param string $userlogin User login
+ * @return int <0 if KO, >0 if OK
*/
function reprogram_jobs($userlogin)
{
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);
- if ($result<0) {
+ if ($result<0)
+ {
$this->error="User Error:".$user->error;
dol_syslog(get_class($this)."::reprogram_jobs ".$this->error, LOG_ERR);
return -1;
- }else {
- if (empty($user->id)) {
+ }
+ else
+ {
+ if (empty($user->id))
+ {
$this->error=" User user login:".$userlogin." do not exists";
dol_syslog(get_class($this)."::reprogram_jobs ".$this->error, LOG_ERR);
return -1;
@@ -1080,17 +1085,41 @@ class Cronjob extends CommonObject
dol_syslog(get_class($this)."::reprogram_jobs ", LOG_DEBUG);
- if (empty($this->datenextrun)) {
- $this->datenextrun=dol_now()+$this->frequency;
- } else {
- if ($this->datenextrun| ';
+ print ' | ';
if(!empty($line->datestart)) {print dol_print_date($line->datestart,'dayhour');}
print ' | ';
- print '';
+ print ' | ';
if(!empty($line->dateend)) {print dol_print_date($line->dateend,'dayhour');}
print ' | ';
- print '';
- if(!empty($line->datelastrun)) {print dol_print_date($line->datelastrun,'dayhour');}
- print ' | ';
-
- print '';
+ print ' | ';
if(!empty($line->datenextrun)) {print dol_print_date($line->datenextrun,'dayhour');}
print ' | ';
@@ -282,15 +278,19 @@ if ($num > 0)
if($line->unitfrequency == "604800") print $langs->trans('CronEach')." ".($line->frequency/$line->unitfrequency)." ".$langs->trans('Weeks');
print '';
- print '';
- if (!empty($line->nbrun)) {print $line->nbrun;} else {print '0';}
- print ' | ';
-
- print '';
+ print ' | ';
if (!empty($line->maxrun)) {print $line->maxrun;}
print ' | ';
- print '';
+ print ' | ';
+ if (!empty($line->nbrun)) {print $line->nbrun;} else {print '0';}
+ print ' | ';
+
+ print '';
+ if(!empty($line->datelastrun)) {print dol_print_date($line->datelastrun,'dayhour');}
+ print ' | ';
+
+ print '';
if(!empty($line->lastresult)) {print dol_trunc($line->lastresult);}
print ' | ';
diff --git a/htdocs/install/mysql/tables/llx_cronjob.sql b/htdocs/install/mysql/tables/llx_cronjob.sql
index 6e076d518a7..dfe9ef127ff 100644
--- a/htdocs/install/mysql/tables/llx_cronjob.sql
+++ b/htdocs/install/mysql/tables/llx_cronjob.sql
@@ -33,18 +33,18 @@ CREATE TABLE llx_cronjob
md5params varchar(32),
module_name varchar(255),
priority integer DEFAULT 0,
- datelastrun datetime, -- date last run and when should be next
+ datelastrun datetime, -- date last run start (see datelastresult for end with a result)
datenextrun datetime, -- job will be run if current date higher that this date
datestart datetime, -- before this date no jobs will be run
dateend datetime, -- after this date, no more jobs will be run
- datelastresult datetime,
+ datelastresult datetime, -- date last run end
lastresult text,
lastoutput text,
unitfrequency integer NOT NULL DEFAULT 0,
frequency integer NOT NULL DEFAULT 0,
maxrun integer NOT NULL DEFAULT 0, -- set this to 1 for a job queued for on run only
nbrun integer, -- nb of run complete (failed or not)
- autodelete integer DEFAULT 0, -- 1=Job must be deleted once finished, 2=Job must be archived once finished (archive = status 2)
+ autodelete integer DEFAULT 0, -- 0=Job is kept unchanged once nbrun > maxrun or date > dateend, 2=Job must be archived (archive = status 2) once nbrun > maxrun or date > dateend
status integer NOT NULL DEFAULT 1, -- 0=disabled, 1=enabled, 2=archived
fk_user_author integer DEFAULT NULL,
fk_user_mod integer DEFAULT NULL,
diff --git a/htdocs/langs/en_US/cron.lang b/htdocs/langs/en_US/cron.lang
index ae997d0a490..b7cdb069346 100644
--- a/htdocs/langs/en_US/cron.lang
+++ b/htdocs/langs/en_US/cron.lang
@@ -36,8 +36,8 @@ CronInfo=Scheduled job module allow to execute job that have been planned
CronWaitingJobs=Waiting jobs
CronTask=Job
CronNone=None
-CronDtStart=Start date
-CronDtEnd=End date
+CronDtStart=Not before
+CronDtEnd=Not after
CronDtNextLaunch=Next execution
CronDtLastLaunch=Last execution
CronFrequency=Frequency
diff --git a/scripts/cron/cron_run_jobs.php b/scripts/cron/cron_run_jobs.php
index e163f41e9fc..20fb55bb213 100755
--- a/scripts/cron/cron_run_jobs.php
+++ b/scripts/cron/cron_run_jobs.php
@@ -1,8 +1,8 @@
#!/usr/bin/env php
+/* Copyright (C) 2012 Nicolas Villa aka Boyquotes http://informetic.fr
+ * Copyright (C) 2013 Florian Henry |