28 if (!defined(
'NOTOKENRENEWAL')) define(
'NOTOKENRENEWAL',
'1');
29 if (!defined(
'NOREQUIREMENU')) define(
'NOREQUIREMENU',
'1');
30 if (!defined(
'NOREQUIREHTML')) define(
'NOREQUIREHTML',
'1');
31 if (!defined(
'NOREQUIREAJAX')) define(
'NOREQUIREAJAX',
'1');
32 if (!defined(
'NOLOGIN')) define(
'NOLOGIN',
'1');
33 if (!defined(
'NOSESSION')) define(
'NOSESSION',
'1');
35 $sapi_type = php_sapi_name();
36 $script_file = basename(__FILE__);
40 if (substr($sapi_type, 0, 3) ==
'cgi') {
41 echo
"Error: You are using PHP for CGI. To execute ".$script_file.
" from command line, you must use PHP for CLI mode.\n";
45 require_once $path.
"../../htdocs/master.inc.php";
46 require_once DOL_DOCUMENT_ROOT.
"/cron/class/cronjob.class.php";
47 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
50 if (!isset($argv[1]) || !$argv[1]) {
51 usage($path, $script_file);
56 if (!isset($argv[2]) || !$argv[2]) {
57 usage($path, $script_file);
61 $userlogin = $argv[2];
64 $version = DOL_VERSION;
68 $langs->loadLangs(array(
'main',
'admin',
'cron',
'dict'));
79 print "***** ".$script_file.
" (".$version.
") pid=".
dol_getmypid().
" ***** userlogin=".$userlogin.
" ***** ".
dol_print_date($now,
'dayhourrfc').
" *****\n";
82 if (empty($conf->cron->enabled)) {
83 print "Error: module Scheduled jobs (cron) not activated\n";
88 if (empty($conf->cron->enabled)) {
89 print "Error: module Scheduled jobs (cron) not activated\n";
94 if ($key != $conf->global->CRON_KEY) {
95 print "Error: securitykey is wrong\n";
100 if ($userlogin ==
'firstadmin') {
101 $sql =
'SELECT login, entity from '.MAIN_DB_PREFIX.
'user WHERE admin = 1 and statut = 1 ORDER BY entity LIMIT 1';
102 $resql = $db->query($sql);
104 $obj = $db->fetch_object(
$resql);
106 $userlogin = $obj->login;
107 echo
"First admin user found is login '".$userlogin.
"', entity ".$obj->entity.
"\n";
113 $user =
new User($db);
114 $result = $user->fetch(
'', $userlogin);
116 echo
"User Error: ".$user->error;
117 dol_syslog(
"cron_run_jobs.php:: User Error:".$user->error, LOG_ERR);
120 if (empty($user->id)) {
121 echo
"User login: ".$userlogin.
" does not exists";
122 dol_syslog(
"User login:".$userlogin.
" does not exists", LOG_ERR);
128 if (isset($argv[3]) || $argv[3]) {
137 if (!is_numeric($id)) {
138 echo
"Error: Bad value for parameter job id";
139 dol_syslog(
"cron_run_jobs.php Bad value for parameter job id", LOG_WARNING);
142 $filter[
't.rowid'] = $id;
145 $result = $object->fetch_all(
'ASC,ASC,ASC',
't.priority,t.entity,t.rowid', 0, 0, 1, $filter, 0);
147 echo
"Error: ".$object->error;
148 dol_syslog(
"cron_run_jobs.php fetch Error ".$object->error, LOG_ERR);
152 $qualifiedjobs = array();
153 foreach ($object->lines as $val) {
158 $qualifiedjobs[] = $val;
163 $nbofjobs = count($qualifiedjobs);
164 $nbofjobslaunchedok = 0;
165 $nbofjobslaunchedko = 0;
167 if (is_array($qualifiedjobs) && (count($qualifiedjobs) > 0)) {
171 foreach ($qualifiedjobs as $line) {
172 dol_syslog(
"cron_run_jobs.php cronjobid: ".$line->id.
" priority=".$line->priority.
" entity=".$line->entity.
" label=".$line->label, LOG_DEBUG);
173 echo
"cron_run_jobs.php cronjobid: ".$line->id.
" priority=".$line->priority.
" entity=".$line->entity.
" label=".$line->label;
176 if ((empty($line->entity) ? 1 : $line->entity) != $conf->entity)
178 dol_syslog(
"cron_run_jobs.php we work on another entity conf than ".$conf->entity.
" so we reload mysoc, langs, user and conf", LOG_DEBUG);
179 echo
" -> we change entity so we reload mysoc, langs, user and conf";
181 $conf->entity = (empty($line->entity) ? 1 : $line->entity);
182 $conf->setValues($db);
183 $mysoc->setMysoc($conf);
186 if ($conf->entity != $user->entity && $user->entity != 0)
188 $result = $user->fetch(
'', $userlogin,
'', 0, $conf->entity);
191 echo
"\nUser Error: ".$user->error.
"\n";
192 dol_syslog(
"cron_run_jobs.php:: User Error:".$user->error, LOG_ERR);
197 echo
"\nUser login: ".$userlogin.
" does not exists for entity ".$conf->entity.
"\n";
198 dol_syslog(
"User login:".$userlogin.
" does not exists", LOG_ERR);
206 $langcode = (empty($conf->global->MAIN_LANG_DEFAULT) ?
'auto' : $conf->global->MAIN_LANG_DEFAULT);
207 if (!empty($user->conf->MAIN_LANG_DEFAULT)) $langcode = $user->conf->MAIN_LANG_DEFAULT;
208 if ($langs->getDefaultLang() != $langcode) $langs->setDefaultLang($langcode);
212 if (($line->datenextrun < $now) && (empty($line->datestart) || $line->datestart <= $now) && (empty($line->dateend) || $line->dateend >= $now)) {
218 $result = $cronjob->fetch($line->id);
220 echo
"Error cronjobid: ".$line->id.
" cronjob->fetch: ".$cronjob->error.
"\n";
221 echo
"Failed to fetch job ".$line->id.
"\n";
222 dol_syslog(
"cron_run_jobs.php::fetch Error ".$cronjob->error, LOG_ERR);
226 $result = $cronjob->run_jobs($userlogin);
228 echo
"Error cronjobid: ".$line->id.
" cronjob->run_job: ".$cronjob->error.
"\n";
229 echo
"At least one job failed. Go on menu Home-Setup-Admin tools to see result for each job.\n";
230 echo
"You can also enable module Log if not yet enabled, run again and take a look into dolibarr.log file\n";
231 dol_syslog(
"cron_run_jobs.php::run_jobs Error ".$cronjob->error, LOG_ERR);
232 $nbofjobslaunchedko++;
233 $resultstring =
'KO';
235 $nbofjobslaunchedok++;
236 $resultstring =
'OK';
239 echo
" - run_jobs ".$resultstring.
" result = ".$result;
242 $result = $cronjob->reprogram_jobs($userlogin, $now);
244 echo
"Error cronjobid: ".$line->id.
" cronjob->reprogram_job: ".$cronjob->error.
"\n";
245 echo
"Enable module Log if not yet enabled, run again and take a look into dolibarr.log file\n";
246 dol_syslog(
"cron_run_jobs.php::reprogram_jobs Error ".$cronjob->error, LOG_ERR);
250 echo
" - reprogrammed\n";
252 echo
" - not qualified\n";
260 echo
"cron_run_jobs.php no qualified job found\n";
265 if ($nbofjobslaunchedko)
278 print "Usage: ".$script_file.
" securitykey userlogin|'firstadmin' [cronjobid]\n";
279 print "The script return 0 when everything worked successfully.\n";
281 print "On Linux system, you can have cron jobs ran automatically by adding an entry into cron.\n";
282 print "For example, to run pending tasks each day at 3:30, you can add this line:\n";
283 print "30 3 * * * ".$path.$script_file.
" securitykey userlogin > ".DOL_DATA_ROOT.
"/".$script_file.
".log\n";
284 print "For example, to run pending tasks every 5mn, you can add this line:\n";
285 print "*/5 * * * * ".$path.$script_file.
" securitykey userlogin > ".DOL_DATA_ROOT.
"/".$script_file.
".log\n";
verifCond($strRights)
Verify if condition in string is ok or not.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for properties) With native = 0: P...
dol_getmypid()
Return getmypid() or random PID when function is disabled Some web hosts disable this php function fo...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
print
Draft customers invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
usage($path, $script_file)
script cron usage