Magento2的 crontab 区域负荷范围 di.xml 档案?或者这是不再使用?或 应该 它可以使用,但它不能作为 crontab 应用程序是一个bug?还是我从根本上误解了什么?

在Magento2中,"区域"功能允许您根据请求上下文加载额外的配置信息(这有点波浪形,但从某个角度来看是准确的)。

例如,Magento将 永远如此 加载以下内容 di.xml

./vendor/magento/module-tax/etc/di.xml

但只会加载以下内容 di.xml 在前端区域时

./vendor/magento/module-tax/etc/frontend/di.xml

目前尚不清楚这是否适用于 di.xml 文件的 crontab 区域。

Magento中的cron runner是一个独立于处理HTTP请求的Magento系统应用程序的Magento系统应用程序。当cron应用程序启动时,其Magento系统应用程序具有非常小的 launch

#File: vendor/magento/framework/App/Cron.php
public function launch()
{
    $this->_state->setAreaCode('crontab');
    $this->_eventManager->dispatch('default');
    $this->_response->setCode(0);
    return $this->_response;
}

你可以看到调用 setAreaCode 在哪里 crontab 区号进行设置。这确保了对配置树的请求将合并到位于模块的任何配置中。 etc/crontab 文件夹

app/etc/crontab/*.xml

然而 -- di.xml 是不同的/特殊的。因为Magento需要比Magento系统应用程序启动更早地访问对象管理器,所以对象管理器最初加载所有 etc/di.xml 调用之前的文件 setAreaCode.

HTTP 请求,Magento系统应用程序(Magento\Framework\App\Http)加载特定区域 di.xml 设置区号后的文件

#File: vendor/magento/framework/App/Http.php
public function launch()
{
    $areaCode = $this->_areaList->getCodeByFrontName($this->_request->getFrontName());
    $this->_state->setAreaCode($areaCode);
    $this->_objectManager->configure($this->_configLoader->load($areaCode));
    //...
}

自从这次呼吁 configure cron应用程序中缺少 launch 方法,它 似乎 就像 crontab 没有装货 etc/crontab/di.xml 文件。然而,有几个 etc/crontab/di.xml 文件存在。

$ find . -wholename '*crontab/di.xml'
./vendor/magento/module-captcha/etc/crontab/di.xml
./vendor/magento/module-catalog-rule-configurable/etc/crontab/di.xml

这就造成了一些关于系统的正确行为应该是什么的混乱。这里有没有人密切关注Magento2的开发,足以知道正确的系统行为是什么?

有帮助吗?

解决方案

根据核心团队的反馈,听起来当前的行为是 不是 预期的行为,在未来的版本中,crontab应用程序将加载到crontab区域的 di.xml.

许可以下: CC-BY-SA归因
scroll top