Environments as collections of settings
Overview
Revise the conception of "environment" so that it can more usefully model these distinctions:
- As a developer working on patches with abstract sample data, you want to toggle some settings/behaviors (eg
backtrace=1
). - As a developer/trainer/etc working on with a local copy of real data, you want to toggle different settings/behaviors (eg restricting cron jobs that might communicate to real people).
This issue proposes that an environment
is merely and strictly a collection of settings - changing the environment will change the active settings.
Off-shoot of discussion circa https://github.com/civicrm/civicrm-core/pull/22377#issuecomment-1006058134
Current behaviour
- Sysadmins can design bespoke meta-settings by editing
civicrm.settings.php
-
civibuild
users can design bespoke meta-settings by placing files/etc/civicrm.settings.d/*.php
- The setting
environment
has the primary effect of toggling some guards forJobManager
/mailing_backend
/runInNonProductionEnvironment
.
Proposed behaviour
- Use
environment
to load files which list standard/default values for various settings. eg-
civicrm-core.git:env/Development.json
has a list of defaults to use in "Development" envs -
/etc/civicrm.settings.d/env/Development.json
has a list of local overrides to use in "Development" envs
-
- Make it easier to set
environment
on new builds, eg- Add an install option (eg
cv core:install --env=Demo
) - Add an env-var (eg
CIVICRM_ENVIRONMENT=Staging
) - respected by both installer+runtime - Add a self-documenting subcommand to configure
civibuild
, egcivibuild config --env=Development
- Add an install option (eg
- Don't hard-code
environment
behaviors in PHP. Always use settings. eg- For the JobManager/runInNonProductionEnvironment stuff, there should be a setting
restrictScheduledJobs
. For "Development" envs, the effective-default isrestrictScheduledJobs=true
.
- For the JobManager/runInNonProductionEnvironment stuff, there should be a setting
For example, the standard definition of a "Development" environment might be:
// FILE: civicrm-core.git:env/Development.json
{
"debug_enabled": true,
"backtrace": true,
"restrictScheduledJobs": true,
"assetCache": 0
}
But I could still tune it for my system:
// FILE: /etc/civicrm.settings.d/env/Development.json
{
"restrictScheduledJobs": false,
"mailing_backend": {
"outBound_option" => 0,
"smtpServer": "localhost",
"smtpPort": 1025,
"smtpAuth": FALSE
}
}
In a similar vein, it may also help to allow global $civicrm_setting
to target by environment:
## Normal usage
$civicrm_setting['domain']['backtrace'] = 1;
## Target settings per environment.
$civicrm_setting['#Development']['backtrace'] = 1;
$civicrm_setting['#Production']['backtrace'] = 0;