44 * See COPYING.txt for license details.
55 */
66
7- /**
8- * Directory module observer
9- *
10- * @author Magento Core Team <core@magentocommerce.com>
11- */
12-
137namespace Magento \Directory \Model ;
148
9+ use Magento \Backend \App \Area \FrontNameResolver ;
10+ use Magento \Directory \Model \Currency \Import \Factory ;
11+ use Magento \Framework \App \Config \ScopeConfigInterface ;
12+ use Magento \Framework \Mail \Template \TransportBuilder ;
13+ use Magento \Framework \Translate \Inline \StateInterface ;
14+ use Magento \Store \Model \ScopeInterface ;
15+ use Magento \Store \Model \Store ;
16+ use Magento \Store \Model \StoreManagerInterface ;
17+
1518/**
16- * Class Observer
17- *
18- * @package Magento\Directory\Model
19+ * Import currency rates
1920 */
2021class Observer
2122{
22- const CRON_STRING_PATH = 'crontab/default/jobs/currency_rates_update/schedule/cron_expr ' ;
23+ public const CRON_STRING_PATH = 'crontab/default/jobs/currency_rates_update/schedule/cron_expr ' ;
2324
24- const IMPORT_ENABLE = 'currency/import/enabled ' ;
25+ public const IMPORT_ENABLE = 'currency/import/enabled ' ;
2526
26- const IMPORT_SERVICE = 'currency/import/service ' ;
27+ public const IMPORT_SERVICE = 'currency/import/service ' ;
2728
28- const XML_PATH_ERROR_TEMPLATE = 'currency/import/error_email_template ' ;
29+ public const XML_PATH_ERROR_TEMPLATE = 'currency/import/error_email_template ' ;
2930
30- const XML_PATH_ERROR_IDENTITY = 'currency/import/error_email_identity ' ;
31+ public const XML_PATH_ERROR_IDENTITY = 'currency/import/error_email_identity ' ;
3132
32- const XML_PATH_ERROR_RECIPIENT = 'currency/import/error_email ' ;
33+ public const XML_PATH_ERROR_RECIPIENT = 'currency/import/error_email ' ;
3334
3435 /**
35- * @var \Magento\Directory\Model\Currency\Import\ Factory
36+ * @var Factory
3637 */
3738 protected $ _importFactory ;
3839
3940 /**
4041 * Core store config
4142 *
42- * @var \Magento\Framework\App\Config\ ScopeConfigInterface
43+ * @var ScopeConfigInterface
4344 */
4445 protected $ _scopeConfig ;
4546
4647 /**
47- * @var \Magento\Framework\Mail\Template\ TransportBuilder
48+ * @var TransportBuilder
4849 */
4950 protected $ _transportBuilder ;
5051
5152 /**
52- * @var \Magento\Store\Model\ StoreManagerInterface
53+ * @var StoreManagerInterface
5354 */
5455 protected $ _storeManager ;
5556
5657 /**
57- * @var \Magento\Directory\Model\ CurrencyFactory
58+ * @var CurrencyFactory
5859 */
5960 protected $ _currencyFactory ;
6061
6162 /**
62- * @var \Magento\Framework\Translate\Inline\ StateInterface
63+ * @var StateInterface
6364 */
6465 protected $ inlineTranslation ;
6566
6667 /**
67- * @param \Magento\Directory\Model\Currency\Import\ Factory $importFactory
68- * @param \Magento\Framework\App\Config\ ScopeConfigInterface $scopeConfig
69- * @param \Magento\Framework\Mail\Template\ TransportBuilder $transportBuilder
70- * @param \Magento\Store\Model\ StoreManagerInterface $storeManager
71- * @param \Magento\Directory\Model\ CurrencyFactory $currencyFactory
72- * @param \Magento\Framework\Translate\Inline\ StateInterface $inlineTranslation
68+ * @param Factory $importFactory
69+ * @param ScopeConfigInterface $scopeConfig
70+ * @param TransportBuilder $transportBuilder
71+ * @param StoreManagerInterface $storeManager
72+ * @param CurrencyFactory $currencyFactory
73+ * @param StateInterface $inlineTranslation
7374 */
7475 public function __construct (
75- \ Magento \ Directory \ Model \ Currency \ Import \ Factory $ importFactory ,
76- \ Magento \ Framework \ App \ Config \ ScopeConfigInterface $ scopeConfig ,
77- \ Magento \ Framework \ Mail \ Template \ TransportBuilder $ transportBuilder ,
78- \ Magento \ Store \ Model \ StoreManagerInterface $ storeManager ,
79- \ Magento \ Directory \ Model \ CurrencyFactory $ currencyFactory ,
80- \ Magento \ Framework \ Translate \ Inline \ StateInterface $ inlineTranslation
76+ Factory $ importFactory ,
77+ ScopeConfigInterface $ scopeConfig ,
78+ TransportBuilder $ transportBuilder ,
79+ StoreManagerInterface $ storeManager ,
80+ CurrencyFactory $ currencyFactory ,
81+ StateInterface $ inlineTranslation
8182 ) {
8283 $ this ->_importFactory = $ importFactory ;
8384 $ this ->_scopeConfig = $ scopeConfig ;
@@ -94,16 +95,17 @@ public function __construct(
9495 * @return void
9596 * @throws \Exception
9697 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
98+ * @SuppressWarnings(PHPMD.CyclomaticComplexity)
9799 */
98100 public function scheduledUpdateCurrencyRates ($ schedule )
99101 {
100102 $ importWarnings = [];
101103 if (!$ this ->_scopeConfig ->getValue (
102104 self ::IMPORT_ENABLE ,
103- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE
105+ ScopeInterface::SCOPE_STORE
104106 ) || !$ this ->_scopeConfig ->getValue (
105107 self ::CRON_STRING_PATH ,
106- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE
108+ ScopeInterface::SCOPE_STORE
107109 )
108110 ) {
109111 return ;
@@ -113,7 +115,7 @@ public function scheduledUpdateCurrencyRates($schedule)
113115 $ rates = [];
114116 $ service = $ this ->_scopeConfig ->getValue (
115117 self ::IMPORT_SERVICE ,
116- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE
118+ ScopeInterface::SCOPE_STORE
117119 );
118120 if ($ service ) {
119121 try {
@@ -137,32 +139,33 @@ public function scheduledUpdateCurrencyRates($schedule)
137139
138140 $ errorRecipient = $ this ->_scopeConfig ->getValue (
139141 self ::XML_PATH_ERROR_RECIPIENT ,
140- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE
142+ ScopeInterface::SCOPE_STORE
141143 );
144+ $ errorRecipients = !empty ($ errorRecipient ) ? explode (', ' , $ errorRecipient ) : [];
142145 if (count ($ importWarnings ) == 0 ) {
143146 $ this ->_currencyFactory ->create ()->saveRates ($ rates );
144- } elseif ($ errorRecipient ) {
147+ } elseif (count ( $ errorRecipients ) > 0 ) {
145148 //if $errorRecipient is not set, there is no sense send email to nobody
146149 $ this ->inlineTranslation ->suspend ();
147150
148151 $ this ->_transportBuilder ->setTemplateIdentifier (
149152 $ this ->_scopeConfig ->getValue (
150153 self ::XML_PATH_ERROR_TEMPLATE ,
151- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE
154+ ScopeInterface::SCOPE_STORE
152155 )
153156 )->setTemplateOptions (
154157 [
155- 'area ' => \ Magento \ Backend \ App \ Area \ FrontNameResolver::AREA_CODE ,
156- 'store ' => \ Magento \ Store \ Model \ Store::DEFAULT_STORE_ID ,
158+ 'area ' => FrontNameResolver::AREA_CODE ,
159+ 'store ' => Store::DEFAULT_STORE_ID ,
157160 ]
158161 )->setTemplateVars (
159162 ['warnings ' => join ("\n" , $ importWarnings )]
160163 )->setFrom (
161164 $ this ->_scopeConfig ->getValue (
162165 self ::XML_PATH_ERROR_IDENTITY ,
163- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE
166+ ScopeInterface::SCOPE_STORE
164167 )
165- )->addTo ($ errorRecipient );
168+ )->addTo ($ errorRecipients );
166169 $ transport = $ this ->_transportBuilder ->getTransport ();
167170 $ transport ->sendMessage ();
168171
0 commit comments