cron.lib.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /* Copyright (C) 2012 Nicolas Villa aka Boyquotes http://informetic.fr
  3. * Copyright (C) 2013 Florian Henry <florian.henry@opn-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. /**
  19. * \file core/lib/cron.lib.php
  20. * \brief Function for module cron
  21. * \ingroup cron
  22. */
  23. /**
  24. * Return array of tabs to used on pages to setup cron module.
  25. *
  26. * @return array Array of tabs
  27. */
  28. function cronadmin_prepare_head()
  29. {
  30. global $langs, $conf, $user;
  31. $h = 0;
  32. $head = array();
  33. $head[$h][0] = DOL_URL_ROOT.'/cron/admin/cron.php';
  34. $head[$h][1] = $langs->trans("Miscellaneous");
  35. $head[$h][2] = 'setup';
  36. $h++;
  37. $head[$h][0] = DOL_URL_ROOT.'/cron/list.php?mode=modulesetup';
  38. $head[$h][1] = $langs->trans("Module2300Name");
  39. $head[$h][2] = 'jobs';
  40. $h++;
  41. complete_head_from_modules($conf, $langs, null, $head, $h, 'cronadmin');
  42. complete_head_from_modules($conf, $langs, null, $head, $h, 'cronadmin', 'remove');
  43. return $head;
  44. }
  45. /**
  46. * Return array of tabs to used on a cron job
  47. *
  48. * @param Cronjob $object Object cron
  49. * @return array Array of tabs
  50. */
  51. function cron_prepare_head(Cronjob $object)
  52. {
  53. global $langs, $conf, $user;
  54. $h = 0;
  55. $head = array();
  56. $head[$h][0] = DOL_URL_ROOT.'/cron/card.php?id='.$object->id;
  57. $head[$h][1] = $langs->trans("CronTask");
  58. $head[$h][2] = 'card';
  59. $h++;
  60. $head[$h][0] = DOL_URL_ROOT.'/cron/info.php?id='.$object->id;
  61. $head[$h][1] = $langs->trans("Info");
  62. $head[$h][2] = 'info';
  63. $h++;
  64. complete_head_from_modules($conf, $langs, $object, $head, $h, 'cron');
  65. complete_head_from_modules($conf, $langs, $object, $head, $h, 'cron', 'remove');
  66. return $head;
  67. }
  68. /**
  69. * Show information with URLs to launch jobs
  70. *
  71. * @return int 0
  72. */
  73. function dol_print_cron_urls()
  74. {
  75. global $conf, $langs, $user;
  76. global $dolibarr_main_url_root;
  77. // Define $urlwithroot
  78. $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
  79. $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  80. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  81. // Cron launch
  82. print '<div class="div-table-responsive-no-min">';
  83. print $langs->trans("URLToLaunchCronJobs").':<br>';
  84. $url = $urlwithroot.'/public/cron/cron_run_jobs_by_url.php?'.(empty($conf->global->CRON_KEY) ? '' : 'securitykey='.$conf->global->CRON_KEY.'&').'userlogin='.$user->login;
  85. print img_picto('', 'globe').' <a href="'.$url.'" target="_blank" rel="noopener noreferrer">'.$url."</a><br>\n";
  86. print ' '.$langs->trans("OrToLaunchASpecificJob").'<br>';
  87. $url = $urlwithroot.'/public/cron/cron_run_jobs_by_url.php?'.(empty($conf->global->CRON_KEY) ? '' : 'securitykey='.$conf->global->CRON_KEY.'&').'userlogin='.$user->login.'&id=cronjobid';
  88. print img_picto('', 'globe').' <a href="'.$url.'" target="_blank" rel="noopener noreferrer">'.$url."</a><br>\n";
  89. print '</div>';
  90. print '<br>';
  91. $logintouse = 'firstadmin';
  92. if ($user->admin) {
  93. $logintouse = $user->login;
  94. }
  95. print '<u>'.$langs->trans("FileToLaunchCronJobs").':</u><br>';
  96. $pathtoscript = '/pathtoscript';
  97. if (!empty($conf->global->MAIN_DOL_SCRIPTS_ROOT)) {
  98. $pathtoscript = $conf->global->MAIN_DOL_SCRIPTS_ROOT;
  99. }
  100. $file = $pathtoscript.'/scripts/cron/cron_run_jobs.php '.(empty($conf->global->CRON_KEY) ? 'securitykey' : ''.$conf->global->CRON_KEY.'').' '.$logintouse.' [cronjobid]';
  101. print '<textarea class="quatrevingtpercent">'.$file."</textarea><br>\n";
  102. print '<br>';
  103. // Add note
  104. if (empty($conf->global->CRON_DISABLE_TUTORIAL_CRON)) {
  105. $linuxlike = 1;
  106. if (preg_match('/^win/i', PHP_OS)) {
  107. $linuxlike = 0;
  108. }
  109. if (preg_match('/^mac/i', PHP_OS)) {
  110. $linuxlike = 0;
  111. }
  112. print $langs->trans("Note").': ';
  113. if ($linuxlike) {
  114. print $langs->trans("CronExplainHowToRunUnix");
  115. print '<br>';
  116. print '<textarea class="quatrevingtpercent">*/5 * * * * '.$pathtoscript.'/scripts/cron/cron_run_jobs.php '.(empty($conf->global->CRON_KEY) ? 'securitykey' : ''.$conf->global->CRON_KEY.'').' '.$logintouse.' &gt; '.DOL_DATA_ROOT.'/cron_run_jobs.php.log</textarea><br>';
  117. } else {
  118. print $langs->trans("CronExplainHowToRunWin");
  119. }
  120. }
  121. return 0;
  122. }