Migrating extension's config

  • Hello everybody,

    some of my extensions - the first two or three - are not yet using namespaced extension names.

    I would like to change this. It shouldn't be a problem:

    1. 'updates' => [
    2. '1.0.1' => function ($app) {
    3. $app['config']->set('spqr/extension', $app->config('extension')->toArray());
    4. $app['config']->remove('extension');
    5. }
    6. ],

    But unfortunately, I'm getting this error:

    1. [Extension exception]: Undefined module: extension

    The extension works after the upgrade, but the old config is lost.

    Hm, so it seems that update is executed before Pagekit knows about the new extension name.

    Any ideas how to solve this?

  • Is this the same for all extensions or only for some?

    You can try to debug it if possible to see in which line it exactly fails and what is the content of the config at this moment. Maybe there is a trivial reason for this (spelling etc.).

  • Well - most of my extensions are already namespaced. So this does only affect 2 extensions.

    But the problem occurs on all two.

    Pagekit does not „know“ that the extension got renamed and can not save the old config to spqr/extension.

    Hm, I will dig a bit deeper :)

  • I cannot debug at the moment, but I think the issue is different. From what I see in the coding, pagekit tries to load the extension module which is not available anymore. This then throws the error.

    The config itself is kind of stupid and only handles values in a database. The config does not care about the renaming.

    What I assume happens:

    1. During startup, pagekit registers all extensions for which a config exists: https://github.com/pagekit/pag…38/app/system/app.php#L12
    2. This then adds the extensions to an internal array in the ModuleManager: https://github.com/pagekit/pag…le/ModuleManager.php#L137
    3. Then the system module is loaded: https://github.com/pagekit/pag…op/app/system/app.php#L22
    4. During loading of the system module, also all other extensions are loaded based on the config: https://github.com/pagekit/pag…/src/SystemModule.php#L55
    5. During loading of the extension module it is recognized that this module does not exist anymore and the error is thrown: https://github.com/pagekit/pag…le/ModuleManager.php#L105
    6. This then is logged: https://github.com/pagekit/pag…/src/SystemModule.php#L58

    So, this should not have an influence on the behavior of the update. The issue seems to be somewhere else. I assume it is during the upgrade process of the extension that something is not working properly.

  • Hm,

    I am still not successful.

    I did the following in the module's main function:

    1.         dump(App::config('exitintent'));
    2.     dump(App::config()->set('spqr/exitintent', App::config('exitintent')) );
    3.     dump(App::config('spqr/exitintent'));

    This is the result:

    1. Config {#435 ▼ #values: array:8 [▶] #dirty: false
    2. }
    1. null
    1. Config {#435 ▼ #values: array:8 [▶] #dirty: false
    2. }

    The config has been moved successfully.

    If I do the same in the update-process, it's still not migrated.

    I need a bit more time to get xdebug working with PHPStorm - maybe one or two of you guys have an idea in-between.

    • Helpful

    It is a bug :/

    I did some more debugging. During the update process the update scripts are never called. This is due to the name change of the function.

    Clicking on update (or install) calls admin/system/package/install , this is mapped to the installAction of the PackageController located in app/installer/src/Controller. This step then calls the install function of the PackageManager. There it is checked whether a module with the same name is already loaded. As your module changed it's name, only the old module is loaded and to the system it seems that your module is completely new. Thus, the update functions are not called.

    The question now is whether it is possible to solve this, as for the system there is no relation between your old package and the new one. If it is only about the config, this is not that bad, but as soon as you have also other update scripts, they are also not called. The only thing which will be called are the install scripts, so as long as there is no solution in pagekit itself it is at least possible to hack into them. But I don't know about side effects if you create tables etc. So might be that you will face further issues if you change the name and create your own tables.

    Code responsible for this:

    1.         foreach ($install as $name => $version) {
    2. if (isset($packages[$name]) && App::module($packages[$name]->get('module'))) {
    3. $this->enable($packages[$name]);
    4. } elseif (isset($packages[$name])) {
    5. $this->doInstall($packages[$name]);
    6. }
    7. }
  • Solved it this way. But it's not really elegant ;)