27 if (!defined(
'NOTOKENRENEWAL')) {
28 define(
'NOTOKENRENEWAL',
'1');
30 if (!defined(
'NOREQUIREMENU')) {
31 define(
'NOREQUIREMENU',
'1');
33 if (!defined(
'NOREQUIREHTML')) {
34 define(
'NOREQUIREHTML',
'1');
36 if (!defined(
'NOREQUIREAJAX')) {
37 define(
'NOREQUIREAJAX',
'1');
39 if (!defined(
'NOLOGIN')) {
40 define(
'NOLOGIN',
'1');
42 if (!defined(
'NOIPCHECK')) {
43 define(
'NOIPCHECK',
'1');
47 if (!defined(
'USESUFFIXINLOG')) {
48 define(
'USESUFFIXINLOG',
'_cron');
53 $entity = (!empty($_GET[
'entity']) ? (int) $_GET[
'entity'] : (!empty($_POST[
'entity']) ? (int) $_POST[
'entity'] : 1));
54 if (is_numeric($entity)) {
55 define(
"DOLENTITY", $entity);
59 if (php_sapi_name() ==
"cli") {
60 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";
66 require
'../../main.inc.php';
74 $langs->loadLangs(array(
"admin",
"cron",
"dict"));
77 if (empty($conf->cron->enabled)) {
91 $key =
GETPOST(
'securitykey',
'alpha');
93 echo
'Securitykey is required. Check setup of cron jobs module.';
97 echo
'Securitykey is wrong.';
101 $userlogin =
GETPOST(
'userlogin',
'alpha');
102 if (empty($userlogin)) {
103 echo
'Userlogin is required.';
106 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
107 $user =
new User($db);
108 $result = $user->fetch(
'', $userlogin);
110 echo
"User Error:".$user->error;
111 dol_syslog(
"cron_run_jobs.php:: User Error:".$user->error, LOG_ERR);
114 if (empty($user->id)) {
115 echo
" User login:".$userlogin.
" do not exists";
116 dol_syslog(
" User login:".$userlogin.
" do not exists", LOG_ERR);
130 if (!is_numeric($id)) {
131 echo
"Error: Bad value for parameter job id";
132 dol_syslog(
"cron_run_jobs.php Bad value for parameter job id", LOG_WARNING);
135 $filter[
't.rowid'] = $id;
138 $result = $object->fetchAll(
'ASC,ASC,ASC',
't.priority,t.entity,t.rowid', 0, 0, 1, $filter, 0);
140 echo
"Error: ".$object->error;
141 dol_syslog(
"cron_run_jobs.php fetch Error".$object->error, LOG_ERR);
145 $qualifiedjobs = array();
146 foreach ($object->lines as $val) {
150 $qualifiedjobs[] = $val;
156 $nbofjobs = count($qualifiedjobs);
157 $nbofjobslaunchedok = 0;
158 $nbofjobslaunchedko = 0;
160 if (is_array($qualifiedjobs) && (count($qualifiedjobs) > 0)) {
164 foreach ($qualifiedjobs as $line) {
165 dol_syslog(
"cron_run_jobs.php cronjobid: ".$line->id.
" priority=".$line->priority.
" entity=".$line->entity.
" label=".$line->label, LOG_DEBUG);
166 echo
"cron_run_jobs.php cronjobid: ".$line->id.
" priority=".$line->priority.
" entity=".$line->entity.
" label=".$line->label;
169 if ($line->entity != $conf->entity) {
170 dol_syslog(
"cron_run_jobs.php we work on another entity so we reload user and conf", LOG_DEBUG);
171 echo
" -> we change entity so we reload user and conf";
173 $conf->entity = (empty($line->entity) ? 1 : $line->entity);
174 $conf->setValues($db);
177 if ($conf->entity != $user->entity && $user->entity != 0) {
178 $result = $user->fetch(
'', $userlogin,
'', 0, $conf->entity);
180 echo
"\nUser Error: ".$user->error.
"\n";
181 dol_syslog(
"cron_run_jobs.php:: User Error:".$user->error, LOG_ERR);
185 echo
"\nUser login: ".$userlogin.
" does not exists for entity ".$conf->entity.
"\n";
186 dol_syslog(
"User login:".$userlogin.
" does not exists", LOG_ERR);
195 if (($line->datenextrun < $now) && (empty($line->datestart) || $line->datestart <= $now) && (empty($line->dateend) || $line->dateend >= $now)) {
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++;
217 $nbofjobslaunchedok++;
220 echo
" - result of run_jobs = ".$result;
223 $result = $cronjob->reprogram_jobs($userlogin, $now);
225 echo
"Error cronjobid: ".$line->id.
" cronjob->reprogram_job: ".$cronjob->error.
"\n";
226 echo
"Enable module Log if not yet enabled, run again and take a look into dolibarr.log file\n";
227 dol_syslog(
"cron_run_jobs.php::reprogram_jobs Error".$cronjob->error, LOG_ERR);
231 echo
" - reprogrammed\n";
233 echo
" - not qualified\n";
241 echo
"Result: ".($nbofjobs).
" jobs - ".($nbofjobslaunchedok + $nbofjobslaunchedko).
" launched = ".$nbofjobslaunchedok.
" OK + ".$nbofjobslaunchedko.
" KO";
243 echo
"Result: No active jobs found.";
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname= '')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default= '')
Return dolibarr global constant string value.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for properties) With native = 0: P...
verifCond($strToEvaluate)
Verify if condition in string is ok or not.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).