Skip to content

Commit 9601e69

Browse files
committed
Load translations for cron area, fixes #8412
1 parent 1e9377a commit 9601e69

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

lib/internal/Magento/Framework/App/Cron.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
namespace Magento\Framework\App;
99

1010
use Magento\Framework\App;
11-
use Magento\Framework\App\Area;
1211
use Magento\Framework\ObjectManagerInterface;
1312

13+
/**
14+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
15+
*/
1416
class Cron implements \Magento\Framework\AppInterface
1517
{
1618
/**
@@ -35,6 +37,11 @@ class Cron implements \Magento\Framework\AppInterface
3537
*/
3638
private $objectManager;
3739

40+
/**
41+
* @var \Magento\Framework\App\AreaList
42+
*/
43+
private $areaList;
44+
3845
/**
3946
* Inject dependencies
4047
*
@@ -69,13 +76,29 @@ public function launch()
6976
$configLoader = $this->objectManager->get(\Magento\Framework\ObjectManager\ConfigLoaderInterface::class);
7077
$this->objectManager->configure($configLoader->load(Area::AREA_CRONTAB));
7178

79+
$areaList = $this->getAreaList();
80+
$areaList->getArea(Area::AREA_CRONTAB)->load(Area::PART_TRANSLATE);
81+
7282
/** @var \Magento\Framework\Event\ManagerInterface $eventManager */
7383
$eventManager = $this->objectManager->get(\Magento\Framework\Event\ManagerInterface::class);
7484
$eventManager->dispatch('default');
7585
$this->_response->setCode(0);
7686
return $this->_response;
7787
}
7888

89+
/**
90+
* @deprecated
91+
*
92+
* @return \Magento\Framework\App\AreaList
93+
*/
94+
private function getAreaList()
95+
{
96+
if ($this->areaList === null) {
97+
$this->areaList = $this->objectManager->get(\Magento\Framework\App\AreaList::class);
98+
}
99+
return $this->areaList;
100+
}
101+
79102
/**
80103
* {@inheritdoc}
81104
*/

lib/internal/Magento/Framework/App/Test/Unit/CronTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,24 @@ public function testLaunchDispatchesCronEvent()
5353
{
5454
$configLoader = $this->getMockForAbstractClass(\Magento\Framework\ObjectManager\ConfigLoaderInterface::class);
5555
$eventManagerMock = $this->getMock(\Magento\Framework\Event\ManagerInterface::class);
56+
57+
$areaMock = $this->getMock(\Magento\Framework\App\Area::class, [], [], '', false);
58+
$areaMock->expects($this->once())
59+
->method('load')
60+
->with(Area::PART_TRANSLATE);
61+
62+
$areaListMock = $this->getMock(\Magento\Framework\App\AreaList::class, [], [], '', false);
63+
$areaListMock->expects($this->any())
64+
->method('getArea')
65+
->with(Area::AREA_CRONTAB)
66+
->willReturn($areaMock);
67+
5668
$this->objectManager->expects($this->any())
5769
->method('get')
5870
->will($this->returnValueMap([
5971
[\Magento\Framework\ObjectManager\ConfigLoaderInterface::class, $configLoader],
6072
[\Magento\Framework\Event\ManagerInterface::class, $eventManagerMock],
73+
[\Magento\Framework\App\AreaList::class, $areaListMock]
6174
]));
6275
$crontabConfig = ['config'];
6376
$configLoader->expects($this->once())

0 commit comments

Comments
 (0)