Set.php
57 lines
| 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 | namespace Piwik\Updater\Migration\Config; |
| 9 | |
| 10 | use Piwik\Config; |
| 11 | use Piwik\Updater\Migration; |
| 12 | |
| 13 | /** |
| 14 | * Sets the given configuration to Matomo config value |
| 15 | */ |
| 16 | class Set extends Migration |
| 17 | { |
| 18 | /** |
| 19 | * @var string |
| 20 | */ |
| 21 | private $section; |
| 22 | |
| 23 | /** |
| 24 | * @var string |
| 25 | */ |
| 26 | private $key; |
| 27 | |
| 28 | /** |
| 29 | * @var string |
| 30 | */ |
| 31 | private $value; |
| 32 | |
| 33 | |
| 34 | public function __construct($section, $key, $value) |
| 35 | { |
| 36 | $this->section = $section; |
| 37 | $this->key = $key; |
| 38 | $this->value = $value; |
| 39 | } |
| 40 | |
| 41 | public function __toString() |
| 42 | { |
| 43 | $domain = Config::getLocalConfigPath() == Config::getDefaultLocalConfigPath() ? '' : Config::getHostname(); |
| 44 | $domainArg = !empty($domain) ? "--matomo-domain=\"$domain\" " : ''; |
| 45 | |
| 46 | return sprintf('./console %sconfig:set --section="%s" --key="%s" --value="%s"', $domainArg, $this->section, $this->key, $this->value); |
| 47 | } |
| 48 | |
| 49 | public function exec() |
| 50 | { |
| 51 | $config = Config::getInstance(); |
| 52 | $config->{$this->section}[$this->key] = $this->value; |
| 53 | $config->forceSave(); |
| 54 | } |
| 55 | |
| 56 | } |
| 57 |