Merge branch '9.0' of git@github.com:Dolibarr/dolibarr.git into develop
Conflicts: htdocs/public/cron/cron_run_jobs.php htdocs/public/payment/newpayment.php scripts/cron/cron_run_jobs.php
This commit is contained in:
commit
848b8f9bc4
@ -4602,6 +4602,7 @@ class FactureLigne extends CommonInvoiceLine
|
||||
if ($result <= 0)
|
||||
{
|
||||
$this->error='ErrorProductIdDoesNotExists';
|
||||
dol_syslog(get_class($this)."::insert Error ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,7 +51,8 @@ dol_include_once("/cron/class/cronjob.class.php");
|
||||
global $langs, $conf;
|
||||
|
||||
// Language Management
|
||||
$langs->loadLangs(array("admin", "cron"));
|
||||
$langs->loadLangs(array("admin", "cron", "dict"));
|
||||
|
||||
|
||||
|
||||
|
||||
@ -59,6 +60,9 @@ $langs->loadLangs(array("admin", "cron"));
|
||||
* View
|
||||
*/
|
||||
|
||||
// current date
|
||||
$now=dol_now();
|
||||
|
||||
// Check the key, avoid that a stranger starts cron
|
||||
$key = GETPOST('securitykey', 'alpha');
|
||||
if (empty($key))
|
||||
@ -84,15 +88,15 @@ $result=$user->fetch('', $userlogin);
|
||||
if ($result < 0)
|
||||
{
|
||||
echo "User Error:".$user->error;
|
||||
dol_syslog("cron_run_jobs.php:: User Error:".$user->error, LOG_WARNING);
|
||||
dol_syslog("cron_run_jobs.php:: User Error:".$user->error, LOG_ERR);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (empty($user->id))
|
||||
{
|
||||
echo " User user login:".$userlogin." do not exists";
|
||||
dol_syslog(" User user login:".$userlogin." do not exists", LOG_WARNING);
|
||||
echo " User login:".$userlogin." do not exists";
|
||||
dol_syslog(" User login:".$userlogin." do not exists", LOG_ERR);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@ -103,8 +107,7 @@ $id = GETPOST('id', 'alpha'); // We accept non numeric id. We will filter later.
|
||||
$object = new Cronjob($db);
|
||||
|
||||
$filter=array();
|
||||
if (! empty($id))
|
||||
{
|
||||
if (! empty($id)) {
|
||||
if (! is_numeric($id))
|
||||
{
|
||||
echo "Error: Bad value for parameter job id";
|
||||
@ -118,7 +121,7 @@ $result = $object->fetch_all('ASC,ASC,ASC', 't.priority,t.entity,t.rowid', 0, 0,
|
||||
if ($result<0)
|
||||
{
|
||||
echo "Error: ".$object->error;
|
||||
dol_syslog("cron_run_jobs.php fetch Error".$object->error, LOG_WARNING);
|
||||
dol_syslog("cron_run_jobs.php fetch Error".$object->error, LOG_ERR);
|
||||
exit;
|
||||
}
|
||||
|
||||
@ -132,37 +135,76 @@ foreach($object->lines as $val)
|
||||
// TODO Duplicate code. This sequence of code must be shared with code into cron_run_jobs.php script.
|
||||
|
||||
// current date
|
||||
$now=dol_now();
|
||||
$nbofjobs=count($qualifiedjobs);
|
||||
$nbofjobslaunchedok=0;
|
||||
$nbofjobslaunchedko=0;
|
||||
|
||||
if (is_array($qualifiedjobs) && (count($qualifiedjobs)>0))
|
||||
{
|
||||
// Loop over job
|
||||
$savconf = dol_clone($conf);
|
||||
|
||||
// Loop over job
|
||||
foreach($qualifiedjobs as $line)
|
||||
{
|
||||
dol_syslog("cron_run_jobs.php cronjobid: ".$line->id, LOG_WARNING);
|
||||
dol_syslog("cron_run_jobs.php cronjobid: ".$line->id." priority=".$line->priority." entity=".$line->entity." label=".$line->label, LOG_DEBUG);
|
||||
echo "cron_run_jobs.php cronjobid: ".$line->id." priority=".$line->priority." entity=".$line->entity." label=".$line->label;
|
||||
|
||||
//If date_next_jobs is less of current dat, execute the program, and store the execution time of the next execution in database
|
||||
// Force reload of setup for the current entity
|
||||
if ($line->entity != $conf->entity)
|
||||
{
|
||||
dol_syslog("cron_run_jobs.php we work on another entity so we reload user and conf", LOG_DEBUG);
|
||||
echo " -> we change entity so we reload user and conf";
|
||||
|
||||
$conf->entity = (empty($line->entity)?1:$line->entity);
|
||||
$conf->setValues($db); // This make also the $mc->setValues($conf); that reload $mc->sharings
|
||||
|
||||
// Force recheck that user is ok for the entity to process and reload permission for entity
|
||||
if ($conf->entity != $user->entity && $user->entity != 0)
|
||||
{
|
||||
$result=$user->fetch('', $userlogin, '', 0, $conf->entity);
|
||||
if ($result < 0)
|
||||
{
|
||||
echo "\nUser Error: ".$user->error."\n";
|
||||
dol_syslog("cron_run_jobs.php:: User Error:".$user->error, LOG_ERR);
|
||||
exit(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($result == 0)
|
||||
{
|
||||
echo "\nUser login: ".$userlogin." does not exists for entity ".$conf->entity."\n";
|
||||
dol_syslog("User login:".$userlogin." does not exists", LOG_ERR);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
$user->getrights();
|
||||
}
|
||||
}
|
||||
|
||||
//If date_next_jobs is less of current date, execute the program, and store the execution time of the next execution in database
|
||||
if (($line->datenextrun < $now) && (empty($line->datestart) || $line->datestart <= $now) && (empty($line->dateend) || $line->dateend >= $now))
|
||||
{
|
||||
dol_syslog("cron_run_jobs.php:: torun line->datenextrun:".dol_print_date($line->datenextrun, 'dayhourtext')." line->dateend:".dol_print_date($line->dateend, 'dayhourtext')." now:".dol_print_date($now, 'dayhourtext'));
|
||||
echo " - qualified";
|
||||
|
||||
dol_syslog("cron_run_jobs.php line->datenextrun:".dol_print_date($line->datenextrun,'dayhourrfc')." line->datestart:".dol_print_date($line->datestart,'dayhourrfc')." line->dateend:".dol_print_date($line->dateend,'dayhourrfc')." now:".dol_print_date($now,'dayhourrfc'));
|
||||
|
||||
$cronjob=new Cronjob($db);
|
||||
$result=$cronjob->fetch($line->id);
|
||||
if ($result<0)
|
||||
{
|
||||
echo "Error cronjob->fetch: ".$cronjob->error."<br>\n";
|
||||
echo "Error cronjobid: ".$line->id." cronjob->fetch: ".$cronjob->error."\n";
|
||||
echo "Failed to fetch job ".$line->id."\n";
|
||||
dol_syslog("cron_run_jobs.php::fetch Error".$cronjob->error, LOG_ERR);
|
||||
exit;
|
||||
}
|
||||
// Execut job
|
||||
// Execute job
|
||||
$result=$cronjob->run_jobs($userlogin);
|
||||
if ($result < 0)
|
||||
{
|
||||
echo "Error cronjob->run_job: ".$cronjob->error."<br>\n";
|
||||
dol_syslog("cron_run_jobs.php::run_jobs Error".$cronjob->error, LOG_ERR);
|
||||
echo "Error cronjobid: ".$line->id." cronjob->run_job: ".$cronjob->error."\n";
|
||||
echo "At least one job failed. Go on menu Home-Setup-Admin tools to see result for each job.\n";
|
||||
echo "You can also enable module Log if not yet enabled, run again and take a look into dolibarr.log file\n";
|
||||
dol_syslog("cron_run_jobs.php::run_jobs Error".$cronjob->error, LOG_ERR);
|
||||
$nbofjobslaunchedko++;
|
||||
}
|
||||
else
|
||||
@ -170,16 +212,30 @@ if (is_array($qualifiedjobs) && (count($qualifiedjobs)>0))
|
||||
$nbofjobslaunchedok++;
|
||||
}
|
||||
|
||||
echo " - result of run_jobs = ".$result;
|
||||
|
||||
// We re-program the next execution and stores the last execution time for this job
|
||||
$result=$cronjob->reprogram_jobs($userlogin, $now);
|
||||
if ($result<0)
|
||||
{
|
||||
echo "Error cronjob->reprogram_job: ".$cronjob->error."<br>\n";
|
||||
dol_syslog("cron_run_jobs.php::reprogram_jobs Error".$cronjob->error, LOG_ERR);
|
||||
echo "Error cronjobid: ".$line->id." cronjob->reprogram_job: ".$cronjob->error."\n";
|
||||
echo "Enable module Log if not yet enabled, run again and take a look into dolibarr.log file\n";
|
||||
dol_syslog("cron_run_jobs.php::reprogram_jobs Error".$cronjob->error, LOG_ERR);
|
||||
exit;
|
||||
}
|
||||
|
||||
echo " - reprogrammed\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo " - not qualified\n";
|
||||
|
||||
dol_syslog("cron_run_jobs.php job not qualified line->datenextrun:".dol_print_date($line->datenextrun,'dayhourrfc')." line->datestart:".dol_print_date($line->datestart,'dayhourrfc')." line->dateend:".dol_print_date($line->dateend,'dayhourrfc')." now:".dol_print_date($now,'dayhourrfc'));
|
||||
}
|
||||
}
|
||||
|
||||
$conf = $savconf;
|
||||
|
||||
echo "Result: ".($nbofjobs)." jobs - ".($nbofjobslaunchedok+$nbofjobslaunchedko)." launched = ".$nbofjobslaunchedok." OK + ".$nbofjobslaunchedko." KO";
|
||||
}
|
||||
else
|
||||
|
||||
@ -24,17 +24,13 @@
|
||||
* \ingroup cron
|
||||
* \brief Execute pendings jobs
|
||||
*/
|
||||
if (! defined('NOTOKENRENEWAL'))
|
||||
define('NOTOKENRENEWAL', '1'); // Disables token renewal
|
||||
if (! defined('NOREQUIREMENU'))
|
||||
define('NOREQUIREMENU', '1');
|
||||
if (! defined('NOREQUIREHTML'))
|
||||
define('NOREQUIREHTML', '1');
|
||||
if (! defined('NOREQUIREAJAX'))
|
||||
define('NOREQUIREAJAX', '1');
|
||||
if (! defined('NOLOGIN'))
|
||||
define('NOLOGIN', '1');
|
||||
// if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
|
||||
|
||||
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal
|
||||
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
|
||||
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
|
||||
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
|
||||
if (! defined('NOLOGIN')) define('NOLOGIN','1');
|
||||
|
||||
|
||||
$sapi_type = php_sapi_name();
|
||||
$script_file = basename(__FILE__);
|
||||
@ -68,12 +64,14 @@ $userlogin = $argv[2];
|
||||
$version = DOL_VERSION;
|
||||
$error = 0;
|
||||
|
||||
// Language Management
|
||||
$langs->loadLangs(array('main', 'admin', 'cron', 'dict'));
|
||||
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
|
||||
$langs->loadLangs(array('main','dict'));
|
||||
|
||||
// current date
|
||||
$now = dol_now();
|
||||
|
||||
@ -148,31 +146,66 @@ if (! empty($id)) {
|
||||
$result = $object->fetch_all('ASC,ASC,ASC', 't.priority,t.entity,t.rowid', 0, 0, 1, $filter, 0);
|
||||
if ($result < 0) {
|
||||
echo "Error: " . $object->error;
|
||||
dol_syslog("cron_run_jobs.php:: fetch Error " . $object->error, LOG_ERR);
|
||||
dol_syslog("cron_run_jobs.php fetch Error " . $object->error, LOG_ERR);
|
||||
exit(- 1);
|
||||
}
|
||||
|
||||
$qualifiedjobs = array();
|
||||
foreach ($object->lines as $val) {
|
||||
if (! verifCond($val->test))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$qualifiedjobs[] = $val;
|
||||
}
|
||||
|
||||
// TODO Duplicate. This sequence of code must be shared with code into public/cron/cron_run_jobs.php php page.
|
||||
// TODO Duplicate code. This sequence of code must be shared with code into public/cron/cron_run_jobs.php php page.
|
||||
|
||||
$nbofjobs = count($qualifiedjobs);
|
||||
$nbofjobslaunchedok = 0;
|
||||
$nbofjobslaunchedko = 0;
|
||||
|
||||
if (is_array($qualifiedjobs) && (count($qualifiedjobs) > 0)) {
|
||||
$savconf = dol_clone($conf);
|
||||
|
||||
// Loop over job
|
||||
foreach ($qualifiedjobs as $line) {
|
||||
dol_syslog("cron_run_jobs.php cronjobid: " . $line->id . " priority=" . $line->priority . " entity=" . $line->entity . " label=" . $line->label, LOG_DEBUG);
|
||||
dol_syslog("cron_run_jobs.php cronjobid: ".$line->id." priority=".$line->priority." entity=".$line->entity." label=".$line->label, LOG_DEBUG);
|
||||
echo "cron_run_jobs.php cronjobid: ".$line->id." priority=".$line->priority." entity=".$line->entity." label=".$line->label;
|
||||
|
||||
echo "cron_run_jobs.php cronjobid: " . $line->id . " priority=" . $line->priority . " entity=" . $line->entity . " label=" . $line->label;
|
||||
// Force reload of setup for the current entity
|
||||
if ($line->entity != $conf->entity)
|
||||
{
|
||||
dol_syslog("cron_run_jobs.php we work on another entity so we reload user and conf", LOG_DEBUG);
|
||||
echo " -> we change entity so we reload user and conf";
|
||||
|
||||
// If date_next_jobs is less of current date, execute the program, and store the execution time of the next execution in database
|
||||
$conf->entity = (empty($line->entity)?1:$line->entity);
|
||||
$conf->setValues($db); // This make also the $mc->setValues($conf); that reload $mc->sharings
|
||||
|
||||
// Force recheck that user is ok for the entity to process and reload permission for entity
|
||||
if ($conf->entity != $user->entity && $user->entity != 0)
|
||||
{
|
||||
$result=$user->fetch('', $userlogin, '', 0, $conf->entity);
|
||||
if ($result < 0)
|
||||
{
|
||||
echo "\nUser Error: ".$user->error."\n";
|
||||
dol_syslog("cron_run_jobs.php:: User Error:".$user->error, LOG_ERR);
|
||||
exit(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($result == 0)
|
||||
{
|
||||
echo "\nUser login: ".$userlogin." does not exists for entity ".$conf->entity."\n";
|
||||
dol_syslog("User login:".$userlogin." does not exists", LOG_ERR);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
$user->getrights();
|
||||
}
|
||||
}
|
||||
|
||||
//If date_next_jobs is less of current date, execute the program, and store the execution time of the next execution in database
|
||||
if (($line->datenextrun < $now) && (empty($line->datestart) || $line->datestart <= $now) && (empty($line->dateend) || $line->dateend >= $now)) {
|
||||
echo " - qualified";
|
||||
|
||||
@ -200,7 +233,7 @@ if (is_array($qualifiedjobs) && (count($qualifiedjobs) > 0)) {
|
||||
|
||||
echo " - result of run_jobs = " . $result;
|
||||
|
||||
// we re-program the next execution and stores the last execution time for this job
|
||||
// We re-program the next execution and stores the last execution time for this job
|
||||
$result = $cronjob->reprogram_jobs($userlogin, $now);
|
||||
if ($result < 0) {
|
||||
echo "Error cronjobid: " . $line->id . " cronjob->reprogram_job: " . $cronjob->error . "\n";
|
||||
@ -216,7 +249,11 @@ if (is_array($qualifiedjobs) && (count($qualifiedjobs) > 0)) {
|
||||
dol_syslog("cron_run_jobs.php job not qualified line->datenextrun:" . dol_print_date($line->datenextrun, 'dayhourrfc') . " line->datestart:" . dol_print_date($line->datestart, 'dayhourrfc') . " line->dateend:" . dol_print_date($line->dateend, 'dayhourrfc') . " now:" . dol_print_date($now, 'dayhourrfc'));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
$conf = $savconf;
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "cron_run_jobs.php no qualified job found\n";
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user