Skip to content

Commit

Permalink
Transactional emails are now database aware with regard to email logo…
Browse files Browse the repository at this point in the history
… image.
  • Loading branch information
Graham Wharton committed Mar 10, 2019
1 parent e457037 commit c764ca3
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion app/code/Magento/Email/Model/AbstractTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Magento\Store\Model\Information as StoreInformation;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\Store;
use Magento\MediaStorage\Helper\File\Storage\Database;

/**
* Template model class
Expand Down Expand Up @@ -163,6 +164,11 @@ abstract class AbstractTemplate extends AbstractModel implements TemplateTypesIn
*/
private $urlModel;

/**
* @var Database
*/
private $fileStorageDatabase;

/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\View\DesignInterface $design
Expand All @@ -177,6 +183,7 @@ abstract class AbstractTemplate extends AbstractModel implements TemplateTypesIn
* @param \Magento\Framework\Filter\FilterManager $filterManager
* @param \Magento\Framework\UrlInterface $urlModel
* @param array $data
* @param Database $fileStorageDatabase
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
Expand All @@ -193,7 +200,8 @@ public function __construct(
\Magento\Email\Model\TemplateFactory $templateFactory,
\Magento\Framework\Filter\FilterManager $filterManager,
\Magento\Framework\UrlInterface $urlModel,
array $data = []
array $data = [],
Database $fileStorageDatabase = null
) {
$this->design = $design;
$this->area = isset($data['area']) ? $data['area'] : null;
Expand All @@ -207,6 +215,7 @@ public function __construct(
$this->templateFactory = $templateFactory;
$this->filterManager = $filterManager;
$this->urlModel = $urlModel;
$this->fileStorageDatabase = $fileStorageDatabase ?: \Magento\Framework\App\ObjectManager::getInstance()->get(Database::class);
parent::__construct($context, $registry, null, null, $data);
}

Expand Down Expand Up @@ -394,6 +403,11 @@ protected function getLogoUrl($store)
if ($fileName) {
$uploadDir = \Magento\Email\Model\Design\Backend\Logo::UPLOAD_DIR;
$mediaDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
if ($this->fileStorageDatabase->checkDbUsage() &&
!$mediaDirectory->isFile($uploadDir . '/' . $fileName)
) {
$this->fileStorageDatabase->saveFileToFilesystem($uploadDir . '/' . $fileName);
}
if ($mediaDirectory->isFile($uploadDir . '/' . $fileName)) {
return $this->storeManager->getStore()->getBaseUrl(
\Magento\Framework\UrlInterface::URL_TYPE_MEDIA
Expand Down

0 comments on commit c764ca3

Please sign in to comment.