6
6
namespace Magento \Sitemap \Model ;
7
7
8
8
use Magento \Store \Model \App \Emulation ;
9
+ use Magento \Sitemap \Model \SitemapSendEmail as SitemapEmail ;
10
+ use Magento \Store \Model \StoreManagerInterface ;
11
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
12
+ use ResourceModel \Sitemap \CollectionFactory ;
13
+ use Magento \Store \Model \ScopeInterface ;
9
14
10
15
/**
11
16
* Sitemap module observer
@@ -26,21 +31,6 @@ class Observer
26
31
*/
27
32
const XML_PATH_CRON_EXPR = 'crontab/default/jobs/generate_sitemaps/schedule/cron_expr ' ;
28
33
29
- /**
30
- * Error email template configuration
31
- */
32
- const XML_PATH_ERROR_TEMPLATE = 'sitemap/generate/error_email_template ' ;
33
-
34
- /**
35
- * Error email identity configuration
36
- */
37
- const XML_PATH_ERROR_IDENTITY = 'sitemap/generate/error_email_identity ' ;
38
-
39
- /**
40
- * 'Send error emails to' configuration
41
- */
42
- const XML_PATH_ERROR_RECIPIENT = 'sitemap/generate/error_email ' ;
43
-
44
34
/**
45
35
* Core store config
46
36
*
@@ -53,49 +43,41 @@ class Observer
53
43
*/
54
44
protected $ _collectionFactory ;
55
45
56
- /**
57
- * @var \Magento\Framework\Mail\Template\TransportBuilder
58
- */
59
- protected $ _transportBuilder ;
60
-
61
46
/**
62
47
* @var \Magento\Store\Model\StoreManagerInterface
63
48
*/
64
49
protected $ _storeManager ;
65
50
66
51
/**
67
- * @var \Magento\Framework\Translate\Inline\StateInterface
52
+ * @var Emulation
68
53
*/
69
- protected $ inlineTranslation ;
54
+ private $ appEmulation ;
70
55
71
56
/**
72
- * @var \Magento\Store\Model\App\Emulation $appEmulation
57
+ * @var $sitemapEmail
73
58
*/
74
- private $ appEmulation ;
59
+ private $ sitemapEmail ;
75
60
76
61
/**
77
62
* Observer constructor.
78
- * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
79
- * @param ResourceModel\Sitemap\CollectionFactory $collectionFactory
80
- * @param \Magento\Store\Model\StoreManagerInterface $storeManager
81
- * @param \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder
82
- * @param \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation
83
- * @param Emulation|null $appEmulation
63
+ * @param ScopeConfigInterface $scopeConfig
64
+ * @param CollectionFactory $collectionFactory
65
+ * @param StoreManagerInterface $storeManager
66
+ * @param SitemapSendEmail $sitemapEmail
67
+ * @param Emulation $appEmulation
84
68
*/
85
69
public function __construct (
86
- \Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig ,
87
- ResourceModel \Sitemap \CollectionFactory $ collectionFactory ,
88
- \Magento \Store \Model \StoreManagerInterface $ storeManager ,
89
- \Magento \Framework \Mail \Template \TransportBuilder $ transportBuilder ,
90
- \Magento \Framework \Translate \Inline \StateInterface $ inlineTranslation ,
70
+ ScopeConfigInterface $ scopeConfig ,
71
+ CollectionFactory $ collectionFactory ,
72
+ StoreManagerInterface $ storeManager ,
73
+ SitemapEmail $ sitemapEmail ,
91
74
Emulation $ appEmulation
92
75
) {
93
76
$ this ->_scopeConfig = $ scopeConfig ;
94
77
$ this ->_collectionFactory = $ collectionFactory ;
95
78
$ this ->_storeManager = $ storeManager ;
96
- $ this ->_transportBuilder = $ transportBuilder ;
97
- $ this ->inlineTranslation = $ inlineTranslation ;
98
79
$ this ->appEmulation = $ appEmulation ;
80
+ $ this ->sitemapEmail = $ sitemapEmail ;
99
81
}
100
82
101
83
/**
@@ -112,7 +94,7 @@ public function scheduledGenerateSitemaps()
112
94
// check if scheduled generation enabled
113
95
if (!$ this ->_scopeConfig ->isSetFlag (
114
96
self ::XML_PATH_GENERATION_ENABLED ,
115
- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE
97
+ ScopeInterface::SCOPE_STORE
116
98
)
117
99
) {
118
100
return ;
@@ -125,52 +107,18 @@ public function scheduledGenerateSitemaps()
125
107
try {
126
108
$ this ->appEmulation ->startEnvironmentEmulation (
127
109
$ sitemap ->getStoreId (),
128
- ' frontend ' ,
110
+ \ Magento \ Framework \ App \Area:: AREA_FRONTEND ,
129
111
true
130
112
);
131
113
132
114
$ sitemap ->generateXml ();
133
115
} catch (\Exception $ e ) {
134
116
$ errors [] = $ e ->getMessage ();
117
+
118
+ $ this ->sitemapEmail ->sendErrorEmail ($ errors );
135
119
} finally {
136
120
$ this ->appEmulation ->stopEnvironmentEmulation ();
137
121
}
138
122
}
139
-
140
- if ($ errors && $ this ->_scopeConfig ->getValue (
141
- self ::XML_PATH_ERROR_RECIPIENT ,
142
- \Magento \Store \Model \ScopeInterface::SCOPE_STORE
143
- )
144
- ) {
145
- $ this ->inlineTranslation ->suspend ();
146
-
147
- $ this ->_transportBuilder ->setTemplateIdentifier (
148
- $ this ->_scopeConfig ->getValue (
149
- self ::XML_PATH_ERROR_TEMPLATE ,
150
- \Magento \Store \Model \ScopeInterface::SCOPE_STORE
151
- )
152
- )->setTemplateOptions (
153
- [
154
- 'area ' => \Magento \Backend \App \Area \FrontNameResolver::AREA_CODE ,
155
- 'store ' => \Magento \Store \Model \Store::DEFAULT_STORE_ID ,
156
- ]
157
- )->setTemplateVars (
158
- ['warnings ' => join ("\n" , $ errors )]
159
- )->setFrom (
160
- $ this ->_scopeConfig ->getValue (
161
- self ::XML_PATH_ERROR_IDENTITY ,
162
- \Magento \Store \Model \ScopeInterface::SCOPE_STORE
163
- )
164
- )->addTo (
165
- $ this ->_scopeConfig ->getValue (
166
- self ::XML_PATH_ERROR_RECIPIENT ,
167
- \Magento \Store \Model \ScopeInterface::SCOPE_STORE
168
- )
169
- );
170
- $ transport = $ this ->_transportBuilder ->getTransport ();
171
- $ transport ->sendMessage ();
172
-
173
- $ this ->inlineTranslation ->resume ();
174
- }
175
123
}
176
124
}
0 commit comments