5
5
*/
6
6
namespace Magento \Sitemap \Model ;
7
7
8
+ use Exception ;
8
9
use Magento \Sitemap \Model \EmailNotification as SitemapEmail ;
9
10
use Magento \Framework \App \Config \ScopeConfigInterface ;
11
+ use Magento \Sitemap \Model \ResourceModel \Sitemap \Collection ;
10
12
use Magento \Sitemap \Model \ResourceModel \Sitemap \CollectionFactory ;
13
+ use Magento \Store \Model \App \Emulation ;
11
14
use Magento \Store \Model \ScopeInterface ;
15
+ use Magento \Framework \App \Area ;
12
16
13
17
/**
14
18
* Sitemap module observer
@@ -47,12 +51,12 @@ class Observer
47
51
/**
48
52
* Core store config
49
53
*
50
- * @var \Magento\Framework\App\Config\ ScopeConfigInterface
54
+ * @var ScopeConfigInterface
51
55
*/
52
56
private $ scopeConfig ;
53
57
54
58
/**
55
- * @var \Magento\Sitemap\Model\ResourceModel\Sitemap\ CollectionFactory
59
+ * @var CollectionFactory
56
60
*/
57
61
private $ collectionFactory ;
58
62
@@ -61,27 +65,37 @@ class Observer
61
65
*/
62
66
private $ emailNotification ;
63
67
68
+ /**
69
+ * @var Emulation
70
+ */
71
+ private $ appEmulation ;
72
+
64
73
/**
65
74
* Observer constructor.
66
75
* @param ScopeConfigInterface $scopeConfig
67
76
* @param CollectionFactory $collectionFactory
68
77
* @param EmailNotification $emailNotification
78
+ * @param Emulation $appEmulation
69
79
*/
70
80
public function __construct (
71
81
ScopeConfigInterface $ scopeConfig ,
72
82
CollectionFactory $ collectionFactory ,
73
- SitemapEmail $ emailNotification
83
+ SitemapEmail $ emailNotification ,
84
+ Emulation $ appEmulation
85
+
74
86
) {
75
87
$ this ->scopeConfig = $ scopeConfig ;
76
88
$ this ->collectionFactory = $ collectionFactory ;
77
89
$ this ->emailNotification = $ emailNotification ;
90
+ $ this ->appEmulation = $ appEmulation ;
91
+
78
92
}
79
93
80
94
/**
81
95
* Generate sitemaps
82
96
*
83
97
* @return void
84
- * @throws \ Exception
98
+ * @throws Exception
85
99
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
86
100
*/
87
101
public function scheduledGenerateSitemaps ()
@@ -101,12 +115,18 @@ public function scheduledGenerateSitemaps()
101
115
}
102
116
103
117
$ collection = $ this ->collectionFactory ->create ();
104
- /* @var $collection \Magento\Sitemap\Model\ResourceModel\Sitemap\ Collection */
118
+ /* @var $collection Collection */
105
119
foreach ($ collection as $ sitemap ) {
106
- /* @var $sitemap \Magento\Sitemap\Model\ Sitemap */
120
+ /* @var $sitemap Sitemap */
107
121
try {
122
+ $ this ->appEmulation ->startEnvironmentEmulation (
123
+ $ sitemap ->getStoreId (),
124
+ Area::AREA_FRONTEND ,
125
+ true
126
+ );
108
127
$ sitemap ->generateXml ();
109
- } catch (\Exception $ e ) {
128
+ $ this ->appEmulation ->stopEnvironmentEmulation ();
129
+ } catch (Exception $ e ) {
110
130
$ errors [] = $ e ->getMessage ();
111
131
}
112
132
}
0 commit comments