Tomas,
The problem is indeed calling importToTarget in a custom Command's execute event handler. The issue is that a very small number of API functions are implemented by executing an existing command, and importToTarget is one of those. Executing a command during the execute event handler (or really any event handler) of another command will cause a problem. Starting the new command will attempt to suspend/end the current custom command, but it is blocked in the event. (In this case, it is trying to commit the current step transaction of the current command by 'executing' it, which causes another invoke of your execute, in which you call importToTarget again. Eventually this infinite recursion will blow the stack.)
I created issue FUS-97456 for this. But the immediate 'fix' would most likely be to increase the error handling around this case and cause nested command based APIs like importToTarget to fail in a more controlled manner. E.g. with an error like 'not allowed during command events'.
So unfortunately, you will currently need to perform the importToTarget outside of the Command. You could fire a CustomEvent to your application from the end of your Command.execute to perform the importToTarget and the remainder of the command logic outside of the command. (I understand that this means you lose the transaction boundary that the command was providing.)
Kris
Kris Kaplan