Skip to content

Commit fc2d4f7

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into MAGETWO-58354-block-cache-exploit
2 parents a6ae954 + 6674762 commit fc2d4f7

File tree

32 files changed

+491
-131
lines changed

32 files changed

+491
-131
lines changed

app/code/Magento/Catalog/Model/Category.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Category extends \Magento\Catalog\Model\AbstractModel implements
6565
*/
6666
const TREE_ROOT_ID = 1;
6767

68-
const CACHE_TAG = 'catalog_category';
68+
const CACHE_TAG = 'cat_c';
6969

7070
/**#@+
7171
* Constants

app/code/Magento/Catalog/Model/Product.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
5858
/**
5959
* Product cache tag
6060
*/
61-
const CACHE_TAG = 'catalog_product';
61+
const CACHE_TAG = 'cat_p';
6262

6363
/**
6464
* Category product relation cache tag
6565
*/
66-
const CACHE_PRODUCT_CATEGORY_TAG = 'catalog_category_product';
66+
const CACHE_PRODUCT_CATEGORY_TAG = 'cat_c_p';
6767

6868
/**
6969
* Product Store Id

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/Block/Product/ListProductTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ protected function tearDown()
114114

115115
public function testGetIdentities()
116116
{
117-
$productTag = 'catalog_product_1';
118-
$categoryTag = 'catalog_category_product_1';
117+
$productTag = 'cat_p_1';
118+
$categoryTag = 'cat_c_p_1';
119119

120120
$this->productMock->expects($this->once())
121121
->method('getIdentities')

app/code/Magento/Catalog/Test/Unit/Block/Product/ViewTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected function setUp()
3232
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
3333
$this->productTypeConfig = $this->getMock(\Magento\Catalog\Model\ProductTypes\ConfigInterface::class);
3434
$this->registryMock = $this->getMock(\Magento\Framework\Registry::class, [], [], '', false);
35-
$this->view = $helper->getObject(
35+
$this->view = $helper->getObject(
3636
\Magento\Catalog\Block\Product\View::class,
3737
['productTypeConfig' => $this->productTypeConfig, 'registry' => $this->registryMock]
3838
);
@@ -65,7 +65,7 @@ public function testShouldRenderQuantity()
6565

6666
public function testGetIdentities()
6767
{
68-
$productTags = ['catalog_product_1'];
68+
$productTags = ['cat_p_1'];
6969
$product = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false);
7070
$category = $this->getMock(\Magento\Catalog\Model\Category::class, [], [], '', false);
7171

@@ -84,6 +84,6 @@ public function testGetIdentities()
8484
]
8585
)
8686
);
87-
$this->assertEquals(['catalog_product_1', 'catalog_category_1'], $this->view->getIdentities());
87+
$this->assertEquals(['cat_p_1', 'cat_c_1'], $this->view->getIdentities());
8888
}
8989
}

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/Test/Unit/Model/ProductTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -708,13 +708,13 @@ public function getIdentitiesProvider()
708708

709709
return [
710710
'no changes' => [
711-
['catalog_product_1'],
711+
['cat_p_1'],
712712
['id' => 1, 'name' => 'value', 'category_ids' => [1]],
713713
['id' => 1, 'name' => 'value', 'category_ids' => [1]],
714714
],
715715
'new product' => $this->getNewProductProviderData(),
716716
'status and category change' => [
717-
[0 => 'catalog_product_1', 1 => 'catalog_category_product_1', 2 => 'catalog_category_product_2'],
717+
[0 => 'cat_p_1', 1 => 'cat_c_p_1', 2 => 'cat_c_p_2'],
718718
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 2],
719719
[
720720
'id' => 1,
@@ -726,18 +726,18 @@ public function getIdentitiesProvider()
726726
],
727727
],
728728
'status change only' => [
729-
[0 => 'catalog_product_1', 1 => 'catalog_category_product_7'],
729+
[0 => 'cat_p_1', 1 => 'cat_c_p_7'],
730730
['id' => 1, 'name' => 'value', 'category_ids' => [7], 'status' => 1],
731731
['id' => 1, 'name' => 'value', 'category_ids' => [7], 'status' => 2],
732732
],
733733
'status changed, category unassigned' => $this->getStatusAndCategoryChangesData(),
734734
'no status changes' => [
735-
[0 => 'catalog_product_1'],
735+
[0 => 'cat_p_1'],
736736
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
737737
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
738738
],
739739
'no stock status changes' => [
740-
[0 => 'catalog_product_1'],
740+
[0 => 'cat_p_1'],
741741
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
742742
[
743743
'id' => 1,
@@ -749,7 +749,7 @@ public function getIdentitiesProvider()
749749
],
750750
],
751751
'no stock status data 1' => [
752-
[0 => 'catalog_product_1'],
752+
[0 => 'cat_p_1'],
753753
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
754754
[
755755
'id' => 1,
@@ -760,7 +760,7 @@ public function getIdentitiesProvider()
760760
],
761761
],
762762
'no stock status data 2' => [
763-
[0 => 'catalog_product_1'],
763+
[0 => 'cat_p_1'],
764764
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
765765
[
766766
'id' => 1,
@@ -780,7 +780,7 @@ public function getIdentitiesProvider()
780780
private function getStatusAndCategoryChangesData()
781781
{
782782
return [
783-
[0 => 'catalog_product_1', 1 => 'catalog_category_product_5'],
783+
[0 => 'cat_p_1', 1 => 'cat_c_p_5'],
784784
['id' => 1, 'name' => 'value', 'category_ids' => [5], 'status' => 2],
785785
[
786786
'id' => 1,
@@ -799,7 +799,7 @@ private function getStatusAndCategoryChangesData()
799799
private function getNewProductProviderData()
800800
{
801801
return [
802-
['catalog_product_1', 'catalog_category_product_1'],
802+
['cat_p_1', 'cat_c_p_1'],
803803
null,
804804
[
805805
'id' => 1,
@@ -818,7 +818,7 @@ private function getNewProductProviderData()
818818
private function getStatusStockProviderData($extensionAttributesMock)
819819
{
820820
return [
821-
[0 => 'catalog_product_1', 1 => 'catalog_category_product_1'],
821+
[0 => 'cat_p_1', 1 => 'cat_c_p_1'],
822822
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
823823
[
824824
'id' => 1,

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>

app/code/Magento/CatalogImportExport/Model/Export/Product.php

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\CatalogImportExport\Model\Export;
77

8+
use Magento\Framework\DB\Ddl\Table;
89
use Magento\ImportExport\Model\Import;
910
use \Magento\Store\Model\Store;
1011
use \Magento\CatalogImportExport\Model\Import\Product as ImportProduct;
@@ -127,6 +128,13 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
127128
*/
128129
protected $_attributeTypes = [];
129130

131+
/**
132+
* Attributes defined by user
133+
*
134+
* @var array
135+
*/
136+
private $userDefinedAttributes = [];
137+
130138
/**
131139
* Product collection
132140
*
@@ -261,7 +269,11 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
261269
*/
262270
protected $dateAttrCodes = [
263271
'special_from_date',
264-
'special_to_date'
272+
'special_to_date',
273+
'news_from_date',
274+
'news_to_date',
275+
'custom_design_from',
276+
'custom_design_to'
265277
];
266278

267279
/**
@@ -910,20 +922,24 @@ protected function collectRawData()
910922
}
911923
$fieldName = isset($this->_fieldsMap[$code]) ? $this->_fieldsMap[$code] : $code;
912924

913-
if (in_array($code, $this->dateAttrCodes)) {
914-
$attrValue = $this->_localeDate->formatDateTime(
915-
new \DateTime($attrValue),
916-
\IntlDateFormatter::SHORT,
917-
\IntlDateFormatter::NONE,
918-
null,
919-
date_default_timezone_get()
920-
);
921-
} else if ($this->_attributeTypes[$code] === 'datetime') {
922-
$attrValue = $this->_localeDate->formatDateTime(
923-
new \DateTime($attrValue),
924-
\IntlDateFormatter::SHORT,
925-
\IntlDateFormatter::SHORT
926-
);
925+
if ($this->_attributeTypes[$code] == 'datetime') {
926+
if (in_array($code, $this->dateAttrCodes)
927+
|| in_array($code, $this->userDefinedAttributes)
928+
) {
929+
$attrValue = $this->_localeDate->formatDateTime(
930+
new \DateTime($attrValue),
931+
\IntlDateFormatter::SHORT,
932+
\IntlDateFormatter::NONE,
933+
null,
934+
date_default_timezone_get()
935+
);
936+
} else {
937+
$attrValue = $this->_localeDate->formatDateTime(
938+
new \DateTime($attrValue),
939+
\IntlDateFormatter::SHORT,
940+
\IntlDateFormatter::SHORT
941+
);
942+
}
927943
}
928944

929945
if ($storeId != Store::DEFAULT_STORE_ID
@@ -1380,6 +1396,9 @@ protected function initAttributes()
13801396
$this->_attributeValues[$attribute->getAttributeCode()] = $this->getAttributeOptions($attribute);
13811397
$this->_attributeTypes[$attribute->getAttributeCode()] =
13821398
\Magento\ImportExport\Model\Import::getAttributeType($attribute);
1399+
if ($attribute->getIsUserDefined()) {
1400+
$this->userDefinedAttributes[] = $attribute->getAttributeCode();
1401+
}
13831402
}
13841403
return $this;
13851404
}

0 commit comments

Comments
 (0)