dolibarr  13.0.2
cronjob.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007-2019 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
24 // Put here all includes required by your class file
25 require_once DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php";
26 
27 
31 class Cronjob extends CommonObject
32 {
36  public $element = 'cronjob';
37 
41  public $table_element = 'cronjob';
42 
46  public $picto = 'cron';
47 
51  public $entity;
52 
53  public $jobtype;
54  public $tms = '';
55  public $datec = '';
56 
60  public $label;
61 
62  public $command;
63  public $classesname;
64  public $objectname;
65  public $methodename;
66  public $params;
67  public $md5params;
68  public $module_name;
69  public $priority;
73  public $datelastrun = '';
77  public $datenextrun = '';
78  public $dateend = '';
79  public $datestart = '';
80  public $datelastresult = '';
81  public $lastresult;
82  public $lastoutput;
83  public $unitfrequency;
84  public $frequency;
85 
89  public $status;
90 
91  public $processing;
92 
96  public $fk_user_author;
97 
101  public $fk_user_mod;
102 
103  public $nbrun;
104  public $libname;
105  public $test; // A test condition to know if job is visible/qualified
106 
107  const STATUS_DISABLED = 0;
108  const STATUS_ENABLED = 1;
109  const STATUS_ARCHIVED = 2;
110 
111 
117  public function __construct($db)
118  {
119  $this->db = $db;
120  }
121 
122 
130  public function create($user, $notrigger = 0)
131  {
132  global $conf, $langs;
133  $error = 0;
134 
135  $now = dol_now();
136 
137  // Clean parameters
138 
139  if (isset($this->label)) $this->label = trim($this->label);
140  if (isset($this->jobtype)) $this->jobtype = trim($this->jobtype);
141  if (isset($this->command)) $this->command = trim($this->command);
142  if (isset($this->classesname)) $this->classesname = trim($this->classesname);
143  if (isset($this->objectname)) $this->objectname = trim($this->objectname);
144  if (isset($this->methodename)) $this->methodename = trim($this->methodename);
145  if (isset($this->params)) $this->params = trim($this->params);
146  if (isset($this->md5params)) $this->md5params = trim($this->md5params);
147  if (isset($this->module_name)) $this->module_name = trim($this->module_name);
148  if (isset($this->priority)) $this->priority = trim($this->priority);
149  if (isset($this->lastoutput)) $this->lastoutput = trim($this->lastoutput);
150  if (isset($this->lastresult)) $this->lastresult = trim($this->lastresult);
151  if (isset($this->unitfrequency)) $this->unitfrequency = trim($this->unitfrequency);
152  if (isset($this->frequency)) $this->frequency = trim($this->frequency);
153  if (isset($this->status)) $this->status = trim($this->status);
154  if (isset($this->note_private)) $this->note_private = trim($this->note_private);
155  if (isset($this->nbrun)) $this->nbrun = trim($this->nbrun);
156  if (isset($this->libname)) $this->libname = trim($this->libname);
157  if (isset($this->test)) $this->test = trim($this->test);
158 
159  // Check parameters
160  // Put here code to add a control on parameters values
161  if (dol_strlen($this->datestart) == 0) {
162  $this->errors[] = $langs->trans('CronFieldMandatory', $langs->transnoentitiesnoconv('CronDtStart'));
163  $error++;
164  }
165  if (empty($this->label)) {
166  $this->errors[] = $langs->trans('CronFieldMandatory', $langs->transnoentitiesnoconv('CronLabel'));
167  $error++;
168  }
169  if ((dol_strlen($this->datestart) != 0) && (dol_strlen($this->dateend) != 0) && ($this->dateend < $this->datestart)) {
170  $this->errors[] = $langs->trans('CronErrEndDateStartDt');
171  $error++;
172  }
173  if (empty($this->unitfrequency)) {
174  $this->errors[] = $langs->trans('CronFieldMandatory', $langs->transnoentitiesnoconv('CronFrequency'));
175  $error++;
176  }
177  if (($this->jobtype == 'command') && (empty($this->command))) {
178  $this->errors[] = $langs->trans('CronFieldMandatory', $langs->transnoentitiesnoconv('CronCommand'));
179  $error++;
180  }
181  if (($this->jobtype == 'method') && (empty($this->classesname))) {
182  $this->errors[] = $langs->trans('CronFieldMandatory', $langs->transnoentitiesnoconv('CronClass'));
183  $error++;
184  }
185  if (($this->jobtype == 'method' || $this->jobtype == 'function') && (empty($this->methodename))) {
186  $this->errors[] = $langs->trans('CronFieldMandatory', $langs->transnoentitiesnoconv('CronMethod'));
187  $error++;
188  }
189  if (($this->jobtype == 'method') && (empty($this->objectname))) {
190  $this->errors[] = $langs->trans('CronFieldMandatory', $langs->transnoentitiesnoconv('CronObject'));
191  $error++;
192  }
193  if (($this->jobtype == 'function') && (empty($this->libname))) {
194  $this->errors[] = $langs->trans('CronFieldMandatory', $langs->transnoentitiesnoconv('CronLib'));
195  $error++;
196  }
197 
198  // Insert request
199  $sql = "INSERT INTO ".MAIN_DB_PREFIX."cronjob(";
200  $sql .= "entity,";
201  $sql .= "datec,";
202  $sql .= "jobtype,";
203  $sql .= "label,";
204  $sql .= "command,";
205  $sql .= "classesname,";
206  $sql .= "objectname,";
207  $sql .= "methodename,";
208  $sql .= "params,";
209  $sql .= "md5params,";
210  $sql .= "module_name,";
211  $sql .= "priority,";
212  $sql .= "datelastrun,";
213  $sql .= "datenextrun,";
214  $sql .= "dateend,";
215  $sql .= "datestart,";
216  $sql .= "lastresult,";
217  $sql .= "datelastresult,";
218  $sql .= "lastoutput,";
219  $sql .= "unitfrequency,";
220  $sql .= "frequency,";
221  $sql .= "status,";
222  $sql .= "fk_user_author,";
223  $sql .= "fk_user_mod,";
224  $sql .= "note,";
225  $sql .= "nbrun,";
226  $sql .= "maxrun,";
227  $sql .= "libname,";
228  $sql .= "test";
229  $sql .= ") VALUES (";
230  $sql .= " ".(!isset($this->entity) ? $conf->entity : $this->db->escape($this->entity)).",";
231  $sql .= " '".$this->db->idate($now)."',";
232  $sql .= " ".(!isset($this->jobtype) ? 'NULL' : "'".$this->db->escape($this->jobtype)."'").",";
233  $sql .= " ".(!isset($this->label) ? 'NULL' : "'".$this->db->escape($this->label)."'").",";
234  $sql .= " ".(!isset($this->command) ? 'NULL' : "'".$this->db->escape($this->command)."'").",";
235  $sql .= " ".(!isset($this->classesname) ? 'NULL' : "'".$this->db->escape($this->classesname)."'").",";
236  $sql .= " ".(!isset($this->objectname) ? 'NULL' : "'".$this->db->escape($this->objectname)."'").",";
237  $sql .= " ".(!isset($this->methodename) ? 'NULL' : "'".$this->db->escape($this->methodename)."'").",";
238  $sql .= " ".(!isset($this->params) ? 'NULL' : "'".$this->db->escape($this->params)."'").",";
239  $sql .= " ".(!isset($this->md5params) ? 'NULL' : "'".$this->db->escape($this->md5params)."'").",";
240  $sql .= " ".(!isset($this->module_name) ? 'NULL' : "'".$this->db->escape($this->module_name)."'").",";
241  $sql .= " ".(!isset($this->priority) ? '0' : $this->priority).",";
242  $sql .= " ".(!isset($this->datelastrun) || dol_strlen($this->datelastrun) == 0 ? 'NULL' : "'".$this->db->idate($this->datelastrun)."'").",";
243  $sql .= " ".(!isset($this->datenextrun) || dol_strlen($this->datenextrun) == 0 ? 'NULL' : "'".$this->db->idate($this->datenextrun)."'").",";
244  $sql .= " ".(!isset($this->dateend) || dol_strlen($this->dateend) == 0 ? 'NULL' : "'".$this->db->idate($this->dateend)."'").",";
245  $sql .= " ".(!isset($this->datestart) || dol_strlen($this->datestart) == 0 ? 'NULL' : "'".$this->db->idate($this->datestart)."'").",";
246  $sql .= " ".(!isset($this->lastresult) ? 'NULL' : "'".$this->db->escape($this->lastresult)."'").",";
247  $sql .= " ".(!isset($this->datelastresult) || dol_strlen($this->datelastresult) == 0 ? 'NULL' : "'".$this->db->idate($this->datelastresult)."'").",";
248  $sql .= " ".(!isset($this->lastoutput) ? 'NULL' : "'".$this->db->escape($this->lastoutput)."'").",";
249  $sql .= " ".(!isset($this->unitfrequency) ? 'NULL' : "'".$this->db->escape($this->unitfrequency)."'").",";
250  $sql .= " ".(!isset($this->frequency) ? '0' : $this->frequency).",";
251  $sql .= " ".(!isset($this->status) ? '0' : $this->status).",";
252  $sql .= " ".$user->id.",";
253  $sql .= " ".$user->id.",";
254  $sql .= " ".(!isset($this->note_private) ? 'NULL' : "'".$this->db->escape($this->note_private)."'").",";
255  $sql .= " ".(!isset($this->nbrun) ? '0' : $this->db->escape($this->nbrun)).",";
256  $sql .= " ".(empty($this->maxrun) ? '0' : $this->db->escape($this->maxrun)).",";
257  $sql .= " ".(!isset($this->libname) ? 'NULL' : "'".$this->db->escape($this->libname)."'").",";
258  $sql .= " ".(!isset($this->test) ? 'NULL' : "'".$this->db->escape($this->test)."'")."";
259  $sql .= ")";
260 
261  $this->db->begin();
262 
263  dol_syslog(get_class($this)."::create", LOG_DEBUG);
264  $resql = $this->db->query($sql);
265  if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
266 
267  if (!$error)
268  {
269  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."cronjob");
270  }
271 
272  // Commit or rollback
273  if ($error)
274  {
275  foreach ($this->errors as $errmsg)
276  {
277  dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
278  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
279  }
280  $this->db->rollback();
281  return -1 * $error;
282  } else {
283  $this->db->commit();
284  return $this->id;
285  }
286  }
287 
288 
297  public function fetch($id, $objectname = '', $methodname = '')
298  {
299  $sql = "SELECT";
300  $sql .= " t.rowid,";
301  $sql .= " t.entity,";
302  $sql .= " t.tms,";
303  $sql .= " t.datec,";
304  $sql .= " t.jobtype,";
305  $sql .= " t.label,";
306  $sql .= " t.command,";
307  $sql .= " t.classesname,";
308  $sql .= " t.objectname,";
309  $sql .= " t.methodename,";
310  $sql .= " t.params,";
311  $sql .= " t.md5params,";
312  $sql .= " t.module_name,";
313  $sql .= " t.priority,";
314  $sql .= " t.datelastrun,";
315  $sql .= " t.datenextrun,";
316  $sql .= " t.dateend,";
317  $sql .= " t.datestart,";
318  $sql .= " t.lastresult,";
319  $sql .= " t.datelastresult,";
320  $sql .= " t.lastoutput,";
321  $sql .= " t.unitfrequency,";
322  $sql .= " t.frequency,";
323  $sql .= " t.status,";
324  $sql .= " t.processing,";
325  $sql .= " t.fk_user_author,";
326  $sql .= " t.fk_user_mod,";
327  $sql .= " t.note as note_private,";
328  $sql .= " t.nbrun,";
329  $sql .= " t.maxrun,";
330  $sql .= " t.libname,";
331  $sql .= " t.test";
332  $sql .= " FROM ".MAIN_DB_PREFIX."cronjob as t";
333  if ($id > 0) {
334  $sql .= " WHERE t.rowid = ".$id;
335  } else {
336  $sql .= " WHERE t.entity IN(0, ".getEntity('cron').")";
337  $sql .= " AND t.objectname = '".$this->db->escape($objectname)."'";
338  $sql .= " AND t.methodename = '".$this->db->escape($methodname)."'";
339  }
340 
341  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
342  $resql = $this->db->query($sql);
343  if ($resql)
344  {
345  if ($this->db->num_rows($resql))
346  {
347  $obj = $this->db->fetch_object($resql);
348 
349  $this->id = $obj->rowid;
350  $this->ref = $obj->rowid;
351  $this->entity = $obj->entity;
352  $this->tms = $this->db->jdate($obj->tms);
353  $this->datec = $this->db->jdate($obj->datec);
354  $this->label = $obj->label;
355  $this->jobtype = $obj->jobtype;
356  $this->command = $obj->command;
357  $this->classesname = $obj->classesname;
358  $this->objectname = $obj->objectname;
359  $this->methodename = $obj->methodename;
360  $this->params = $obj->params;
361  $this->md5params = $obj->md5params;
362  $this->module_name = $obj->module_name;
363  $this->priority = $obj->priority;
364  $this->datelastrun = $this->db->jdate($obj->datelastrun);
365  $this->datenextrun = $this->db->jdate($obj->datenextrun);
366  $this->dateend = $this->db->jdate($obj->dateend);
367  $this->datestart = $this->db->jdate($obj->datestart);
368  $this->lastresult = $obj->lastresult;
369  $this->lastoutput = $obj->lastoutput;
370  $this->datelastresult = $this->db->jdate($obj->datelastresult);
371  $this->unitfrequency = $obj->unitfrequency;
372  $this->frequency = $obj->frequency;
373  $this->status = $obj->status;
374  $this->processing = $obj->processing;
375  $this->fk_user_author = $obj->fk_user_author;
376  $this->fk_user_mod = $obj->fk_user_mod;
377  $this->note_private = $obj->note_private;
378  $this->nbrun = $obj->nbrun;
379  $this->maxrun = $obj->maxrun;
380  $this->libname = $obj->libname;
381  $this->test = $obj->test;
382  }
383  $this->db->free($resql);
384 
385  return 1;
386  } else {
387  $this->error = "Error ".$this->db->lasterror();
388  return -1;
389  }
390  }
391 
392  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
405  public function fetch_all($sortorder = 'DESC', $sortfield = 't.rowid', $limit = 0, $offset = 0, $status = 1, $filter = '', $processing = -1)
406  {
407  // phpcs:enable
408  global $langs;
409 
410  $this->lines = array();
411 
412  $sql = "SELECT";
413  $sql .= " t.rowid,";
414  $sql .= " t.entity,";
415  $sql .= " t.tms,";
416  $sql .= " t.datec,";
417  $sql .= " t.jobtype,";
418  $sql .= " t.label,";
419  $sql .= " t.command,";
420  $sql .= " t.classesname,";
421  $sql .= " t.objectname,";
422  $sql .= " t.methodename,";
423  $sql .= " t.params,";
424  $sql .= " t.md5params,";
425  $sql .= " t.module_name,";
426  $sql .= " t.priority,";
427  $sql .= " t.datelastrun,";
428  $sql .= " t.datenextrun,";
429  $sql .= " t.dateend,";
430  $sql .= " t.datestart,";
431  $sql .= " t.lastresult,";
432  $sql .= " t.datelastresult,";
433  $sql .= " t.lastoutput,";
434  $sql .= " t.unitfrequency,";
435  $sql .= " t.frequency,";
436  $sql .= " t.status,";
437  $sql .= " t.processing,";
438  $sql .= " t.fk_user_author,";
439  $sql .= " t.fk_user_mod,";
440  $sql .= " t.note as note_private,";
441  $sql .= " t.nbrun,";
442  $sql .= " t.libname,";
443  $sql .= " t.test";
444  $sql .= " FROM ".MAIN_DB_PREFIX."cronjob as t";
445  $sql .= " WHERE 1 = 1";
446  if ($processing >= 0) $sql .= " AND t.processing = ".(empty($processing) ? '0' : '1');
447  if ($status >= 0 && $status < 2) $sql .= " AND t.status = ".(empty($status) ? '0' : '1');
448  elseif ($status == 2) $sql .= " AND t.status = 2";
449  //Manage filter
450  if (is_array($filter) && count($filter) > 0) {
451  foreach ($filter as $key => $value)
452  {
453  if ($key == 't.rowid') $sql .= ' AND '.$key.' = '.$this->db->escape($value);
454  else $sql .= ' AND '.$key.' LIKE \'%'.$this->db->escape($value).'%\'';
455  }
456  }
457 
458  $sql .= $this->db->order($sortfield, $sortorder);
459  if (!empty($limit) && !empty($offset)) {
460  $sql .= $this->db->plimit($limit + 1, $offset);
461  }
462 
463  $sqlwhere = array();
464 
465  if (count($sqlwhere) > 0) {
466  $sql .= " WHERE ".implode(' AND ', $sqlwhere);
467  }
468 
469  dol_syslog(get_class($this)."::fetch_all", LOG_DEBUG);
470  $resql = $this->db->query($sql);
471  if ($resql)
472  {
473  $num = $this->db->num_rows($resql);
474  $i = 0;
475 
476  if ($num)
477  {
478  while ($i < $num)
479  {
480  $line = new Cronjobline();
481 
482  $obj = $this->db->fetch_object($resql);
483 
484  $line->id = $obj->rowid;
485  $line->ref = $obj->rowid;
486  $line->entity = $obj->entity;
487  $line->tms = $this->db->jdate($obj->tms);
488  $line->datec = $this->db->jdate($obj->datec);
489  $line->label = $obj->label;
490  $line->jobtype = $obj->jobtype;
491  $line->command = $obj->command;
492  $line->classesname = $obj->classesname;
493  $line->objectname = $obj->objectname;
494  $line->methodename = $obj->methodename;
495  $line->params = $obj->params;
496  $line->md5params = $obj->md5params;
497  $line->module_name = $obj->module_name;
498  $line->priority = $obj->priority;
499  $line->datelastrun = $this->db->jdate($obj->datelastrun);
500  $line->datenextrun = $this->db->jdate($obj->datenextrun);
501  $line->dateend = $this->db->jdate($obj->dateend);
502  $line->datestart = $this->db->jdate($obj->datestart);
503  $line->lastresult = $obj->lastresult;
504  $line->datelastresult = $this->db->jdate($obj->datelastresult);
505  $line->lastoutput = $obj->lastoutput;
506  $line->unitfrequency = $obj->unitfrequency;
507  $line->frequency = $obj->frequency;
508  $line->status = $obj->status;
509  $line->processing = $obj->processing;
510  $line->fk_user_author = $obj->fk_user_author;
511  $line->fk_user_mod = $obj->fk_user_mod;
512  $line->note_private = $obj->note_private;
513  $line->nbrun = $obj->nbrun;
514  $line->libname = $obj->libname;
515  $line->test = $obj->test;
516  $this->lines[] = $line;
517 
518  $i++;
519  }
520  }
521  $this->db->free($resql);
522 
523  return 1;
524  } else {
525  $this->error = "Error ".$this->db->lasterror();
526  return -1;
527  }
528  }
529 
530 
538  public function update($user = null, $notrigger = 0)
539  {
540  global $conf, $langs;
541 
542  $langs->load('cron');
543 
544  $error = 0;
545 
546  // Clean parameters
547  if (isset($this->label)) $this->label = trim($this->label);
548  if (isset($this->jobtype)) $this->jobtype = trim($this->jobtype);
549  if (isset($this->command)) $this->command = trim($this->command);
550  if (isset($this->classesname)) $this->classesname = trim($this->classesname);
551  if (isset($this->objectname)) $this->objectname = trim($this->objectname);
552  if (isset($this->methodename)) $this->methodename = trim($this->methodename);
553  if (isset($this->params)) $this->params = trim($this->params);
554  if (isset($this->md5params)) $this->md5params = trim($this->md5params);
555  if (isset($this->module_name)) $this->module_name = trim($this->module_name);
556  if (isset($this->priority)) $this->priority = trim($this->priority);
557  if (isset($this->lastoutput)) $this->lastoutput = trim($this->lastoutput);
558  if (isset($this->lastresult)) $this->lastresult = trim($this->lastresult);
559  if (isset($this->unitfrequency)) $this->unitfrequency = trim($this->unitfrequency);
560  if (isset($this->frequency)) $this->frequency = trim($this->frequency);
561  if (isset($this->status)) $this->status = trim($this->status);
562  if (isset($this->note_private)) $this->note_private = trim($this->note_private);
563  if (isset($this->nbrun)) $this->nbrun = trim($this->nbrun);
564  if (isset($this->libname)) $this->libname = trim($this->libname);
565  if (isset($this->test)) $this->test = trim($this->test);
566 
567  if (empty($this->maxrun)) $this->maxrun = 0;
568  if (empty($this->processing)) $this->processing = 0;
569 
570  // Check parameters
571  // Put here code to add a control on parameters values
572  if (dol_strlen($this->datestart) == 0) {
573  $this->errors[] = $langs->trans('CronFieldMandatory', $langs->transnoentitiesnoconv('CronDtStart'));
574  $error++;
575  }
576  if ((dol_strlen($this->datestart) != 0) && (dol_strlen($this->dateend) != 0) && ($this->dateend < $this->datestart)) {
577  $this->errors[] = $langs->trans('CronErrEndDateStartDt');
578  $error++;
579  }
580  if (empty($this->label)) {
581  $this->errors[] = $langs->trans('CronFieldMandatory', $langs->transnoentitiesnoconv('CronLabel'));
582  $error++;
583  }
584  if (empty($this->unitfrequency)) {
585  $this->errors[] = $langs->trans('CronFieldMandatory', $langs->transnoentitiesnoconv('CronFrequency'));
586  $error++;
587  }
588  if (($this->jobtype == 'command') && (empty($this->command))) {
589  $this->errors[] = $langs->trans('CronFieldMandatory', $langs->transnoentitiesnoconv('CronCommand'));
590  $error++;
591  }
592  if (($this->jobtype == 'method') && (empty($this->classesname))) {
593  $this->errors[] = $langs->trans('CronFieldMandatory', $langs->transnoentitiesnoconv('CronClass'));
594  $error++;
595  }
596  if (($this->jobtype == 'method' || $this->jobtype == 'function') && (empty($this->methodename))) {
597  $this->errors[] = $langs->trans('CronFieldMandatory', $langs->transnoentitiesnoconv('CronMethod'));
598  $error++;
599  }
600  if (($this->jobtype == 'method') && (empty($this->objectname))) {
601  $this->errors[] = $langs->trans('CronFieldMandatory', $langs->transnoentitiesnoconv('CronObject'));
602  $error++;
603  }
604 
605  if (($this->jobtype == 'function') && (empty($this->libname))) {
606  $this->errors[] = $langs->trans('CronFieldMandatory', $langs->transnoentitiesnoconv('CronLib'));
607  $error++;
608  }
609 
610 
611  // Update request
612  $sql = "UPDATE ".MAIN_DB_PREFIX."cronjob SET";
613  $sql .= " entity=".(isset($this->entity) ? $this->db->escape($this->entity) : $conf->entity).",";
614  $sql .= " label=".(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").",";
615  $sql .= " jobtype=".(isset($this->jobtype) ? "'".$this->db->escape($this->jobtype)."'" : "null").",";
616  $sql .= " command=".(isset($this->command) ? "'".$this->db->escape($this->command)."'" : "null").",";
617  $sql .= " classesname=".(isset($this->classesname) ? "'".$this->db->escape($this->classesname)."'" : "null").",";
618  $sql .= " objectname=".(isset($this->objectname) ? "'".$this->db->escape($this->objectname)."'" : "null").",";
619  $sql .= " methodename=".(isset($this->methodename) ? "'".$this->db->escape($this->methodename)."'" : "null").",";
620  $sql .= " params=".(isset($this->params) ? "'".$this->db->escape($this->params)."'" : "null").",";
621  $sql .= " md5params=".(isset($this->md5params) ? "'".$this->db->escape($this->md5params)."'" : "null").",";
622  $sql .= " module_name=".(isset($this->module_name) ? "'".$this->db->escape($this->module_name)."'" : "null").",";
623  $sql .= " priority=".(isset($this->priority) ? $this->priority : "null").",";
624  $sql .= " datelastrun=".(dol_strlen($this->datelastrun) != 0 ? "'".$this->db->idate($this->datelastrun)."'" : 'null').",";
625  $sql .= " datenextrun=".(dol_strlen($this->datenextrun) != 0 ? "'".$this->db->idate($this->datenextrun)."'" : 'null').",";
626  $sql .= " dateend=".(dol_strlen($this->dateend) != 0 ? "'".$this->db->idate($this->dateend)."'" : 'null').",";
627  $sql .= " datestart=".(dol_strlen($this->datestart) != 0 ? "'".$this->db->idate($this->datestart)."'" : 'null').",";
628  $sql .= " datelastresult=".(dol_strlen($this->datelastresult) != 0 ? "'".$this->db->idate($this->datelastresult)."'" : 'null').",";
629  $sql .= " lastresult=".(isset($this->lastresult) ? "'".$this->db->escape($this->lastresult)."'" : "null").",";
630  $sql .= " lastoutput=".(isset($this->lastoutput) ? "'".$this->db->escape($this->lastoutput)."'" : "null").",";
631  $sql .= " unitfrequency=".(isset($this->unitfrequency) ? $this->unitfrequency : "null").",";
632  $sql .= " frequency=".(isset($this->frequency) ? $this->frequency : "null").",";
633  $sql .= " status=".(isset($this->status) ? $this->status : "null").",";
634  $sql .= " processing=".((isset($this->processing) && $this->processing > 0) ? $this->processing : "0").",";
635  $sql .= " fk_user_mod=".$user->id.",";
636  $sql .= " note=".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null").",";
637  $sql .= " nbrun=".((isset($this->nbrun) && $this->nbrun > 0) ? $this->nbrun : "null").",";
638  $sql .= " maxrun=".((isset($this->maxrun) && $this->maxrun > 0) ? $this->maxrun : "0").",";
639  $sql .= " libname=".(isset($this->libname) ? "'".$this->db->escape($this->libname)."'" : "null").",";
640  $sql .= " test=".(isset($this->test) ? "'".$this->db->escape($this->test)."'" : "null");
641  $sql .= " WHERE rowid=".$this->id;
642 
643  $this->db->begin();
644 
645  dol_syslog(get_class($this)."::update", LOG_DEBUG);
646  $resql = $this->db->query($sql);
647  if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
648 
649  // Commit or rollback
650  if ($error)
651  {
652  foreach ($this->errors as $errmsg)
653  {
654  dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
655  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
656  }
657  $this->db->rollback();
658  return -1 * $error;
659  } else {
660  $this->db->commit();
661  return 1;
662  }
663  }
664 
665 
673  public function delete($user, $notrigger = 0)
674  {
675  $error = 0;
676 
677  $this->db->begin();
678 
679  $sql = "DELETE FROM ".MAIN_DB_PREFIX."cronjob";
680  $sql .= " WHERE rowid=".$this->id;
681 
682  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
683  $resql = $this->db->query($sql);
684  if (!$resql) {
685  $error++;
686  $this->errors[] = "Error ".$this->db->lasterror();
687  }
688 
689  // Commit or rollback
690  if ($error)
691  {
692  foreach ($this->errors as $errmsg)
693  {
694  dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
695  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
696  }
697  $this->db->rollback();
698  return -1 * $error;
699  } else {
700  $this->db->commit();
701  return 1;
702  }
703  }
704 
705 
706 
714  public function createFromClone(User $user, $fromid)
715  {
716  $error = 0;
717 
718  $object = new Cronjob($this->db);
719 
720  $this->db->begin();
721 
722  // Load source object
723  $object->fetch($fromid);
724  $object->id = 0;
725  $object->statut = 0;
726 
727  // Clear fields
728  // ...
729 
730  // Create clone
731  $object->context['createfromclone'] = 'createfromclone';
732  $result = $object->create($user);
733 
734  // Other options
735  if ($result < 0)
736  {
737  $this->error = $object->error;
738  $error++;
739  }
740 
741  //if (! $error)
742  //{
743 
744  //}
745 
746  unset($object->context['createfromclone']);
747 
748  // End
749  if (!$error)
750  {
751  $this->db->commit();
752  return $object->id;
753  } else {
754  $this->db->rollback();
755  return -1;
756  }
757  }
758 
759 
766  public function initAsSpecimen()
767  {
768  $this->id = 0;
769  $this->ref = 0;
770  $this->entity = 0;
771  $this->tms = '';
772  $this->datec = '';
773  $this->label = '';
774  $this->jobtype = '';
775  $this->command = '';
776  $this->classesname = '';
777  $this->objectname = '';
778  $this->methodename = '';
779  $this->params = '';
780  $this->md5params = '';
781  $this->module_name = '';
782  $this->priority = '';
783  $this->datelastrun = '';
784  $this->datenextrun = '';
785  $this->dateend = '';
786  $this->datestart = '';
787  $this->datelastresult = '';
788  $this->lastoutput = '';
789  $this->lastresult = '';
790  $this->unitfrequency = '';
791  $this->frequency = '';
792  $this->status = 0;
793  $this->processing = 0;
794  $this->fk_user_author = 0;
795  $this->fk_user_mod = 0;
796  $this->note_private = '';
797  $this->nbrun = '';
798  $this->maxrun = 100;
799  $this->libname = '';
800  }
801 
802 
813  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
814  {
815  global $db, $conf, $langs;
816  global $dolibarr_main_authentication, $dolibarr_main_demo;
817  global $menumanager;
818 
819  if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
820 
821  $result = '';
822 
823  $label = img_picto('', 'object_'.$this->picto).' <u>'.$langs->trans("CronTask").'</u>';
824  if (isset($this->status)) {
825  $label .= ' '.$this->getLibStatut(5);
826  }
827  $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
828  $label .= '<br><b>'.$langs->trans('Title').':</b> '.$this->label;
829 
830  $url = DOL_URL_ROOT.'/cron/card.php?id='.$this->id;
831 
832  if ($option != 'nolink')
833  {
834  // Add param to save lastsearch_values or not
835  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
836  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
837  if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
838  }
839 
840  $linkclose = '';
841  if (empty($notooltip))
842  {
843  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
844  {
845  $label = $langs->trans("ShowCronJob");
846  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
847  }
848  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
849  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
850  } else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
851 
852  $linkstart = '<a href="'.$url.'"';
853  $linkstart .= $linkclose.'>';
854  $linkend = '</a>';
855 
856  $result .= $linkstart;
857  if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
858  if ($withpicto != 2) $result .= $this->ref;
859  $result .= $linkend;
860  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
861 
862  return $result;
863  }
864 
865 
872  public function info($id)
873  {
874  $sql = "SELECT";
875  $sql .= " f.rowid, f.datec, f.tms, f.fk_user_mod, f.fk_user_author";
876  $sql .= " FROM ".MAIN_DB_PREFIX."cronjob as f";
877  $sql .= " WHERE f.rowid = ".$id;
878 
879  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
880  $resql = $this->db->query($sql);
881  if ($resql)
882  {
883  if ($this->db->num_rows($resql))
884  {
885  $obj = $this->db->fetch_object($resql);
886  $this->id = $obj->rowid;
887  $this->date_creation = $this->db->jdate($obj->datec);
888  $this->date_modification = $this->db->jdate($obj->tms);
889  $this->user_modification = $obj->fk_user_mod;
890  $this->user_creation = $obj->fk_user_author;
891  }
892  $this->db->free($resql);
893 
894  return 1;
895  } else {
896  $this->error = "Error ".$this->db->lasterror();
897  return -1;
898  }
899  }
900 
901 
902  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
911  public function run_jobs($userlogin)
912  {
913  // phpcs:enable
914  global $langs, $conf, $hookmanager;
915 
916  $hookmanager->initHooks(array('cron'));
917 
918  $now = dol_now();
919  $error = 0;
920  $retval = '';
921 
922  $langs->load('cron');
923 
924  if (empty($userlogin))
925  {
926  $this->error = "User login is mandatory";
927  dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
928  return -1;
929  }
930 
931  // Force the environment of running to the environment declared for job, so jobs launched from command line will run into correct environment
932  // When job is ran from GUI, the environment should already be same, except if job has entity 0 (visible into all environments)
933  if ($conf->entity != $this->entity && $this->entity > 0)
934  {
935  dol_syslog("We try to run a job in entity ".$this->entity." when we are in entity ".$conf->entity, LOG_WARNING);
936  }
937  $savcurrententity = $conf->entity;
938  $conf->entity = $this->entity;
939  dol_syslog(get_class($this)."::run_jobs entity for running job is ".$conf->entity);
940 
941  require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
942  $user = new User($this->db);
943  $result = $user->fetch('', $userlogin);
944  if ($result < 0)
945  {
946  $this->error = "User Error:".$user->error;
947  dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
948  $conf->entity = $savcurrententity;
949  return -1;
950  } else {
951  if (empty($user->id))
952  {
953  $this->error = " User user login:".$userlogin." do not exists";
954  dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
955  $conf->entity = $savcurrententity;
956  return -1;
957  }
958  }
959 
960  dol_syslog(get_class($this)."::run_jobs jobtype=".$this->jobtype." userlogin=".$userlogin, LOG_DEBUG);
961 
962  // Increase limit of time. Works only if we are not in safe mode
963  $ExecTimeLimit = 600;
964  if (!empty($ExecTimeLimit))
965  {
966  $err = error_reporting();
967  error_reporting(0); // Disable all errors
968  //error_reporting(E_ALL);
969  @set_time_limit($ExecTimeLimit); // Need more than 240 on Windows 7/64
970  error_reporting($err);
971  }
972  if (!empty($MemoryLimit))
973  {
974  @ini_set('memory_limit', $MemoryLimit);
975  }
976 
977  // Update last run date start (to track running jobs)
978  $this->datelastrun = $now;
979  $this->datelastresult = null;
980  $this->lastoutput = '';
981  $this->lastresult = '';
982  $this->processing = 1; // To know job was started
983  $this->nbrun = $this->nbrun + 1;
984  $result = $this->update($user); // This include begin/commit
985  if ($result < 0) {
986  dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
987  $conf->entity = $savcurrententity;
988  return -1;
989  }
990 
991  // Run a method
992  if ($this->jobtype == 'method')
993  {
994  // load classes
995  if (!$error)
996  {
997  $ret = dol_include_once($this->classesname);
998  if ($ret === false || (!class_exists($this->objectname)))
999  {
1000  if ($ret === false) $this->error = $langs->trans('CronCannotLoadClass', $this->classesname, $this->objectname);
1001  else $this->error = $langs->trans('CronCannotLoadObject', $this->classesname, $this->objectname);
1002  dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
1003  $this->lastoutput = $this->error;
1004  $this->lastresult = -1;
1005  $retval = $this->lastresult;
1006  $error++;
1007  }
1008  }
1009 
1010  // test if method exists
1011  if (!$error)
1012  {
1013  if (!method_exists($this->objectname, $this->methodename))
1014  {
1015  $this->error = $langs->trans('CronMethodDoesNotExists', $this->objectname, $this->methodename);
1016  dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
1017  $this->lastoutput = $this->error;
1018  $this->lastresult = -1;
1019  $retval = $this->lastresult;
1020  $error++;
1021  }
1022  if (in_array(strtolower(trim($this->methodename)), array('executecli')))
1023  {
1024  $this->error = $langs->trans('CronMethodNotAllowed', $this->methodename, $this->objectname);
1025  dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
1026  $this->lastoutput = $this->error;
1027  $this->lastresult = -1;
1028  $retval = $this->lastresult;
1029  $error++;
1030  }
1031  }
1032 
1033  // Load langs
1034  if (!$error)
1035  {
1036  $result = $langs->load($this->module_name);
1037  $result = $langs->load($this->module_name.'@'.$this->module_name, 0, 0, '', 0, 1);
1038 
1039  if ($result < 0) // If technical error
1040  {
1041  dol_syslog(get_class($this)."::run_jobs Cannot load module lang file - ".$langs->error, LOG_ERR);
1042  $this->error = $langs->error;
1043  $this->lastoutput = $this->error;
1044  $this->lastresult = -1;
1045  $retval = $this->lastresult;
1046  $error++;
1047  }
1048  }
1049 
1050  if (!$error)
1051  {
1052  dol_syslog(get_class($this)."::run_jobs START ".$this->objectname."->".$this->methodename."(".$this->params.");", LOG_DEBUG);
1053 
1054  // Create Object for the called module
1055  $object = new $this->objectname($this->db);
1056  if ($this->entity > 0) $object->entity = $this->entity; // We work on a dedicated entity
1057 
1058  $params_arr = array();
1059  if (!empty($this->params) || $this->params === '0') {
1060  $params_arr = array_map('trim', explode(",", $this->params));
1061  }
1062 
1063  if (!is_array($params_arr))
1064  {
1065  $result = call_user_func(array($object, $this->methodename), $this->params);
1066  } else {
1067  $result = call_user_func_array(array($object, $this->methodename), $params_arr);
1068  }
1069 
1070  if ($result === false || (!is_bool($result) && $result != 0))
1071  {
1072  $langs->load("errors");
1073 
1074  $errmsg = '';
1075  if (!is_array($object->errors) || !in_array($object->error, $object->errors)) $errmsg .= $object->error;
1076  if (is_array($object->errors) && count($object->errors)) $errmsg .= (($errmsg ? ', ' : '').join(', ', $object->errors));
1077  if (empty($errmsg)) $errmsg = $langs->trans('ErrorUnknown');
1078 
1079  dol_syslog(get_class($this)."::run_jobs END result=".$result." error=".$errmsg, LOG_ERR);
1080 
1081  $this->error = $errmsg;
1082  $this->lastoutput = ($object->output ? $object->output."\n" : "").$errmsg;
1083  $this->lastresult = is_numeric($result) ? $result : -1;
1084  $retval = $this->lastresult;
1085  $error++;
1086  } else {
1087  dol_syslog(get_class($this)."::run_jobs END");
1088  $this->lastoutput = $object->output;
1089  $this->lastresult = var_export($result, true);
1090  $retval = $this->lastresult;
1091  }
1092  }
1093  }
1094 
1095  if ($this->jobtype == 'function') {
1096  //load lib
1097  $libpath = '/'.strtolower($this->module_name).'/lib/'.$this->libname;
1098  $ret = dol_include_once($libpath);
1099  if ($ret === false)
1100  {
1101  $this->error = $langs->trans('CronCannotLoadLib').': '.$libpath;
1102  dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
1103  $conf->entity = $savcurrententity;
1104  return -1;
1105  }
1106 
1107  // Load langs
1108  $result = $langs->load($this->module_name);
1109  $result = $langs->load($this->module_name.'@'.$this->module_name); // If this->module_name was an existing language file, this will make nothing
1110  if ($result < 0) // If technical error
1111  {
1112  dol_syslog(get_class($this)."::run_jobs Cannot load module langs".$langs->error, LOG_ERR);
1113  $conf->entity = $savcurrententity;
1114  return -1;
1115  }
1116 
1117  dol_syslog(get_class($this)."::run_jobs ".$this->libname."::".$this->methodename."(".$this->params.");", LOG_DEBUG);
1118  $params_arr = explode(", ", $this->params);
1119  if (!is_array($params_arr))
1120  {
1121  $result = call_user_func($this->methodename, $this->params);
1122  } else {
1123  $result = call_user_func_array($this->methodename, $params_arr);
1124  }
1125 
1126  if ($result === false || (!is_bool($result) && $result != 0))
1127  {
1128  $langs->load("errors");
1129  dol_syslog(get_class($this)."::run_jobs result=".$result, LOG_ERR);
1130  $this->error = $langs->trans('ErrorUnknown');
1131  $this->lastoutput = $this->error;
1132  $this->lastresult = is_numeric($result) ? $result : -1;
1133  $retval = $this->lastresult;
1134  $error++;
1135  } else {
1136  $this->lastoutput = var_export($result, true);
1137  $this->lastresult = var_export($result, true); // Return code
1138  $retval = $this->lastresult;
1139  }
1140  }
1141 
1142  // Run a command line
1143  if ($this->jobtype == 'command')
1144  {
1145  global $dolibarr_cron_allow_cli;
1146 
1147  if (empty($dolibarr_cron_allow_cli)) {
1148  $langs->load("errors");
1149  $this->error = $langs->trans("FailedToExecutCommandJob");
1150  $this->lastoutput = '';
1151  $this->lastresult = $langs->trans("ErrorParameterMustBeEnabledToAllwoThisFeature", 'dolibarr_cron_allow_cli');
1152  } else {
1153  $outputdir = $conf->cron->dir_temp;
1154  if (empty($outputdir)) $outputdir = $conf->cronjob->dir_temp;
1155 
1156  if (!empty($outputdir))
1157  {
1158  dol_mkdir($outputdir);
1159  $outputfile = $outputdir.'/cronjob.'.$userlogin.'.out'; // File used with popen method
1160 
1161  // Execute a CLI
1162  include_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php';
1163  $utils = new Utils($this->db);
1164  $arrayresult = $utils->executeCLI($this->command, $outputfile);
1165 
1166  $retval = $arrayresult['result'];
1167  $this->error = $arrayresult['error'];
1168  $this->lastoutput = $arrayresult['output'];
1169  $this->lastresult = $arrayresult['result'];
1170  }
1171  }
1172  }
1173 
1174  dol_syslog(get_class($this)."::run_jobs now we update job to track it is finished (with success or error)");
1175 
1176  $this->datelastresult = dol_now();
1177  $this->processing = 0;
1178  $result = $this->update($user); // This include begin/commit
1179  if ($result < 0)
1180  {
1181  dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
1182  $conf->entity = $savcurrententity;
1183  return -1;
1184  }
1185 
1186  $conf->entity = $savcurrententity;
1187  return $error ?-1 : 1;
1188  }
1189 
1190 
1191  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1199  public function reprogram_jobs($userlogin, $now)
1200  {
1201  // phpcs:enable
1202  dol_syslog(get_class($this)."::reprogram_jobs userlogin:$userlogin", LOG_DEBUG);
1203 
1204  require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
1205  $user = new User($this->db);
1206  $result = $user->fetch('', $userlogin);
1207  if ($result < 0)
1208  {
1209  $this->error = "User Error : ".$user->error;
1210  dol_syslog(get_class($this)."::reprogram_jobs ".$this->error, LOG_ERR);
1211  return -1;
1212  } else {
1213  if (empty($user->id))
1214  {
1215  $this->error = " User user login:".$userlogin." do not exists";
1216  dol_syslog(get_class($this)."::reprogram_jobs ".$this->error, LOG_ERR);
1217  return -1;
1218  }
1219  }
1220 
1221  dol_syslog(get_class($this)."::reprogram_jobs datenextrun=".$this->datenextrun." ".dol_print_date($this->datenextrun, 'dayhourrfc')." frequency=".$this->frequency." unitfrequency=".$this->unitfrequency, LOG_DEBUG);
1222 
1223  if (empty($this->datenextrun))
1224  {
1225  if (empty($this->datestart)) $this->datenextrun = $now + ($this->frequency * $this->unitfrequency);
1226  else $this->datenextrun = $this->datestart + ($this->frequency * $this->unitfrequency);
1227  }
1228 
1229  if ($this->datenextrun < $now && $this->frequency > 0 && $this->unitfrequency > 0)
1230  {
1231  // Loop until date is after future
1232  while ($this->datenextrun < $now)
1233  {
1234  $this->datenextrun += ($this->frequency * $this->unitfrequency);
1235 
1236  // TODO For exact frequency (every month, every year, ...), use instead a dol_time_plus_duree($time, $duration_value, $duration_unit)
1237  }
1238  } else {
1239  //$this->datenextrun=$this->datenextrun + ($this->frequency * $this->unitfrequency);
1240  dol_syslog(get_class($this)."::reprogram_jobs datenextrun is already in future, we do not change it");
1241  }
1242 
1243 
1244  // Archive job
1245  if ($this->autodelete == 2)
1246  {
1247  if (($this->maxrun > 0 && ($this->nbrun >= $this->maxrun))
1248  || ($this->dateend && ($this->datenextrun > $this->dateend)))
1249  {
1250  $this->status = self::STATUS_ARCHIVED;
1251  dol_syslog(get_class($this)."::reprogram_jobs Job will be set to archived", LOG_ERR);
1252  }
1253  }
1254 
1255  $result = $this->update($user);
1256  if ($result < 0)
1257  {
1258  dol_syslog(get_class($this)."::reprogram_jobs ".$this->error, LOG_ERR);
1259  return -1;
1260  }
1261 
1262  return 1;
1263  }
1264 
1271  public function getLibStatut($mode = 0)
1272  {
1273  return $this->LibStatut($this->status, $mode, $this->processing, $this->lastresult);
1274  }
1275 
1276  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1286  public function LibStatut($status, $mode = 0, $processing = 0, $lastresult = 0)
1287  {
1288  // phpcs:enable
1289  $this->labelStatus = array(); // Force reset o array because label depends on other fields
1290  $this->labelStatusShort = array();
1291 
1292  if (empty($this->labelStatus) || empty($this->labelStatusShort))
1293  {
1294  global $langs;
1295  $langs->load('users');
1296 
1297  $moretext = '';
1298  if ($processing) $moretext = ' ('.$langs->trans("Running").')';
1299  elseif ($lastresult) $moretext .= ' ('.$langs->trans("Error").')';
1300 
1301  $this->labelStatus[self::STATUS_DISABLED] = $langs->trans('Disabled').$moretext;
1302  $this->labelStatus[self::STATUS_ENABLED] = $langs->trans('Scheduled').$moretext;
1303  $this->labelStatusShort[self::STATUS_DISABLED] = $langs->trans('Disabled');
1304  $this->labelStatusShort[self::STATUS_ENABLED] = $langs->trans('Scheduled');
1305  }
1306 
1307  $statusType = 'status4';
1308  if ($status == 1 && $processing) $statusType = 'status1';
1309  if ($status == 0) $statusType = 'status5';
1310  if ($this->lastresult) $statusType = 'status8';
1311 
1312  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
1313  }
1314 }
1315 
1316 
1321 {
1322 
1326  public $id;
1327 
1331  public $ref;
1332 
1333  public $tms = '';
1334  public $datec = '';
1335 
1339  public $label;
1340 
1341  public $jobtype;
1342  public $command;
1343  public $classesname;
1344  public $objectname;
1345  public $methodename;
1346  public $params;
1347  public $md5params;
1348  public $module_name;
1349  public $priority;
1350  public $datelastrun = '';
1351  public $datenextrun = '';
1352  public $dateend = '';
1353  public $datestart = '';
1354  public $lastresult = '';
1355  public $lastoutput;
1356  public $unitfrequency;
1357  public $frequency;
1358 
1362  public $status;
1363 
1367  public $fk_user_author;
1368 
1372  public $fk_user_mod;
1373 
1374  public $note;
1375  public $nbrun;
1376  public $libname;
1377 
1382  public function __construct()
1383  {
1384  return 1;
1385  }
1386 }
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname= '')
Make an include_once using default root and alternate root if it fails.
Crob Job line class.
Class to manage utility methods.
Definition: utils.class.php:28
create($user, $notrigger=0)
Create object into database.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
info($id)
Load object information.
__construct()
Constructor.
dol_now($mode= 'auto')
Return date for now.
reprogram_jobs($userlogin, $now)
Reprogram a job.
Class to manage Dolibarr users.
Definition: user.class.php:44
getLibStatut($mode=0)
Return label of status of user (active, inactive)
__construct($db)
Constructor.
getNomUrl($withpicto=0, $option= '', $notooltip=0, $morecss= '', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
run_jobs($userlogin)
Run a job.
$conf db
API class for accounts.
Definition: inc.php:54
update($user=null, $notrigger=0)
Update object into database.
fetch($id, $objectname= '', $methodname= '')
Load object in memory from the database.
LibStatut($status, $mode=0, $processing=0, $lastresult=0)
Renvoi le libelle d&#39;un statut donne.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
Cron Job class.
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
fetch_all($sortorder= 'DESC', $sortfield= 't.rowid', $limit=0, $offset=0, $status=1, $filter= '', $processing=-1)
Load object in memory from the database.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)