diff --git a/CHANGELOG.md b/CHANGELOG.md index f57c866..91efeeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Changelog +### 5.0.4 - 2026-10-19 +- Support list configuration values via JSON arrays, e.g. for `trusted_hosts` via `MATOMO_GENERAL_TRUSTED_HOSTS=["example.com","example.net"]` + ### 5.0.3 - 2025-01-20 - Added missing license file diff --git a/README.md b/README.md index 0eea0a4..4e97c65 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## Description -Override any Matomo config with environment variables. To overwrite any setting simply specify an environment variable in the following format: +Override any Matomo config with environment variables. To overwrite any setting, specify an environment variable in the following format: ``` MATOMO_$CATEGORY_$SETTING @@ -23,8 +23,16 @@ export MATOMO_DATABASE_USERNAME=root export MATOMO_DATABASE_PASSWORD=secure ``` +List values can be set via encoded JSON arrays: + +```bash +export MATOMO_GENERAL_TRUSTED_HOSTS='["1.2.3.4","5.6.7.8"]' +``` + +JSON objects are decoded too, into keyed arrays. Any other value, including JSON that fails to decode, is used literally. + ### Known issues: -* Configuration arrays are currently not supported, for example you cannot define which `Plugins[]` should be loaded. + * At some point your Matomo may save/write the config file, for example when changing certain settings through the UI such as the trusted hosts. In this case, the currently read environment variables will be saved in the config file. * If this plugin is used with PHP-FPM, for example in combination with NGINX, PHP-FPM will not have access to the environment variables by default. The pool used by PHP-FPM must either explicit define which ENVs should be exposed, or set `clear_env = no` in `/etc/php7/php-fpm.f/.conf`. * When defining the database credentials as environment variables, you may have to hard code the configs indicating that this plugin is activated, like the following: diff --git a/config/config.php b/config/config.php index 413df30..fa75e9d 100644 --- a/config/config.php +++ b/config/config.php @@ -1,4 +1,5 @@ $settings) { $categoryEnvName = 'MATOMO_' . strtoupper($category); foreach ($settings as $settingName => $value) { - $settingEnvName = $categoryEnvName . '_' .strtoupper($settingName); + $settingEnvName = $categoryEnvName . '_' . strtoupper($settingName); $envValue = getenv($settingEnvName); if ($envValue !== false) { + $decodedEnvValue = json_decode($envValue, true); + $settingValue = is_array($decodedEnvValue) ? $decodedEnvValue : $envValue; + $general = $previous->$category; - $general[$settingName] = $envValue; + $general[$settingName] = $settingValue; $previous->$category = $general; } } @@ -29,4 +33,4 @@ return $previous; }), -]; \ No newline at end of file +]; diff --git a/plugin.json b/plugin.json index b9b146a..7ddbcce 100644 --- a/plugin.json +++ b/plugin.json @@ -1,7 +1,7 @@ { "name": "EnvironmentVariables", "description": "Allows you to specify Matomo config in environment variables instead of the config file.", - "version": "5.0.3", + "version": "5.0.4", "theme": false, "require": { "matomo": ">=5.0.0-b1,<6.0.0-b1"