28 if (!defined(
'NOTOKENRENEWAL')) {
 
   29   define(
'NOTOKENRENEWAL', 
'1'); 
 
   31 if (!defined(
'NOREQUIREMENU')) {
 
   32   define(
'NOREQUIREMENU', 
'1');
 
   34 if (!defined(
'NOREQUIREHTML')) {
 
   35   define(
'NOREQUIREHTML', 
'1');
 
   37 if (!defined(
'NOREQUIREAJAX')) {
 
   38   define(
'NOREQUIREAJAX', 
'1');
 
   40 if (!defined(
'NOLOGIN')) {
 
   41   define(
'NOLOGIN', 
'1');
 
   43 if (!defined(
'NOSESSION')) {
 
   44   define(
'NOSESSION', 
'1');
 
   48 if (!defined(
'USESUFFIXINLOG')) {
 
   49   define(
'USESUFFIXINLOG', 
'_cron');
 
   52 $sapi_type = php_sapi_name();
 
   53 $script_file = basename(__FILE__);
 
   57 if (substr($sapi_type, 0, 3) == 
'cgi') {
 
   58   echo 
"Error: You are using PHP for CGI. To execute ".$script_file.
" from command line, you must use PHP for CLI mode.\n";
 
   62 require_once $path.
"../../htdocs/master.inc.php";
 
   63 require_once DOL_DOCUMENT_ROOT.
"/cron/class/cronjob.class.php";
 
   64 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
 
   67 if (!isset($argv[1]) || !$argv[1]) {
 
   68   usage($path, $script_file);
 
   73 if (!isset($argv[2]) || !$argv[2]) {
 
   74   usage($path, $script_file);
 
   78 $userlogin = $argv[2];
 
   81 $version = DOL_VERSION;
 
   84 $hookmanager->initHooks(array(
'cli'));
 
   95 print 
"***** ".$script_file.
" (".$version.
") pid=".
dol_getmypid().
" - userlogin=".$userlogin.
" - ".
dol_print_date($now, 
'dayhourrfc').
" *****\n";
 
   98 if (empty($conf->cron->enabled)) {
 
   99   print 
"Error: module Scheduled jobs (cron) not activated\n";
 
  104 if (empty($conf->cron->enabled)) {
 
  105   print 
"Error: module Scheduled jobs (cron) not activated\n";
 
  110 if ($key != $conf->global->CRON_KEY) {
 
  111   print 
"Error: securitykey is wrong\n";
 
  115 if (!empty($dolibarr_main_db_readonly)) {
 
  116   print 
"Error: instance in read-only mode\n";
 
  121 if ($userlogin == 
'firstadmin') {
 
  122   $sql = 
'SELECT login, entity from '.MAIN_DB_PREFIX.
'user WHERE admin = 1 and statut = 1 ORDER BY entity LIMIT 1';
 
  123   $resql = $db->query($sql);
 
  125     $obj = $db->fetch_object(
$resql);
 
  127       $userlogin = $obj->login;
 
  128       echo 
"First admin user found is login '".$userlogin.
"', entity ".$obj->entity.
"\n";
 
  136 $user = 
new User($db);
 
  137 $result = $user->fetch(
'', $userlogin, 
'', 1);
 
  139   echo 
"User Error: ".$user->error;
 
  140   dol_syslog(
"cron_run_jobs.php:: User Error:".$user->error, LOG_ERR);
 
  143   if (empty($user->id)) {
 
  144     echo 
"User login: ".$userlogin.
" does not exists";
 
  145     dol_syslog(
"User login:".$userlogin.
" does not exists", LOG_ERR);
 
  151 $langcode = (empty($conf->global->MAIN_LANG_DEFAULT) ? 
'auto' : $conf->global->MAIN_LANG_DEFAULT);
 
  152 if (!empty($user->conf->MAIN_LANG_DEFAULT)) {
 
  153   $langcode = $user->conf->MAIN_LANG_DEFAULT;
 
  155 if ($langs->getDefaultLang() != $langcode) {
 
  156   $langs->setDefaultLang($langcode);
 
  157   $langs->tab_translate = array();
 
  160 $langs->loadLangs(array(
'main', 
'admin', 
'cron', 
'dict'));
 
  164 if (isset($argv[3]) && $argv[3]) {
 
  168 if (isset($argv[4]) && $argv[4] == 
'--force') {
 
  177   if (!is_numeric($id)) {
 
  178     echo 
"Error: Bad value for parameter job id";
 
  179     dol_syslog(
"cron_run_jobs.php Bad value for parameter job id", LOG_WARNING);
 
  182   $filter[
't.rowid'] = $id;
 
  185 $result = $object->fetchAll(
'ASC,ASC,ASC', 
't.priority,t.entity,t.rowid', 0, 0, 1, $filter, 0);
 
  187   echo 
"Error: ".$object->error;
 
  188   dol_syslog(
"cron_run_jobs.php fetch Error ".$object->error, LOG_ERR);
 
  194 $nbofjobs = count($object->lines);
 
  195 $nbofjobslaunchedok = 0;
 
  196 $nbofjobslaunchedko = 0;
 
  198 if (is_array($object->lines) && (count($object->lines) > 0)) {
 
  202   foreach ($object->lines as $line) {
 
  203     dol_syslog(
"cron_run_jobs.php cronjobid: ".$line->id.
" priority=".$line->priority.
" entity=".$line->entity.
" label=".$line->label, LOG_DEBUG);
 
  204     echo 
"cron_run_jobs.php cronjobid: ".$line->id.
" priority=".$line->priority.
" entity=".$line->entity.
" label=".$line->label;
 
  207     if ((empty($line->entity) ? 1 : $line->entity) != $conf->entity) {
 
  208       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);
 
  209       echo 
" -> we change entity so we reload mysoc, langs, user and conf";
 
  211       $conf->entity = (empty($line->entity) ? 1 : $line->entity);
 
  212       $conf->setValues($db); 
 
  213       $mysoc->setMysoc($conf);
 
  216       if ($conf->entity != $user->entity) {
 
  217         $result = $user->fetch(
'', $userlogin, 
'', 1);
 
  219           echo 
"\nUser Error: ".$user->error.
"\n";
 
  220           dol_syslog(
"cron_run_jobs.php:: User Error:".$user->error, LOG_ERR);
 
  224             echo 
"\nUser login: ".$userlogin.
" does not exists for entity ".$conf->entity.
"\n";
 
  225             dol_syslog(
"User login:".$userlogin.
" does not exists", LOG_ERR);
 
  233       $langcode = (empty($conf->global->MAIN_LANG_DEFAULT) ? 
'auto' : $conf->global->MAIN_LANG_DEFAULT);
 
  234       if (!empty($user->conf->MAIN_LANG_DEFAULT)) {
 
  235         $langcode = $user->conf->MAIN_LANG_DEFAULT;
 
  237       if ($langs->getDefaultLang() != $langcode) {
 
  238         $langs->setDefaultLang($langcode);
 
  239         $langs->tab_translate = array();
 
  240         $langs->loadLangs(array(
'main', 
'admin', 
'cron', 
'dict'));
 
  249     if ($forcequalified || (($line->datenextrun < $now) && (empty($line->datestart) || $line->datestart <= $now) && (empty($line->dateend) || $line->dateend >= $now))) {
 
  255       $result = $cronjob->fetch($line->id);
 
  257         echo 
"Error cronjobid: ".$line->id.
" cronjob->fetch: ".$cronjob->error.
"\n";
 
  258         echo 
"Failed to fetch job ".$line->id.
"\n";
 
  259         dol_syslog(
"cron_run_jobs.php::fetch Error ".$cronjob->error, LOG_ERR);
 
  263       $result = $cronjob->run_jobs($userlogin);
 
  265         echo 
"Error cronjobid: ".$line->id.
" cronjob->run_job: ".$cronjob->error.
"\n";
 
  266         echo 
"At least one job failed. Go on menu Home-Setup-Admin tools to see result for each job.\n";
 
  267         echo 
"You can also enable module Log if not yet enabled, run again and take a look into dolibarr.log file\n";
 
  268         dol_syslog(
"cron_run_jobs.php::run_jobs Error ".$cronjob->error, LOG_ERR);
 
  269         $nbofjobslaunchedko++;
 
  270         $resultstring = 
'KO';
 
  272         $nbofjobslaunchedok++;
 
  273         $resultstring = 
'OK';
 
  276       echo 
" - run_jobs ".$resultstring.
" result = ".$result;
 
  279       $result = $cronjob->reprogram_jobs($userlogin, $now);
 
  281         echo 
"Error cronjobid: ".$line->id.
" cronjob->reprogram_job: ".$cronjob->error.
"\n";
 
  282         echo 
"Enable module Log if not yet enabled, run again and take a look into dolibarr.log file\n";
 
  283         dol_syslog(
"cron_run_jobs.php::reprogram_jobs Error ".$cronjob->error, LOG_ERR);
 
  287       echo 
" - reprogrammed\n";
 
  289       echo 
" - not qualified\n";
 
  297   echo 
"cron_run_jobs.php no qualified job found\n";
 
  302 if ($nbofjobslaunchedko) {
 
  316   print 
"Usage: ".$script_file.
" securitykey userlogin|'firstadmin' [cronjobid] [--force]\n";
 
  317   print 
"The script return 0 when everything worked successfully.\n";
 
  319   print 
"On Linux system, you can have cron jobs ran automatically by adding an entry into cron.\n";
 
  320   print 
"For example, to run pending tasks each day at 3:30, you can add this line:\n";
 
  321   print 
"30 3 * * * ".$path.$script_file.
" securitykey userlogin > ".DOL_DATA_ROOT.
"/".$script_file.
".log\n";
 
  322   print 
"For example, to run pending tasks every 5mn, you can add this line:\n";
 
  323   print 
"*/5 * * * * ".$path.$script_file.
" securitykey userlogin > ".DOL_DATA_ROOT.
"/".$script_file.
".log\n";
 
  325   print 
"The option --force allow to bypass the check on date of execution so job will be executed even if date is not yet reached.\n";
 
Class to manage Dolibarr users.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
usage($path, $script_file)
script cron usage
dol_getmypid()
Return getmypid() or random PID when function is disabled Some web hosts disable this php function fo...
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
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.