dolibarr/htdocs/core/lib/cron.lib.php

157 lines
5.2 KiB
PHP
Raw Permalink Normal View History

2013-03-22 17:10:17 +01:00
<?php
/* Copyright (C) 2012 Nicolas Villa aka Boyquotes http://informetic.fr
* Copyright (C) 2013 Florian Henry <florian.henry@opn-concept.pro>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
2013-03-22 17:10:17 +01:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2013-03-22 17:10:17 +01:00
*/
2013-03-22 17:10:17 +01:00
/**
2013-08-22 16:49:23 +02:00
* \file core/lib/cron.lib.php
* \brief Function for module cron
* \ingroup cron
2013-03-22 17:10:17 +01:00
*/
2013-03-22 17:10:17 +01:00
/**
* Return array of tabs to used on pages to setup cron module.
2013-03-22 17:10:17 +01:00
*
* @return array<array{0:string,1:string,2:string}> Array of tabs to show
2013-03-22 17:10:17 +01:00
*/
function cronadmin_prepare_head()
{
global $langs, $conf, $user;
$h = 0;
$head = array();
2013-03-22 17:10:17 +01:00
2021-03-14 17:36:27 +01:00
$head[$h][0] = DOL_URL_ROOT.'/cron/admin/cron.php';
$head[$h][1] = $langs->trans("Miscellaneous");
$head[$h][2] = 'setup';
$h++;
2021-03-14 17:36:27 +01:00
$head[$h][0] = DOL_URL_ROOT.'/cron/list.php?mode=modulesetup';
2020-11-21 14:14:53 +01:00
$head[$h][1] = $langs->trans("Module2300Name");
$head[$h][2] = 'jobs';
$h++;
complete_head_from_modules($conf, $langs, null, $head, $h, 'cronadmin');
complete_head_from_modules($conf, $langs, null, $head, $h, 'cronadmin', 'remove');
2013-03-22 17:10:17 +01:00
return $head;
2013-03-22 17:10:17 +01:00
}
/**
* Return array of tabs to used on a cron job
*
* @param Cronjob $object Object cron
* @return array<array{0:string,1:string,2:string}> Array of tabs to show
*/
function cron_prepare_head(Cronjob $object)
2013-03-22 17:10:17 +01:00
{
global $langs, $conf, $user;
$h = 0;
$head = array();
2021-03-14 17:36:27 +01:00
$head[$h][0] = DOL_URL_ROOT.'/cron/card.php?id='.$object->id;
2013-03-22 17:10:17 +01:00
$head[$h][1] = $langs->trans("CronTask");
$head[$h][2] = 'card';
$h++;
2021-03-14 17:36:27 +01:00
$head[$h][0] = DOL_URL_ROOT.'/cron/info.php?id='.$object->id;
$head[$h][1] = $langs->trans("Info");
2013-03-22 17:10:17 +01:00
$head[$h][2] = 'info';
$h++;
complete_head_from_modules($conf, $langs, $object, $head, $h, 'cron');
complete_head_from_modules($conf, $langs, $object, $head, $h, 'cron', 'remove');
return $head;
}
2013-06-24 17:36:33 +02:00
/**
* Show information with URLs to launch jobs
*
* @return int 0
*/
function dol_print_cron_urls()
{
global $conf, $langs, $user;
global $dolibarr_main_url_root;
// Define $urlwithroot
$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
2013-06-24 17:36:33 +02:00
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
// Cron launch
2017-01-17 20:04:41 +01:00
print '<div class="div-table-responsive-no-min">';
2019-03-11 20:54:25 +01:00
print $langs->trans("URLToLaunchCronJobs").':<br>';
2023-11-27 11:39:32 +01:00
$url = $urlwithroot.'/public/cron/cron_run_jobs_by_url.php?'.(!getDolGlobalString('CRON_KEY') ? '' : 'securitykey=' . getDolGlobalString('CRON_KEY').'&').'userlogin='.$user->login;
2022-07-24 19:45:37 +02:00
print '<div class="urllink">';
print '<input type="text" id="publicurlmember" class="quatrevingtpercentminusx" value="'.$url.'">';
print ' <a href="'.$url.'" target="_blank" rel="noopener noreferrer">'.img_picto('', 'globe')."</a>\n";
print '</div>';
print '<br> '.$langs->trans("OrToLaunchASpecificJob").'<br>';
2023-11-27 11:39:32 +01:00
$url = $urlwithroot.'/public/cron/cron_run_jobs_by_url.php?'.(!getDolGlobalString('CRON_KEY') ? '' : 'securitykey=' . getDolGlobalString('CRON_KEY').'&').'userlogin='.$user->login.'&id=cronjobid';
2022-07-24 19:45:37 +02:00
print '<div class="urllink">';
print '<input type="text" id="publicurlmemberall" class="quatrevingtpercentminusx" value="'.$url.'">';
print ' <a href="'.$url.'" target="_blank" rel="noopener noreferrer">'.img_picto('', 'globe')."</a>\n";
print '</div>';
print '</div>';
print '<br>';
2019-03-11 20:54:25 +01:00
2022-07-24 19:45:37 +02:00
print ajax_autoselect("publicurlmember");
print ajax_autoselect("publicurlmemberall");
2016-09-29 13:55:46 +02:00
$logintouse = 'firstadmin';
2021-02-23 22:03:23 +01:00
if ($user->admin) {
$logintouse = $user->login;
}
2019-03-11 20:54:25 +01:00
2013-06-24 17:36:33 +02:00
print '<u>'.$langs->trans("FileToLaunchCronJobs").':</u><br>';
2021-07-11 01:58:37 +02:00
$pathtoscript = '/pathtoscript';
2023-11-27 11:39:32 +01:00
if (getDolGlobalString('MAIN_DOL_SCRIPTS_ROOT')) {
2024-01-05 04:18:53 +01:00
$pathtoscript = getDolGlobalString('MAIN_DOL_SCRIPTS_ROOT');
2021-07-11 01:58:37 +02:00
}
2023-11-27 11:39:32 +01:00
$file = $pathtoscript.'/scripts/cron/cron_run_jobs.php '.(!getDolGlobalString('CRON_KEY') ? 'securitykey' : '' . getDolGlobalString('CRON_KEY')).' '.$logintouse.' [cronjobid]';
2021-07-11 01:58:37 +02:00
print '<textarea class="quatrevingtpercent">'.$file."</textarea><br>\n";
2013-06-24 17:36:33 +02:00
print '<br>';
// Add note
2023-11-27 11:39:32 +01:00
if (!getDolGlobalString('CRON_DISABLE_TUTORIAL_CRON')) {
$linuxlike = 1;
2021-02-23 22:03:23 +01:00
if (preg_match('/^win/i', PHP_OS)) {
$linuxlike = 0;
}
if (preg_match('/^mac/i', PHP_OS)) {
$linuxlike = 0;
}
print $langs->trans("Note").': ';
2021-02-23 22:03:23 +01:00
if ($linuxlike) {
print $langs->trans("CronExplainHowToRunUnix");
print '<br>';
2023-11-27 11:39:32 +01:00
print '<textarea class="quatrevingtpercent">*/5 * * * * '.$pathtoscript.'/scripts/cron/cron_run_jobs.php '.(!getDolGlobalString('CRON_KEY') ? 'securitykey' : '' . getDolGlobalString('CRON_KEY')).' '.$logintouse.' &gt; '.DOL_DATA_ROOT.'/cron_run_jobs.php.log</textarea><br>';
} else {
print $langs->trans("CronExplainHowToRunWin");
}
2013-06-24 17:36:33 +02:00
}
2019-03-11 20:54:25 +01:00
2013-06-24 17:36:33 +02:00
return 0;
}