Skip to content

Commit 9dc31d5

Browse files
author
Robert He
committed
Merge branch 'develop' into MAGETWO-69004-upgrade_captcha-2.2
2 parents 3c57282 + 34b0747 commit 9dc31d5

File tree

74 files changed

+1647
-612
lines changed

Some content is hidden

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

74 files changed

+1647
-612
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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,9 @@ public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveO
564564
$this->resourceModel->getLinkField(),
565565
$existingProduct->getData($this->resourceModel->getLinkField())
566566
);
567+
if (!$product->hasData(Product::STATUS)) {
568+
$product->setStatus($existingProduct->getStatus());
569+
}
567570
} catch (NoSuchEntityException $e) {
568571
$existingProduct = null;
569572
}
@@ -679,9 +682,7 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
679682
$collection = $this->collectionFactory->create();
680683
$this->extensionAttributesJoinProcessor->process($collection);
681684

682-
foreach ($this->metadataService->getList($this->searchCriteriaBuilder->create())->getItems() as $metadata) {
683-
$collection->addAttributeToSelect($metadata->getAttributeCode());
684-
}
685+
$collection->addAttributeToSelect('*');
685686
$collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner');
686687
$collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner');
687688

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/Catalog/view/adminhtml/ui_component/category_form.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@
193193
<item name="add_variables" xsi:type="boolean">false</item>
194194
<item name="add_widgets" xsi:type="boolean">false</item>
195195
<item name="add_images" xsi:type="boolean">false</item>
196+
<item name="add_directives" xsi:type="boolean">true</item>
196197
</item>
197198
<item name="source" xsi:type="string">category</item>
198199
</item>

app/code/Magento/Config/Console/Command/ConfigSet/EmulatedProcessorFacade.php

Lines changed: 0 additions & 95 deletions
This file was deleted.

app/code/Magento/Config/Console/Command/ConfigSetCommand.php

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
namespace Magento\Config\Console\Command;
77

88
use Magento\Config\App\Config\Type\System;
9-
use Magento\Config\Console\Command\ConfigSet\EmulatedProcessorFacade;
9+
use Magento\Config\Console\Command\ConfigSet\ProcessorFacadeFactory;
1010
use Magento\Deploy\Model\DeploymentConfig\ChangeDetector;
1111
use Magento\Deploy\Model\DeploymentConfig\Hash;
12-
use Magento\Deploy\Model\DeploymentConfig\Validator;
1312
use Magento\Framework\App\Config\ScopeConfigInterface;
1413
use Magento\Framework\Console\Cli;
1514
use Symfony\Component\Console\Command\Command;
@@ -34,11 +33,11 @@ class ConfigSetCommand extends Command
3433
/**#@-*/
3534

3635
/**
37-
* The emulated processor facade.
36+
* Emulator adminhtml area for CLI command.
3837
*
39-
* @var EmulatedProcessorFacade
38+
* @var EmulatedAdminhtmlAreaProcessor
4039
*/
41-
private $emulatedProcessorFacade;
40+
private $emulatedAreaProcessor;
4241

4342
/**
4443
* The config change detector.
@@ -55,18 +54,28 @@ class ConfigSetCommand extends Command
5554
private $hash;
5655

5756
/**
58-
* @param EmulatedProcessorFacade $emulatedProcessorFacade The emulated processor facade
57+
* The factory for processor facade.
58+
*
59+
* @var ProcessorFacadeFactory
60+
*/
61+
private $processorFacadeFactory;
62+
63+
/**
64+
* @param EmulatedAdminhtmlAreaProcessor $emulatedAreaProcessor Emulator adminhtml area for CLI command
5965
* @param ChangeDetector $changeDetector The config change detector
6066
* @param Hash $hash The hash manager
67+
* @param ProcessorFacadeFactory $processorFacadeFactory The factory for processor facade
6168
*/
6269
public function __construct(
63-
EmulatedProcessorFacade $emulatedProcessorFacade,
70+
EmulatedAdminhtmlAreaProcessor $emulatedAreaProcessor,
6471
ChangeDetector $changeDetector,
65-
Hash $hash
72+
Hash $hash,
73+
ProcessorFacadeFactory $processorFacadeFactory
6674
) {
67-
$this->emulatedProcessorFacade = $emulatedProcessorFacade;
75+
$this->emulatedAreaProcessor = $emulatedAreaProcessor;
6876
$this->changeDetector = $changeDetector;
6977
$this->hash = $hash;
78+
$this->processorFacadeFactory = $processorFacadeFactory;
7079

7180
parent::__construct();
7281
}
@@ -128,13 +137,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
128137
}
129138

130139
try {
131-
$message = $this->emulatedProcessorFacade->process(
132-
$input->getArgument(static::ARG_PATH),
133-
$input->getArgument(static::ARG_VALUE),
134-
$input->getOption(static::OPTION_SCOPE),
135-
$input->getOption(static::OPTION_SCOPE_CODE),
136-
$input->getOption(static::OPTION_LOCK)
137-
);
140+
$message = $this->emulatedAreaProcessor->process(function () use ($input) {
141+
return $this->processorFacadeFactory->create()->process(
142+
$input->getArgument(static::ARG_PATH),
143+
$input->getArgument(static::ARG_VALUE),
144+
$input->getOption(static::OPTION_SCOPE),
145+
$input->getOption(static::OPTION_SCOPE_CODE),
146+
$input->getOption(static::OPTION_LOCK)
147+
);
148+
});
138149

139150
$this->hash->regenerate(System::CONFIG_TYPE);
140151

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Config\Console\Command;
7+
8+
use Magento\Framework\App\Area;
9+
use Magento\Framework\App\State;
10+
use Magento\Framework\Config\ScopeInterface;
11+
12+
/**
13+
* Emulates callback inside adminhtml area code and adminhtml scope.
14+
* It is used for CLI commands which should work with data available only in adminhtml scope.
15+
*/
16+
class EmulatedAdminhtmlAreaProcessor
17+
{
18+
/**
19+
* The application scope manager.
20+
*
21+
* @var ScopeInterface
22+
*/
23+
private $scope;
24+
25+
/**
26+
* The application state manager.
27+
*
28+
* @var State
29+
*/
30+
private $state;
31+
32+
/**
33+
* @param ScopeInterface $scope The application scope manager
34+
* @param State $state The application state manager
35+
*/
36+
public function __construct(ScopeInterface $scope, State $state)
37+
{
38+
$this->scope = $scope;
39+
$this->state = $state;
40+
}
41+
42+
/**
43+
* Emulates callback inside adminhtml area code and adminhtml scope.
44+
*
45+
* Returns the return value of the callback.
46+
*
47+
* @param callable $callback The callable to be called
48+
* @param array $params The parameters to be passed to the callback, as an indexed array
49+
* @return bool|int|float|string|array|null - as the result of this method is the result of callback,
50+
* you can use callback only with specified in this method return types
51+
* @throws \Exception The exception is thrown if the parameter $callback throws an exception
52+
*/
53+
public function process(callable $callback, array $params = [])
54+
{
55+
$currentScope = $this->scope->getCurrentScope();
56+
try {
57+
return $this->state->emulateAreaCode(Area::AREA_ADMINHTML, function () use ($callback, $params) {
58+
$this->scope->setCurrentScope(Area::AREA_ADMINHTML);
59+
return call_user_func_array($callback, $params);
60+
});
61+
} catch (\Exception $exception) {
62+
throw $exception;
63+
} finally {
64+
$this->scope->setCurrentScope($currentScope);
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)