Skip to content

Commit d0bf224

Browse files
committed
Merge branch 'develop' into patch-5
2 parents be39d4e + 1eb9d76 commit d0bf224

File tree

86 files changed

+1978
-769
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+1978
-769
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,14 @@ public function execute()
213213
$category->save();
214214
$this->messageManager->addSuccess(__('You saved the category.'));
215215
} catch (\Magento\Framework\Exception\AlreadyExistsException $e) {
216-
var_dump($e->getMessage());
217216
$this->messageManager->addError($e->getMessage());
218217
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
219218
$this->_getSession()->setCategoryData($categoryPostData);
220219
} catch (\Magento\Framework\Exception\LocalizedException $e) {
221-
var_dump($e->getMessage());
222220
$this->messageManager->addError($e->getMessage());
223221
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
224222
$this->_getSession()->setCategoryData($categoryPostData);
225223
} catch (\Exception $e) {
226-
var_dump($e->getMessage());
227224
$this->messageManager->addError(__('Something went wrong while saving the category.'));
228225
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
229226
$this->_getSession()->setCategoryData($categoryPostData);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,7 @@ public function save($product)
723723
protected function _removeNotApplicableAttributes($product)
724724
{
725725
$entityType = $product->getResource()->getEntityType();
726-
foreach ($this->_eavConfig->getEntityAttributeCodes($entityType, $product) as $attributeCode) {
727-
$attribute = $this->_eavConfig->getAttribute($entityType, $attributeCode);
726+
foreach ($this->_eavConfig->getEntityAttributes($entityType, $product) as $attribute) {
728727
$applyTo = $attribute->getApplyTo();
729728
if (is_array($applyTo) && count($applyTo) > 0 && !in_array($product->getTypeId(), $applyTo)) {
730729
$product->unsetData($attribute->getAttributeCode());

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,9 +682,7 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
682682
$collection = $this->collectionFactory->create();
683683
$this->extensionAttributesJoinProcessor->process($collection);
684684

685-
foreach ($this->metadataService->getList($this->searchCriteriaBuilder->create())->getItems() as $metadata) {
686-
$collection->addAttributeToSelect($metadata->getAttributeCode());
687-
}
685+
$collection->addAttributeToSelect('*');
688686
$collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner');
689687
$collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner');
690688

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,16 @@ public function countVisible()
10111011
public function load($object, $entityId, $attributes = [])
10121012
{
10131013
$this->_attributes = [];
1014-
$this->loadAttributesMetadata($attributes);
1014+
$select = $this->_getLoadRowSelect($object, $entityId);
1015+
$row = $this->getConnection()->fetchRow($select);
1016+
1017+
if (is_array($row)) {
1018+
$object->addData($row);
1019+
} else {
1020+
$object->isObjectNew(true);
1021+
}
1022+
1023+
$this->loadAttributesForObject($attributes, $object);
10151024
$object = $this->getEntityManager()->load($object, $entityId);
10161025
if (!$this->getEntityManager()->has($object)) {
10171026
$object->isObjectNew(true);

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,16 @@ public function validate($object)
577577
*/
578578
public function load($object, $entityId, $attributes = [])
579579
{
580-
$this->loadAttributesMetadata($attributes);
580+
$select = $this->_getLoadRowSelect($object, $entityId);
581+
$row = $this->getConnection()->fetchRow($select);
582+
583+
if (is_array($row)) {
584+
$object->addData($row);
585+
} else {
586+
$object->isObjectNew(true);
587+
}
588+
589+
$this->loadAttributesForObject($attributes, $object);
581590
$this->getEntityManager()->load($object, $entityId);
582591
return $this;
583592
}

app/code/Magento/Catalog/Test/Unit/Model/Product/Gallery/ProcessorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function testValidate($value)
165165
$attributeCode = 'attr_code';
166166
$attribute = $this->getMock(
167167
\Magento\Eav\Model\Entity\Attribute::class,
168-
['getAttributeCode', 'getIsRequired', 'isValueEmpty', 'getIsUnique', 'getEntityType', '__wakeup'],
168+
['getAttributeCode', 'getIsRequired', 'isValueEmpty', 'getIsUnique', 'getEntity', '__wakeup'],
169169
[],
170170
'',
171171
false
@@ -178,7 +178,7 @@ public function testValidate($value)
178178
$attribute->expects($this->any())->method('getIsRequired')->will($this->returnValue(true));
179179
$attribute->expects($this->any())->method('isValueEmpty')->will($this->returnValue($value));
180180
$attribute->expects($this->any())->method('getIsUnique')->will($this->returnValue(true));
181-
$attribute->expects($this->any())->method('getEntityType')->will($this->returnValue($attributeEntity));
181+
$attribute->expects($this->any())->method('getEntity')->will($this->returnValue($attributeEntity));
182182
$attributeEntity->expects($this->any())->method('checkAttributeUniqueValue')->will($this->returnValue(true));
183183

184184
$this->attributeRepository->expects($this->once())

app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -707,36 +707,17 @@ public function testDeleteById()
707707
public function testGetList()
708708
{
709709
$searchCriteriaMock = $this->getMock(\Magento\Framework\Api\SearchCriteriaInterface::class, [], [], '', false);
710-
$attributeCode = 'attribute_code';
711710
$collectionMock = $this->getMock(
712711
\Magento\Catalog\Model\ResourceModel\Product\Collection::class,
713712
[],
714713
[],
715714
'',
716715
false
717716
);
718-
$extendedSearchCriteriaMock = $this->getMock(\Magento\Framework\Api\SearchCriteria::class, [], [], '', false);
719-
$productAttributeSearchResultsMock = $this->getMockBuilder(ProductAttributeInterface::class)
720-
->disableOriginalConstructor()
721-
->setMethods(['getItems'])
722-
->getMockForAbstractClass();
723-
$productAttributeMock = $this->getMock(
724-
\Magento\Catalog\Api\Data\ProductAttributeInterface::class,
725-
[],
726-
[],
727-
'',
728-
false
729-
);
730717

731718
$this->collectionFactoryMock->expects($this->once())->method('create')->willReturn($collectionMock);
732-
$this->searchCriteriaBuilderMock->expects($this->once())->method('create')
733-
->willReturn($extendedSearchCriteriaMock);
734-
$this->metadataServiceMock->expects($this->once())->method('getList')->with($extendedSearchCriteriaMock)
735-
->willReturn($productAttributeSearchResultsMock);
736-
$productAttributeSearchResultsMock->expects($this->once())->method('getItems')
737-
->willReturn([$productAttributeMock]);
738-
$productAttributeMock->expects($this->once())->method('getAttributeCode')->willReturn($attributeCode);
739-
$collectionMock->expects($this->once())->method('addAttributeToSelect')->with($attributeCode);
719+
720+
$collectionMock->expects($this->once())->method('addAttributeToSelect')->with('*');
740721
$collectionMock->expects($this->exactly(2))->method('joinAttribute')->withConsecutive(
741722
['status', 'catalog_product/status', 'entity_id', null, 'inner'],
742723
['visibility', 'catalog_product/visibility', 'entity_id', null, 'inner']

app/code/Magento/Config/App/Config/Type/System.php

Lines changed: 143 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Config\App\Config\Type;
78

89
use Magento\Framework\App\Config\ConfigTypeInterface;
@@ -23,7 +24,7 @@ class System implements ConfigTypeInterface
2324
private $source;
2425

2526
/**
26-
* @var DataObject[]
27+
* @var DataObject
2728
*/
2829
private $data;
2930

@@ -64,6 +65,16 @@ class System implements ConfigTypeInterface
6465
*/
6566
private $configType;
6667

68+
/**
69+
* Key name for flag which displays whether configuration is cached or not.
70+
*
71+
* Once configuration is cached additional flag pushed to cache storage
72+
* to be able check cache existence without data load.
73+
*
74+
* @var string
75+
*/
76+
private $cacheExistenceKey;
77+
6778
/**
6879
* @param \Magento\Framework\App\Config\ConfigSourceInterface $source
6980
* @param \Magento\Framework\App\Config\Spi\PostProcessorInterface $postProcessor
@@ -92,6 +103,7 @@ public function __construct(
92103
$this->fallback = $fallback;
93104
$this->serializer = $serializer;
94105
$this->configType = $configType;
106+
$this->cacheExistenceKey = $this->configType . '_CACHE_EXISTS';
95107
}
96108

97109
/**
@@ -102,23 +114,135 @@ public function get($path = '')
102114
if ($path === null) {
103115
$path = '';
104116
}
105-
if (!$this->data) {
106-
$data = $this->cache->load($this->configType);
107-
if (!$data) {
108-
$data = $this->preProcessor->process($this->source->get());
109-
$this->data = new DataObject($data);
110-
$data = $this->fallback->process($data);
111-
$this->data = new DataObject($data);
112-
//Placeholder processing need system config - so we need to save intermediate result
113-
$data = $this->postProcessor->process($data);
114-
$this->data = new DataObject($data);
117+
if ($this->isConfigRead($path)) {
118+
return $this->data->getData($path);
119+
}
120+
121+
if (!empty($path) && $this->isCacheExists()) {
122+
return $this->readFromCache($path);
123+
}
124+
125+
$config = $this->loadConfig();
126+
$this->cacheConfig($config);
127+
$this->data = new DataObject($config);
128+
return $this->data->getData($path);
129+
}
130+
131+
/**
132+
* Check whether configuration is cached
133+
*
134+
* In case configuration cache exists method 'load' returns
135+
* value equal to $this->cacheExistenceKey
136+
*
137+
* @return bool
138+
*/
139+
private function isCacheExists()
140+
{
141+
return $this->cache->load($this->cacheExistenceKey) !== false;
142+
}
143+
144+
/**
145+
* Explode path by '/'(forward slash) separator
146+
*
147+
* In case $path string contains forward slash symbol(/) the $path is exploded and parts array is returned
148+
* In other case empty array is returned
149+
*
150+
* @param string $path
151+
* @return array
152+
*/
153+
private function getPathParts($path)
154+
{
155+
$pathParts = [];
156+
if (strpos($path, '/') !== false) {
157+
$pathParts = explode('/', $path);
158+
}
159+
return $pathParts;
160+
}
161+
162+
/**
163+
* Check whether requested configuration data is read to memory
164+
*
165+
* Because of configuration is cached partially each part can be loaded separately
166+
* Method performs check if corresponding system configuration part is already loaded to memory
167+
* and value can be retrieved directly without cache look up
168+
*
169+
*
170+
* @param string $path
171+
* @return bool
172+
*/
173+
private function isConfigRead($path)
174+
{
175+
$pathParts = $this->getPathParts($path);
176+
return !empty($pathParts) && isset($this->data[$pathParts[0]][$pathParts[1]]);
177+
}
178+
179+
/**
180+
* Load configuration from all the sources
181+
*
182+
* System configuration is loaded in 3 steps performing consecutive calls to
183+
* Pre Processor, Fallback Processor, Post Processor accordingly
184+
*
185+
* @return array
186+
*/
187+
private function loadConfig()
188+
{
189+
$data = $this->preProcessor->process($this->source->get());
190+
$this->data = new DataObject($data);
191+
$data = $this->fallback->process($data);
192+
$this->data = new DataObject($data);
193+
194+
return $this->postProcessor->process($data);
195+
}
196+
197+
/**
198+
*
199+
* Load configuration and caching it by parts.
200+
*
201+
* To be cached configuration is loaded first.
202+
* Then it is cached by parts to minimize memory usage on load.
203+
* Additional flag cached as well to give possibility check cache existence without data load.
204+
*
205+
* @param array $data
206+
* @return void
207+
*/
208+
private function cacheConfig($data)
209+
{
210+
foreach ($data as $scope => $scopeData) {
211+
foreach ($scopeData as $key => $config) {
115212
$this->cache->save(
116-
$this->serializer->serialize($this->data->getData()),
117-
$this->configType,
213+
$this->serializer->serialize($config),
214+
$this->configType . '_' . $scope . $key,
118215
[self::CACHE_TAG]
119216
);
120-
} else {
121-
$this->data = new DataObject($this->serializer->unserialize($data));
217+
}
218+
}
219+
$this->cache->save($this->cacheExistenceKey, $this->cacheExistenceKey, [self::CACHE_TAG]);
220+
}
221+
222+
/**
223+
* Read cached configuration
224+
*
225+
* Read section of system configuration corresponding to requested $path from cache
226+
* Configuration stored to internal property right after load to prevent additional
227+
* requests to cache storage
228+
*
229+
* @param string $path
230+
* @return mixed
231+
*/
232+
private function readFromCache($path)
233+
{
234+
if ($this->data === null) {
235+
$this->data = new DataObject();
236+
}
237+
238+
$result = null;
239+
$pathParts = $this->getPathParts($path);
240+
if (!empty($pathParts)) {
241+
$result = $this->cache->load($this->configType . '_' . $pathParts[0] . $pathParts[1]);
242+
if ($result !== false) {
243+
$readData = $this->data->getData();
244+
$readData[$pathParts[0]][$pathParts[1]] = $this->serializer->unserialize($result);
245+
$this->data->setData($readData);
122246
}
123247
}
124248

@@ -128,6 +252,10 @@ public function get($path = '')
128252
/**
129253
* Clean cache and global variables cache
130254
*
255+
* Next items cleared:
256+
* - Internal property intended to store already loaded configuration data
257+
* - All records in cache storage tagged with CACHE_TAG
258+
*
131259
* @return void
132260
*/
133261
public function clean()

0 commit comments

Comments
 (0)