27if (!defined(
'NOTOKENRENEWAL')) {
28 define(
'NOTOKENRENEWAL',
'1');
30if (!defined(
'NOREQUIREMENU')) {
31 define(
'NOREQUIREMENU',
'1');
33if (!defined(
'NOREQUIREHTML')) {
34 define(
'NOREQUIREHTML',
'1');
36if (!defined(
'NOREQUIREAJAX')) {
37 define(
'NOREQUIREAJAX',
'1');
39if (!defined(
'NOLOGIN')) {
40 define(
'NOLOGIN',
'1');
42if (!defined(
'NOIPCHECK')) {
43 define(
'NOIPCHECK',
'1');
47if (!defined(
'USESUFFIXINLOG')) {
48 define(
'USESUFFIXINLOG',
'_cron');
54$entity = (!empty($_GET[
'entity']) ? (int) $_GET[
'entity'] : (!empty($_POST[
'entity']) ? (int) $_POST[
'entity'] : 1));
55if (is_numeric($entity)) {
56 define(
"DOLENTITY", $entity);
60if (php_sapi_name() ==
"cli") {
61 echo
"Error: This page can't be used as a CLI script. For the CLI version of script, launch cron_run_job.php available into scripts/cron/ directory.\n";
67require
'../../main.inc.php';
75$langs->loadLangs(array(
"admin",
"cron",
"dict"));
78if (empty($conf->cron->enabled)) {
92$key =
GETPOST(
'securitykey',
'alpha');
94 echo
'Securitykey is required. Check setup of cron jobs module.';
98 echo
'Securitykey is wrong.';
102$userlogin =
GETPOST(
'userlogin',
'alpha');
103if (empty($userlogin)) {
104 echo
'Userlogin is required.';
107require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
108$user =
new User($db);
109$result = $user->fetch(
'', $userlogin);
111 echo
"User Error:".$user->error;
112 dol_syslog(
"cron_run_jobs.php:: User Error:".$user->error, LOG_ERR);
115 if (empty($user->id)) {
116 echo
" User login:".$userlogin.
" do not exists";
117 dol_syslog(
" User login:".$userlogin.
" do not exists", LOG_ERR);
131 if (!is_numeric($id)) {
132 echo
"Error: Bad value for parameter job id";
133 dol_syslog(
"cron_run_jobs.php Bad value for parameter job id", LOG_WARNING);
136 $filter[
't.rowid'] =
$id;
139$result =
$object->fetchAll(
'ASC,ASC,ASC',
't.priority,t.entity,t.rowid', 0, 0, 1, $filter, 0);
141 echo
"Error: ".$object->error;
149$nbofjobs = count(
$object->lines);
150$nbofjobslaunchedok = 0;
151$nbofjobslaunchedko = 0;
157 foreach (
$object->lines as $line) {
158 dol_syslog(
"cron_run_jobs.php cronjobid: ".$line->id.
" priority=".$line->priority.
" entity=".$line->entity.
" label=".$line->label, LOG_DEBUG);
159 echo
"cron_run_jobs.php cronjobid: ".$line->id.
" priority=".$line->priority.
" entity=".$line->entity.
" label=".$line->label;
162 if ($line->entity != $conf->entity) {
163 dol_syslog(
"cron_run_jobs.php we work on another entity so we reload user and conf", LOG_DEBUG);
164 echo
" -> we change entity so we reload user and conf";
166 $conf->entity = (empty($line->entity) ? 1 : $line->entity);
167 $conf->setValues($db);
170 if ($conf->entity != $user->entity && $user->entity != 0) {
171 $result = $user->fetch(
'', $userlogin,
'', 0, $conf->entity);
173 echo
"\nUser Error: ".$user->error.
"\n";
174 dol_syslog(
"cron_run_jobs.php:: User Error:".$user->error, LOG_ERR);
178 echo
"\nUser login: ".$userlogin.
" does not exists for entity ".$conf->entity.
"\n";
179 dol_syslog(
"User login:".$userlogin.
" does not exists", LOG_ERR);
192 $datenextrunok = (empty($line->datenextrun) || (int) $line->datenextrun < $now);
193 $datestartok = (empty($line->datestart) || $line->datestart <= $now);
194 $dateendok = (empty($line->dateend) || $line->dateend >= $now);
195 if ($datenextrunok && $datestartok && $dateendok) {
201 $result = $cronjob->fetch($line->id);
203 echo
"Error cronjobid: ".$line->id.
" cronjob->fetch: ".$cronjob->error.
"\n";
204 echo
"Failed to fetch job ".$line->id.
"\n";
205 dol_syslog(
"cron_run_jobs.php::fetch Error".$cronjob->error, LOG_ERR);
209 $result = $cronjob->run_jobs($userlogin);
211 echo
"Error cronjobid: ".$line->id.
" cronjob->run_job: ".$cronjob->error.
"\n";
212 echo
"At least one job failed. Go on menu Home-Setup-Admin tools to see result for each job.\n";
213 echo
"You can also enable module Log if not yet enabled, run again and take a look into dolibarr.log file\n";
214 dol_syslog(
"cron_run_jobs.php::run_jobs Error".$cronjob->error, LOG_ERR);
215 $nbofjobslaunchedko++;
216 $resultstring =
'KO';
218 $nbofjobslaunchedok++;
219 $resultstring =
'OK';
222 echo
"Result of run_jobs = ".$resultstring.
" result = ".$result;
225 $result = $cronjob->reprogram_jobs($userlogin, $now);
227 echo
"Error cronjobid: ".$line->id.
" cronjob->reprogram_job: ".$cronjob->error.
"\n";
228 echo
"Enable module Log if not yet enabled, run again and take a look into dolibarr.log file\n";
229 dol_syslog(
"cron_run_jobs.php::reprogram_jobs Error".$cronjob->error, LOG_ERR);
233 echo
"Job re-scheduled\n";
235 echo
" - not qualified (datenextrunok=".($datenextrunok ?: 0).
", datestartok=".($datestartok ?: 0).
", dateendok=".($dateendok ?: 0).
")\n";
243 echo
"Result: ".($nbofjobs).
" jobs - ".($nbofjobslaunchedok + $nbofjobslaunchedko).
" launched = ".$nbofjobslaunchedok.
" OK + ".$nbofjobslaunchedko.
" KO";
245 echo
"Result: No active jobs found.";
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Class to manage Dolibarr users.
verifCond($strToEvaluate, $onlysimplestring='1')
Verify if condition in string is ok or not.
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.