Skip to content

Commit b9fe38f

Browse files
authored
Merge pull request #20 from MITLibraries/update-to-5.1.2
Update to 5.1.2
2 parents 640c444 + 8cf4360 commit b9fe38f

File tree

7 files changed

+166
-3
lines changed

7 files changed

+166
-3
lines changed

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
FROM matomo:5.1.1
1+
FROM matomo:5.1.2
22

33
# Add the EnvironmentVariables plugin
4-
COPY ./files/plugin-EnvironmentVariables-5.0.0/ /var/www/html/plugins/EnvironmentVariables
4+
COPY ./files/plugin-EnvironmentVariables-5.0.2/ /var/www/html/plugins/EnvironmentVariables
55

66
# Add the CustomVariables plugin
77
COPY ./files/plugin-CustomVariables-5.0.2/ /var/www/html/plugins/CustomVariables

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Merge a PR to `main` to build, tag, and push the container to Stage-Workloads. A
2424

2525
## Implementation notes
2626

27-
For detailed instructions on initial setup, migration, database upgrades, and application upgrades, see [docs/HOWTO.md](./docs/HOWTO.md).
27+
For detailed instructions on initial setup, migration, database upgrades, and application upgrades, check the [HowTos](./docs/HowTos/) folder.
2828

2929
### Configuration Management
3030

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
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+
}
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+
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+
];
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)