-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from MITLibraries/update-to-5.1.2
Update to 5.1.2
- Loading branch information
Showing
7 changed files
with
166 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
## Changelog | ||
|
||
### 5.0.2 - 2024-10-21 | ||
- Documentation updated to hard code config | ||
|
||
### 5.0.1 | ||
- Added plugin category for Marketplace | ||
|
||
### 5.0.0 | ||
- Compatibility with Matomo 5 | ||
|
||
### 4.0.1 | ||
- Compatibility with PHP DI 6 | ||
|
||
### 4.0.0 | ||
- Compatibility with Matomo 4 | ||
|
||
### 3.0.0 | ||
* Initial version |
44 changes: 44 additions & 0 deletions
44
files/plugin-EnvironmentVariables-5.0.2/EnvironmentVariables.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
/** | ||
* Plugin Name: Environment Variables (Matomo Plugin) | ||
* Plugin URI: http://plugins.matomo.org/EnvironmentVariables | ||
* Description: Allows you to specify Matomo config in environment variables instead of the config file. | ||
* Author: Matomo | ||
* Author URI: https://matomo.org | ||
* Version: 5.0.2 | ||
*/ | ||
?><?php | ||
/** | ||
* Matomo - free/libre analytics platform | ||
* | ||
* @link https://matomo.org | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
* | ||
*/ | ||
namespace Piwik\Plugins\EnvironmentVariables; | ||
|
||
|
||
if (defined( 'ABSPATH') | ||
&& function_exists('add_action')) { | ||
$path = '/matomo/app/core/Plugin.php'; | ||
if (defined('WP_PLUGIN_DIR') && WP_PLUGIN_DIR && file_exists(WP_PLUGIN_DIR . $path)) { | ||
require_once WP_PLUGIN_DIR . $path; | ||
} elseif (defined('WPMU_PLUGIN_DIR') && WPMU_PLUGIN_DIR && file_exists(WPMU_PLUGIN_DIR . $path)) { | ||
require_once WPMU_PLUGIN_DIR . $path; | ||
} else { | ||
return; | ||
} | ||
add_action('plugins_loaded', function () { | ||
if (function_exists('matomo_add_plugin')) { | ||
matomo_add_plugin(__DIR__, __FILE__, true); | ||
} | ||
}); | ||
} | ||
|
||
class EnvironmentVariables extends \Piwik\Plugin | ||
{ | ||
public function isTrackerPlugin() | ||
{ | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Matomo EnvironmentVariables Plugin | ||
|
||
## Description | ||
|
||
Override any Matomo config with environment variables. To overwrite any setting simply specify an environment variable in the following format: | ||
|
||
``` | ||
MATOMO_$CATEGORY_$SETTING | ||
``` | ||
|
||
For example to overwrite the database username and password which is usually defined in the `config/config.ini.php` like this: | ||
|
||
```ini | ||
[database] | ||
username = "root" | ||
password = "secure" | ||
``` | ||
|
||
using environment variables like this: | ||
|
||
```bash | ||
export MATOMO_DATABASE_USERNAME=root | ||
export MATOMO_DATABASE_PASSWORD=secure | ||
``` | ||
|
||
### 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/<pool>.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: | ||
``` | ||
[PluginsInstalled] | ||
PluginsInstalled[] = "EnvironmentVariables" | ||
[Plugins] | ||
Plugins[] = "EnvironmentVariables" | ||
``` | ||
Another option is to use the following console commands during the deployment process: | ||
``` | ||
./console config:set 'Plugins.Plugins[]="EnvironmentVariables"' | ||
./console config:set 'PluginsInstalled.PluginsInstalled[]="EnvironmentVariables"' | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
/** | ||
* Matomo - free/libre analytics platform | ||
* | ||
* @link https://matomo.org | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
* | ||
*/ | ||
|
||
return [ | ||
'Piwik\Config' => \Piwik\DI::decorate(function ($previous, \Piwik\Container\Container $c) { | ||
$settings = $c->get(\Piwik\Application\Kernel\GlobalSettingsProvider::class); | ||
|
||
$ini = $settings->getIniFileChain(); | ||
$all = $ini->getAll(); | ||
foreach ($all as $category => $settings) { | ||
$categoryEnvName = 'MATOMO_' . strtoupper($category); | ||
foreach ($settings as $settingName => $value) { | ||
$settingEnvName = $categoryEnvName . '_' .strtoupper($settingName); | ||
|
||
$envValue = getenv($settingEnvName); | ||
if ($envValue !== false) { | ||
$general = $previous->$category; | ||
$general[$settingName] = $envValue; | ||
$previous->$category = $general; | ||
} | ||
} | ||
} | ||
|
||
return $previous; | ||
}), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "EnvironmentVariables", | ||
"description": "Allows you to specify Matomo config in environment variables instead of the config file.", | ||
"version": "5.0.2", | ||
"theme": false, | ||
"require": { | ||
"matomo": ">=5.0.0-b1,<6.0.0-b1" | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Matomo", | ||
"email": "[email protected]", | ||
"homepage": "https://matomo.org" | ||
} | ||
], | ||
"support": { | ||
"email": "", | ||
"issues": "https://github.com/matomo-org/plugin-EnvironmentVariables/issues/", | ||
"forum": "https://forum.matomo.org" | ||
}, | ||
"homepage": "https://matomo.org", | ||
"license": "GPL v3+", | ||
"keywords": ["php", "environment", "variables", "configuration"], | ||
"category": "database" | ||
} |