forked from Wavyzz/dolibarr
Fix CLI tools must return a positive value on error for better cross
platform compatibility
This commit is contained in:
@@ -56,7 +56,7 @@ $path = __DIR__.'/';
|
||||
// Error if Web mode
|
||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
|
||||
exit(-1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
require_once $path."../../htdocs/master.inc.php";
|
||||
@@ -66,13 +66,13 @@ require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
|
||||
// Check parameters
|
||||
if (!isset($argv[1]) || !$argv[1]) {
|
||||
usage($path, $script_file);
|
||||
exit(-1);
|
||||
exit(1);
|
||||
}
|
||||
$key = $argv[1];
|
||||
|
||||
if (!isset($argv[2]) || !$argv[2]) {
|
||||
usage($path, $script_file);
|
||||
exit(-1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$userlogin = $argv[2];
|
||||
@@ -97,18 +97,18 @@ print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." - userlogin=
|
||||
// Check module cron is activated
|
||||
if (!isModEnabled('cron')) {
|
||||
print "Error: module Scheduled jobs (cron) not activated\n";
|
||||
exit(-1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Check security key
|
||||
if ($key != getDolGlobalString('CRON_KEY')) {
|
||||
print "Error: securitykey is wrong\n";
|
||||
exit(-1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!empty($dolibarr_main_db_readonly)) {
|
||||
print "Error: instance in read-only mode\n";
|
||||
exit(-1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// If param userlogin is reserved word 'firstadmin'
|
||||
@@ -132,12 +132,12 @@ $result = $user->fetch('', $userlogin, '', 1);
|
||||
if ($result < 0) {
|
||||
echo "User Error: ".$user->error;
|
||||
dol_syslog("cron_run_jobs.php:: User Error:".$user->error, LOG_ERR);
|
||||
exit(-1);
|
||||
exit(1);
|
||||
} else {
|
||||
if (empty($user->id)) {
|
||||
echo "User login: ".$userlogin." does not exists\n";
|
||||
dol_syslog("User login:".$userlogin." does not exists", LOG_ERR);
|
||||
exit(-1);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ if (!empty($id)) {
|
||||
if (!is_numeric($id)) {
|
||||
echo "Error: Bad value for parameter job id\n";
|
||||
dol_syslog("cron_run_jobs.php Bad value for parameter job id", LOG_WARNING);
|
||||
exit();
|
||||
exit(2);
|
||||
}
|
||||
$filter['t.rowid'] = $id;
|
||||
}
|
||||
@@ -180,7 +180,7 @@ $result = $object->fetchAll('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_ERR);
|
||||
exit(-1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// TODO Duplicate code. This sequence of code must be shared with code into public/cron/cron_run_jobs.php php page.
|
||||
@@ -212,12 +212,12 @@ if (is_array($object->lines) && (count($object->lines) > 0)) {
|
||||
if ($result < 0) {
|
||||
echo "\nUser Error: ".$user->error."\n";
|
||||
dol_syslog("cron_run_jobs.php: User Error:".$user->error, LOG_ERR);
|
||||
exit(-1);
|
||||
exit(1);
|
||||
} else {
|
||||
if ($result == 0) {
|
||||
echo "\nUser login: ".$userlogin." does not exist for entity ".$conf->entity."\n";
|
||||
dol_syslog("cron_run_jobs.php: User login: ".$userlogin." does not exist", LOG_ERR);
|
||||
exit(-1);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
$user->getrights();
|
||||
@@ -251,7 +251,7 @@ if (is_array($object->lines) && (count($object->lines) > 0)) {
|
||||
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(-1);
|
||||
exit(1);
|
||||
}
|
||||
// Execute job
|
||||
$result = $cronjob->run_jobs($userlogin);
|
||||
@@ -275,7 +275,7 @@ if (is_array($object->lines) && (count($object->lines) > 0)) {
|
||||
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(-1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
echo " - reprogrammed\n";
|
||||
|
||||
Reference in New Issue
Block a user