dolibarr  9.0.0
cronjob.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007-2012 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 <http://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;
70  public $datelastrun='';
71  public $datenextrun='';
72  public $dateend='';
73  public $datestart='';
74  public $datelastresult='';
75  public $lastresult;
76  public $lastoutput;
77  public $unitfrequency;
78  public $frequency;
79 
83  public $status;
84 
85  public $processing;
86 
90  public $fk_user_author;
91 
95  public $fk_user_mod;
96 
97  public $nbrun;
98  public $libname;
99  public $test; // A test condition to know if job is visible/qualified
100 
101  const STATUS_DISABLED = 0;
102  const STATUS_ENABLED = 1;
103  const STATUS_ARCHIVED = 2;
104 
105 
111  function __construct($db)
112  {
113  $this->db = $db;
114  }
115 
116 
124  function create($user, $notrigger=0)
125  {
126  global $conf, $langs;
127  $error=0;
128 
129  $now=dol_now();
130 
131  // Clean parameters
132 
133  if (isset($this->label)) $this->label=trim($this->label);
134  if (isset($this->jobtype)) $this->jobtype=trim($this->jobtype);
135  if (isset($this->command)) $this->command=trim($this->command);
136  if (isset($this->classesname)) $this->classesname=trim($this->classesname);
137  if (isset($this->objectname)) $this->objectname=trim($this->objectname);
138  if (isset($this->methodename)) $this->methodename=trim($this->methodename);
139  if (isset($this->params)) $this->params=trim($this->params);
140  if (isset($this->md5params)) $this->md5params=trim($this->md5params);
141  if (isset($this->module_name)) $this->module_name=trim($this->module_name);
142  if (isset($this->priority)) $this->priority=trim($this->priority);
143  if (isset($this->lastoutput)) $this->lastoutput=trim($this->lastoutput);
144  if (isset($this->lastresult)) $this->lastresult=trim($this->lastresult);
145  if (isset($this->unitfrequency)) $this->unitfrequency=trim($this->unitfrequency);
146  if (isset($this->frequency)) $this->frequency=trim($this->frequency);
147  if (isset($this->status)) $this->status=trim($this->status);
148  if (isset($this->note)) $this->note=trim($this->note);
149  if (isset($this->nbrun)) $this->nbrun=trim($this->nbrun);
150  if (isset($this->libname)) $this->libname = trim($this->libname);
151  if (isset($this->test)) $this->test = trim($this->test);
152 
153  // Check parameters
154  // Put here code to add a control on parameters values
155  if (dol_strlen($this->datestart)==0) {
156  $this->errors[]=$langs->trans('CronFieldMandatory',$langs->trans('CronDtStart'));
157  $error++;
158  }
159  if (empty($this->label)) {
160  $this->errors[]=$langs->trans('CronFieldMandatory',$langs->trans('CronLabel'));
161  $error++;
162  }
163  if ((dol_strlen($this->datestart)!=0) && (dol_strlen($this->dateend)!=0) && ($this->dateend<$this->datestart)) {
164  $this->errors[]=$langs->trans('CronErrEndDateStartDt');
165  $error++;
166  }
167  if (empty($this->unitfrequency)) {
168  $this->errors[]=$langs->trans('CronFieldMandatory',$langs->trans('CronFrequency'));
169  $error++;
170  }
171  if (($this->jobtype=='command') && (empty($this->command))) {
172  $this->errors[]=$langs->trans('CronFieldMandatory',$langs->trans('CronCommand'));
173  $error++;
174  }
175  if (($this->jobtype=='method') && (empty($this->classesname))) {
176  $this->errors[]=$langs->trans('CronFieldMandatory',$langs->trans('CronClass'));
177  $error++;
178  }
179  if (($this->jobtype=='method' || $this->jobtype == 'function') && (empty($this->methodename))) {
180  $this->errors[]=$langs->trans('CronFieldMandatory',$langs->trans('CronMethod'));
181  $error++;
182  }
183  if (($this->jobtype=='method') && (empty($this->objectname))) {
184  $this->errors[]=$langs->trans('CronFieldMandatory',$langs->trans('CronObject'));
185  $error++;
186  }
187 
188  if (($this->jobtype=='function') && (empty($this->libname))) {
189  $this->errors[]=$langs->trans('CronFieldMandatory',$langs->trans('CronLib'));
190  $error++;
191  }
192 
193  // Insert request
194  $sql = "INSERT INTO ".MAIN_DB_PREFIX."cronjob(";
195  $sql.= "entity,";
196  $sql.= "datec,";
197  $sql.= "jobtype,";
198  $sql.= "label,";
199  $sql.= "command,";
200  $sql.= "classesname,";
201  $sql.= "objectname,";
202  $sql.= "methodename,";
203  $sql.= "params,";
204  $sql.= "md5params,";
205  $sql.= "module_name,";
206  $sql.= "priority,";
207  $sql.= "datelastrun,";
208  $sql.= "datenextrun,";
209  $sql.= "dateend,";
210  $sql.= "datestart,";
211  $sql.= "lastresult,";
212  $sql.= "datelastresult,";
213  $sql.= "lastoutput,";
214  $sql.= "unitfrequency,";
215  $sql.= "frequency,";
216  $sql.= "status,";
217  $sql.= "fk_user_author,";
218  $sql.= "fk_user_mod,";
219  $sql.= "note,";
220  $sql.= "nbrun,";
221  $sql.= "maxrun,";
222  $sql.= "libname,";
223  $sql.= "test";
224  $sql.= ") VALUES (";
225  $sql.= " ".(! isset($this->entity)?$conf->entity:$this->db->escape($this->entity)).",";
226  $sql.= " '".$this->db->idate($now)."',";
227  $sql.= " ".(! isset($this->jobtype)?'NULL':"'".$this->db->escape($this->jobtype)."'").",";
228  $sql.= " ".(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").",";
229  $sql.= " ".(! isset($this->command)?'NULL':"'".$this->db->escape($this->command)."'").",";
230  $sql.= " ".(! isset($this->classesname)?'NULL':"'".$this->db->escape($this->classesname)."'").",";
231  $sql.= " ".(! isset($this->objectname)?'NULL':"'".$this->db->escape($this->objectname)."'").",";
232  $sql.= " ".(! isset($this->methodename)?'NULL':"'".$this->db->escape($this->methodename)."'").",";
233  $sql.= " ".(! isset($this->params)?'NULL':"'".$this->db->escape($this->params)."'").",";
234  $sql.= " ".(! isset($this->md5params)?'NULL':"'".$this->db->escape($this->md5params)."'").",";
235  $sql.= " ".(! isset($this->module_name)?'NULL':"'".$this->db->escape($this->module_name)."'").",";
236  $sql.= " ".(! isset($this->priority)?'0':$this->priority).",";
237  $sql.= " ".(! isset($this->datelastrun) || dol_strlen($this->datelastrun)==0?'NULL':"'".$this->db->idate($this->datelastrun)."'").",";
238  $sql.= " ".(! isset($this->datenextrun) || dol_strlen($this->datenextrun)==0?'NULL':"'".$this->db->idate($this->datenextrun)."'").",";
239  $sql.= " ".(! isset($this->dateend) || dol_strlen($this->dateend)==0?'NULL':"'".$this->db->idate($this->dateend)."'").",";
240  $sql.= " ".(! isset($this->datestart) || dol_strlen($this->datestart)==0?'NULL':"'".$this->db->idate($this->datestart)."'").",";
241  $sql.= " ".(! isset($this->lastresult)?'NULL':"'".$this->db->escape($this->lastresult)."'").",";
242  $sql.= " ".(! isset($this->datelastresult) || dol_strlen($this->datelastresult)==0?'NULL':"'".$this->db->idate($this->datelastresult)."'").",";
243  $sql.= " ".(! isset($this->lastoutput)?'NULL':"'".$this->db->escape($this->lastoutput)."'").",";
244  $sql.= " ".(! isset($this->unitfrequency)?'NULL':"'".$this->db->escape($this->unitfrequency)."'").",";
245  $sql.= " ".(! isset($this->frequency)?'0':$this->frequency).",";
246  $sql.= " ".(! isset($this->status)?'0':$this->status).",";
247  $sql.= " ".$user->id.",";
248  $sql.= " ".$user->id.",";
249  $sql.= " ".(! isset($this->note)?'NULL':"'".$this->db->escape($this->note)."'").",";
250  $sql.= " ".(! isset($this->nbrun)?'0':$this->db->escape($this->nbrun)).",";
251  $sql.= " ".(empty($this->maxrun)?'0':$this->db->escape($this->maxrun)).",";
252  $sql.= " ".(! isset($this->libname)?'NULL':"'".$this->db->escape($this->libname)."'").",";
253  $sql.= " ".(! isset($this->test)?'NULL':"'".$this->db->escape($this->test)."'")."";
254  $sql.= ")";
255 
256  $this->db->begin();
257 
258  dol_syslog(get_class($this)."::create", LOG_DEBUG);
259  $resql=$this->db->query($sql);
260  if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
261 
262  if (! $error)
263  {
264  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."cronjob");
265 
266  //if (! $notrigger)
267  //{
268  // Uncomment this and change MYOBJECT to your own tag if you
269  // want this action calls a trigger.
270 
272  //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
273  //$interface=new Interfaces($this->db);
274  //$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf);
275  //if ($result < 0) { $error++; $this->errors=$interface->errors; }
277  //}
278  }
279 
280  // Commit or rollback
281  if ($error)
282  {
283  foreach($this->errors as $errmsg)
284  {
285  dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
286  $this->error.=($this->error?', '.$errmsg:$errmsg);
287  }
288  $this->db->rollback();
289  return -1*$error;
290  }
291  else
292  {
293  $this->db->commit();
294  return $this->id;
295  }
296  }
297 
298 
305  function fetch($id)
306  {
307  $sql = "SELECT";
308  $sql.= " t.rowid,";
309  $sql.= " t.entity,";
310  $sql.= " t.tms,";
311  $sql.= " t.datec,";
312  $sql.= " t.jobtype,";
313  $sql.= " t.label,";
314  $sql.= " t.command,";
315  $sql.= " t.classesname,";
316  $sql.= " t.objectname,";
317  $sql.= " t.methodename,";
318  $sql.= " t.params,";
319  $sql.= " t.md5params,";
320  $sql.= " t.module_name,";
321  $sql.= " t.priority,";
322  $sql.= " t.datelastrun,";
323  $sql.= " t.datenextrun,";
324  $sql.= " t.dateend,";
325  $sql.= " t.datestart,";
326  $sql.= " t.lastresult,";
327  $sql.= " t.datelastresult,";
328  $sql.= " t.lastoutput,";
329  $sql.= " t.unitfrequency,";
330  $sql.= " t.frequency,";
331  $sql.= " t.status,";
332  $sql.= " t.processing,";
333  $sql.= " t.fk_user_author,";
334  $sql.= " t.fk_user_mod,";
335  $sql.= " t.note,";
336  $sql.= " t.nbrun,";
337  $sql.= " t.maxrun,";
338  $sql.= " t.libname,";
339  $sql.= " t.test";
340  $sql.= " FROM ".MAIN_DB_PREFIX."cronjob as t";
341  $sql.= " WHERE t.rowid = ".$id;
342 
343  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
344  $resql=$this->db->query($sql);
345  if ($resql)
346  {
347  if ($this->db->num_rows($resql))
348  {
349  $obj = $this->db->fetch_object($resql);
350 
351  $this->id = $obj->rowid;
352  $this->ref = $obj->rowid;
353  $this->entity = $obj->entity;
354  $this->tms = $this->db->jdate($obj->tms);
355  $this->datec = $this->db->jdate($obj->datec);
356  $this->label = $obj->label;
357  $this->jobtype = $obj->jobtype;
358  $this->command = $obj->command;
359  $this->classesname = $obj->classesname;
360  $this->objectname = $obj->objectname;
361  $this->methodename = $obj->methodename;
362  $this->params = $obj->params;
363  $this->md5params = $obj->md5params;
364  $this->module_name = $obj->module_name;
365  $this->priority = $obj->priority;
366  $this->datelastrun = $this->db->jdate($obj->datelastrun);
367  $this->datenextrun = $this->db->jdate($obj->datenextrun);
368  $this->dateend = $this->db->jdate($obj->dateend);
369  $this->datestart = $this->db->jdate($obj->datestart);
370  $this->lastresult = $obj->lastresult;
371  $this->lastoutput = $obj->lastoutput;
372  $this->datelastresult = $this->db->jdate($obj->datelastresult);
373  $this->unitfrequency = $obj->unitfrequency;
374  $this->frequency = $obj->frequency;
375  $this->status = $obj->status;
376  $this->processing = $obj->processing;
377  $this->fk_user_author = $obj->fk_user_author;
378  $this->fk_user_mod = $obj->fk_user_mod;
379  $this->note = $obj->note;
380  $this->nbrun = $obj->nbrun;
381  $this->maxrun = $obj->maxrun;
382  $this->libname = $obj->libname;
383  $this->test = $obj->test;
384  }
385  $this->db->free($resql);
386 
387  return 1;
388  }
389  else
390  {
391  $this->error="Error ".$this->db->lasterror();
392  return -1;
393  }
394  }
395 
396  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
409  function fetch_all($sortorder='DESC', $sortfield='t.rowid', $limit=0, $offset=0, $status=1, $filter='', $processing=-1)
410  {
411  // phpcs:enable
412  global $langs;
413 
414  $this->lines=array();
415 
416  $sql = "SELECT";
417  $sql.= " t.rowid,";
418  $sql.= " t.entity,";
419  $sql.= " t.tms,";
420  $sql.= " t.datec,";
421  $sql.= " t.jobtype,";
422  $sql.= " t.label,";
423  $sql.= " t.command,";
424  $sql.= " t.classesname,";
425  $sql.= " t.objectname,";
426  $sql.= " t.methodename,";
427  $sql.= " t.params,";
428  $sql.= " t.md5params,";
429  $sql.= " t.module_name,";
430  $sql.= " t.priority,";
431  $sql.= " t.datelastrun,";
432  $sql.= " t.datenextrun,";
433  $sql.= " t.dateend,";
434  $sql.= " t.datestart,";
435  $sql.= " t.lastresult,";
436  $sql.= " t.datelastresult,";
437  $sql.= " t.lastoutput,";
438  $sql.= " t.unitfrequency,";
439  $sql.= " t.frequency,";
440  $sql.= " t.status,";
441  $sql.= " t.processing,";
442  $sql.= " t.fk_user_author,";
443  $sql.= " t.fk_user_mod,";
444  $sql.= " t.note,";
445  $sql.= " t.nbrun,";
446  $sql.= " t.libname,";
447  $sql.= " t.test";
448  $sql.= " FROM ".MAIN_DB_PREFIX."cronjob as t";
449  $sql.= " WHERE 1 = 1";
450  if ($processing >= 0) $sql.= " AND t.processing = ".(empty($processing)?'0':'1');
451  if ($status >= 0 && $status < 2) $sql.= " AND t.status = ".(empty($status)?'0':'1');
452  elseif ($status == 2) $sql.= " AND t.status = 2";
453  //Manage filter
454  if (is_array($filter) && count($filter)>0) {
455  foreach($filter as $key => $value)
456  {
457  if ($key == 't.rowid') $sql.= ' AND '.$key.' = '.$this->db->escape($value);
458  else $sql.= ' AND '.$key.' LIKE \'%'.$this->db->escape($value).'%\'';
459  }
460  }
461 
462  $sql.= $this->db->order($sortfield,$sortorder);
463  if (!empty($limit) && !empty($offset)) {
464  $sql.= $this->db->plimit($limit + 1,$offset);
465  }
466 
467  $sqlwhere = array();
468 
469  if (count($sqlwhere)>0) {
470  $sql.= " WHERE ".implode(' AND ',$sqlwhere);
471  }
472 
473  dol_syslog(get_class($this)."::fetch_all", LOG_DEBUG);
474  $resql=$this->db->query($sql);
475  if ($resql)
476  {
477  $num=$this->db->num_rows($resql);
478  $i=0;
479 
480  if ($num)
481  {
482  while ($i < $num)
483  {
484  $line = new Cronjobline();
485 
486  $obj = $this->db->fetch_object($resql);
487 
488  $line->id = $obj->rowid;
489  $line->ref = $obj->rowid;
490  $line->entity = $obj->entity;
491  $line->tms = $this->db->jdate($obj->tms);
492  $line->datec = $this->db->jdate($obj->datec);
493  $line->label = $obj->label;
494  $line->jobtype = $obj->jobtype;
495  $line->command = $obj->command;
496  $line->classesname = $obj->classesname;
497  $line->objectname = $obj->objectname;
498  $line->methodename = $obj->methodename;
499  $line->params = $obj->params;
500  $line->md5params = $obj->md5params;
501  $line->module_name = $obj->module_name;
502  $line->priority = $obj->priority;
503  $line->datelastrun = $this->db->jdate($obj->datelastrun);
504  $line->datenextrun = $this->db->jdate($obj->datenextrun);
505  $line->dateend = $this->db->jdate($obj->dateend);
506  $line->datestart = $this->db->jdate($obj->datestart);
507  $line->lastresult = $obj->lastresult;
508  $line->datelastresult = $this->db->jdate($obj->datelastresult);
509  $line->lastoutput = $obj->lastoutput;
510  $line->unitfrequency = $obj->unitfrequency;
511  $line->frequency = $obj->frequency;
512  $line->status = $obj->status;
513  $line->processing = $obj->processing;
514  $line->fk_user_author = $obj->fk_user_author;
515  $line->fk_user_mod = $obj->fk_user_mod;
516  $line->note = $obj->note;
517  $line->nbrun = $obj->nbrun;
518  $line->libname = $obj->libname;
519  $line->test = $obj->test;
520  $this->lines[]=$line;
521 
522  $i++;
523  }
524  }
525  $this->db->free($resql);
526 
527  return 1;
528  }
529  else
530  {
531  $this->error="Error ".$this->db->lasterror();
532  return -1;
533  }
534  }
535 
536 
544  function update($user=null, $notrigger=0)
545  {
546  global $conf, $langs;
547 
548  $langs->load('cron');
549 
550  $error=0;
551 
552  // Clean parameters
553  if (isset($this->label)) $this->label=trim($this->label);
554  if (isset($this->jobtype)) $this->jobtype=trim($this->jobtype);
555  if (isset($this->command)) $this->command=trim($this->command);
556  if (isset($this->classesname)) $this->classesname=trim($this->classesname);
557  if (isset($this->objectname)) $this->objectname=trim($this->objectname);
558  if (isset($this->methodename)) $this->methodename=trim($this->methodename);
559  if (isset($this->params)) $this->params=trim($this->params);
560  if (isset($this->md5params)) $this->md5params=trim($this->md5params);
561  if (isset($this->module_name)) $this->module_name=trim($this->module_name);
562  if (isset($this->priority)) $this->priority=trim($this->priority);
563  if (isset($this->lastoutput)) $this->lastoutput=trim($this->lastoutput);
564  if (isset($this->lastresult)) $this->lastresult=trim($this->lastresult);
565  if (isset($this->unitfrequency)) $this->unitfrequency=trim($this->unitfrequency);
566  if (isset($this->frequency)) $this->frequency=trim($this->frequency);
567  if (isset($this->status)) $this->status=trim($this->status);
568  if (isset($this->note)) $this->note=trim($this->note);
569  if (isset($this->nbrun)) $this->nbrun=trim($this->nbrun);
570  if (isset($this->libname)) $this->libname = trim($this->libname);
571  if (isset($this->test)) $this->test = trim($this->test);
572 
573  if (empty($this->maxrun)) $this->maxrun=0;
574  if (empty($this->processing)) $this->processing=0;
575 
576  // Check parameters
577  // Put here code to add a control on parameters values
578  if (dol_strlen($this->datestart)==0) {
579  $this->errors[]=$langs->trans('CronFieldMandatory',$langs->transnoentitiesnoconv('CronDtStart'));
580  $error++;
581  }
582  if ((dol_strlen($this->datestart)!=0) && (dol_strlen($this->dateend)!=0) && ($this->dateend<$this->datestart)) {
583  $this->errors[]=$langs->trans('CronErrEndDateStartDt');
584  $error++;
585  }
586  if (empty($this->label)) {
587  $this->errors[]=$langs->trans('CronFieldMandatory',$langs->transnoentitiesnoconv('CronLabel'));
588  $error++;
589  }
590  if (empty($this->unitfrequency)) {
591  $this->errors[]=$langs->trans('CronFieldMandatory',$langs->transnoentitiesnoconv('CronFrequency'));
592  $error++;
593  }
594  if (($this->jobtype=='command') && (empty($this->command))) {
595  $this->errors[]=$langs->trans('CronFieldMandatory',$langs->transnoentitiesnoconv('CronCommand'));
596  $error++;
597  }
598  if (($this->jobtype=='method') && (empty($this->classesname))) {
599  $this->errors[]=$langs->trans('CronFieldMandatory',$langs->transnoentitiesnoconv('CronClass'));
600  $error++;
601  }
602  if (($this->jobtype=='method' || $this->jobtype == 'function') && (empty($this->methodename))) {
603  $this->errors[]=$langs->trans('CronFieldMandatory',$langs->transnoentitiesnoconv('CronMethod'));
604  $error++;
605  }
606  if (($this->jobtype=='method') && (empty($this->objectname))) {
607  $this->errors[]=$langs->trans('CronFieldMandatory',$langs->transnoentitiesnoconv('CronObject'));
608  $error++;
609  }
610 
611  if (($this->jobtype=='function') && (empty($this->libname))) {
612  $this->errors[]=$langs->trans('CronFieldMandatory',$langs->transnoentitiesnoconv('CronLib'));
613  $error++;
614  }
615 
616 
617  // Update request
618  $sql = "UPDATE ".MAIN_DB_PREFIX."cronjob SET";
619  $sql.= " entity=".(isset($this->entity)?$this->db->escape($this->entity):$conf->entity).",";
620  $sql.= " label=".(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").",";
621  $sql.= " jobtype=".(isset($this->jobtype)?"'".$this->db->escape($this->jobtype)."'":"null").",";
622  $sql.= " command=".(isset($this->command)?"'".$this->db->escape($this->command)."'":"null").",";
623  $sql.= " classesname=".(isset($this->classesname)?"'".$this->db->escape($this->classesname)."'":"null").",";
624  $sql.= " objectname=".(isset($this->objectname)?"'".$this->db->escape($this->objectname)."'":"null").",";
625  $sql.= " methodename=".(isset($this->methodename)?"'".$this->db->escape($this->methodename)."'":"null").",";
626  $sql.= " params=".(isset($this->params)?"'".$this->db->escape($this->params)."'":"null").",";
627  $sql.= " md5params=".(isset($this->md5params)?"'".$this->db->escape($this->md5params)."'":"null").",";
628  $sql.= " module_name=".(isset($this->module_name)?"'".$this->db->escape($this->module_name)."'":"null").",";
629  $sql.= " priority=".(isset($this->priority)?$this->priority:"null").",";
630  $sql.= " datelastrun=".(dol_strlen($this->datelastrun)!=0 ? "'".$this->db->idate($this->datelastrun)."'" : 'null').",";
631  $sql.= " datenextrun=".(dol_strlen($this->datenextrun)!=0 ? "'".$this->db->idate($this->datenextrun)."'" : 'null').",";
632  $sql.= " dateend=".(dol_strlen($this->dateend)!=0 ? "'".$this->db->idate($this->dateend)."'" : 'null').",";
633  $sql.= " datestart=".(dol_strlen($this->datestart)!=0 ? "'".$this->db->idate($this->datestart)."'" : 'null').",";
634  $sql.= " datelastresult=".(dol_strlen($this->datelastresult)!=0 ? "'".$this->db->idate($this->datelastresult)."'" : 'null').",";
635  $sql.= " lastresult=".(isset($this->lastresult)?"'".$this->db->escape($this->lastresult)."'":"null").",";
636  $sql.= " lastoutput=".(isset($this->lastoutput)?"'".$this->db->escape($this->lastoutput)."'":"null").",";
637  $sql.= " unitfrequency=".(isset($this->unitfrequency)?$this->unitfrequency:"null").",";
638  $sql.= " frequency=".(isset($this->frequency)?$this->frequency:"null").",";
639  $sql.= " status=".(isset($this->status)?$this->status:"null").",";
640  $sql.= " processing=".((isset($this->processing) && $this->processing > 0)?$this->processing:"0").",";
641  $sql.= " fk_user_mod=".$user->id.",";
642  $sql.= " note=".(isset($this->note)?"'".$this->db->escape($this->note)."'":"null").",";
643  $sql.= " nbrun=".((isset($this->nbrun) && $this->nbrun >0)?$this->nbrun:"null").",";
644  $sql.= " maxrun=".((isset($this->maxrun) && $this->maxrun > 0)?$this->maxrun:"0").",";
645  $sql.= " libname=".(isset($this->libname)?"'".$this->db->escape($this->libname)."'":"null").",";
646  $sql.= " test=".(isset($this->test)?"'".$this->db->escape($this->test)."'":"null");
647  $sql.= " WHERE rowid=".$this->id;
648 
649  $this->db->begin();
650 
651  dol_syslog(get_class($this)."::update", LOG_DEBUG);
652  $resql = $this->db->query($sql);
653  if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
654 
655  //if (! $error && ! $notrigger)
656  //{
657  // Uncomment this and change MYOBJECT to your own tag if you
658  // want this action calls a trigger.
659 
661  //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
662  //$interface=new Interfaces($this->db);
663  //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf);
664  //if ($result < 0) { $error++; $this->errors=$interface->errors; }
666  //}
667 
668  // Commit or rollback
669  if ($error)
670  {
671  foreach($this->errors as $errmsg)
672  {
673  dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
674  $this->error.=($this->error?', '.$errmsg:$errmsg);
675  }
676  $this->db->rollback();
677  return -1*$error;
678  }
679  else
680  {
681  $this->db->commit();
682  return 1;
683  }
684  }
685 
686 
694  function delete($user, $notrigger=0)
695  {
696  $error=0;
697 
698  $this->db->begin();
699 
700 // if (! $error)
701 // {
702 // if (! $notrigger)
703 // {
704  // Uncomment this and change MYOBJECT to your own tag if you
705  // want this action calls a trigger.
706 
708  //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
709  //$interface=new Interfaces($this->db);
710  //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf);
711  //if ($result < 0) { $error++; $this->errors=$interface->errors; }
713 // }
714 // }
715 
716 // if (! $error)
717 // {
718  $sql = "DELETE FROM ".MAIN_DB_PREFIX."cronjob";
719  $sql.= " WHERE rowid=".$this->id;
720 
721  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
722  $resql = $this->db->query($sql);
723  if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
724 // }
725 
726  // Commit or rollback
727  if ($error)
728  {
729  foreach($this->errors as $errmsg)
730  {
731  dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
732  $this->error.=($this->error?', '.$errmsg:$errmsg);
733  }
734  $this->db->rollback();
735  return -1*$error;
736  }
737  else
738  {
739  $this->db->commit();
740  return 1;
741  }
742  }
743 
744 
745 
752  function createFromClone($fromid)
753  {
754  global $user,$langs;
755 
756  $error=0;
757 
758  $object=new Cronjob($this->db);
759 
760  $this->db->begin();
761 
762  // Load source object
763  $object->fetch($fromid);
764  $object->id=0;
765  $object->statut=0;
766 
767  // Clear fields
768  // ...
769 
770  // Create clone
771  $object->context['createfromclone'] = 'createfromclone';
772  $result=$object->create($user);
773 
774  // Other options
775  if ($result < 0)
776  {
777  $this->error=$object->error;
778  $error++;
779  }
780 
781  //if (! $error)
782  //{
783 
784  //}
785 
786  unset($object->context['createfromclone']);
787 
788  // End
789  if (! $error)
790  {
791  $this->db->commit();
792  return $object->id;
793  }
794  else
795  {
796  $this->db->rollback();
797  return -1;
798  }
799  }
800 
801 
808  function initAsSpecimen()
809  {
810  $this->id=0;
811  $this->ref=0;
812  $this->entity=0;
813  $this->tms='';
814  $this->datec='';
815  $this->label='';
816  $this->jobtype='';
817  $this->command='';
818  $this->classesname='';
819  $this->objectname='';
820  $this->methodename='';
821  $this->params='';
822  $this->md5params='';
823  $this->module_name='';
824  $this->priority='';
825  $this->datelastrun='';
826  $this->datenextrun='';
827  $this->dateend='';
828  $this->datestart='';
829  $this->datelastresult='';
830  $this->lastoutput='';
831  $this->lastresult='';
832  $this->unitfrequency='';
833  $this->frequency='';
834  $this->status=0;
835  $this->processing=0;
836  $this->fk_user_author='';
837  $this->fk_user_mod='';
838  $this->note='';
839  $this->nbrun='';
840  $this->maxrun=100;
841  $this->libname = '';
842  }
843 
844 
855  function getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
856  {
857  global $db, $conf, $langs;
858  global $dolibarr_main_authentication, $dolibarr_main_demo;
859  global $menumanager;
860 
861  if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips
862 
863  $result = '';
864  $companylink = '';
865 
866  $label = '<u>' . $langs->trans("CronJob") . '</u>';
867  $label.= '<br>';
868  $label.= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
869 
870  $url = DOL_URL_ROOT.'/cron/card.php?id='.$this->id;
871 
872  if ($option != 'nolink')
873  {
874  // Add param to save lastsearch_values or not
875  $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
876  if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
877  if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
878  }
879 
880  $linkclose='';
881  if (empty($notooltip))
882  {
883  if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
884  {
885  $label=$langs->trans("ShowCronJob");
886  $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
887  }
888  $linkclose.=' title="'.dol_escape_htmltag($label, 1).'"';
889  $linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"';
890  }
891  else $linkclose = ($morecss?' class="'.$morecss.'"':'');
892 
893  $linkstart = '<a href="'.$url.'"';
894  $linkstart.=$linkclose.'>';
895  $linkend='</a>';
896 
897  $result .= $linkstart;
898  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);
899  if ($withpicto != 2) $result.= $this->ref;
900  $result .= $linkend;
901  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
902 
903  return $result;
904  }
905 
906 
912  function info()
913  {
914  $sql = "SELECT";
915  $sql.= " f.rowid, f.datec, f.tms, f.fk_user_mod, f.fk_user_author";
916  $sql.= " FROM ".MAIN_DB_PREFIX."cronjob as f";
917  $sql.= " WHERE f.rowid = ".$this->id;
918 
919  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
920  $resql=$this->db->query($sql);
921  if ($resql)
922  {
923  if ($this->db->num_rows($resql))
924  {
925  $obj = $this->db->fetch_object($resql);
926  $this->id = $obj->rowid;
927  $this->date_creation = $this->db->jdate($obj->datec);
928  $this->date_modification = $this->db->jdate($obj->tms);
929  $this->user_modification = $obj->fk_user_mod;
930  $this->user_creation = $obj->fk_user_author;
931  }
932  $this->db->free($resql);
933 
934  return 1;
935  }
936  else
937  {
938  $this->error="Error ".$this->db->lasterror();
939  return -1;
940  }
941  }
942 
943 
944  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
953  function run_jobs($userlogin)
954  {
955  // phpcs:enable
956  global $langs, $conf;
957 
958  $now=dol_now();
959  $error = 0;
960  $retval = '';
961 
962  $langs->load('cron');
963 
964  if (empty($userlogin))
965  {
966  $this->error="User login is mandatory";
967  dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
968  return -1;
969  }
970 
971  // Force the environment of running to the environment declared for job, so jobs launched from command line will run into correct environment
972  // When job is ran from GUI, the environment should already be same, except if job has entity 0 (visible into all environments)
973  if ($conf->entity != $this->entity && $this->entity > 0)
974  {
975  dol_syslog("We try to run a job in entity ".$this->entity." when we are in entity ".$conf->entity, LOG_WARNING);
976  }
977  $savcurrententity = $conf->entity;
978  $conf->entity = $this->entity;
979  dol_syslog(get_class($this)."::run_jobs entity for running job is ".$conf->entity);
980 
981  require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
982  $user=new User($this->db);
983  $result=$user->fetch('',$userlogin);
984  if ($result<0)
985  {
986  $this->error="User Error:".$user->error;
987  dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
988  $conf->entity = $savcurrententity;
989  return -1;
990  }
991  else
992  {
993  if (empty($user->id))
994  {
995  $this->error=" User user login:".$userlogin." do not exists";
996  dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
997  $conf->entity = $savcurrententity;
998  return -1;
999  }
1000  }
1001 
1002  dol_syslog(get_class($this)."::run_jobs jobtype=".$this->jobtype." userlogin=".$userlogin, LOG_DEBUG);
1003 
1004  // Increase limit of time. Works only if we are not in safe mode
1005  $ExecTimeLimit=600;
1006  if (!empty($ExecTimeLimit))
1007  {
1008  $err=error_reporting();
1009  error_reporting(0); // Disable all errors
1010  //error_reporting(E_ALL);
1011  @set_time_limit($ExecTimeLimit); // Need more than 240 on Windows 7/64
1012  error_reporting($err);
1013  }
1014  if (!empty($MemoryLimit))
1015  {
1016  @ini_set('memory_limit', $MemoryLimit);
1017  }
1018 
1019  // Update last run date start (to track running jobs)
1020  $this->datelastrun=$now;
1021  $this->datelastresult=null;
1022  $this->lastoutput='';
1023  $this->lastresult='';
1024  $this->processing = 1; // To know job was started
1025  $this->nbrun=$this->nbrun + 1;
1026  $result = $this->update($user); // This include begin/commit
1027  if ($result<0) {
1028  dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
1029  $conf->entity = $savcurrententity;
1030  return -1;
1031  }
1032 
1033  // Run a method
1034  if ($this->jobtype=='method')
1035  {
1036  // load classes
1037  if (! $error)
1038  {
1039  $ret=dol_include_once($this->classesname);
1040  if ($ret===false || (! class_exists($this->objectname)))
1041  {
1042  if ($ret===false) $this->error=$langs->trans('CronCannotLoadClass',$this->classesname,$this->objectname);
1043  else $this->error=$langs->trans('CronCannotLoadObject',$this->classesname,$this->objectname);
1044  dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
1045  $this->lastoutput = $this->error;
1046  $this->lastresult = -1;
1047  $retval = $this->lastresult;
1048  $error++;
1049  }
1050  }
1051 
1052  // test if method exists
1053  if (! $error)
1054  {
1055  if (! method_exists($this->objectname, $this->methodename))
1056  {
1057  $this->error=$langs->trans('CronMethodDoesNotExists',$this->objectname,$this->methodename);
1058  dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
1059  $this->lastoutput = $this->error;
1060  $this->lastresult = -1;
1061  $retval = $this->lastresult;
1062  $error++;
1063  }
1064  }
1065 
1066  // Load langs
1067  if (! $error)
1068  {
1069  $result=$langs->load($this->module_name);
1070  $result=$langs->load($this->module_name.'@'.$this->module_name); // If this->module_name was an existing language file, this will make nothing
1071  if ($result < 0) // If technical error
1072  {
1073  dol_syslog(get_class($this)."::run_jobs Cannot load module lang file - ".$langs->error, LOG_ERR);
1074  $this->error = $langs->error;
1075  $this->lastoutput = $this->error;
1076  $this->lastresult = -1;
1077  $retval = $this->lastresult;
1078  $error++;
1079  }
1080  }
1081 
1082  if (! $error)
1083  {
1084  dol_syslog(get_class($this)."::run_jobs START ".$this->objectname."->".$this->methodename."(".$this->params.");", LOG_DEBUG);
1085 
1086  // Create Object for the called module
1087  $object = new $this->objectname($this->db);
1088  if ($this->entity > 0) $object->entity = $this->entity; // We work on a dedicated entity
1089 
1090  $params_arr = array_map('trim', explode(",",$this->params));
1091 
1092  if (!is_array($params_arr))
1093  {
1094  $result = call_user_func(array($object, $this->methodename), $this->params);
1095  }
1096  else
1097  {
1098  $result = call_user_func_array(array($object, $this->methodename), $params_arr);
1099  }
1100 
1101  if ($result === false || (! is_bool($result) && $result != 0))
1102  {
1103  $langs->load("errors");
1104 
1105  $errmsg='';
1106  if (! is_array($object->errors) || ! in_array($object->error, $object->errors)) $errmsg.=$object->error;
1107  if (is_array($object->errors) && count($object->errors)) $errmsg.=($errmsg?', '.$errmsg:'').join(', ',$object->errors);
1108  if (empty($errmsg)) $errmsg=$langs->trans('ErrorUnknown');
1109 
1110  dol_syslog(get_class($this)."::run_jobs END result=".$result." error=".$errmsg, LOG_ERR);
1111 
1112  $this->error = $errmsg;
1113  $this->lastoutput = ($object->output?$object->output."\n":"").$errmsg;
1114  $this->lastresult = is_numeric($result)?$result:-1;
1115  $retval = $this->lastresult;
1116  $error++;
1117  }
1118  else
1119  {
1120  dol_syslog(get_class($this)."::run_jobs END");
1121  $this->lastoutput=$object->output;
1122  $this->lastresult=var_export($result,true);
1123  $retval = $this->lastresult;
1124  }
1125  }
1126  }
1127 
1128  if($this->jobtype == 'function')
1129  {
1130  //load lib
1131  $libpath = '/' . strtolower($this->module_name) . '/lib/' . $this->libname;
1132  $ret = dol_include_once($libpath);
1133  if ($ret === false)
1134  {
1135  $this->error = $langs->trans('CronCannotLoadLib') . ': ' . $libpath;
1136  dol_syslog(get_class($this) . "::run_jobs " . $this->error, LOG_ERR);
1137  $conf->entity = $savcurrententity;
1138  return -1;
1139  }
1140 
1141  // Load langs
1142  $result=$langs->load($this->module_name);
1143  $result=$langs->load($this->module_name.'@'.$this->module_name); // If this->module_name was an existing language file, this will make nothing
1144  if ($result < 0) // If technical error
1145  {
1146  dol_syslog(get_class($this) . "::run_jobs Cannot load module langs" . $langs->error, LOG_ERR);
1147  $conf->entity = $savcurrententity;
1148  return -1;
1149  }
1150 
1151  dol_syslog(get_class($this) . "::run_jobs " . $this->libname . "::" . $this->methodename."(" . $this->params . ");", LOG_DEBUG);
1152  $params_arr = explode(", ", $this->params);
1153  if (!is_array($params_arr))
1154  {
1155  $result = call_user_func($this->methodename, $this->params);
1156  }
1157  else
1158  {
1159  $result = call_user_func_array($this->methodename, $params_arr);
1160  }
1161 
1162  if ($result === false || (! is_bool($result) && $result != 0))
1163  {
1164  $langs->load("errors");
1165  dol_syslog(get_class($this)."::run_jobs result=".$result, LOG_ERR);
1166  $this->error = $langs->trans('ErrorUnknown');
1167  $this->lastoutput = $this->error;
1168  $this->lastresult = is_numeric($result)?$result:-1;
1169  $retval = $this->lastresult;
1170  $error++;
1171  }
1172  else
1173  {
1174  $this->lastoutput=var_export($result,true);
1175  $this->lastresult=var_export($result,true); // Return code
1176  $retval = $this->lastresult;
1177  }
1178  }
1179 
1180  // Run a command line
1181  if ($this->jobtype=='command')
1182  {
1183  $outputdir = $conf->cron->dir_temp;
1184  if (empty($outputdir)) $outputdir = $conf->cronjob->dir_temp;
1185 
1186  if (! empty($outputdir))
1187  {
1188  dol_mkdir($outputdir);
1189  $outputfile=$outputdir.'/cronjob.'.$userlogin.'.out'; // File used with popen method
1190 
1191  // Execute a CLI
1192  include_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php';
1193  $utils = new Utils($this->db);
1194  $arrayresult = $utils->executeCLI($this->command, $outputfile);
1195 
1196  $retval = $arrayresult['result'];
1197  $this->error = $arrayresult['error'];
1198  $this->lastoutput = $arrayresult['output'];
1199  $this->lastresult = $arrayresult['result'];
1200  }
1201  }
1202 
1203  dol_syslog(get_class($this)."::run_jobs now we update job to track it is finished (with success or error)");
1204 
1205  $this->datelastresult=dol_now();
1206  $this->processing=0;
1207  $result = $this->update($user); // This include begin/commit
1208  if ($result < 0)
1209  {
1210  dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
1211  $conf->entity = $savcurrententity;
1212  return -1;
1213  }
1214 
1215  $conf->entity = $savcurrententity;
1216  return $error?-1:1;
1217  }
1218 
1219 
1220  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1228  function reprogram_jobs($userlogin, $now)
1229  {
1230  // phpcs:enable
1231  dol_syslog(get_class($this)."::reprogram_jobs userlogin:$userlogin", LOG_DEBUG);
1232 
1233  require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
1234  $user=new User($this->db);
1235  $result=$user->fetch('',$userlogin);
1236  if ($result<0)
1237  {
1238  $this->error="User Error:".$user->error;
1239  dol_syslog(get_class($this)."::reprogram_jobs ".$this->error, LOG_ERR);
1240  return -1;
1241  }
1242  else
1243  {
1244  if (empty($user->id))
1245  {
1246  $this->error=" User user login:".$userlogin." do not exists";
1247  dol_syslog(get_class($this)."::reprogram_jobs ".$this->error, LOG_ERR);
1248  return -1;
1249  }
1250  }
1251 
1252  dol_syslog(get_class($this)."::reprogram_jobs datenextrun=".$this->datenextrun." ".dol_print_date($this->datenextrun, 'dayhourrfc')." frequency=".$this->frequency." unitfrequency=".$this->unitfrequency, LOG_DEBUG);
1253 
1254  if (empty($this->datenextrun))
1255  {
1256  if (empty($this->datestart)) $this->datenextrun = $now + ($this->frequency * $this->unitfrequency);
1257  else $this->datenextrun = $this->datestart + ($this->frequency * $this->unitfrequency);
1258  }
1259 
1260  if ($this->datenextrun < $now && $this->frequency > 0 && $this->unitfrequency > 0)
1261  {
1262  // Loop until date is after future
1263  while ($this->datenextrun < $now)
1264  {
1265  $this->datenextrun += ($this->frequency * $this->unitfrequency);
1266 
1267  // TODO For exact frequency (every month, every year, ...), use instead a dol_time_plus_duree($time, $duration_value, $duration_unit)
1268  }
1269  }
1270  else
1271  {
1272  //$this->datenextrun=$this->datenextrun + ($this->frequency * $this->unitfrequency);
1273  dol_syslog(get_class($this)."::reprogram_jobs datenextrun is already in future, we do not change it");
1274  }
1275 
1276 
1277  // Archive job
1278  if ($this->autodelete == 2)
1279  {
1280  if (($this->maxrun > 0 && ($this->nbrun >= $this->maxrun))
1281  || ($this->dateend && ($this->datenextrun > $this->dateend)))
1282  {
1283  $this->status = 2;
1284  dol_syslog(get_class($this)."::reprogram_jobs Job will be set to archived", LOG_ERR);
1285  }
1286  }
1287 
1288  $result = $this->update($user);
1289  if ($result<0)
1290  {
1291  dol_syslog(get_class($this)."::reprogram_jobs ".$this->error, LOG_ERR);
1292  return -1;
1293  }
1294 
1295  return 1;
1296  }
1297 
1304  function getLibStatut($mode=0)
1305  {
1306  return $this->LibStatut($this->status, $mode, $this->processing);
1307  }
1308 
1309  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1318  function LibStatut($status, $mode=0, $processing=0)
1319  {
1320  // phpcs:enable
1321  global $langs;
1322  $langs->load('users');
1323 
1324  $moretext = '';
1325  if ($processing) $moretext=' ('.$langs->trans("Running").')';
1326 
1327  if ($mode == 0)
1328  {
1329  if ($status == 1) return $langs->trans('Enabled').$moretext;
1330  elseif ($status == 0) return $langs->trans('Disabled').$moretext;
1331  }
1332  elseif ($mode == 1)
1333  {
1334  if ($status == 1) return $langs->trans('Enabled').$moretext;
1335  elseif ($status == 0) return $langs->trans('Disabled').$moretext;
1336  }
1337  elseif ($mode == 2)
1338  {
1339  if ($status == 1) return img_picto($langs->trans('Enabled'),'statut'.($processing?'1':'4'),'class="pictostatus"').' '.$langs->trans('Enabled').$moretext;
1340  elseif ($status == 0) return img_picto($langs->trans('Disabled'),'statut5','class="pictostatus"').' '.$langs->trans('Disabled').$moretext;
1341  }
1342  elseif ($mode == 3)
1343  {
1344  if ($status == 1) return img_picto($langs->trans('Enabled').$moretext,'statut'.($processing?'1':'4'),'class="pictostatus"');
1345  elseif ($status == 0) return img_picto($langs->trans('Disabled').$moretext,'statut5','class="pictostatus"');
1346  }
1347  elseif ($mode == 4)
1348  {
1349  if ($status == 1) return img_picto($langs->trans('Enabled').$moretext,'statut'.($processing?'1':'4'),'class="pictostatus"').' '.$langs->trans('Enabled').$moretext;
1350  elseif ($status == 0) return img_picto($langs->trans('Disabled').$moretext,'statut5','class="pictostatus"').' '.$langs->trans('Disabled').$moretext;
1351  }
1352  elseif ($mode == 5)
1353  {
1354  if ($status == 1) return $langs->trans('Enabled').$moretext.' '.img_picto($langs->trans('Enabled').$moretext,'statut'.($processing?'1':'4'),'class="pictostatus"');
1355  elseif ($status == 0) return $langs->trans('Disabled').$moretext.' '.img_picto($langs->trans('Disabled').$moretext,'statut5','class="pictostatus"');
1356  }
1357  }
1358 }
1359 
1360 
1365 {
1366 
1370  public $id;
1371 
1375  public $ref;
1376 
1377  public $tms='';
1378  public $datec='';
1379 
1383  public $label;
1384 
1385  public $jobtype;
1386  public $command;
1387  public $classesname;
1388  public $objectname;
1389  public $methodename;
1390  public $params;
1391  public $md5params;
1392  public $module_name;
1393  public $priority;
1394  public $datelastrun='';
1395  public $datenextrun='';
1396  public $dateend='';
1397  public $datestart='';
1398  public $lastresult='';
1399  public $lastoutput;
1400  public $unitfrequency;
1401  public $frequency;
1402 
1406  public $status;
1407 
1411  public $fk_user_author;
1412 
1416  public $fk_user_mod;
1417 
1418  public $note;
1419  public $nbrun;
1420  public $libname;
1421 
1426  function __construct()
1427  {
1428  return 1;
1429  }
1430 }
print $object label
hash of file content (md5_file(dol_osencode($destfull))
Definition: edit.php:153
Crob Job line class.
Class to manage utility methods.
Definition: utils.class.php:28
create($user, $notrigger=0)
Create object into database.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->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) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
fetch_all($sortorder='DESC', $sortfield='t.rowid', $limit=0, $offset=0, $status=1, $filter='', $processing=-1)
Load object in memory from the database.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
createFromClone($fromid)
Load an object from its id and create a new one in database.
if(! empty($search_group)) natural_search(array("g.nom" g note
Definition: list.php:123
__construct()
Constructor.
reprogram_jobs($userlogin, $now)
Reprogram a job.
Class to manage Dolibarr users.
Definition: user.class.php:41
getLibStatut($mode=0)
Return label of status of user (active, inactive)
__construct($db)
Constructor.
run_jobs($userlogin)
Run a job.
update($user=null, $notrigger=0)
Update object into database.
info()
Load object information.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
if(! function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_now($mode='gmt')
Return date for now.
fetch($id)
Load object in memory from the database.
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
Cron Job class.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
LibStatut($status, $mode=0, $processing=0)
Renvoi le libelle d&#39;un statut donne.