NEW Can send an email on scheduled job error
This commit is contained in:
parent
c0dac5d5db
commit
bb624dd0a1
@ -141,6 +141,7 @@ if ($action == 'add') {
|
|||||||
$object->unitfrequency = GETPOST('unitfrequency', 'int');
|
$object->unitfrequency = GETPOST('unitfrequency', 'int');
|
||||||
$object->frequency = GETPOST('nbfrequency', 'int');
|
$object->frequency = GETPOST('nbfrequency', 'int');
|
||||||
$object->maxrun = GETPOST('maxrun', 'int');
|
$object->maxrun = GETPOST('maxrun', 'int');
|
||||||
|
$object->email_alert = GETPOST('email_alert');
|
||||||
|
|
||||||
// Add cron task
|
// Add cron task
|
||||||
$result = $object->create($user);
|
$result = $object->create($user);
|
||||||
@ -175,6 +176,7 @@ if ($action == 'update') {
|
|||||||
$object->unitfrequency = GETPOST('unitfrequency', 'int');
|
$object->unitfrequency = GETPOST('unitfrequency', 'int');
|
||||||
$object->frequency = GETPOST('nbfrequency', 'int');
|
$object->frequency = GETPOST('nbfrequency', 'int');
|
||||||
$object->maxrun = GETPOST('maxrun', 'int');
|
$object->maxrun = GETPOST('maxrun', 'int');
|
||||||
|
$object->email_alert = GETPOST('email_alert');
|
||||||
|
|
||||||
// Add cron task
|
// Add cron task
|
||||||
$result = $object->update($user);
|
$result = $object->update($user);
|
||||||
@ -415,6 +417,15 @@ if (($action == "create") || ($action == "edit")) {
|
|||||||
print "</td>";
|
print "</td>";
|
||||||
print "</tr>\n";
|
print "</tr>\n";
|
||||||
|
|
||||||
|
print '<tr class="blockemailalert"><td>';
|
||||||
|
print $langs->trans('EmailIfError')."</td><td>";
|
||||||
|
print '<input type="text" class="minwidth150" name="email_alert" value="'.dol_escape_htmltag($object->email_alert).'" /> ';
|
||||||
|
print "</td>";
|
||||||
|
print "<td>";
|
||||||
|
//print $form->textwithpicto('', $langs->trans("CronCommandHelp"), 1, 'help');
|
||||||
|
print "</td>";
|
||||||
|
print "</tr>\n";
|
||||||
|
|
||||||
print '<tr><td class="fieldrequired">';
|
print '<tr><td class="fieldrequired">';
|
||||||
print $langs->trans('CronEvery')."</td>";
|
print $langs->trans('CronEvery')."</td>";
|
||||||
print "<td>";
|
print "<td>";
|
||||||
@ -578,32 +589,32 @@ if (($action == "create") || ($action == "edit")) {
|
|||||||
|
|
||||||
print '<tr class="blockmethod"><td>';
|
print '<tr class="blockmethod"><td>';
|
||||||
print $langs->trans('CronModule')."</td><td>";
|
print $langs->trans('CronModule')."</td><td>";
|
||||||
print $object->module_name;
|
print dol_escape_htmltag($object->module_name);
|
||||||
print "</td></tr>";
|
print "</td></tr>";
|
||||||
|
|
||||||
print '<tr class="blockmethod"><td>';
|
print '<tr class="blockmethod"><td>';
|
||||||
print $langs->trans('CronClassFile')."</td><td>";
|
print $langs->trans('CronClassFile')."</td><td>";
|
||||||
print $object->classesname;
|
print dol_escape_htmltag($object->classesname);
|
||||||
print "</td></tr>";
|
print "</td></tr>";
|
||||||
|
|
||||||
print '<tr class="blockmethod"><td>';
|
print '<tr class="blockmethod"><td>';
|
||||||
print $langs->trans('CronObject')."</td><td>";
|
print $langs->trans('CronObject')."</td><td>";
|
||||||
print $object->objectname;
|
print dol_escape_htmltag($object->objectname);
|
||||||
print "</td></tr>";
|
print "</td></tr>";
|
||||||
|
|
||||||
print '<tr class="blockmethod"><td>';
|
print '<tr class="blockmethod"><td>';
|
||||||
print $langs->trans('CronMethod')."</td><td>";
|
print $langs->trans('CronMethod')."</td><td>";
|
||||||
print $object->methodename;
|
print dol_escape_htmltag($object->methodename);
|
||||||
print "</td></tr>";
|
print "</td></tr>";
|
||||||
|
|
||||||
print '<tr class="blockmethod"><td>';
|
print '<tr class="blockmethod"><td>';
|
||||||
print $langs->trans('CronArgs')."</td><td>";
|
print $langs->trans('CronArgs')."</td><td>";
|
||||||
print $object->params;
|
print dol_escape_htmltag($object->params);
|
||||||
print "</td></tr>";
|
print "</td></tr>";
|
||||||
|
|
||||||
print '<tr class="blockcommand"><td>';
|
print '<tr class="blockcommand"><td>';
|
||||||
print $langs->trans('CronCommand')."</td><td>";
|
print $langs->trans('CronCommand')."</td><td>";
|
||||||
print $object->command;
|
print dol_escape_htmltag($object->command);
|
||||||
print "</td></tr>";
|
print "</td></tr>";
|
||||||
|
|
||||||
print '<tr><td>';
|
print '<tr><td>';
|
||||||
@ -613,6 +624,11 @@ if (($action == "create") || ($action == "edit")) {
|
|||||||
}
|
}
|
||||||
print "</td></tr>";
|
print "</td></tr>";
|
||||||
|
|
||||||
|
print '<tr class="blockemailalert"><td>';
|
||||||
|
print $langs->trans('EmailIfError')."</td><td>";
|
||||||
|
print dol_escape_htmltag($object->email_alert);
|
||||||
|
print "</td></tr>";
|
||||||
|
|
||||||
if (isModEnabled('multicompany')) {
|
if (isModEnabled('multicompany')) {
|
||||||
print '<tr><td>';
|
print '<tr><td>';
|
||||||
print $langs->trans('Entity')."</td><td>";
|
print $langs->trans('Entity')."</td><td>";
|
||||||
|
|||||||
@ -142,6 +142,11 @@ class Cronjob extends CommonObject
|
|||||||
*/
|
*/
|
||||||
public $pid;
|
public $pid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string Email when an error occurs
|
||||||
|
*/
|
||||||
|
public $email_alert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int User ID of creation
|
* @var int User ID of creation
|
||||||
*/
|
*/
|
||||||
@ -428,6 +433,7 @@ class Cronjob extends CommonObject
|
|||||||
$sql .= " t.status,";
|
$sql .= " t.status,";
|
||||||
$sql .= " t.processing,";
|
$sql .= " t.processing,";
|
||||||
$sql .= " t.pid,";
|
$sql .= " t.pid,";
|
||||||
|
$sql .= " t.email_alert,";
|
||||||
$sql .= " t.fk_user_author,";
|
$sql .= " t.fk_user_author,";
|
||||||
$sql .= " t.fk_user_mod,";
|
$sql .= " t.fk_user_mod,";
|
||||||
$sql .= " t.note as note_private,";
|
$sql .= " t.note as note_private,";
|
||||||
@ -477,6 +483,7 @@ class Cronjob extends CommonObject
|
|||||||
$this->status = $obj->status;
|
$this->status = $obj->status;
|
||||||
$this->processing = $obj->processing;
|
$this->processing = $obj->processing;
|
||||||
$this->pid = $obj->pid;
|
$this->pid = $obj->pid;
|
||||||
|
$this->email_alert = $obj->email_alert;
|
||||||
$this->fk_user_author = $obj->fk_user_author;
|
$this->fk_user_author = $obj->fk_user_author;
|
||||||
$this->fk_user_mod = $obj->fk_user_mod;
|
$this->fk_user_mod = $obj->fk_user_mod;
|
||||||
$this->note_private = $obj->note_private;
|
$this->note_private = $obj->note_private;
|
||||||
@ -538,6 +545,7 @@ class Cronjob extends CommonObject
|
|||||||
$sql .= " t.status,";
|
$sql .= " t.status,";
|
||||||
$sql .= " t.processing,";
|
$sql .= " t.processing,";
|
||||||
$sql .= " t.pid,";
|
$sql .= " t.pid,";
|
||||||
|
$sql .= " t.email_alert,";
|
||||||
$sql .= " t.fk_user_author,";
|
$sql .= " t.fk_user_author,";
|
||||||
$sql .= " t.fk_user_mod,";
|
$sql .= " t.fk_user_mod,";
|
||||||
$sql .= " t.note as note_private,";
|
$sql .= " t.note as note_private,";
|
||||||
@ -615,6 +623,7 @@ class Cronjob extends CommonObject
|
|||||||
$line->status = $obj->status;
|
$line->status = $obj->status;
|
||||||
$line->processing = $obj->processing;
|
$line->processing = $obj->processing;
|
||||||
$line->pid = $obj->pid;
|
$line->pid = $obj->pid;
|
||||||
|
$line->email_alert = $obj->email_alert;
|
||||||
$line->fk_user_author = $obj->fk_user_author;
|
$line->fk_user_author = $obj->fk_user_author;
|
||||||
$line->fk_user_mod = $obj->fk_user_mod;
|
$line->fk_user_mod = $obj->fk_user_mod;
|
||||||
$line->note_private = $obj->note_private;
|
$line->note_private = $obj->note_private;
|
||||||
@ -716,10 +725,12 @@ class Cronjob extends CommonObject
|
|||||||
if (empty($this->processing)) {
|
if (empty($this->processing)) {
|
||||||
$this->processing = 0;
|
$this->processing = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($this->pid)) {
|
if (empty($this->pid)) {
|
||||||
$this->pid = null;
|
$this->pid = null;
|
||||||
}
|
}
|
||||||
|
if (empty($this->email_alert)) {
|
||||||
|
$this->email_alert = '';
|
||||||
|
}
|
||||||
|
|
||||||
// Check parameters
|
// Check parameters
|
||||||
// Put here code to add a control on parameters values
|
// Put here code to add a control on parameters values
|
||||||
@ -764,7 +775,7 @@ class Cronjob extends CommonObject
|
|||||||
|
|
||||||
// Update request
|
// Update request
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."cronjob SET";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."cronjob SET";
|
||||||
$sql .= " entity=".(isset($this->entity) ? $this->db->escape($this->entity) : $conf->entity).",";
|
$sql .= " entity=".(isset($this->entity) ? ((int) $this->entity) : $conf->entity).",";
|
||||||
$sql .= " label=".(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").",";
|
$sql .= " label=".(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").",";
|
||||||
$sql .= " jobtype=".(isset($this->jobtype) ? "'".$this->db->escape($this->jobtype)."'" : "null").",";
|
$sql .= " jobtype=".(isset($this->jobtype) ? "'".$this->db->escape($this->jobtype)."'" : "null").",";
|
||||||
$sql .= " command=".(isset($this->command) ? "'".$this->db->escape($this->command)."'" : "null").",";
|
$sql .= " command=".(isset($this->command) ? "'".$this->db->escape($this->command)."'" : "null").",";
|
||||||
@ -774,7 +785,7 @@ class Cronjob extends CommonObject
|
|||||||
$sql .= " params=".(isset($this->params) ? "'".$this->db->escape($this->params)."'" : "null").",";
|
$sql .= " params=".(isset($this->params) ? "'".$this->db->escape($this->params)."'" : "null").",";
|
||||||
$sql .= " md5params=".(isset($this->md5params) ? "'".$this->db->escape($this->md5params)."'" : "null").",";
|
$sql .= " md5params=".(isset($this->md5params) ? "'".$this->db->escape($this->md5params)."'" : "null").",";
|
||||||
$sql .= " module_name=".(isset($this->module_name) ? "'".$this->db->escape($this->module_name)."'" : "null").",";
|
$sql .= " module_name=".(isset($this->module_name) ? "'".$this->db->escape($this->module_name)."'" : "null").",";
|
||||||
$sql .= " priority=".(isset($this->priority) ? $this->priority : "null").",";
|
$sql .= " priority=".(isset($this->priority) ? ((int) $this->priority) : "null").",";
|
||||||
$sql .= " datelastrun=".(dol_strlen($this->datelastrun) != 0 ? "'".$this->db->idate($this->datelastrun)."'" : 'null').",";
|
$sql .= " datelastrun=".(dol_strlen($this->datelastrun) != 0 ? "'".$this->db->idate($this->datelastrun)."'" : 'null').",";
|
||||||
$sql .= " datenextrun=".(dol_strlen($this->datenextrun) != 0 ? "'".$this->db->idate($this->datenextrun)."'" : 'null').",";
|
$sql .= " datenextrun=".(dol_strlen($this->datenextrun) != 0 ? "'".$this->db->idate($this->datenextrun)."'" : 'null').",";
|
||||||
$sql .= " dateend=".(dol_strlen($this->dateend) != 0 ? "'".$this->db->idate($this->dateend)."'" : 'null').",";
|
$sql .= " dateend=".(dol_strlen($this->dateend) != 0 ? "'".$this->db->idate($this->dateend)."'" : 'null').",";
|
||||||
@ -786,8 +797,9 @@ class Cronjob extends CommonObject
|
|||||||
$sql .= " frequency=".(isset($this->frequency) ? $this->frequency : "null").",";
|
$sql .= " frequency=".(isset($this->frequency) ? $this->frequency : "null").",";
|
||||||
$sql .= " status=".(isset($this->status) ? $this->status : "null").",";
|
$sql .= " status=".(isset($this->status) ? $this->status : "null").",";
|
||||||
$sql .= " processing=".((isset($this->processing) && $this->processing > 0) ? $this->processing : "0").",";
|
$sql .= " processing=".((isset($this->processing) && $this->processing > 0) ? $this->processing : "0").",";
|
||||||
$sql .= " pid=".(isset($this->pid) ? $this->pid : "null").",";
|
$sql .= " pid=".(isset($this->pid) ? ((int) $this->pid) : "null").",";
|
||||||
$sql .= " fk_user_mod=".$user->id.",";
|
$sql .= " email_alert = ".(isset($this->email_alert) ? "'".$this->db->escape($this->email_alert)."'" : "null").",";
|
||||||
|
$sql .= " fk_user_mod = ".((int) $user->id).",";
|
||||||
$sql .= " note=".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null").",";
|
$sql .= " note=".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null").",";
|
||||||
$sql .= " nbrun=".((isset($this->nbrun) && $this->nbrun > 0) ? $this->nbrun : "null").",";
|
$sql .= " nbrun=".((isset($this->nbrun) && $this->nbrun > 0) ? $this->nbrun : "null").",";
|
||||||
$sql .= " maxrun=".((isset($this->maxrun) && $this->maxrun > 0) ? $this->maxrun : "0").",";
|
$sql .= " maxrun=".((isset($this->maxrun) && $this->maxrun > 0) ? $this->maxrun : "0").",";
|
||||||
@ -940,6 +952,7 @@ class Cronjob extends CommonObject
|
|||||||
$this->status = 0;
|
$this->status = 0;
|
||||||
$this->processing = 0;
|
$this->processing = 0;
|
||||||
$this->pid = null;
|
$this->pid = null;
|
||||||
|
$this->email_alert = '';
|
||||||
$this->fk_user_author = 0;
|
$this->fk_user_author = 0;
|
||||||
$this->fk_user_mod = 0;
|
$this->fk_user_mod = 0;
|
||||||
$this->note_private = '';
|
$this->note_private = '';
|
||||||
@ -1130,6 +1143,7 @@ class Cronjob extends CommonObject
|
|||||||
@set_time_limit($ExecTimeLimit); // Need more than 240 on Windows 7/64
|
@set_time_limit($ExecTimeLimit); // Need more than 240 on Windows 7/64
|
||||||
error_reporting($err);
|
error_reporting($err);
|
||||||
}
|
}
|
||||||
|
$MemoryLimit = 0;
|
||||||
if (!empty($MemoryLimit)) {
|
if (!empty($MemoryLimit)) {
|
||||||
@ini_set('memory_limit', $MemoryLimit);
|
@ini_set('memory_limit', $MemoryLimit);
|
||||||
}
|
}
|
||||||
@ -1341,6 +1355,16 @@ class Cronjob extends CommonObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
$conf->setEntityValues($this->db, $savcurrententity);
|
$conf->setEntityValues($this->db, $savcurrententity);
|
||||||
|
|
||||||
|
if ($error && !empty($this->email_alert)) {
|
||||||
|
include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
|
||||||
|
$subject = $langs->trans("ErrorInBatch", $this->label);
|
||||||
|
$msg = $langs->trans("ErrorInBatch", $this->label);
|
||||||
|
$from = getDolGlobalString('MAIN_MAIL_EMAIL_FROM');
|
||||||
|
$cmailfile = new CMailFile($subject, $this->email_alert, $from, $msg);
|
||||||
|
$result = $cmailfile->sendfile(); // Do not test result
|
||||||
|
}
|
||||||
|
|
||||||
return $error ?-1 : 1;
|
return $error ?-1 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -89,6 +89,9 @@ CleanUnfinishedCronjob=Clean cronjob stuck in processing when the process is no
|
|||||||
WarningCronDelayed=Attention, for performance purpose, whatever is next date of execution of enabled jobs, your jobs may be delayed to a maximum of %s hours, before being run.
|
WarningCronDelayed=Attention, for performance purpose, whatever is next date of execution of enabled jobs, your jobs may be delayed to a maximum of %s hours, before being run.
|
||||||
DATAPOLICYJob=Data cleaner and anonymizer
|
DATAPOLICYJob=Data cleaner and anonymizer
|
||||||
JobXMustBeEnabled=Job %s must be enabled
|
JobXMustBeEnabled=Job %s must be enabled
|
||||||
|
EmailIfError=Email for warning on error
|
||||||
|
ErrorInBatch=Error when running the job %s
|
||||||
|
|
||||||
# Cron Boxes
|
# Cron Boxes
|
||||||
LastExecutedScheduledJob=Last executed scheduled job
|
LastExecutedScheduledJob=Last executed scheduled job
|
||||||
NextScheduledJobExecute=Next scheduled job to execute
|
NextScheduledJobExecute=Next scheduled job to execute
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user