Skip to content

Commit 36e4f44

Browse files
author
Roman Lytvynenko
committed
MC-37306: Sitemap generated by cron have wrong image URL (cache path)
1 parent 40f9a4b commit 36e4f44

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

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

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
*/
66
namespace Magento\Sitemap\Model;
77

8+
use Exception;
89
use Magento\Sitemap\Model\EmailNotification as SitemapEmail;
910
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Sitemap\Model\ResourceModel\Sitemap\Collection;
1012
use Magento\Sitemap\Model\ResourceModel\Sitemap\CollectionFactory;
13+
use Magento\Store\Model\App\Emulation;
1114
use Magento\Store\Model\ScopeInterface;
15+
use Magento\Framework\App\Area;
1216

1317
/**
1418
* Sitemap module observer
@@ -47,12 +51,12 @@ class Observer
4751
/**
4852
* Core store config
4953
*
50-
* @var \Magento\Framework\App\Config\ScopeConfigInterface
54+
* @var ScopeConfigInterface
5155
*/
5256
private $scopeConfig;
5357

5458
/**
55-
* @var \Magento\Sitemap\Model\ResourceModel\Sitemap\CollectionFactory
59+
* @var CollectionFactory
5660
*/
5761
private $collectionFactory;
5862

@@ -61,27 +65,37 @@ 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
85+
7486
) {
7587
$this->scopeConfig = $scopeConfig;
7688
$this->collectionFactory = $collectionFactory;
7789
$this->emailNotification = $emailNotification;
90+
$this->appEmulation = $appEmulation;
91+
7892
}
7993

8094
/**
8195
* Generate sitemaps
8296
*
8397
* @return void
84-
* @throws \Exception
98+
* @throws Exception
8599
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
86100
*/
87101
public function scheduledGenerateSitemaps()
@@ -101,12 +115,18 @@ public function scheduledGenerateSitemaps()
101115
}
102116

103117
$collection = $this->collectionFactory->create();
104-
/* @var $collection \Magento\Sitemap\Model\ResourceModel\Sitemap\Collection */
118+
/* @var $collection Collection */
105119
foreach ($collection as $sitemap) {
106-
/* @var $sitemap \Magento\Sitemap\Model\Sitemap */
120+
/* @var $sitemap Sitemap */
107121
try {
122+
$this->appEmulation->startEnvironmentEmulation(
123+
$sitemap->getStoreId(),
124+
Area::AREA_FRONTEND,
125+
true
126+
);
108127
$sitemap->generateXml();
109-
} catch (\Exception $e) {
128+
$this->appEmulation->stopEnvironmentEmulation();
129+
} catch (Exception $e) {
110130
$errors[] = $e->getMessage();
111131
}
112132
}

0 commit comments

Comments
 (0)