grav icon indicating copy to clipboard operation
grav copied to clipboard

Plugin::saveConfig stores config into wrong folder

Open ViliusS opened this issue 2 years ago • 7 comments

I'm trying to remove/rename old legacy configuration data from plugin's user configuration. However, if I try to use saveConfig('pluginname') it stores rewritten configuration into /user/environment.domain.name/config/plugins/pluginname.yaml instead of /user/config/plugins/pluginname.yaml

Is this a bug? Maybe there are better ways to remove/rename legacy configuration between plugin versions? I'm using the following code:

    private function onPluginsInitialized()
    {
        // 1.x => 2.0
        // Field "async" removed
        $async = $this->config->get('plugins.pluginname.async');
        if (!is_null($async)) {
            $settings = $this->config();
            unset($settings['async']);
            $this->config->set('plugins.pluginname', $settings);
            $this->saveConfig('pluginname');
        }
    }

Maybe I'm missing something in the plugin itself? I've got it inherited and I believe it was written for Grav 1.5. I've already added type and slug into the blueprint, but this didn't help either.

ViliusS avatar Mar 11 '23 21:03 ViliusS

UPDATE: looks like it is a bug. When calling findResource here the locator returns /gravpath/user/environment.domain.name/config/plugins/pluginname.yaml. If i change last findResource parameter to false, it returns good path, however I have no idea how interpret that. Rockettheme resource locator code is a total mistery to me.

ViliusS avatar Mar 11 '23 22:03 ViliusS

But if there is a folder for separate env, this folder should be resolved. Why doo you say it's a bug? For me it looks like the correct behavior 🤔

Karmalakas avatar Mar 13 '23 05:03 Karmalakas

I don't have multi-site or environments configured in my Grav instance. All configuration lives under /user/config and this is where it is read from when calling $this->grav['config']. So I expect it to be saved to the same place.

ViliusS avatar Mar 13 '23 05:03 ViliusS

Is there a better place to fill such bug issues? This one really blocks the release of the plugin.

ViliusS avatar Apr 12 '23 19:04 ViliusS

Related: #3497 and there are a few more near-duplicates. Like @Karmalakas, I'm not sure about "wrong" either but I would value the choice (well, my Admin user clients would). Plugins like custom-css become useless in the multi-environment setup I have. Would it be difficult set up a simple toggle near the save button? This discussion is probably more appropriate in the Admin repo issues.

hughbris avatar Jun 30 '23 04:06 hughbris

@hughbris but I don't use multi-environment setup. All my plugins live under /user/config/plugins. And saving actually works correctly from Admin UI, it's just Plugin::saveConfig which doesn't follow this behaviour. Or is there another way to actually check if set configuration somewhere but just don't know about?

ViliusS avatar Jun 30 '23 04:06 ViliusS

@hughbris but I don't use multi-environment setup

I knew that. From what I can tell, Grav developers use several kinds of setup that hopefully all enjoy good support.

I think I conflated your issue with something similar I noticed in Admin, though they may stem from the same backend limitation. My comment should have gone in Admin.

Or is there another way to actually check if set configuration somewhere but just don't know about?

Sorry I don't know.

hughbris avatar Jul 01 '23 00:07 hughbris