Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 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,8 @@ 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 +404,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
20 changes: 18 additions & 2 deletions app/code/Magento/Email/Test/Unit/Model/BackendTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class BackendTemplateTest extends \PHPUnit\Framework\TestCase
*/
private $serializerMock;

/**
* @var \Magento\MediaStorage\Helper\File\Storage\Database|\PHPUnit_Framework_MockObject_MockObject
*/
private $databaseHelperMock;

protected function setUp()
{
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
Expand All @@ -58,14 +63,25 @@ protected function setUp()
$this->structureMock = $this->createMock(\Magento\Config\Model\Config\Structure::class);
$this->structureMock->expects($this->any())->method('getFieldPathsByAttribute')->willReturn(['path' => 'test']);

$this->databaseHelperMock = $this->createMock(\Magento\MediaStorage\Helper\File\Storage\Database::class);
$this->resourceModelMock = $this->createMock(\Magento\Email\Model\ResourceModel\Template::class);
$this->resourceModelMock->expects($this->any())->method('getSystemConfigByPathsAndTemplateId')->willReturn(['test_config' => 2015]);
/** @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject $objectManagerMock*/
$objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
$objectManagerMock->expects($this->any())
->method('get')
->with(\Magento\Email\Model\ResourceModel\Template::class)
->will($this->returnValue($this->resourceModelMock));
->willReturnCallback(
function ($value) {
switch($value) {
case \Magento\MediaStorage\Helper\File\Storage\Database::class:
return ($this->databaseHelperMock);
case \Magento\Email\Model\ResourceModel\Template::class:
return ($this->resourceModelMock);
default:
return(NULL);
}
}
);

\Magento\Framework\App\ObjectManager::setInstance($objectManagerMock);

Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Email/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"magento/module-cms": "102.0.*",
"magento/module-backend": "100.2.*",
"magento/module-variable": "100.2.*",
"magento/module-media-storage": "100.2.*",
"magento/framework": "101.0.*"
},
"suggest": {
Expand Down