Pre- and post-import hook

I have been experimenting with the pre and post import hooks.

Given a solution main that contains modules before_import, after_import and methods. These problems I face:

  1. When solution main is imported in an empty application server the onOpen-method of the before_import solution is correctly called. But when this onOpen-method references something from module methods (eg. globals.doSomething()) this results in an error. This means that the new (first) version of before_import is loaded and runs but that there is no version of module methods available yet.
    Output looks something like this:
Importing main.servoy...
[info]	Import contains XML version 15 and repository version 38.
[info]	Executing pre-import hook module 'before_import'.
[info]	EXCEPTION CAUGHT!!! e: TypeError: Cannot find function doSomething.
[info]	Executing post-import hook module 'after_import'.
[info]	Import successful...
[info]	Activated solution main release 1
[info]	Activated solution methods release 1
[info]	Activated solution before_import_vision release 1
[info]	Activated solution after_import_vision release 1
  1. When solution main is imported the next time the onOpen method of the before_import solution is correctly called, but the version that is called is not the version that we are about to import, it runs the last version on the server. This is also the case for the after_import solution and the referenced (methods) solution. This means if we want the new code to be executed we have to import the same file twice!

My questions:
A. How can I execute the new version of my solutions during the import, is there another way?

B. What is the difference between the before and after import hook? The way I see it now, only time. We cannot act or react on things happening between before- and after-import and for what I have seen there is no difference in result when putting the same code in them.

C. Wouldn’t it be nice that the after_import would execute the version of the modules after the import is actually done (maybe after activation of the imported solutions)?

No one working with these hooks?

Did I come to the right conclusion that we cannot execute our new code in the before_import or after_import solution?

Hi Michel,

It’s a pretty new feature, so maybe not.
Did you file an issue in the support system?

Can someone of Servoy comment on the built behaviour of these pre and post import hooks as asked by Michel? (as it is not described in the wiki)

Regards,

Hi,

The pre- and post import hooks are to be selfcontained, thus not rely on included modules. This is indeed not made clear in the documentation (http://wiki.servoy.com/display/DOCS/maintenance).

In the next major version, the pre/post_import hooks modules will get their own SolutionType (instead of them being identified by their name prefix) and then we’ll also make sure that they cannot include modules of their own.

The difference between the pre_ and post_import hook is that when the pre_import hook gets executed, the sample_data import hasn’t ahppened yet, whereas in the post_import hook that has happened (when the rules for importing sample data are met: sample_data included in export, sample_data import flag set in import and the destination table being empty).

Hope this clarifies things,

Paul

Hi Paul,

But can you clarify then the current behaviour of running the ‘old’ / currently active solution code ?

And what will the behaviour be in the next major relase ? Hopefully it runs the code of the solution you are currently importing…

Regards,

As far as I can tell from the description Michel posted about what you guys are experiencing, the correct code is run, as far as that code is contained inside the pre/post import hook module.

Only when you call code that is part of modules included in the pre/post import hooks do you get error because of non-existent (first import) functions or the previous version of the code is executed. This is because you are calling code contained in modules, which isn’t supported.

In the next version, you’ll not be able to include modules in the pre/port import hooks, so you can only execute code that is contained in the pre/post import module itself and that already works properly now (as it should and as far as I can deduct from what Michel wrote).

Paul

Hi Paul,

Ok, thanks for the info. We’re gonna test again without global method calls in the pre and post import modules.

Regards,

pbakker:
As far as I can tell from the description Michel posted about what you guys are experiencing, the correct code is run, as far as that code is contained inside the pre/post import hook module.

Not true

michel:

  1. When solution main is imported in an empty application server the onOpen-method of the before_import solution is correctly called. […] This means that the new (first) version of before_import is loaded and runs

michel:
2. When solution main is imported the next time the onOpen method of the before_import solution is correctly called, but the version that is called is not the version that we are about to import, it runs the last version on the server. This is also the case for the after_import solution and the referenced (methods) solution. This means if we want the new code to be executed we have to import the same file twice!

So the very first import it’s okay, but all imports after it, it isn’t…

pbakker:
In the next version, you’ll not be able to include modules in the pre/port import hooks, so you can only execute code that is contained in the pre/post import module itself

I think you can leave the effort. The pre/post import hooks are not heavily used at the moment I think and won’t be used at all (except for switching maintenance mode on and off on the application server). Because in this way the pre/post import hooks will lack functionality. For instance I would like to import tables using the same methods I also use in my main solution. A true after import hook would be fine, I’m afraid we are going to switch to our old solution of this problem: do the processing the first time a user logs in after an import…

Hi Michel,

If on subsequent imports the old version of the onOpen method of the pre/post import hook fires, that is definitely a bug. Could you file a case for that in our support system?

As for the access to the (new version of the) main solution code in the post import hook: could you file a feature request for that in the support system, so we can have a look if that is achievable?

Paul

Hi Paul,
Most important for us is running the imported version of the before_import (or after_import) and not the one already present on the server. I tested this and in our setup this is definitely going wrong. I filed a case for this (324569).