Shopware 6 在计划任务中获取上下文

Shopware 6 get context in scheduled task

我只是想知道如何在计划任务中获取上下文。有静态方法

Context::createDefaultContext()

但它被标记为内部。我知道不应该创建上下文,而是从更高的服务传递给您的服务。但这在计划任务中似乎是不可能的。

我想我在 GitHub 问题评论中找到了答案:https://github.com/shopware/platform/issues/1245#issuecomment-673537348

The only valid use case to create a default context is when you are in a CLI context, meaning when you write your own CLI command (or scheduled task in that regard). But you should be fully aware that you need to take care of handling translations and currency for example by yourself in that case.

Another valid use case for the default context is the usage in tests of course, that was the original intent behind that method. In the docs the method is used to not bloat the code examples.

所以这似乎是在计划任务中创建上下文的方法。