Make sure Joomla timezone is set for cron jobs #12609
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
When running CiviCRM on Joomla the timezone is not being set correctly when running cron from the command line (eg. via a server cron job).
Example:
/usr/local/bin/ea-php70 /path/to/site/administrator/components/com_civicrm/civicrm/bin/cli.php -s urltosite.org -u cronjob_user -p cronjob_pwd -e Job -a execute >/dev/null 2>&1
The impact of this is that currently (ie. during British Summer Time (BST)) when you view the list of cron jobs the last_run date is one hour behind when it was actually run - but when you view the job log for each job the start/end date/time is correct and current.
So, for example at 11:00 the mailings job says it was last run at 10:00 but the mailings job log says started at 11:00:05, ended at 11:00:15.
Before
The CRON job is always being executed with timezone set to UTC.
After
The CRON job is executed using the same timezone as Joomla (and the same timezone that is configured for Joomla/CiviCRM/database when running via web).
Technical Details
A similar "fix" was added to the Wordpress loadBootStrap() function a few years ago.
Comments
It is likely that this issue may/may not arise depending on specific server timezone configurations. In this case this is a shared WHM/cpanel server which I only have access to the cpanel account.
The configured Joomla timezone is Europe/London and PHP is also configured for both the domain and home directory to be Europe/London.
The timezone check in CiviCRM passes both before and after this PR because the environment is configured properly when run via web.
I think this may also have an impact on some IPN transactions as I've seen them with the wrong time in the past from PayPal. However, I have not investigated this further at this stage.