3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types = 1 );
6
7
7
8
namespace Magento \Sitemap \Model ;
8
9
11
12
use Magento \Framework \Mail \Template \TransportBuilder ;
12
13
use Magento \Store \Model \ScopeInterface ;
13
14
use Magento \Backend \App \Area \FrontNameResolver ;
14
- use Magento \Store \Model \Store ;
15
+ use Magento \Sitemap \Model \Observer as Observer ;
16
+ use Psr \Log \LoggerInterface ;
15
17
16
18
/**
17
19
* Sends emails for the scheduled generation of the sitemap file
18
20
*/
19
- class SitemapSendEmail
21
+ class EmailNotification
20
22
{
21
- /**
22
- * Error email template configuration
23
- */
24
- const XML_PATH_ERROR_TEMPLATE = 'sitemap/generate/error_email_template ' ;
25
-
26
- /**
27
- * Error email identity configuration
28
- */
29
- const XML_PATH_ERROR_IDENTITY = 'sitemap/generate/error_email_identity ' ;
30
-
31
- /**
32
- * 'Send error emails to' configuration
33
- */
34
- const XML_PATH_ERROR_RECIPIENT = 'sitemap/generate/error_email ' ;
35
-
36
23
/**
37
24
* @var \Magento\Framework\Translate\Inline\StateInterface
38
25
*/
@@ -43,66 +30,75 @@ class SitemapSendEmail
43
30
*
44
31
* @var \Magento\Framework\App\Config\ScopeConfigInterface
45
32
*/
46
- private $ _scopeConfig ;
33
+ private $ scopeConfig ;
47
34
48
35
/**
49
36
* @var \Magento\Framework\Mail\Template\TransportBuilder
50
37
*/
51
- private $ _transportBuilder ;
38
+ private $ transportBuilder ;
39
+
40
+ /**
41
+ * @var $logger
42
+ */
43
+ private $ logger ;
52
44
53
45
/**
54
- * SitemapSendEmail constructor.
46
+ * EmailNotification constructor.
55
47
* @param StateInterface $inlineTranslation
56
48
* @param TransportBuilder $transportBuilder
57
49
* @param ScopeConfigInterface $scopeConfig
50
+ * @param LoggerInterface $logger
58
51
*/
59
52
public function __construct (
60
53
StateInterface $ inlineTranslation ,
61
54
TransportBuilder $ transportBuilder ,
62
- ScopeConfigInterface $ scopeConfig
55
+ ScopeConfigInterface $ scopeConfig ,
56
+ LoggerInterface $ logger
63
57
) {
64
58
$ this ->inlineTranslation = $ inlineTranslation ;
65
- $ this ->_scopeConfig = $ scopeConfig ;
66
- $ this ->_transportBuilder = $ transportBuilder ;
59
+ $ this ->scopeConfig = $ scopeConfig ;
60
+ $ this ->transportBuilder = $ transportBuilder ;
61
+ $ this ->logger = $ logger ;
67
62
}
68
63
69
64
/**
70
65
* Send's error email if sitemap generated with errors.
71
66
*
72
- * @param array $errors
73
- * @throws \Magento\Framework\Exception\MailException
67
+ * @param array| $errors
74
68
*/
75
- public function sendErrorEmail ($ errors )
69
+ public function sendErrors ($ errors )
76
70
{
77
- $ recipient = $ this ->_scopeConfig ->getValue (
78
- self ::XML_PATH_ERROR_RECIPIENT ,
79
- ScopeInterface::SCOPE_STORE
80
- );
81
- if ($ errors && $ recipient ) {
82
- $ this ->inlineTranslation ->suspend ();
83
-
84
- $ this ->_transportBuilder ->setTemplateIdentifier (
85
- $ this ->_scopeConfig ->getValue (
86
- self ::XML_PATH_ERROR_TEMPLATE ,
71
+ $ this ->inlineTranslation ->suspend ();
72
+ try {
73
+ $ this ->transportBuilder ->setTemplateIdentifier (
74
+ $ this ->scopeConfig ->getValue (
75
+ Observer::XML_PATH_ERROR_TEMPLATE ,
87
76
ScopeInterface::SCOPE_STORE
88
77
)
89
78
)->setTemplateOptions (
90
79
[
91
80
'area ' => FrontNameResolver::AREA_CODE ,
92
- 'store ' => Store::DEFAULT_STORE_ID ,
81
+ 'store ' => \ Magento \ Store \ Model \ Store::DEFAULT_STORE_ID ,
93
82
]
94
83
)->setTemplateVars (
95
84
['warnings ' => join ("\n" , $ errors )]
96
85
)->setFrom (
97
- $ this ->_scopeConfig ->getValue (
98
- self ::XML_PATH_ERROR_IDENTITY ,
86
+ $ this ->scopeConfig ->getValue (
87
+ Observer::XML_PATH_ERROR_IDENTITY ,
88
+ ScopeInterface::SCOPE_STORE
89
+ )
90
+ )->addTo (
91
+ $ this ->scopeConfig ->getValue (
92
+ Observer::XML_PATH_ERROR_RECIPIENT ,
99
93
ScopeInterface::SCOPE_STORE
100
94
)
101
- )-> addTo ( $ recipient ) ;
95
+ );
102
96
103
- $ transport = $ this ->_transportBuilder ->getTransport ();
97
+ $ transport = $ this ->transportBuilder ->getTransport ();
104
98
$ transport ->sendMessage ();
105
-
99
+ } catch (\Exception $ e ) {
100
+ $ this ->logger ->error ('Sitemap sendErrors: ' .$ e ->getMessage ());
101
+ } finally {
106
102
$ this ->inlineTranslation ->resume ();
107
103
}
108
104
}
0 commit comments