Commit ae848634 authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic Committed by Gerrit Code Review

Merge "Bug 1851699: Adding a condition to cron.php for PHP FastCGI environment."

parents c138ae62 6a035b64
......@@ -33,7 +33,7 @@ if (param_integer('finished', 0)) {
}
// Check if we have come via browser and have the right urlsecret
if (php_sapi_name() != 'cli' && get_config('urlsecret') !== null) {
if (!is_cli() && get_config('urlsecret') !== null) {
$urlsecret = param_alphanumext('urlsecret', -1);
if ($urlsecret !== get_config('urlsecret')) {
die_info(get_string('accessdeniednourlsecret', 'error'));
......
......@@ -11,7 +11,7 @@
defined('INTERNAL') || die();
if (defined('CLI') && php_sapi_name() != 'cli') {
if (defined('CLI') && !is_cli()) {
die();
}
......@@ -562,3 +562,22 @@ function init_performance_info() {
$PERF->startposixtimes = posix_times();
}
}
/**
* Do some robust checking to see if we are accessing site via CLI mode or not
*/
function is_cli() {
if (defined('STDIN')) {
return true;
}
if (php_sapi_name() === 'cli') {
return true;
}
if (array_key_exists('SHELL', $_ENV)) {
return true;
}
if (!array_key_exists('REQUEST_METHOD', $_SERVER)) {
return true;
}
return false;
}
\ No newline at end of file
......@@ -25,7 +25,7 @@ require_once(get_config('docroot') . 'webservice/lib.php');
// If we are running behat tests, we only run cron via the behat step:
// I trigger (the )?cron
if (defined('BEHAT_TEST')) {
if (php_sapi_name() == 'cli') {
if (is_cli()) {
die_info("Can not run cron from command line when behat environment is enabled");
}
$behattrigger = param_boolean('behattrigger', false);
......@@ -37,7 +37,7 @@ if (defined('BEHAT_TEST')) {
// Check if we have come via browser and have the right urlsecret
// Note: if your crontab hits this file via curl/http thenyou will need
// to add the urlsecret there for the cron to work.
if (php_sapi_name() != 'cli' && get_config('urlsecret') !== null) {
if (!is_cli() && get_config('urlsecret') !== null) {
$urlsecret = param_alphanumext('urlsecret', -1);
if ($urlsecret !== get_config('urlsecret')) {
die_info(get_string('accessdeniednourlsecret', 'error'));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment