Skip to content

Commit 9cd3798

Browse files
author
Joan He
committed
MAGETWO-58446: Remove uses of unserialize in usages of \Magento\Framework\Cache\FrontendInterface::load()
1 parent f4779eb commit 9cd3798

File tree

10 files changed

+111
-160
lines changed

10 files changed

+111
-160
lines changed

app/code/Magento/Backend/Model/Url.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Backend\Model;
77

8+
use Magento\Framework\Url\HostChecker;
9+
use Magento\Framework\App\ObjectManager;
810

911
/**
1012
* Class \Magento\Backend\Model\UrlInterface
@@ -77,6 +79,8 @@ class Url extends \Magento\Framework\Url implements \Magento\Backend\Model\UrlIn
7779
protected $_scope;
7880

7981
/**
82+
* Constructor
83+
*
8084
* @param \Magento\Framework\App\Route\ConfigInterface $routeConfig
8185
* @param \Magento\Framework\App\RequestInterface $request
8286
* @param \Magento\Framework\Url\SecurityInfoInterface $urlSecurityInfo
@@ -96,7 +100,7 @@ class Url extends \Magento\Framework\Url implements \Magento\Backend\Model\UrlIn
96100
* @param \Magento\Store\Model\StoreFactory $storeFactory
97101
* @param \Magento\Framework\Data\Form\FormKey $formKey
98102
* @param array $data
99-
*
103+
* @param HostChecker|null $hostChecker
100104
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
101105
*/
102106
public function __construct(
@@ -118,9 +122,11 @@ public function __construct(
118122
\Magento\Framework\Encryption\EncryptorInterface $encryptor,
119123
\Magento\Store\Model\StoreFactory $storeFactory,
120124
\Magento\Framework\Data\Form\FormKey $formKey,
121-
array $data = []
125+
array $data = [],
126+
HostChecker $hostChecker = null
122127
) {
123128
$this->_encryptor = $encryptor;
129+
$hostChecker = $hostChecker ?: ObjectManager::getInstance()->get(HostChecker::class);
124130
parent::__construct(
125131
$routeConfig,
126132
$request,
@@ -133,7 +139,8 @@ public function __construct(
133139
$scopeConfig,
134140
$routeParamsPreprocessor,
135141
$scopeType,
136-
$data
142+
$data,
143+
$hostChecker
137144
);
138145
$this->_backendHelper = $backendHelper;
139146
$this->_menuConfig = $menuConfig;

app/code/Magento/Backend/Test/Unit/Model/UrlTest.php

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@
33
* Copyright © 2016 Magento. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
7-
// @codingStandardsIgnoreFile
8-
9-
/**
10-
* Test class for \Magento\Backend\Model\Url
11-
*/
126
namespace Magento\Backend\Test\Unit\Model;
137

8+
use Magento\Framework\Url\HostChecker;
9+
1410
/**
1511
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
12+
* @codingStandardsIgnoreFile
1613
*/
1714
class UrlTest extends \PHPUnit_Framework_TestCase
1815
{
@@ -21,10 +18,12 @@ class UrlTest extends \PHPUnit_Framework_TestCase
2118
*/
2219
protected $_model;
2320

21+
/**
22+
* @var string
23+
*/
2424
protected $_areaFrontName = 'backendArea';
2525

2626
/**
27-
* Mock menu model
2827
* @var \PHPUnit_Framework_MockObject_MockObject
2928
*/
3029
protected $_menuMock;
@@ -62,7 +61,7 @@ class UrlTest extends \PHPUnit_Framework_TestCase
6261
/**
6362
* @var \PHPUnit_Framework_MockObject_MockObject
6463
*/
65-
protected $_paramsResolverMock;
64+
protected $routeParamsResolverFactoryMock;
6665

6766
/**
6867
* @var \Magento\Framework\Encryption\EncryptorInterface
@@ -75,6 +74,7 @@ class UrlTest extends \PHPUnit_Framework_TestCase
7574
*/
7675
protected function setUp()
7776
{
77+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
7878
$this->_menuMock = $this->getMock(
7979
\Magento\Backend\Model\Menu::class,
8080
[],
@@ -141,25 +141,21 @@ protected function setUp()
141141
false,
142142
false
143143
);
144-
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
145144
$this->_encryptor = $this->getMock(\Magento\Framework\Encryption\Encryptor::class, null, [], '', false);
146-
$this->_paramsResolverMock = $this->getMock(
145+
$routeParamsResolver = $this->getMock(\Magento\Framework\Url\RouteParamsResolver::class, [], [], '', false);
146+
$this->routeParamsResolverFactoryMock = $this->getMock(
147147
\Magento\Framework\Url\RouteParamsResolverFactory::class,
148148
[],
149149
[],
150150
'',
151151
false
152152
);
153-
$this->_paramsResolverMock->expects(
154-
$this->any()
155-
)->method(
156-
'create'
157-
)->will(
158-
$this->returnValue(
159-
$this->getMock(\Magento\Framework\Url\RouteParamsResolver::class, [], [], '', false)
160-
)
161-
);
162-
$this->_model = $helper->getObject(
153+
$this->routeParamsResolverFactoryMock->expects($this->any())
154+
->method('create')
155+
->willReturn($routeParamsResolver);
156+
/** @var HostChecker|\PHPUnit_Framework_MockObject_MockObject $hostCheckerMock */
157+
$hostCheckerMock = $this->getMock(HostChecker::class, [], [], '', false);
158+
$this->_model = $objectManager->getObject(
163159
\Magento\Backend\Model\Url::class,
164160
[
165161
'scopeConfig' => $this->_scopeConfigMock,
@@ -168,31 +164,10 @@ protected function setUp()
168164
'menuConfig' => $this->_menuConfigMock,
169165
'authSession' => $this->_authSessionMock,
170166
'encryptor' => $this->_encryptor,
171-
'routeParamsResolverFactory' => $this->_paramsResolverMock
167+
'routeParamsResolverFactory' => $this->routeParamsResolverFactoryMock,
168+
'hostChecker' => $hostCheckerMock
172169
]
173170
);
174-
$this->_paramsResolverMock->expects(
175-
$this->any()
176-
)->method(
177-
'create'
178-
)->will(
179-
$this->returnValue(
180-
$this->getMock(\Magento\Framework\Url\RouteParamsResolver::class, [], [], '', false)
181-
)
182-
);
183-
$this->_model = $helper->getObject(
184-
\Magento\Backend\Model\Url::class,
185-
[
186-
'scopeConfig' => $this->_scopeConfigMock,
187-
'backendHelper' => $helperMock,
188-
'formKey' => $this->_formKey,
189-
'menuConfig' => $this->_menuConfigMock,
190-
'authSession' => $this->_authSessionMock,
191-
'encryptor' => $this->_encryptor,
192-
'routeParamsResolverFactory' => $this->_paramsResolverMock
193-
]
194-
);
195-
196171
$this->_requestMock = $this->getMock(\Magento\Framework\App\Request\Http::class, [], [], '', false);
197172
$this->_model->setRequest($this->_requestMock);
198173
}
@@ -262,7 +237,7 @@ public function testGetAreaFrontName()
262237
[
263238
'backendHelper' => $helperMock,
264239
'authSession' => $this->_authSessionMock,
265-
'routeParamsResolverFactory' => $this->_paramsResolverMock
240+
'routeParamsResolverFactory' => $this->routeParamsResolverFactoryMock
266241
]
267242
);
268243
$urlModel->getAreaFrontName();

app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use Magento\Catalog\Api\Data\ProductInterface;
1414
use Magento\CatalogImportExport\Model\Import\Product as ImportProduct;
15+
use Magento\Framework\EntityManager\MetadataPool;
1516

1617
/**
1718
* Importing configurable products
@@ -140,6 +141,7 @@ class Configurable extends \Magento\CatalogImportExport\Model\Import\Product\Typ
140141
* Instance of database adapter.
141142
*
142143
* @var \Magento\Framework\DB\Adapter\AdapterInterface
144+
* @deprecated
143145
*/
144146
protected $_connection;
145147

@@ -200,6 +202,7 @@ class Configurable extends \Magento\CatalogImportExport\Model\Import\Product\Typ
200202
* @param \Magento\Catalog\Model\ProductTypes\ConfigInterface $productTypesConfig
201203
* @param \Magento\ImportExport\Model\ResourceModel\Helper $resourceHelper
202204
* @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $_productColFac
205+
* @param MetadataPool $metadataPool
203206
*/
204207
public function __construct(
205208
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory $attrSetColFac,
@@ -208,12 +211,12 @@ public function __construct(
208211
array $params,
209212
\Magento\Catalog\Model\ProductTypes\ConfigInterface $productTypesConfig,
210213
\Magento\ImportExport\Model\ResourceModel\Helper $resourceHelper,
211-
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $_productColFac
214+
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $_productColFac,
215+
MetadataPool $metadataPool = null
212216
) {
213-
parent::__construct($attrSetColFac, $prodAttrColFac, $resource, $params);
217+
parent::__construct($attrSetColFac, $prodAttrColFac, $resource, $params, $metadataPool);
214218
$this->_productTypesConfig = $productTypesConfig;
215219
$this->_resourceHelper = $resourceHelper;
216-
$this->_resource = $resource;
217220
$this->_productColFac = $_productColFac;
218221
$this->_connection = $this->_entityModel->getConnection();
219222
}
@@ -379,14 +382,14 @@ protected function _loadSkuSuperDataForBunch(array $bunch)
379382
if (!empty($productIds)) {
380383
$mainTable = $this->_resource->getTableName('catalog_product_super_attribute');
381384
$optionTable = $this->_resource->getTableName('eav_attribute_option');
382-
$select = $this->_connection->select()->from(
385+
$select = $this->connection->select()->from(
383386
['m' => $mainTable],
384387
['product_id', 'attribute_id', 'product_super_attribute_id']
385388
)->joinLeft(
386389
['o' => $optionTable],
387-
$this->_connection->quoteIdentifier(
390+
$this->connection->quoteIdentifier(
388391
'o.attribute_id'
389-
) . ' = ' . $this->_connection->quoteIdentifier(
392+
) . ' = ' . $this->connection->quoteIdentifier(
390393
'o.attribute_id'
391394
),
392395
['option_id']
@@ -395,7 +398,7 @@ protected function _loadSkuSuperDataForBunch(array $bunch)
395398
$productIds
396399
);
397400

398-
foreach ($this->_connection->fetchAll($select) as $row) {
401+
foreach ($this->connection->fetchAll($select) as $row) {
399402
$attrId = $row['attribute_id'];
400403
$productId = $row['product_id'];
401404
if ($row['option_id']) {
@@ -448,8 +451,8 @@ protected function _processSuperData()
448451
'product_id' => $this->_productSuperData['assoc_entity_ids'][$assocId],
449452
'parent_id' => $this->_productSuperData['product_id'],
450453
];
451-
$subEntityId = $this->_connection->fetchOne(
452-
$this->_connection->select()->from(
454+
$subEntityId = $this->connection->fetchOne(
455+
$this->connection->select()->from(
453456
['cpe' => $this->_resource->getTableName('catalog_product_entity')], ['entity_id']
454457
)->where($metadata->getLinkField() . ' = ?', $assocId)
455458
);
@@ -557,10 +560,10 @@ protected function _deleteData()
557560
&& !empty($this->_productSuperData['product_id'])
558561
&& !empty($this->_simpleIdsToDelete)
559562
) {
560-
$quoted = $this->_connection->quoteInto('IN (?)', [$this->_productSuperData['product_id']]);
561-
$quotedChildren = $this->_connection->quoteInto('IN (?)', $this->_simpleIdsToDelete);
562-
$this->_connection->delete($linkTable, "parent_id {$quoted} AND product_id {$quotedChildren}");
563-
$this->_connection->delete($relationTable, "parent_id {$quoted} AND child_id {$quotedChildren}");
563+
$quoted = $this->connection->quoteInto('IN (?)', [$this->_productSuperData['product_id']]);
564+
$quotedChildren = $this->connection->quoteInto('IN (?)', $this->_simpleIdsToDelete);
565+
$this->connection->delete($linkTable, "parent_id {$quoted} AND product_id {$quotedChildren}");
566+
$this->connection->delete($relationTable, "parent_id {$quoted} AND child_id {$quotedChildren}");
564567
}
565568
return $this;
566569
}
@@ -587,16 +590,16 @@ protected function _insertData()
587590
}
588591
}
589592
if ($mainData) {
590-
$this->_connection->insertOnDuplicate($mainTable, $mainData);
593+
$this->connection->insertOnDuplicate($mainTable, $mainData);
591594
}
592595
if ($this->_superAttributesData['labels']) {
593-
$this->_connection->insertOnDuplicate($labelTable, $this->_superAttributesData['labels']);
596+
$this->connection->insertOnDuplicate($labelTable, $this->_superAttributesData['labels']);
594597
}
595598
if ($this->_superAttributesData['super_link']) {
596-
$this->_connection->insertOnDuplicate($linkTable, $this->_superAttributesData['super_link']);
599+
$this->connection->insertOnDuplicate($linkTable, $this->_superAttributesData['super_link']);
597600
}
598601
if ($this->_superAttributesData['relation']) {
599-
$this->_connection->insertOnDuplicate($relationTable, $this->_superAttributesData['relation']);
602+
$this->connection->insertOnDuplicate($relationTable, $this->_superAttributesData['relation']);
600603
}
601604
return $this;
602605
}

app/code/Magento/ConfigurableImportExport/Test/Unit/Model/Import/Product/Type/ConfigurableTest.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,10 @@ protected function setUp()
312312
'prodAttrColFac' => $this->attrCollectionFactory,
313313
'params' => $this->params,
314314
'resource' => $this->resource,
315-
'productColFac' => $this->productCollectionFactory
315+
'productColFac' => $this->productCollectionFactory,
316+
'metadataPool' => $metadataPoolMock,
316317
]
317318
);
318-
$reflection = new \ReflectionClass(
319-
\Magento\ConfigurableImportExport\Model\Import\Product\Type\Configurable::class
320-
);
321-
$reflectionProperty = $reflection->getProperty('metadataPool');
322-
$reflectionProperty->setAccessible(true);
323-
$reflectionProperty->setValue($this->configurable, $metadataPoolMock);
324319
}
325320

326321
/**

0 commit comments

Comments
 (0)