Skip to content

Commit c56eb37

Browse files
committed
MAGETWO-2745: added appEmulation to the obserber
1 parent 715d9de commit c56eb37

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

app/code/Magento/Sitemap/Model/Observer.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Sitemap\Model;
79

8-
use Magento\Sitemap\Model\EmailNotification as SitemapEmail;
10+
use Magento\Framework\App\Area;
911
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Sitemap\Model\EmailNotification as SitemapEmail;
1013
use Magento\Sitemap\Model\ResourceModel\Sitemap\CollectionFactory;
14+
use Magento\Store\Model\App\Emulation;
1115
use Magento\Store\Model\ScopeInterface;
1216

1317
/**
@@ -61,20 +65,28 @@ class Observer
6165
*/
6266
private $emailNotification;
6367

68+
/**
69+
* @var Emulation
70+
*/
71+
private $appEmulation;
72+
6473
/**
6574
* Observer constructor.
6675
* @param ScopeConfigInterface $scopeConfig
6776
* @param CollectionFactory $collectionFactory
6877
* @param EmailNotification $emailNotification
78+
* @param Emulation $appEmulation
6979
*/
7080
public function __construct(
7181
ScopeConfigInterface $scopeConfig,
7282
CollectionFactory $collectionFactory,
73-
SitemapEmail $emailNotification
83+
SitemapEmail $emailNotification,
84+
Emulation $appEmulation
7485
) {
7586
$this->scopeConfig = $scopeConfig;
7687
$this->collectionFactory = $collectionFactory;
7788
$this->emailNotification = $emailNotification;
89+
$this->appEmulation = $appEmulation;
7890
}
7991

8092
/**
@@ -105,7 +117,13 @@ public function scheduledGenerateSitemaps()
105117
foreach ($collection as $sitemap) {
106118
/* @var $sitemap \Magento\Sitemap\Model\Sitemap */
107119
try {
120+
$this->appEmulation->startEnvironmentEmulation(
121+
$sitemap->getStoreId(),
122+
Area::AREA_FRONTEND,
123+
true
124+
);
108125
$sitemap->generateXml();
126+
$this->appEmulation->stopEnvironmentEmulation();
109127
} catch (\Exception $e) {
110128
$errors[] = $e->getMessage();
111129
}

0 commit comments

Comments
 (0)