--- /tmp/dsg/dolibarr/htdocs/cron/class/github_cronjob.class.php
+++ /tmp/dsg/dolibarr/htdocs/cron/class/client_cronjob.class.php
@@ -40,24 +40,24 @@
*/
public $table_element = 'cronjob';
- /**
+ /**
* @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
*/
public $picto = 'cron';
- /**
+ /**
* @var int Entity
*/
public $entity;
- public $jobtype;
+ public $jobtype;
public $tms = '';
public $datec = '';
/**
- * @var string Cron Job label
- */
- public $label;
+ * @var string Cron Job label
+ */
+ public $label;
public $command;
public $classesname;
@@ -91,13 +91,13 @@
public $processing;
/**
- * @var int ID
- */
+ * @var int ID
+ */
public $fk_user_author;
/**
- * @var int ID
- */
+ * @var int ID
+ */
public $fk_user_mod;
public $nbrun;
@@ -109,27 +109,27 @@
const STATUS_ARCHIVED = 2;
- /**
- * Constructor
- *
- * @param DoliDb $db Database handler
- */
- public function __construct($db)
- {
- $this->db = $db;
- }
-
-
- /**
- * Create object into database
- *
- * @param User $user User that creates
- * @param int $notrigger 0=launch triggers after, 1=disable triggers
- * @return int <0 if KO, Id of created object if OK
- */
- public function create($user, $notrigger = 0)
- {
- global $conf, $langs;
+ /**
+ * Constructor
+ *
+ * @param DoliDb $db Database handler
+ */
+ public function __construct($db)
+ {
+ $this->db = $db;
+ }
+
+
+ /**
+ * Create object into database
+ *
+ * @param User $user User that creates
+ * @param int $notrigger 0=launch triggers after, 1=disable triggers
+ * @return int <0 if KO, Id of created object if OK
+ */
+ public function create($user, $notrigger = 0)
+ {
+ global $conf, $langs;
$error = 0;
$now = dol_now();
@@ -151,7 +151,7 @@
if (isset($this->unitfrequency)) $this->unitfrequency = trim($this->unitfrequency);
if (isset($this->frequency)) $this->frequency = trim($this->frequency);
if (isset($this->status)) $this->status = trim($this->status);
- if (isset($this->note_private)) $this->note_private = trim($this->note_private);
+ 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);
@@ -195,7 +195,7 @@
$error++;
}
- // Insert request
+ // Insert request
$sql = "INSERT INTO ".MAIN_DB_PREFIX."cronjob(";
$sql .= "entity,";
$sql .= "datec,";
@@ -251,7 +251,7 @@
$sql .= " ".(!isset($this->status) ? '0' : $this->status).",";
$sql .= " ".$user->id.",";
$sql .= " ".$user->id.",";
- $sql .= " ".(!isset($this->note_private) ? 'NULL' : "'".$this->db->escape($this->note_private)."'").",";
+ $sql .= " ".(!isset($this->note) ? 'NULL' : "'".$this->db->escape($this->note)."'").",";
$sql .= " ".(!isset($this->nbrun) ? '0' : $this->db->escape($this->nbrun)).",";
$sql .= " ".(empty($this->maxrun) ? '0' : $this->db->escape($this->maxrun)).",";
$sql .= " ".(!isset($this->libname) ? 'NULL' : "'".$this->db->escape($this->libname)."'").",";
@@ -261,44 +261,44 @@
$this->db->begin();
dol_syslog(get_class($this)."::create", LOG_DEBUG);
- $resql = $this->db->query($sql);
- if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
+ $resql = $this->db->query($sql);
+ if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
if (!$error)
- {
- $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."cronjob");
- }
-
- // Commit or rollback
- if ($error)
+ {
+ $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."cronjob");
+ }
+
+ // Commit or rollback
+ if ($error)
{
foreach ($this->errors as $errmsg)
{
- dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
- $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
+ dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
+ $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
$this->db->rollback();
return -1 * $error;
- } else {
+ }
+ else
+ {
$this->db->commit();
- return $this->id;
- }
- }
-
-
- /**
- * Load object in memory from the database
- *
- * @param int $id Id object
- * @param string $objectname Object name
- * @param string $methodname Method name
- * @return int <0 if KO, >0 if OK
- */
- public function fetch($id, $objectname = '', $methodname = '')
- {
- $sql = "SELECT";
- $sql .= " t.rowid,";
- $sql .= " t.entity,";
+ return $this->id;
+ }
+ }
+
+
+ /**
+ * Load object in memory from the database
+ *
+ * @param int $id Id object
+ * @return int <0 if KO, >0 if OK
+ */
+ public function fetch($id)
+ {
+ $sql = "SELECT";
+ $sql .= " t.rowid,";
+ $sql .= " t.entity,";
$sql .= " t.tms,";
$sql .= " t.datec,";
$sql .= " t.jobtype,";
@@ -324,30 +324,24 @@
$sql .= " t.processing,";
$sql .= " t.fk_user_author,";
$sql .= " t.fk_user_mod,";
- $sql .= " t.note as note_private,";
+ $sql .= " t.note,";
$sql .= " t.nbrun,";
$sql .= " t.maxrun,";
$sql .= " t.libname,";
$sql .= " t.test";
- $sql .= " FROM ".MAIN_DB_PREFIX."cronjob as t";
- if ($id > 0) {
- $sql .= " WHERE t.rowid = ".$id;
- } else {
- $sql .= " WHERE t.entity IN(0, ".getEntity('cron').")";
- $sql .= " AND t.objectname = '".$this->db->escape($objectname)."'";
- $sql .= " AND t.methodename = '".$this->db->escape($methodname)."'";
- }
-
- dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
- $resql = $this->db->query($sql);
- if ($resql)
- {
- if ($this->db->num_rows($resql))
- {
- $obj = $this->db->fetch_object($resql);
-
- $this->id = $obj->rowid;
- $this->ref = $obj->rowid;
+ $sql .= " FROM ".MAIN_DB_PREFIX."cronjob as t";
+ $sql .= " WHERE t.rowid = ".$id;
+
+ dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if ($resql)
+ {
+ if ($this->db->num_rows($resql))
+ {
+ $obj = $this->db->fetch_object($resql);
+
+ $this->id = $obj->rowid;
+ $this->ref = $obj->rowid;
$this->entity = $obj->entity;
$this->tms = $this->db->jdate($obj->tms);
$this->datec = $this->db->jdate($obj->datec);
@@ -374,25 +368,27 @@
$this->processing = $obj->processing;
$this->fk_user_author = $obj->fk_user_author;
$this->fk_user_mod = $obj->fk_user_mod;
- $this->note_private = $obj->note_private;
+ $this->note = $obj->note;
$this->nbrun = $obj->nbrun;
$this->maxrun = $obj->maxrun;
$this->libname = $obj->libname;
$this->test = $obj->test;
- }
- $this->db->free($resql);
-
- return 1;
- } else {
- $this->error = "Error ".$this->db->lasterror();
- return -1;
- }
- }
-
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
- /**
- * Load object in memory from the database
- *
+ }
+ $this->db->free($resql);
+
+ return 1;
+ }
+ else
+ {
+ $this->error = "Error ".$this->db->lasterror();
+ return -1;
+ }
+ }
+
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ /**
+ * Load object in memory from the database
+ *
* @param string $sortorder sort order
* @param string $sortfield sort field
* @param int $limit limit page
@@ -400,146 +396,148 @@
* @param int $status display active or not
* @param array $filter filter output
* @param int $processing Processing or not
- * @return int <0 if KO, >0 if OK
- */
- public function fetch_all($sortorder = 'DESC', $sortfield = 't.rowid', $limit = 0, $offset = 0, $status = 1, $filter = '', $processing = -1)
- {
- // phpcs:enable
- global $langs;
-
- $this->lines = array();
-
- $sql = "SELECT";
- $sql .= " t.rowid,";
- $sql .= " t.entity,";
- $sql .= " t.tms,";
- $sql .= " t.datec,";
- $sql .= " t.jobtype,";
- $sql .= " t.label,";
- $sql .= " t.command,";
- $sql .= " t.classesname,";
- $sql .= " t.objectname,";
- $sql .= " t.methodename,";
- $sql .= " t.params,";
- $sql .= " t.md5params,";
- $sql .= " t.module_name,";
- $sql .= " t.priority,";
- $sql .= " t.datelastrun,";
- $sql .= " t.datenextrun,";
- $sql .= " t.dateend,";
- $sql .= " t.datestart,";
- $sql .= " t.lastresult,";
- $sql .= " t.datelastresult,";
- $sql .= " t.lastoutput,";
- $sql .= " t.unitfrequency,";
- $sql .= " t.frequency,";
- $sql .= " t.status,";
- $sql .= " t.processing,";
- $sql .= " t.fk_user_author,";
- $sql .= " t.fk_user_mod,";
- $sql .= " t.note as note_private,";
- $sql .= " t.nbrun,";
- $sql .= " t.libname,";
- $sql .= " t.test";
- $sql .= " FROM ".MAIN_DB_PREFIX."cronjob as t";
- $sql .= " WHERE 1 = 1";
- if ($processing >= 0) $sql .= " AND t.processing = ".(empty($processing) ? '0' : '1');
- if ($status >= 0 && $status < 2) $sql .= " AND t.status = ".(empty($status) ? '0' : '1');
- elseif ($status == 2) $sql .= " AND t.status = 2";
- //Manage filter
- if (is_array($filter) && count($filter) > 0) {
- foreach ($filter as $key => $value)
- {
- if ($key == 't.rowid') $sql .= ' AND '.$key.' = '.$this->db->escape($value);
+ * @return int <0 if KO, >0 if OK
+ */
+ public function fetch_all($sortorder = 'DESC', $sortfield = 't.rowid', $limit = 0, $offset = 0, $status = 1, $filter = '', $processing = -1)
+ {
+ // phpcs:enable
+ global $langs;
+
+ $this->lines = array();
+
+ $sql = "SELECT";
+ $sql .= " t.rowid,";
+ $sql .= " t.entity,";
+ $sql .= " t.tms,";
+ $sql .= " t.datec,";
+ $sql .= " t.jobtype,";
+ $sql .= " t.label,";
+ $sql .= " t.command,";
+ $sql .= " t.classesname,";
+ $sql .= " t.objectname,";
+ $sql .= " t.methodename,";
+ $sql .= " t.params,";
+ $sql .= " t.md5params,";
+ $sql .= " t.module_name,";
+ $sql .= " t.priority,";
+ $sql .= " t.datelastrun,";
+ $sql .= " t.datenextrun,";
+ $sql .= " t.dateend,";
+ $sql .= " t.datestart,";
+ $sql .= " t.lastresult,";
+ $sql .= " t.datelastresult,";
+ $sql .= " t.lastoutput,";
+ $sql .= " t.unitfrequency,";
+ $sql .= " t.frequency,";
+ $sql .= " t.status,";
+ $sql .= " t.processing,";
+ $sql .= " t.fk_user_author,";
+ $sql .= " t.fk_user_mod,";
+ $sql .= " t.note,";
+ $sql .= " t.nbrun,";
+ $sql .= " t.libname,";
+ $sql .= " t.test";
+ $sql .= " FROM ".MAIN_DB_PREFIX."cronjob as t";
+ $sql .= " WHERE 1 = 1";
+ if ($processing >= 0) $sql .= " AND t.processing = ".(empty($processing) ? '0' : '1');
+ if ($status >= 0 && $status < 2) $sql .= " AND t.status = ".(empty($status) ? '0' : '1');
+ elseif ($status == 2) $sql .= " AND t.status = 2";
+ //Manage filter
+ if (is_array($filter) && count($filter) > 0) {
+ foreach ($filter as $key => $value)
+ {
+ if ($key == 't.rowid') $sql .= ' AND '.$key.' = '.$this->db->escape($value);
else $sql .= ' AND '.$key.' LIKE \'%'.$this->db->escape($value).'%\'';
- }
- }
-
- $sql .= $this->db->order($sortfield, $sortorder);
- if (!empty($limit) && !empty($offset)) {
- $sql .= $this->db->plimit($limit + 1, $offset);
- }
-
- $sqlwhere = array();
-
- if (count($sqlwhere) > 0) {
- $sql .= " WHERE ".implode(' AND ', $sqlwhere);
- }
-
- dol_syslog(get_class($this)."::fetch_all", LOG_DEBUG);
- $resql = $this->db->query($sql);
- if ($resql)
- {
- $num = $this->db->num_rows($resql);
- $i = 0;
-
- if ($num)
- {
- while ($i < $num)
- {
- $line = new Cronjobline();
-
- $obj = $this->db->fetch_object($resql);
-
- $line->id = $obj->rowid;
- $line->ref = $obj->rowid;
- $line->entity = $obj->entity;
- $line->tms = $this->db->jdate($obj->tms);
- $line->datec = $this->db->jdate($obj->datec);
- $line->label = $obj->label;
- $line->jobtype = $obj->jobtype;
- $line->command = $obj->command;
- $line->classesname = $obj->classesname;
- $line->objectname = $obj->objectname;
- $line->methodename = $obj->methodename;
- $line->params = $obj->params;
- $line->md5params = $obj->md5params;
- $line->module_name = $obj->module_name;
- $line->priority = $obj->priority;
- $line->datelastrun = $this->db->jdate($obj->datelastrun);
- $line->datenextrun = $this->db->jdate($obj->datenextrun);
- $line->dateend = $this->db->jdate($obj->dateend);
- $line->datestart = $this->db->jdate($obj->datestart);
- $line->lastresult = $obj->lastresult;
- $line->datelastresult = $this->db->jdate($obj->datelastresult);
- $line->lastoutput = $obj->lastoutput;
- $line->unitfrequency = $obj->unitfrequency;
- $line->frequency = $obj->frequency;
- $line->status = $obj->status;
- $line->processing = $obj->processing;
- $line->fk_user_author = $obj->fk_user_author;
- $line->fk_user_mod = $obj->fk_user_mod;
- $line->note_private = $obj->note_private;
- $line->nbrun = $obj->nbrun;
- $line->libname = $obj->libname;
- $line->test = $obj->test;
- $this->lines[] = $line;
-
- $i++;
- }
- }
- $this->db->free($resql);
-
- return 1;
- } else {
- $this->error = "Error ".$this->db->lasterror();
- return -1;
- }
- }
-
-
- /**
- * Update object into database
- *
- * @param User $user User that modifies
- * @param int $notrigger 0=launch triggers after, 1=disable triggers
- * @return int <0 if KO, >0 if OK
- */
- public function update($user = null, $notrigger = 0)
- {
- global $conf, $langs;
-
- $langs->load('cron');
+ }
+ }
+
+ $sql .= $this->db->order($sortfield, $sortorder);
+ if (!empty($limit) && !empty($offset)) {
+ $sql .= $this->db->plimit($limit + 1, $offset);
+ }
+
+ $sqlwhere = array();
+
+ if (count($sqlwhere) > 0) {
+ $sql .= " WHERE ".implode(' AND ', $sqlwhere);
+ }
+
+ dol_syslog(get_class($this)."::fetch_all", LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if ($resql)
+ {
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+
+ if ($num)
+ {
+ while ($i < $num)
+ {
+ $line = new Cronjobline();
+
+ $obj = $this->db->fetch_object($resql);
+
+ $line->id = $obj->rowid;
+ $line->ref = $obj->rowid;
+ $line->entity = $obj->entity;
+ $line->tms = $this->db->jdate($obj->tms);
+ $line->datec = $this->db->jdate($obj->datec);
+ $line->label = $obj->label;
+ $line->jobtype = $obj->jobtype;
+ $line->command = $obj->command;
+ $line->classesname = $obj->classesname;
+ $line->objectname = $obj->objectname;
+ $line->methodename = $obj->methodename;
+ $line->params = $obj->params;
+ $line->md5params = $obj->md5params;
+ $line->module_name = $obj->module_name;
+ $line->priority = $obj->priority;
+ $line->datelastrun = $this->db->jdate($obj->datelastrun);
+ $line->datenextrun = $this->db->jdate($obj->datenextrun);
+ $line->dateend = $this->db->jdate($obj->dateend);
+ $line->datestart = $this->db->jdate($obj->datestart);
+ $line->lastresult = $obj->lastresult;
+ $line->datelastresult = $this->db->jdate($obj->datelastresult);
+ $line->lastoutput = $obj->lastoutput;
+ $line->unitfrequency = $obj->unitfrequency;
+ $line->frequency = $obj->frequency;
+ $line->status = $obj->status;
+ $line->processing = $obj->processing;
+ $line->fk_user_author = $obj->fk_user_author;
+ $line->fk_user_mod = $obj->fk_user_mod;
+ $line->note = $obj->note;
+ $line->nbrun = $obj->nbrun;
+ $line->libname = $obj->libname;
+ $line->test = $obj->test;
+ $this->lines[] = $line;
+
+ $i++;
+ }
+ }
+ $this->db->free($resql);
+
+ return 1;
+ }
+ else
+ {
+ $this->error = "Error ".$this->db->lasterror();
+ return -1;
+ }
+ }
+
+
+ /**
+ * Update object into database
+ *
+ * @param User $user User that modifies
+ * @param int $notrigger 0=launch triggers after, 1=disable triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ public function update($user = null, $notrigger = 0)
+ {
+ global $conf, $langs;
+
+ $langs->load('cron');
$error = 0;
@@ -559,13 +557,13 @@
if (isset($this->unitfrequency)) $this->unitfrequency = trim($this->unitfrequency);
if (isset($this->frequency)) $this->frequency = trim($this->frequency);
if (isset($this->status)) $this->status = trim($this->status);
- if (isset($this->note_private)) $this->note_private = trim($this->note_private);
+ 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);
+ if (isset($this->libname)) $this->libname = trim($this->libname);
+ if (isset($this->test)) $this->test = trim($this->test);
if (empty($this->maxrun)) $this->maxrun = 0;
- if (empty($this->processing)) $this->processing = 0;
+ if (empty($this->processing)) $this->processing = 0;
// Check parameters
// Put here code to add a control on parameters values
@@ -608,9 +606,9 @@
}
- // Update request
- $sql = "UPDATE ".MAIN_DB_PREFIX."cronjob SET";
- $sql .= " entity=".(isset($this->entity) ? $this->db->escape($this->entity) : $conf->entity).",";
+ // Update request
+ $sql = "UPDATE ".MAIN_DB_PREFIX."cronjob SET";
+ $sql .= " entity=".(isset($this->entity) ? $this->db->escape($this->entity) : $conf->entity).",";
$sql .= " label=".(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").",";
$sql .= " jobtype=".(isset($this->jobtype) ? "'".$this->db->escape($this->jobtype)."'" : "null").",";
$sql .= " command=".(isset($this->command) ? "'".$this->db->escape($this->command)."'" : "null").",";
@@ -633,70 +631,74 @@
$sql .= " status=".(isset($this->status) ? $this->status : "null").",";
$sql .= " processing=".((isset($this->processing) && $this->processing > 0) ? $this->processing : "0").",";
$sql .= " fk_user_mod=".$user->id.",";
- $sql .= " note=".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null").",";
+ $sql .= " note=".(isset($this->note) ? "'".$this->db->escape($this->note)."'" : "null").",";
$sql .= " nbrun=".((isset($this->nbrun) && $this->nbrun > 0) ? $this->nbrun : "null").",";
$sql .= " maxrun=".((isset($this->maxrun) && $this->maxrun > 0) ? $this->maxrun : "0").",";
$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();
+ $this->db->begin();
dol_syslog(get_class($this)."::update", LOG_DEBUG);
- $resql = $this->db->query($sql);
- if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
-
- // Commit or rollback
+ $resql = $this->db->query($sql);
+ if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
+
+ // Commit or rollback
if ($error)
{
foreach ($this->errors as $errmsg)
{
- dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
- $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
+ dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
+ $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
$this->db->rollback();
return -1 * $error;
- } else {
+ }
+ else
+ {
$this->db->commit();
return 1;
}
- }
+ }
/**
- * Delete object in database
- *
- * @param User $user User that deletes
- * @param int $notrigger 0=launch triggers after, 1=disable triggers
- * @return int <0 if KO, >0 if OK
- */
- public function delete($user, $notrigger = 0)
+ * Delete object in database
+ *
+ * @param User $user User that deletes
+ * @param int $notrigger 0=launch triggers after, 1=disable triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ public function delete($user, $notrigger = 0)
{
$error = 0;
$this->db->begin();
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."cronjob";
- $sql .= " WHERE rowid=".$this->id;
-
- dol_syslog(get_class($this)."::delete", LOG_DEBUG);
- $resql = $this->db->query($sql);
- if (!$resql) {
- $error++;
- $this->errors[] = "Error ".$this->db->lasterror();
- }
-
- // Commit or rollback
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."cronjob";
+ $sql .= " WHERE rowid=".$this->id;
+
+ dol_syslog(get_class($this)."::delete", LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if (!$resql) {
+ $error++;
+ $this->errors[] = "Error ".$this->db->lasterror();
+ }
+
+ // Commit or rollback
if ($error)
{
foreach ($this->errors as $errmsg)
{
- dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
- $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
+ dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
+ $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
$this->db->rollback();
return -1 * $error;
- } else {
+ }
+ else
+ {
$this->db->commit();
return 1;
}
@@ -750,7 +752,9 @@
{
$this->db->commit();
return $object->id;
- } else {
+ }
+ else
+ {
$this->db->rollback();
return -1;
}
@@ -793,10 +797,10 @@
$this->processing = 0;
$this->fk_user_author = 0;
$this->fk_user_mod = 0;
- $this->note_private = '';
+ $this->note = '';
$this->nbrun = '';
$this->maxrun = 100;
- $this->libname = '';
+ $this->libname = '';
}
@@ -820,12 +824,9 @@
$result = '';
- $label = img_picto('', 'object_'.$this->picto).' '.$langs->trans("CronTask").'';
- if (isset($this->status)) {
- $label .= ' '.$this->getLibStatut(5);
- }
- $label .= '
'.$langs->trans('Ref').': '.$this->ref;
- $label .= '
'.$langs->trans('Title').': '.$this->label;
+ $label = ''.$langs->trans("CronJob").'';
+ $label .= '
';
+ $label .= ''.$langs->trans('Ref').': '.$this->ref;
$url = DOL_URL_ROOT.'/cron/card.php?id='.$this->id;
@@ -847,7 +848,8 @@
}
$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
- } else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
+ }
+ else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
$linkstart = '';
@@ -892,14 +894,16 @@
$this->db->free($resql);
return 1;
- } else {
+ }
+ else
+ {
$this->error = "Error ".$this->db->lasterror();
return -1;
}
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Run a job.
* Once job is finished, status and nb of run is updated.
@@ -910,7 +914,7 @@
*/
public function run_jobs($userlogin)
{
- // phpcs:enable
+ // phpcs:enable
global $langs, $conf, $hookmanager;
$hookmanager->initHooks(array('cron'));
@@ -947,7 +951,9 @@
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
$conf->entity = $savcurrententity;
return -1;
- } else {
+ }
+ else
+ {
if (empty($user->id))
{
$this->error = " User user login:".$userlogin." do not exists";
@@ -1010,40 +1016,30 @@
// test if method exists
if (!$error)
{
- if (!method_exists($this->objectname, $this->methodename))
- {
- $this->error = $langs->trans('CronMethodDoesNotExists', $this->objectname, $this->methodename);
- dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
- $this->lastoutput = $this->error;
- $this->lastresult = -1;
- $retval = $this->lastresult;
- $error++;
- }
- if (in_array(strtolower(trim($this->methodename)), array('executecli')))
- {
- $this->error = $langs->trans('CronMethodNotAllowed', $this->methodename, $this->objectname);
- dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
- $this->lastoutput = $this->error;
- $this->lastresult = -1;
- $retval = $this->lastresult;
- $error++;
- }
+ if (!method_exists($this->objectname, $this->methodename))
+ {
+ $this->error = $langs->trans('CronMethodDoesNotExists', $this->objectname, $this->methodename);
+ dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
+ $this->lastoutput = $this->error;
+ $this->lastresult = -1;
+ $retval = $this->lastresult;
+ $error++;
+ }
}
// Load langs
if (!$error)
{
$result = $langs->load($this->module_name);
- $result = $langs->load($this->module_name.'@'.$this->module_name, 0, 0, '', 0, 1);
-
+ $result = $langs->load($this->module_name.'@'.$this->module_name); // If this->module_name was an existing language file, this will make nothing
if ($result < 0) // If technical error
{
dol_syslog(get_class($this)."::run_jobs Cannot load module lang file - ".$langs->error, LOG_ERR);
$this->error = $langs->error;
$this->lastoutput = $this->error;
$this->lastresult = -1;
- $retval = $this->lastresult;
- $error++;
+ $retval = $this->lastresult;
+ $error++;
}
}
@@ -1055,37 +1051,38 @@
$object = new $this->objectname($this->db);
if ($this->entity > 0) $object->entity = $this->entity; // We work on a dedicated entity
- $params_arr = array();
- if (!empty($this->params) || $this->params === '0') {
- $params_arr = array_map('trim', explode(",", $this->params));
- }
+ $params_arr = array_map('trim', explode(",", $this->params));
if (!is_array($params_arr))
{
$result = call_user_func(array($object, $this->methodename), $this->params);
- } else {
+ }
+ else
+ {
$result = call_user_func_array(array($object, $this->methodename), $params_arr);
}
if ($result === false || (!is_bool($result) && $result != 0))
{
- $langs->load("errors");
-
- $errmsg = '';
- if (!is_array($object->errors) || !in_array($object->error, $object->errors)) $errmsg .= $object->error;
- if (is_array($object->errors) && count($object->errors)) $errmsg .= (($errmsg ? ', ' : '').join(', ', $object->errors));
- if (empty($errmsg)) $errmsg = $langs->trans('ErrorUnknown');
-
- dol_syslog(get_class($this)."::run_jobs END result=".$result." error=".$errmsg, LOG_ERR);
-
- $this->error = $errmsg;
- $this->lastoutput = ($object->output ? $object->output."\n" : "").$errmsg;
+ $langs->load("errors");
+
+ $errmsg = '';
+ if (!is_array($object->errors) || !in_array($object->error, $object->errors)) $errmsg .= $object->error;
+ if (is_array($object->errors) && count($object->errors)) $errmsg .= (($errmsg ? ', ' : '').join(', ', $object->errors));
+ if (empty($errmsg)) $errmsg = $langs->trans('ErrorUnknown');
+
+ dol_syslog(get_class($this)."::run_jobs END result=".$result." error=".$errmsg, LOG_ERR);
+
+ $this->error = $errmsg;
+ $this->lastoutput = ($object->output ? $object->output."\n" : "").$errmsg;
$this->lastresult = is_numeric($result) ? $result : -1;
- $retval = $this->lastresult;
- $error++;
- } else {
+ $retval = $this->lastresult;
+ $error++;
+ }
+ else
+ {
dol_syslog(get_class($this)."::run_jobs END");
- $this->lastoutput = $object->output;
+ $this->lastoutput = $object->output;
$this->lastresult = var_export($result, true);
$retval = $this->lastresult;
}
@@ -1119,55 +1116,50 @@
if (!is_array($params_arr))
{
$result = call_user_func($this->methodename, $this->params);
- } else {
+ }
+ else
+ {
$result = call_user_func_array($this->methodename, $params_arr);
}
if ($result === false || (!is_bool($result) && $result != 0))
{
- $langs->load("errors");
- dol_syslog(get_class($this)."::run_jobs result=".$result, LOG_ERR);
- $this->error = $langs->trans('ErrorUnknown');
- $this->lastoutput = $this->error;
- $this->lastresult = is_numeric($result) ? $result : -1;
- $retval = $this->lastresult;
- $error++;
- } else {
- $this->lastoutput = var_export($result, true);
- $this->lastresult = var_export($result, true); // Return code
- $retval = $this->lastresult;
+ $langs->load("errors");
+ dol_syslog(get_class($this)."::run_jobs result=".$result, LOG_ERR);
+ $this->error = $langs->trans('ErrorUnknown');
+ $this->lastoutput = $this->error;
+ $this->lastresult = is_numeric($result) ? $result : -1;
+ $retval = $this->lastresult;
+ $error++;
+ }
+ else
+ {
+ $this->lastoutput = var_export($result, true);
+ $this->lastresult = var_export($result, true); // Return code
+ $retval = $this->lastresult;
}
}
// Run a command line
if ($this->jobtype == 'command')
{
- global $dolibarr_cron_allow_cli;
-
- if (empty($dolibarr_cron_allow_cli)) {
- $langs->load("errors");
- $this->error = $langs->trans("FailedToExecutCommandJob");
- $this->lastoutput = '';
- $this->lastresult = $langs->trans("ErrorParameterMustBeEnabledToAllwoThisFeature", 'dolibarr_cron_allow_cli');
- } else {
- $outputdir = $conf->cron->dir_temp;
- if (empty($outputdir)) $outputdir = $conf->cronjob->dir_temp;
-
- if (!empty($outputdir))
- {
- dol_mkdir($outputdir);
- $outputfile = $outputdir.'/cronjob.'.$userlogin.'.out'; // File used with popen method
-
- // Execute a CLI
- include_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php';
- $utils = new Utils($this->db);
- $arrayresult = $utils->executeCLI($this->command, $outputfile);
-
- $retval = $arrayresult['result'];
- $this->error = $arrayresult['error'];
- $this->lastoutput = $arrayresult['output'];
- $this->lastresult = $arrayresult['result'];
- }
+ $outputdir = $conf->cron->dir_temp;
+ if (empty($outputdir)) $outputdir = $conf->cronjob->dir_temp;
+
+ if (!empty($outputdir))
+ {
+ dol_mkdir($outputdir);
+ $outputfile = $outputdir.'/cronjob.'.$userlogin.'.out'; // File used with popen method
+
+ // Execute a CLI
+ include_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php';
+ $utils = new Utils($this->db);
+ $arrayresult = $utils->executeCLI($this->command, $outputfile);
+
+ $retval = $arrayresult['result'];
+ $this->error = $arrayresult['error'];
+ $this->lastoutput = $arrayresult['output'];
+ $this->lastresult = $arrayresult['result'];
}
}
@@ -1188,7 +1180,7 @@
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Reprogram a job
*
@@ -1198,7 +1190,7 @@
*/
public function reprogram_jobs($userlogin, $now)
{
- // phpcs:enable
+ // phpcs:enable
dol_syslog(get_class($this)."::reprogram_jobs userlogin:$userlogin", LOG_DEBUG);
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
@@ -1209,7 +1201,9 @@
$this->error = "User Error : ".$user->error;
dol_syslog(get_class($this)."::reprogram_jobs ".$this->error, LOG_ERR);
return -1;
- } else {
+ }
+ else
+ {
if (empty($user->id))
{
$this->error = " User user login:".$userlogin." do not exists";
@@ -1228,28 +1222,30 @@
if ($this->datenextrun < $now && $this->frequency > 0 && $this->unitfrequency > 0)
{
- // Loop until date is after future
- while ($this->datenextrun < $now)
- {
- $this->datenextrun += ($this->frequency * $this->unitfrequency);
-
- // TODO For exact frequency (every month, every year, ...), use instead a dol_time_plus_duree($time, $duration_value, $duration_unit)
- }
- } else {
+ // Loop until date is after future
+ while ($this->datenextrun < $now)
+ {
+ $this->datenextrun += ($this->frequency * $this->unitfrequency);
+
+ // TODO For exact frequency (every month, every year, ...), use instead a dol_time_plus_duree($time, $duration_value, $duration_unit)
+ }
+ }
+ else
+ {
//$this->datenextrun=$this->datenextrun + ($this->frequency * $this->unitfrequency);
- dol_syslog(get_class($this)."::reprogram_jobs datenextrun is already in future, we do not change it");
+ dol_syslog(get_class($this)."::reprogram_jobs datenextrun is already in future, we do not change it");
}
// Archive job
if ($this->autodelete == 2)
{
- if (($this->maxrun > 0 && ($this->nbrun >= $this->maxrun))
- || ($this->dateend && ($this->datenextrun > $this->dateend)))
- {
- $this->status = self::STATUS_ARCHIVED;
- dol_syslog(get_class($this)."::reprogram_jobs Job will be set to archived", LOG_ERR);
- }
+ if (($this->maxrun > 0 && ($this->nbrun >= $this->maxrun))
+ || ($this->dateend && ($this->datenextrun > $this->dateend)))
+ {
+ $this->status = 2;
+ dol_syslog(get_class($this)."::reprogram_jobs Job will be set to archived", LOG_ERR);
+ }
}
$result = $this->update($user);
@@ -1270,10 +1266,10 @@
*/
public function getLibStatut($mode = 0)
{
- return $this->LibStatut($this->status, $mode, $this->processing, $this->lastresult);
+ return $this->LibStatut($this->status, $mode, $this->processing, $this->lastresult);
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Renvoi le libelle d'un statut donne
*
@@ -1283,7 +1279,7 @@
* @param int $lastresult Value of last result (0=no error, error otherwise)
* @return string Label of status
*/
- public function LibStatut($status, $mode = 0, $processing = 0, $lastresult = 0)
+ public function LibStatut($status, $mode = 0, $processing = 0, $lastresult = 0)
{
// phpcs:enable
$this->labelStatus = array(); // Force reset o array because label depends on other fields
@@ -1299,9 +1295,9 @@
elseif ($lastresult) $moretext .= ' ('.$langs->trans("Error").')';
$this->labelStatus[self::STATUS_DISABLED] = $langs->trans('Disabled').$moretext;
- $this->labelStatus[self::STATUS_ENABLED] = $langs->trans('Scheduled').$moretext;
+ $this->labelStatus[self::STATUS_ENABLED] = $langs->trans('Enabled').$moretext;
$this->labelStatusShort[self::STATUS_DISABLED] = $langs->trans('Disabled');
- $this->labelStatusShort[self::STATUS_ENABLED] = $langs->trans('Scheduled');
+ $this->labelStatusShort[self::STATUS_ENABLED] = $langs->trans('Enabled');
}
$statusType = 'status4';
@@ -1310,7 +1306,7 @@
if ($this->lastresult) $statusType = 'status8';
return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
- }
+ }
}
@@ -1334,9 +1330,9 @@
public $datec = '';
/**
- * @var string Cron Job Line label
- */
- public $label;
+ * @var string Cron Job Line label
+ */
+ public $label;
public $jobtype;
public $command;
@@ -1362,13 +1358,13 @@
public $status;
/**
- * @var int ID
- */
+ * @var int ID
+ */
public $fk_user_author;
/**
- * @var int ID
- */
+ * @var int ID
+ */
public $fk_user_mod;
public $note;