Skip to content

Commit debf84d

Browse files
author
cspruiell
committed
MAGETWO-59105: Errors on storefront after install for MPAF builds
- Merge remote-tracking branch 'mainline/develop' into MAGETWO-59105-SortOrder
2 parents 3e53d45 + 4d69ecb commit debf84d

File tree

20 files changed

+415
-85
lines changed

20 files changed

+415
-85
lines changed

app/code/Magento/Catalog/Model/Product/Option/Type/File.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Catalog\Model\Product\Option\Type;
77

8+
use Magento\Framework\App\Filesystem\DirectoryList;
89
use Magento\Framework\Filesystem;
910
use Magento\Framework\Exception\LocalizedException;
1011
use Magento\Catalog\Model\Product\Exception as ProductException;
@@ -69,17 +70,23 @@ class File extends \Magento\Catalog\Model\Product\Option\Type\DefaultType
6970
*/
7071
protected $validatorFile;
7172

73+
/**
74+
* @var Filesystem
75+
*/
76+
private $filesystem;
77+
7278
/**
7379
* @param \Magento\Checkout\Model\Session $checkoutSession
7480
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
7581
* @param \Magento\Quote\Model\Quote\Item\OptionFactory $itemOptionFactory
76-
* @param \Magento\Catalog\Model\Product\Option\UrlBuilder $urlBuilder
77-
* @param \Magento\Framework\Escaper $escaper
7882
* @param \Magento\MediaStorage\Helper\File\Storage\Database $coreFileStorageDatabase
7983
* @param File\ValidatorInfo $validatorInfo
8084
* @param File\ValidatorFile $validatorFile
85+
* @param \Magento\Catalog\Model\Product\Option\UrlBuilder $urlBuilder
86+
* @param \Magento\Framework\Escaper $escaper
8187
* @param array $data
82-
* @throws \Magento\Framework\Exception\FileSystemException
88+
* @param Filesystem $filesystem
89+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
8390
*/
8491
public function __construct(
8592
\Magento\Checkout\Model\Session $checkoutSession,
@@ -90,12 +97,15 @@ public function __construct(
9097
\Magento\Catalog\Model\Product\Option\Type\File\ValidatorFile $validatorFile,
9198
\Magento\Catalog\Model\Product\Option\UrlBuilder $urlBuilder,
9299
\Magento\Framework\Escaper $escaper,
93-
array $data = []
100+
array $data = [],
101+
Filesystem $filesystem = null
94102
) {
95103
$this->_itemOptionFactory = $itemOptionFactory;
96104
$this->_urlBuilder = $urlBuilder;
97105
$this->_escaper = $escaper;
98106
$this->_coreFileStorageDatabase = $coreFileStorageDatabase;
107+
$this->filesystem = $filesystem ?: \Magento\Framework\App\ObjectManager::getInstance()->get(Filesystem::class);
108+
$this->_rootDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
99109
$this->validatorInfo = $validatorInfo;
100110
$this->validatorFile = $validatorFile;
101111
parent::__construct($checkoutSession, $scopeConfig, $data);

app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Type/FileTest.php

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
*/
66
namespace Magento\Catalog\Test\Unit\Model\Product\Option\Type;
77

8+
use Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface;
9+
use Magento\Framework\App\Filesystem\DirectoryList;
10+
use Magento\Framework\Filesystem;
11+
use Magento\Framework\Filesystem\Directory\ReadInterface;
12+
use Magento\Framework\Filesystem\DriverPool;
13+
814
class FileTest extends \PHPUnit_Framework_TestCase
915
{
1016
/**
@@ -13,7 +19,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
1319
protected $objectManager;
1420

1521
/**
16-
* @var \Magento\Framework\Filesystem\Directory\ReadInterface|\PHPUnit_Framework_MockObject_MockObject
22+
* @var ReadInterface|\PHPUnit_Framework_MockObject_MockObject
1723
*/
1824
protected $rootDirectory;
1925

@@ -22,14 +28,26 @@ class FileTest extends \PHPUnit_Framework_TestCase
2228
*/
2329
protected $coreFileStorageDatabase;
2430

31+
/**
32+
* @var Filesystem|\PHPUnit_Framework_MockObject_MockObject
33+
*/
34+
private $filesystemMock;
35+
2536
protected function setUp()
2637
{
2738
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
2839

29-
$this->rootDirectory = $this->getMockBuilder(\Magento\Framework\Filesystem\Directory\ReadInterface::class)
40+
$this->filesystemMock = $this->getMockBuilder(Filesystem::class)
3041
->disableOriginalConstructor()
31-
->setMethods(['isFile', 'isReadable', 'getAbsolutePath'])
32-
->getMockForAbstractClass();
42+
->getMock();
43+
44+
$this->rootDirectory = $this->getMockBuilder(ReadInterface::class)
45+
->getMock();
46+
47+
$this->filesystemMock->expects($this->once())
48+
->method('getDirectoryRead')
49+
->with(DirectoryList::MEDIA, DriverPool::FILE)
50+
->willReturn($this->rootDirectory);
3351

3452
$this->coreFileStorageDatabase = $this->getMock(
3553
\Magento\MediaStorage\Helper\File\Storage\Database::class,
@@ -48,26 +66,27 @@ protected function getFileObject()
4866
return $this->objectManager->getObject(
4967
\Magento\Catalog\Model\Product\Option\Type\File::class,
5068
[
51-
'saleableItem' => $this->rootDirectory,
52-
'priceCurrency' => $this->coreFileStorageDatabase
69+
'filesystem' => $this->filesystemMock,
70+
'coreFileStorageDatabase' => $this->coreFileStorageDatabase
5371
]
5472
);
5573
}
5674

5775
public function testCopyQuoteToOrder()
5876
{
59-
$optionMock = $this->getMockBuilder(
60-
\Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface::class
61-
)->disableOriginalConstructor()->setMethods(['getValue'])->getMockForAbstractClass();
77+
$optionMock = $this->getMockBuilder(OptionInterface::class)
78+
->disableOriginalConstructor()
79+
->setMethods(['getValue'])
80+
->getMockForAbstractClass();
6281

6382
$quotePath = '/quote/path/path/uploaded.file';
6483
$orderPath = '/order/path/path/uploaded.file';
6584

6685
$optionMock->expects($this->any())
6786
->method('getValue')
68-
->will($this->returnValue(['quote_path' => $quotePath, 'order_path' => $orderPath]));
87+
->will($this->returnValue(serialize(['quote_path' => $quotePath, 'order_path' => $orderPath])));
6988

70-
$this->rootDirectory->expects($this->any())
89+
$this->rootDirectory->expects($this->once())
7190
->method('isFile')
7291
->with($this->equalTo($quotePath))
7392
->will($this->returnValue(true));

app/code/Magento/Catalog/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,4 +834,7 @@
834834
<argument name="collectionProcessor" xsi:type="object">Magento\Eav\Model\Api\SearchCriteria\CollectionProcessor</argument>
835835
</arguments>
836836
</type>
837+
<type name="Magento\Quote\Model\Quote\Item\ToOrderItem">
838+
<plugin name="copy_quote_files_to_order" type="Magento\Catalog\Model\Plugin\QuoteItemProductOption"/>
839+
</type>
837840
</config>

app/code/Magento/Catalog/etc/frontend/di.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
<argument name="fetchStrategy" xsi:type="object">Magento\Catalog\Model\ResourceModel\Category\Collection\FetchStrategy</argument>
1919
</arguments>
2020
</type>
21-
<type name="Magento\Quote\Model\Quote\Item\ToOrderItem">
22-
<plugin name="copy_quote_files_to_order" type="Magento\Catalog\Model\Plugin\QuoteItemProductOption"/>
23-
</type>
2421
<type name="Magento\Catalog\Model\Indexer\AbstractFlatState">
2522
<arguments>
2623
<argument name="isAvailable" xsi:type="boolean">true</argument>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Email\Model\Mail;
7+
8+
use Magento\Framework\App\Config\ScopeConfigInterface;
9+
use Magento\Framework\Exception\MailException;
10+
use Magento\Framework\Mail\TransportInterface;
11+
use Magento\Store\Model\ScopeInterface;
12+
13+
class TransportInterfacePlugin
14+
{
15+
/**
16+
* Config path to mail sending setting that shows if email communications are disabled
17+
*/
18+
const XML_PATH_SYSTEM_SMTP_DISABLE = 'system/smtp/disable';
19+
20+
/**
21+
* @var ScopeConfigInterface
22+
*/
23+
private $scopeConfig;
24+
25+
/**
26+
* @param ScopeConfigInterface $scopeConfig
27+
*/
28+
public function __construct(
29+
ScopeConfigInterface $scopeConfig
30+
) {
31+
$this->scopeConfig = $scopeConfig;
32+
}
33+
34+
/**
35+
* Omit email sending if disabled
36+
*
37+
* @param TransportInterface $subject
38+
* @param \Closure $proceed
39+
* @return void
40+
* @throws MailException
41+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
42+
*/
43+
public function aroundSendMessage(
44+
TransportInterface $subject,
45+
\Closure $proceed
46+
) {
47+
if (!$this->scopeConfig->isSetFlag(self::XML_PATH_SYSTEM_SMTP_DISABLE, ScopeInterface::SCOPE_STORE)) {
48+
$proceed();
49+
}
50+
}
51+
}

app/code/Magento/Email/Model/Template.php

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,11 @@
55
*/
66
namespace Magento\Email\Model;
77

8-
use Magento\Store\Model\ScopeInterface;
98
use Magento\Store\Model\StoreManagerInterface;
109

1110
/**
1211
* Template model
1312
*
14-
* Example:
15-
*
16-
* // Loading of template
17-
* \Magento\Email\Model\TemplateFactory $templateFactory
18-
* $templateFactory->create()->load($this->_scopeConfig->getValue(
19-
* 'path_to_email_template_id_config',
20-
* \Magento\Store\Model\ScopeInterface::SCOPE_STORE
21-
* ));
22-
* $variables = array(
23-
* 'someObject' => $this->_coreResourceEmailTemplate
24-
* 'someString' => 'Some string value'
25-
* );
26-
* $emailTemplate->send('some@domain.com', 'Name Of User', $variables);
27-
*
2813
* @method \Magento\Email\Model\ResourceModel\Template _getResource()
2914
* @method \Magento\Email\Model\ResourceModel\Template getResource()
3015
* @method string getTemplateCode()
@@ -63,6 +48,8 @@ class Template extends AbstractTemplate implements \Magento\Framework\Mail\Templ
6348

6449
/**
6550
* Config path to mail sending setting that shows if email communications are disabled
51+
* @deprecated
52+
* @see \Magento\Email\Model\Mail\TransportInterfacePlugin::XML_PATH_SYSTEM_SMTP_DISABLE
6653
*/
6754
const XML_PATH_SYSTEM_SMTP_DISABLE = 'system/smtp/disable';
6855

@@ -196,8 +183,7 @@ public function setId($value)
196183
*/
197184
public function isValidForSend()
198185
{
199-
return !$this->scopeConfig->isSetFlag(Template::XML_PATH_SYSTEM_SMTP_DISABLE, ScopeInterface::SCOPE_STORE)
200-
&& $this->getSenderName() && $this->getSenderEmail() && $this->getTemplateSubject();
186+
return $this->getSenderName() && $this->getSenderEmail() && $this->getTemplateSubject();
201187
}
202188

203189
/**
@@ -344,7 +330,8 @@ public function beforeSave()
344330
if ($this->_getResource()->checkCodeUsage($this)) {
345331
throw new \Magento\Framework\Exception\MailException(__('Duplicate Of Template Name'));
346332
}
347-
return parent::beforeSave();
333+
parent::beforeSave();
334+
return $this;
348335
}
349336

350337
/**

app/code/Magento/Email/Test/Unit/Model/TemplateTest.php

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
namespace Magento\Email\Test\Unit\Model;
77

8-
use Magento\Email\Model\Template\Filter;
98
use Magento\Framework\App\Area;
109
use Magento\Framework\App\Filesystem\DirectoryList;
1110
use Magento\Framework\App\TemplateTypesInterface;
@@ -426,18 +425,13 @@ public function testGetAndSetId()
426425
}
427426

428427
/**
429-
* @param $isSMTPDisabled bool
430428
* @param $senderName string
431429
* @param $senderEmail string
432430
* @param $templateSubject string
433431
* @dataProvider isValidForSendDataProvider
434432
*/
435-
public function testIsValidForSend($isSMTPDisabled, $senderName, $senderEmail, $templateSubject, $expectedValue)
433+
public function testIsValidForSend($senderName, $senderEmail, $templateSubject, $expectedValue)
436434
{
437-
$this->scopeConfig->expects($this->once())
438-
->method('isSetFlag')
439-
->with('system/smtp/disable', ScopeInterface::SCOPE_STORE)
440-
->will($this->returnValue($isSMTPDisabled));
441435
$model = $this->getModelMock(['getSenderName', 'getSenderEmail', 'getTemplateSubject']);
442436
$model->expects($this->any())
443437
->method('getSenderName')
@@ -455,35 +449,24 @@ public function isValidForSendDataProvider()
455449
{
456450
return [
457451
'should be valid' => [
458-
'isSMTPDisabled' => false,
459452
'senderName' => 'sender name',
460453
'senderEmail' => 'email@example.com',
461454
'templateSubject' => 'template subject',
462455
'expectedValue' => true
463456
],
464-
'no smtp so not valid' => [
465-
'isSMTPDisabled' => true,
466-
'senderName' => 'sender name',
467-
'senderEmail' => 'email@example.com',
468-
'templateSubject' => 'template subject',
469-
'expectedValue' => false
470-
],
471457
'no sender name so not valid' => [
472-
'isSMTPDisabled' => false,
473458
'senderName' => '',
474459
'senderEmail' => 'email@example.com',
475460
'templateSubject' => 'template subject',
476461
'expectedValue' => false
477462
],
478463
'no sender email so not valid' => [
479-
'isSMTPDisabled' => false,
480464
'senderName' => 'sender name',
481465
'senderEmail' => '',
482466
'templateSubject' => 'template subject',
483467
'expectedValue' => false
484468
],
485469
'no subject so not valid' => [
486-
'isSMTPDisabled' => false,
487470
'senderName' => 'sender name',
488471
'senderEmail' => 'email@example.com',
489472
'templateSubject' => '',

app/code/Magento/Email/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,6 @@
5959
</type>
6060
<type name="Magento\Framework\Mail\TransportInterface">
6161
<plugin name="WindowsSmtpConfig" type="Magento\Email\Model\Plugin\WindowsSmtpConfig" />
62+
<plugin name="disableSending" type="Magento\Email\Model\Mail\TransportInterfacePlugin" />
6263
</type>
6364
</config>

app/code/Magento/Newsletter/Model/Template.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ public function validate()
174174
public function beforeSave()
175175
{
176176
$this->validate();
177-
return parent::beforeSave();
177+
parent::beforeSave();
178+
return $this;
178179
}
179180

180181
/**
@@ -238,9 +239,6 @@ protected function getFilterFactory()
238239
*/
239240
public function isValidForSend()
240241
{
241-
return !$this->scopeConfig->isSetFlag(
242-
\Magento\Email\Model\Template::XML_PATH_SYSTEM_SMTP_DISABLE,
243-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
244-
) && $this->getTemplateSenderName() && $this->getTemplateSenderEmail() && $this->getTemplateSubject();
242+
return $this->getTemplateSenderName() && $this->getTemplateSenderEmail() && $this->getTemplateSubject();
245243
}
246244
}

0 commit comments

Comments
 (0)