Skip to content

Commit c1f6f3e

Browse files
committed
Update EnvironmentVariables PlugIn
Why these changes are being introduced: A new release (5.0.2) of the EnvironmentVariables plugin is now available from the Matomo Plugins directory. How this addresses that need: * Add the unzipped EnvironmentVariables 5.0.2 to the plugins list. Side effects of this change: None.
1 parent 640c444 commit c1f6f3e

File tree

5 files changed

+163
-0
lines changed

5 files changed

+163
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## Changelog
2+
3+
### 5.0.2 - 2024-10-21
4+
- Documentation updated to hard code config
5+
6+
### 5.0.1
7+
- Added plugin category for Marketplace
8+
9+
### 5.0.0
10+
- Compatibility with Matomo 5
11+
12+
### 4.0.1
13+
- Compatibility with PHP DI 6
14+
15+
### 4.0.0
16+
- Compatibility with Matomo 4
17+
18+
### 3.0.0
19+
* Initial version
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* Plugin Name: Environment Variables (Matomo Plugin)
4+
* Plugin URI: http://plugins.matomo.org/EnvironmentVariables
5+
* Description: Allows you to specify Matomo config in environment variables instead of the config file.
6+
* Author: Matomo
7+
* Author URI: https://matomo.org
8+
* Version: 5.0.2
9+
*/
10+
?><?php
11+
/**
12+
* Matomo - free/libre analytics platform
13+
*
14+
* @link https://matomo.org
15+
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
16+
*
17+
*/
18+
namespace Piwik\Plugins\EnvironmentVariables;
19+
20+
21+
if (defined( 'ABSPATH')
22+
&& function_exists('add_action')) {
23+
$path = '/matomo/app/core/Plugin.php';
24+
if (defined('WP_PLUGIN_DIR') && WP_PLUGIN_DIR && file_exists(WP_PLUGIN_DIR . $path)) {
25+
require_once WP_PLUGIN_DIR . $path;
26+
} elseif (defined('WPMU_PLUGIN_DIR') && WPMU_PLUGIN_DIR && file_exists(WPMU_PLUGIN_DIR . $path)) {
27+
require_once WPMU_PLUGIN_DIR . $path;
28+
} else {
29+
return;
30+
}
31+
add_action('plugins_loaded', function () {
32+
if (function_exists('matomo_add_plugin')) {
33+
matomo_add_plugin(__DIR__, __FILE__, true);
34+
}
35+
});
36+
}
37+
38+
class EnvironmentVariables extends \Piwik\Plugin
39+
{
40+
public function isTrackerPlugin()
41+
{
42+
return true;
43+
}
44+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Matomo EnvironmentVariables Plugin
2+
3+
## Description
4+
5+
Override any Matomo config with environment variables. To overwrite any setting simply specify an environment variable in the following format:
6+
7+
```
8+
MATOMO_$CATEGORY_$SETTING
9+
```
10+
11+
For example to overwrite the database username and password which is usually defined in the `config/config.ini.php` like this:
12+
13+
```ini
14+
[database]
15+
username = "root"
16+
password = "secure"
17+
```
18+
19+
using environment variables like this:
20+
21+
```bash
22+
export MATOMO_DATABASE_USERNAME=root
23+
export MATOMO_DATABASE_PASSWORD=secure
24+
```
25+
26+
### Known issues:
27+
* Configuration arrays are currently not supported, for example you cannot define which `Plugins[]` should be loaded.
28+
* 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.
29+
* 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/<pool>.conf`.
30+
* 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:
31+
```
32+
[PluginsInstalled]
33+
PluginsInstalled[] = "EnvironmentVariables"
34+
35+
[Plugins]
36+
Plugins[] = "EnvironmentVariables"
37+
```
38+
Another option is to use the following console commands during the deployment process:
39+
```
40+
./console config:set 'Plugins.Plugins[]="EnvironmentVariables"'
41+
./console config:set 'PluginsInstalled.PluginsInstalled[]="EnvironmentVariables"'
42+
```
43+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Matomo - free/libre analytics platform
4+
*
5+
* @link https://matomo.org
6+
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7+
*
8+
*/
9+
10+
return [
11+
'Piwik\Config' => \Piwik\DI::decorate(function ($previous, \Piwik\Container\Container $c) {
12+
$settings = $c->get(\Piwik\Application\Kernel\GlobalSettingsProvider::class);
13+
14+
$ini = $settings->getIniFileChain();
15+
$all = $ini->getAll();
16+
foreach ($all as $category => $settings) {
17+
$categoryEnvName = 'MATOMO_' . strtoupper($category);
18+
foreach ($settings as $settingName => $value) {
19+
$settingEnvName = $categoryEnvName . '_' .strtoupper($settingName);
20+
21+
$envValue = getenv($settingEnvName);
22+
if ($envValue !== false) {
23+
$general = $previous->$category;
24+
$general[$settingName] = $envValue;
25+
$previous->$category = $general;
26+
}
27+
}
28+
}
29+
30+
return $previous;
31+
}),
32+
];
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "EnvironmentVariables",
3+
"description": "Allows you to specify Matomo config in environment variables instead of the config file.",
4+
"version": "5.0.2",
5+
"theme": false,
6+
"require": {
7+
"matomo": ">=5.0.0-b1,<6.0.0-b1"
8+
},
9+
"authors": [
10+
{
11+
"name": "Matomo",
12+
"email": "[email protected]",
13+
"homepage": "https://matomo.org"
14+
}
15+
],
16+
"support": {
17+
"email": "",
18+
"issues": "https://github.com/matomo-org/plugin-EnvironmentVariables/issues/",
19+
"forum": "https://forum.matomo.org"
20+
},
21+
"homepage": "https://matomo.org",
22+
"license": "GPL v3+",
23+
"keywords": ["php", "environment", "variables", "configuration"],
24+
"category": "database"
25+
}

0 commit comments

Comments
 (0)