modCron.class.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. *
  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. /**
  19. * \defgroup cron Module cron
  20. * \brief cron module descriptor.
  21. * \file htdocs/core/modules/modCron.class.php
  22. * \ingroup cron
  23. * \brief Description and activation file for module Jobs
  24. */
  25. include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
  26. /**
  27. * Class to describe a Cron module
  28. */
  29. class modCron extends DolibarrModules
  30. {
  31. /**
  32. * Constructor. Define names, constants, directories, boxes, permissions
  33. *
  34. * @param DoliDB $db Database handler
  35. */
  36. function __construct($db)
  37. {
  38. global $langs,$conf;
  39. $this->db = $db;
  40. $this->numero = 2300;
  41. // Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
  42. // It is used to group modules in module setup page
  43. $this->family = "base";
  44. // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
  45. $this->name = preg_replace('/^mod/i','',get_class($this));
  46. $this->description = "Enable the Dolibarr cron service";
  47. $this->version = 'dolibarr'; // 'experimental' or 'dolibarr' or version
  48. // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
  49. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  50. // Where to store the module in setup page (0=common,1=interface,2=others,3=very specific)
  51. $this->special = 2;
  52. // Name of image file used for this module.
  53. $this->picto='technic';
  54. // Data directories to create when module is enabled
  55. $this->dirs = array();
  56. // Config pages
  57. //-------------
  58. $this->config_page_url = array("cron.php@cron");
  59. // Dependancies
  60. //-------------
  61. $this->hidden = ! empty($conf->global->CRON_MODULE_DISABLED); // A condition to disable module
  62. $this->depends = array(); // List of modules id that must be enabled if this module is enabled
  63. $this->requiredby = array(); // List of modules id to disable if this one is disabled
  64. $this->conflictwith = array(); // List of modules id this module is in conflict with
  65. $this->langfiles = array("cron");
  66. // Constants
  67. //-----------
  68. $this->const = array(
  69. 0=>array(
  70. 'CRON_KEY',
  71. 'chaine',
  72. '',
  73. 'CRON KEY',
  74. 0,
  75. 'main',
  76. 0
  77. ),);
  78. // New pages on tabs
  79. // -----------------
  80. $this->tabs = array();
  81. // Boxes
  82. //------
  83. $this->boxes = array();
  84. // Permissions
  85. $this->rights = array(); // Permission array used by this module
  86. $this->rights_class = 'cron';
  87. $r=0;
  88. // Cronjobs
  89. $this->cronjobs = array(
  90. 0=>array('label'=>'PurgeDeleteTemporaryFilesShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'purgeFiles', 'parameters'=>'', 'comment'=>'PurgeDeleteTemporaryFiles', 'frequency'=>1, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>10, 'status'=>1, 'test'=>'1'),
  91. 1=>array('label'=>'MakeLocalDatabaseDumpShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'dumpDatabase', 'parameters'=>'', 'comment'=>'MakeLocalDatabaseDump', 'frequency'=>1, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>20, 'status'=>0, 'test'=>'0'),
  92. // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24)
  93. );
  94. $this->rights[$r][0] = 23001;
  95. $this->rights[$r][1] = 'Read cron jobs';
  96. $this->rights[$r][3] = 1;
  97. $this->rights[$r][4] = 'read';
  98. $r++;
  99. $this->rights[$r][0] = 23002;
  100. $this->rights[$r][1] = 'Create cron Jobs';
  101. $this->rights[$r][3] = 0;
  102. $this->rights[$r][4] = 'create';
  103. $r++;
  104. $this->rights[$r][0] = 23003;
  105. $this->rights[$r][1] = 'Delete cron Jobs';
  106. $this->rights[$r][3] = 0;
  107. $this->rights[$r][4] = 'delete';
  108. $r++;
  109. $this->rights[$r][0] = 23004;
  110. $this->rights[$r][1] = 'Execute cron Jobs';
  111. $this->rights[$r][3] = 0;
  112. $this->rights[$r][4] = 'execute';
  113. $r++;
  114. // Main menu entries
  115. $r=0;
  116. $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
  117. 'type'=>'left', // This is a Left menu entry
  118. 'titre'=>'CronList',
  119. 'url'=>'/cron/list.php?status=-2',
  120. 'langs'=>'cron', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  121. 'position'=>200,
  122. 'enabled'=>'$leftmenu==\'admintools\'', // 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.
  123. 'perms'=>'$user->rights->cron->read', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
  124. 'target'=>'',
  125. 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
  126. $r++;
  127. }
  128. }