14
14
use Magento \Store \Model \Information as StoreInformation ;
15
15
use Magento \Store \Model \ScopeInterface ;
16
16
use Magento \Store \Model \Store ;
17
+ use Magento \MediaStorage \Helper \File \Storage \Database ;
17
18
18
19
/**
19
- * Template model class
20
+ * Template model class.
20
21
*
22
+ * phpcs:disable Magento2.Classes.AbstractApi
21
23
* @author Magento Core Team <core@magentocommerce.com>
22
24
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
23
25
* @SuppressWarnings(PHPMD.TooManyFields)
@@ -163,6 +165,11 @@ abstract class AbstractTemplate extends AbstractModel implements TemplateTypesIn
163
165
*/
164
166
private $ urlModel ;
165
167
168
+ /**
169
+ * @var Database
170
+ */
171
+ private $ fileStorageDatabase ;
172
+
166
173
/**
167
174
* @param \Magento\Framework\Model\Context $context
168
175
* @param \Magento\Framework\View\DesignInterface $design
@@ -177,6 +184,7 @@ abstract class AbstractTemplate extends AbstractModel implements TemplateTypesIn
177
184
* @param \Magento\Framework\Filter\FilterManager $filterManager
178
185
* @param \Magento\Framework\UrlInterface $urlModel
179
186
* @param array $data
187
+ * @param Database $fileStorageDatabase
180
188
*
181
189
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
182
190
*/
@@ -193,7 +201,8 @@ public function __construct(
193
201
\Magento \Email \Model \TemplateFactory $ templateFactory ,
194
202
\Magento \Framework \Filter \FilterManager $ filterManager ,
195
203
\Magento \Framework \UrlInterface $ urlModel ,
196
- array $ data = []
204
+ array $ data = [],
205
+ Database $ fileStorageDatabase = null
197
206
) {
198
207
$ this ->design = $ design ;
199
208
$ this ->area = isset ($ data ['area ' ]) ? $ data ['area ' ] : null ;
@@ -207,6 +216,8 @@ public function __construct(
207
216
$ this ->templateFactory = $ templateFactory ;
208
217
$ this ->filterManager = $ filterManager ;
209
218
$ this ->urlModel = $ urlModel ;
219
+ $ this ->fileStorageDatabase = $ fileStorageDatabase ?:
220
+ \Magento \Framework \App \ObjectManager::getInstance ()->get (Database::class);
210
221
parent ::__construct ($ context , $ registry , null , null , $ data );
211
222
}
212
223
@@ -394,6 +405,11 @@ protected function getLogoUrl($store)
394
405
if ($ fileName ) {
395
406
$ uploadDir = \Magento \Email \Model \Design \Backend \Logo::UPLOAD_DIR ;
396
407
$ mediaDirectory = $ this ->filesystem ->getDirectoryRead (DirectoryList::MEDIA );
408
+ if ($ this ->fileStorageDatabase ->checkDbUsage () &&
409
+ !$ mediaDirectory ->isFile ($ uploadDir . '/ ' . $ fileName )
410
+ ) {
411
+ $ this ->fileStorageDatabase ->saveFileToFilesystem ($ uploadDir . '/ ' . $ fileName );
412
+ }
397
413
if ($ mediaDirectory ->isFile ($ uploadDir . '/ ' . $ fileName )) {
398
414
return $ this ->storeManager ->getStore ()->getBaseUrl (
399
415
\Magento \Framework \UrlInterface::URL_TYPE_MEDIA
@@ -490,7 +506,6 @@ protected function addEmailVariables($variables, $storeId)
490
506
491
507
/**
492
508
* Apply design config so that emails are processed within the context of the appropriate area/store/theme.
493
- * Can be called multiple times without issue.
494
509
*
495
510
* @return bool
496
511
*/
@@ -664,8 +679,7 @@ public function getTemplateFilter()
664
679
}
665
680
666
681
/**
667
- * Save current design config and replace with design config from specified store
668
- * Event is not dispatched.
682
+ * Save current design config and replace with design config from specified store. Event is not dispatched.
669
683
*
670
684
* @param null|bool|int|string $storeId
671
685
* @param string $area
0 commit comments