Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No config reload on save #14824

Merged
merged 1 commit into from Sep 21, 2019
Merged

No config reload on save #14824

merged 1 commit into from Sep 21, 2019

Conversation

tsteur
Copy link
Member

@tsteur tsteur commented Aug 28, 2019

Found an interesting issue today re config... when the config is saved, we reload the config afterwards in https://github.com/matomo-org/matomo/blob/3.12.0-b2/core/Config.php#L447

The problem is, that any plugins/*/config/config.php or config/config.php that is changing the config using DI is then ignored when reloading the config. Looks like something like this:

'Piwik\Config' => DI\decorate(function ($previous) {
        $general = $previous->General;
        $general['force_ssl'] = 1;
        $previous->General = $general;

        return $previous;
    }),

We're using this quite intensively in various places. I wonder in that case how to best re-initialise the config to make sure DI is executed again. Like removing it from DI, and then initialising it again using DI... would that work somehow? Problem is that maybe there could be still outdated references to the old config instance... I wonder maybe by default we should not reload the config simply? Not sure why we do it. It was likely not really an issue before since it would have simply saved all changes in Config to the local config and then reloaded it again.

However, in a new plugin I will have an event to not save some config parameters to the config file. I will have an event postEvent('Config.beforeSave', array(&$config)) where I then do something like unset($config['General']['force_ssl']) to avoid saving some values in the config. Eg to not save DB credentials in the config etc.

Found an interesting issue today re config... when the config is saved, we reload the config afterwards in https://github.com/matomo-org/matomo/blob/3.12.0-b2/core/Config.php#L447 

The problem is, that any `plugins/*/config/config.php` or `config/config.php` that is changing the config using DI is then ignored when reloading the config. Looks like something like this:

```
'Piwik\Config' => DI\decorate(function ($previous) {
        $general = $previous->General;
        $general['force_ssl'] = 1;
        $previous->General = $general;

        return $previous;
    }),
```

We're using this quite intensively in various places. I wonder in that case how to best re-initialise the config to make sure DI is executed again. Like removing it from DI, and then initialising it again using DI... would that work somehow? Problem is that maybe there could be still outdated references to the old config instance... I wonder maybe by default we should not reload the config simply? Not sure why we do it. It was likely not really an issue before since it would have simply saved all changes in `Config` to the local config and then reloaded it again.

However, in a new plugin I will have an event to not save some config parameters to the config file. I will have an event `postEvent('Config.beforeSave', array(&$config))` where I then do something like `unset($config['General']['force_ssl'])` to avoid saving some values in the config. Eg to not save DB credentials in the config etc.
@tsteur tsteur added the Needs Review PRs that need a code review label Aug 28, 2019
@tsteur tsteur added this to the 3.12.0 milestone Aug 28, 2019
@diosmosis
Copy link
Member

It's kind of a hack, but for DI we might be able to make use of make(), for example:

$newConfig = StaticContainer::getContainer()->make();
StaticContainer::getContainer()->set(Config::class, $newConfig);

I haven't tested it, but I think it might work.

@tsteur
Copy link
Member Author

tsteur commented Sep 20, 2019

@diosmosis I figured there's actually no reason the reload the config at all. It maybe used to be needed when there were a lot of references used but we removed the references a while ago before encoding the config values so it simply should not be needed anymore.

@diosmosis diosmosis merged commit f3dc40b into 3.x-dev Sep 21, 2019
@diosmosis diosmosis deleted the configreloadsave branch September 21, 2019 01:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants