NEW Can edit next execution date of a cron job.

This commit is contained in:
Laurent Destailleur 2016-01-31 15:37:23 +01:00
parent 2cde6f39ff
commit 475cc24e13
5 changed files with 41 additions and 22 deletions

View File

@ -4134,7 +4134,7 @@ class Form
* - local date in user area, if set_time is '' (so if set_time is '', output may differs when done from two different location)
* - Empty (fields empty), if set_time is -1 (in this case, parameter empty must also have value 1)
*
* @param timestamp $set_time Pre-selected date (must be a local PHP server timestamp), -1 to keep date not preselected, '' to use current date.
* @param timestamp $set_time Pre-selected date (must be a local PHP server timestamp), -1 to keep date not preselected, '' to use current date (emptydate must be 0).
* @param string $prefix Prefix for fields name
* @param int $h 1=Show also hours
* @param int $m 1=Show also minutes

View File

@ -142,6 +142,7 @@ if ($action=='add')
$object->note=GETPOST('note');
$object->datestart=dol_mktime(GETPOST('datestarthour','int'), GETPOST('datestartmin','int'), 0, GETPOST('datestartmonth','int'), GETPOST('datestartday','int'), GETPOST('datestartyear','int'));
$object->dateend=dol_mktime(GETPOST('dateendhour','int'), GETPOST('dateendmin','int'), 0, GETPOST('dateendmonth','int'), GETPOST('dateendday','int'), GETPOST('dateendyear','int'));
$object->datenextrun=dol_mktime(GETPOST('datenextrunhour','int'), GETPOST('datenextrunmin','int'), 0, GETPOST('datenextrunmonth','int'), GETPOST('datenextrunday','int'), GETPOST('datenextrunyear','int'));
$object->unitfrequency=GETPOST('unitfrequency','int');
$object->frequency=GETPOST('nbfrequency','int');
$object->maxrun=GETPOST('maxrun','int');
@ -177,6 +178,7 @@ if ($action=='update')
$object->note=GETPOST('note');
$object->datestart=dol_mktime(GETPOST('datestarthour','int'), GETPOST('datestartmin','int'), 0, GETPOST('datestartmonth','int'), GETPOST('datestartday','int'), GETPOST('datestartyear','int'));
$object->dateend=dol_mktime(GETPOST('dateendhour','int'), GETPOST('dateendmin','int'), 0, GETPOST('dateendmonth','int'), GETPOST('dateendday','int'), GETPOST('dateendyear','int'));
$object->datenextrun=dol_mktime(GETPOST('datenextrunhour','int'), GETPOST('datenextrunmin','int'), 0, GETPOST('datenextrunmonth','int'), GETPOST('datenextrunday','int'), GETPOST('datenextrunyear','int'));
$object->unitfrequency=GETPOST('unitfrequency','int');
$object->frequency=GETPOST('nbfrequency','int');
$object->maxrun=GETPOST('maxrun','int');
@ -475,7 +477,7 @@ if (($action=="create") || ($action=="edit"))
$form->select_date($object->dateend,'dateend',1,1,'',"cronform");
}
else{
$form->select_date('','dateend',1,1,1,"cronform");
$form->select_date(-1,'dateend',1,1,1,"cronform");
}
print "</td>";
print "<td>";
@ -506,6 +508,23 @@ if (($action=="create") || ($action=="edit"))
print "</td>";
print "</tr>\n";
print '<tr><td>';
print $langs->trans('CronDtNextLaunch');
print ' ('.$langs->trans('CronFrom').')';
print "</td><td>";
if(!empty($object->datenextrun))
{
$form->select_date($object->datenextrun,'datenextrun',1,1,'',"cronform");
}
else
{
$form->select_date(-1,'datenextrun',1,1,'',"cronform");
}
print "</td>";
print "<td>";
print "</td>";
print "</tr>";
print '</table>';
dol_fiche_end();

View File

@ -107,7 +107,8 @@ class Cronjob extends CommonObject
if (isset($this->note)) $this->note=trim($this->note);
if (isset($this->nbrun)) $this->nbrun=trim($this->nbrun);
if (isset($this->libname)) $this->libname = trim($this->libname);
if (isset($this->test)) $this->test = trim($this->test);
// Check parameters
// Put here code to add a control on parameters values
if (dol_strlen($this->datestart)==0) {
@ -177,11 +178,9 @@ class Cronjob extends CommonObject
$sql.= "note,";
$sql.= "nbrun,";
$sql.= "maxrun,";
$sql.= "libname";
$sql.= "libname,";
$sql.= "test";
$sql.= ") VALUES (";
$sql.= " '".$this->db->idate($now)."',";
$sql.= " ".(! isset($this->jobtype)?'NULL':"'".$this->db->escape($this->jobtype)."'").",";
$sql.= " ".(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").",";
@ -208,7 +207,8 @@ class Cronjob extends CommonObject
$sql.= " ".(! isset($this->note)?'NULL':"'".$this->db->escape($this->note)."'").",";
$sql.= " ".(! isset($this->nbrun)?'0':"'".$this->db->escape($this->nbrun)."'").",";
$sql.= " ".(empty($this->maxrun)?'null':"'".$this->db->escape($this->maxrun)."'").",";
$sql.= " ".(! isset($this->libname)?'NULL':"'".$this->db->escape($this->libname)."'")."";
$sql.= " ".(! isset($this->libname)?'NULL':"'".$this->db->escape($this->libname)."'").",";
$sql.= " ".(! isset($this->test)?'NULL':"'".$this->db->escape($this->test)."'")."";
$sql.= ")";
$this->db->begin();
@ -292,9 +292,8 @@ class Cronjob extends CommonObject
$sql.= " t.note,";
$sql.= " t.nbrun,";
$sql.= " t.maxrun,";
$sql.= " t.libname";
$sql.= " t.libname,";
$sql.= " t.test";
$sql.= " FROM ".MAIN_DB_PREFIX."cronjob as t";
$sql.= " WHERE t.rowid = ".$id;
@ -337,7 +336,7 @@ class Cronjob extends CommonObject
$this->nbrun = $obj->nbrun;
$this->maxrun = $obj->maxrun;
$this->libname = $obj->libname;
$this->test = $obj->test;
}
$this->db->free($resql);
@ -394,7 +393,6 @@ class Cronjob extends CommonObject
$sql.= " t.nbrun,";
$sql.= " t.libname,";
$sql.= " t.test";
$sql.= " FROM ".MAIN_DB_PREFIX."cronjob as t";
$sql.= " WHERE 1 = 1";
if ($status >= 0) $sql.= " AND t.status = ".(empty($status)?'0':'1');
@ -521,7 +519,8 @@ class Cronjob extends CommonObject
if (isset($this->nbrun)) $this->nbrun=trim($this->nbrun);
if (isset($this->maxrun)) $this->maxrun=trim($this->maxrun);
if (isset($this->libname)) $this->libname = trim($this->libname);
if (isset($this->test)) $this->test = trim($this->test);
// Check parameters
// Put here code to add a control on parameters values
if (dol_strlen($this->datestart)==0) {
@ -588,10 +587,11 @@ class Cronjob extends CommonObject
$sql.= " status=".(isset($this->status)?$this->status:"null").",";
$sql.= " fk_user_mod=".$user->id.",";
$sql.= " note=".(isset($this->note)?"'".$this->db->escape($this->note)."'":"null").",";
$sql.= " nbrun=".(isset($this->nbrun)?$this->nbrun:"null").",";
$sql.= " maxrun=".(isset($this->maxrun)?$this->maxrun:"null").",";
$sql.= " libname=".(isset($this->libname)?"'".$this->db->escape($this->libname)."'":"null");
$sql.= " WHERE rowid=".$this->id;
$sql.= " nbrun=".((isset($this->nbrun) && $this->nbrun >0)?$this->nbrun:"null").",";
$sql.= " maxrun=".((isset($this->maxrun) && $this->maxrun > 0)?$this->maxrun:"null").",";
$sql.= " libname=".(isset($this->libname)?"'".$this->db->escape($this->libname)."'":"null").",";
$sql.= " test=".(isset($this->test)?"'".$this->db->escape($this->test)."'":"null");
$sql.= " WHERE rowid=".$this->id;
$this->db->begin();

View File

@ -228,7 +228,7 @@ if ($num > 0)
print '<tr class="'.$style.'">';
print '<td>';
print '<td class="nowrap">';
print '<a href="'.DOL_URL_ROOT.'/cron/card.php?id='.$line->id.'">';
print img_picto('', 'object_cron').' ';
print $line->id;

View File

@ -144,7 +144,7 @@ if (is_array($object->lines) && (count($object->lines)>0))
$result=$cronjob->fetch($line->id);
if ($result<0)
{
echo "Error:".$cronjob->error;
echo "Error:".$cronjob->error."<br>\n";
dol_syslog("cron_run_jobs.php:: fetch Error".$cronjob->error, LOG_ERR);
exit;
}
@ -152,7 +152,7 @@ if (is_array($object->lines) && (count($object->lines)>0))
$result=$cronjob->run_jobs($userlogin);
if ($result < 0)
{
echo "Error:".$cronjob->error;
echo "Error:".$cronjob->error."<br>\n";
dol_syslog("cron_run_jobs.php:: run_jobs Error".$cronjob->error, LOG_ERR);
$nbofjobslaunchedko++;
}
@ -165,7 +165,7 @@ if (is_array($object->lines) && (count($object->lines)>0))
$result=$cronjob->reprogram_jobs($userlogin, $now);
if ($result<0)
{
echo "Error:".$cronjob->error;
echo "Error:".$cronjob->error."<br>\n";
dol_syslog("cron_run_jobs.php:: reprogram_jobs Error".$cronjob->error, LOG_ERR);
exit;
}