dolibarr  17.0.4
modCron.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2012 Nicolas Villa aka Boyquotes http://informetic.fr
3  * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
4  * Copyright (C) 2022 Anthony Berton <anthony.berton@bb2a.fr>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
27 include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
28 
29 
33 class modCron extends DolibarrModules
34 {
35 
41  public function __construct($db)
42  {
43  global $langs, $conf;
44 
45  $this->db = $db;
46  $this->numero = 2300;
47 
48  // Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
49  // It is used to group modules in module setup page
50  $this->family = "base";
51  // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
52  $this->name = preg_replace('/^mod/i', '', get_class($this));
53  $this->description = "Enable the Dolibarr cron service";
54  // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
55  $this->version = 'dolibarr';
56  // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
57  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
58  // Name of image file used for this module.
59  $this->picto = 'cron';
60 
61  // Data directories to create when module is enabled
62  $this->dirs = array();
63 
64  // Config pages
65  //-------------
66  $this->config_page_url = array("cron.php@cron");
67 
68  // Dependancies
69  //-------------
70  $this->hidden = !empty($conf->global->MODULE_CRON_DISABLED); // A condition to disable module
71  $this->depends = array(); // List of modules id that must be enabled if this module is enabled
72  $this->requiredby = array(); // List of modules id to disable if this one is disabled
73  $this->conflictwith = array(); // List of modules id this module is in conflict with
74  $this->langfiles = array("cron");
75 
76  // Constants
77  //-----------
78  $this->const = array(
79  0=>array(
80  'CRON_KEY',
81  'chaine',
82  '',
83  'CRON KEY',
84  0,
85  'main',
86  0
87  ),);
88 
89  // New pages on tabs
90  // -----------------
91  $this->tabs = array();
92 
93  // Boxes
94  //------
95  $this->boxes = array(
96  0 => array('file' => 'box_scheduled_jobs.php', 'enabledbydefaulton' => 'Home')
97  );
98 
99  // Cronjobs
100  $this->cronjobs = array(
101  0=>array('entity'=>0, 'label'=>'PurgeDeleteTemporaryFilesShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'purgeFiles', 'parameters'=>'tempfilesold+logfiles', 'comment'=>'PurgeDeleteTemporaryFiles', 'frequency'=>2, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>50, 'status'=>1, 'test'=>true),
102  1=>array('entity'=>0, 'label'=>'MakeLocalDatabaseDumpShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'dumpDatabase', 'parameters'=>'none,auto,1,auto,10,0,0', 'comment'=>'MakeLocalDatabaseDump', 'frequency'=>1, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>90, 'status'=>0, 'test'=>'in_array($conf->db->type, array(\'mysql\', \'mysqli\'))'),
103  2=>array('entity'=>0, 'label'=>'MakeSendLocalDatabaseDumpShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'sendBackup', 'parameters'=>',,,,,sql', 'comment'=>'MakeSendLocalDatabaseDump', 'frequency'=>1, 'unitfrequency'=>604800, 'priority'=>91, 'status'=>0, 'test'=>'!empty($conf->global->MAIN_ALLOW_BACKUP_BY_EMAIL) && in_array($conf->db->type, array(\'mysql\', \'mysqli\'))'),
104  3=>array('entity'=>0, 'label'=>'CleanUnfinishedCronjobShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'cleanUnfinishedCronjob', 'parameters'=>'', 'comment'=>'CleanUnfinishedCronjob', 'frequency'=>5, 'unitfrequency'=>60, 'priority'=>10, 'status'=>0, 'test'=>'getDolGlobalInt("MAIN_FEATURES_LEVEL") >= 2'),
105  // 1=>array('entity'=>0, 'label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24)
106  );
107 
108  // Permissions
109  $this->rights = array(); // Permission array used by this module
110  $this->rights_class = 'cron';
111  $r = 0;
112 
113  $this->rights[$r][0] = 23001;
114  $this->rights[$r][1] = 'Read cron jobs';
115  $this->rights[$r][3] = 0;
116  $this->rights[$r][4] = 'read';
117  $r++;
118 
119  $this->rights[$r][0] = 23002;
120  $this->rights[$r][1] = 'Create cron Jobs';
121  $this->rights[$r][3] = 0;
122  $this->rights[$r][4] = 'create';
123  $r++;
124 
125  $this->rights[$r][0] = 23003;
126  $this->rights[$r][1] = 'Delete cron Jobs';
127  $this->rights[$r][3] = 0;
128  $this->rights[$r][4] = 'delete';
129  $r++;
130 
131  $this->rights[$r][0] = 23004;
132  $this->rights[$r][1] = 'Execute cron Jobs';
133  $this->rights[$r][3] = 0;
134  $this->rights[$r][4] = 'execute';
135  $r++;
136 
137  // Main menu entries
138  $r = 0;
139  $this->menu[$r] = array('fk_menu'=>'fk_mainmenu=home,fk_leftmenu=admintools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
140  'type'=>'left', // This is a Left menu entry
141  'titre'=>'CronList',
142  'url'=>'/cron/list.php?leftmenu=admintools',
143  'langs'=>'cron', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
144  'position'=>500,
145  'enabled'=>'$conf->cron->enabled && preg_match(\'/^(admintools|all)/\', $leftmenu)', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
146  'perms'=>'$user->rights->cron->read', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
147  'target'=>'',
148  'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
149  $r++;
150  }
151 }
Class DolibarrModules.
Class to describe a Cron module.
__construct($db)
Constructor.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:122
$conf db
API class for accounts.
Definition: inc.php:41