Skip to content

Commit a0756f2

Browse files
committed
Merge branch 'develop' of github.com:magento/magento2ce into MM-2551-EQP-Sniffs-To-Magento
2 parents 11429cd + 4067591 commit a0756f2

File tree

135 files changed

+3965
-934
lines changed

Some content is hidden

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

135 files changed

+3965
-934
lines changed

app/code/Magento/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes/Extend.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ public function getExtendedElement($switchAttributeCode)
142142
[
143143
'name' => "product[{$switchAttributeCode}]",
144144
'values' => $this->getOptions(),
145-
'value' => $switchAttributeCode,
146145
'class' => 'required-entry next-toinput',
147146
'no_span' => true,
148147
'disabled' => $this->isDisabledField(),

app/code/Magento/Catalog/Model/Indexer/Category/Flat/AbstractAction.php

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,22 +369,55 @@ protected function getAttributeValues($entityIds, $storeId)
369369
}
370370
$values = [];
371371

372+
$linkIds = $this->getLinkIds($entityIds);
373+
foreach ($linkIds as $linkId) {
374+
$values[$linkId] = [];
375+
}
376+
372377
$attributes = $this->getAttributes();
373378
$attributesType = ['varchar', 'int', 'decimal', 'text', 'datetime'];
379+
$linkField = $this->getCategoryMetadata()->getLinkField();
374380
foreach ($attributesType as $type) {
375381
foreach ($this->getAttributeTypeValues($type, $entityIds, $storeId) as $row) {
376-
if (isset($row['entity_id']) && isset($row['attribute_id'])) {
382+
if (isset($row[$linkField]) && isset($row['attribute_id'])) {
377383
$attributeId = $row['attribute_id'];
378384
if (isset($attributes[$attributeId])) {
379385
$attributeCode = $attributes[$attributeId]['attribute_code'];
380-
$values[$row['entity_id']][$attributeCode] = $row['value'];
386+
$values[$row[$linkField]][$attributeCode] = $row['value'];
381387
}
382388
}
383389
}
384390
}
391+
385392
return $values;
386393
}
387394

395+
/**
396+
* Translate entity ids into link ids
397+
*
398+
* Used for rows with no EAV attributes set.
399+
*
400+
* @param array $entityIds
401+
* @return array
402+
*/
403+
private function getLinkIds(array $entityIds)
404+
{
405+
$linkField = $this->getCategoryMetadata()->getLinkField();
406+
if ($linkField === 'entity_id') {
407+
return $entityIds;
408+
}
409+
410+
$select = $this->connection->select()->from(
411+
['e' => $this->connection->getTableName($this->getTableName('catalog_category_entity'))],
412+
[$linkField]
413+
)->where(
414+
'e.entity_id IN (?)',
415+
$entityIds
416+
);
417+
418+
return $this->connection->fetchCol($select);
419+
}
420+
388421
/**
389422
* Return attribute values for given entities and store of specific attribute type
390423
*

app/code/Magento/Catalog/Model/Indexer/Category/Flat/Action/Full.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,22 @@ protected function populateFlatTables(array $stores)
6464
}
6565
/** @TODO Do something with chunks */
6666
$categoriesIdsChunks = array_chunk($categoriesIds[$store->getRootCategoryId()], 500);
67+
6768
foreach ($categoriesIdsChunks as $categoriesIdsChunk) {
6869
$attributesData = $this->getAttributeValues($categoriesIdsChunk, $store->getId());
70+
$linkField = $this->categoryMetadata->getLinkField();
71+
6972
$data = [];
7073
foreach ($categories[$store->getRootCategoryId()] as $category) {
71-
if (!isset($attributesData[$category[$this->categoryMetadata->getLinkField()]])) {
74+
if (!isset($attributesData[$category[$linkField]])) {
7275
continue;
7376
}
7477
$category['store_id'] = $store->getId();
7578
$data[] = $this->prepareValuesToInsert(
76-
array_merge($category, $attributesData[$category[$this->categoryMetadata->getLinkField()]])
79+
array_merge($category, $attributesData[$category[$linkField]])
7780
);
7881
}
82+
7983
$this->connection->insertMultiple(
8084
$this->addTemporaryTableSuffix($this->getMainStoreTable($store->getId())),
8185
$data

app/code/Magento/Catalog/Model/Indexer/Category/Flat/Action/Rows.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,22 @@ private function reindexStore(Store $store, array $entityIds, $useTempTable)
164164
*/
165165
private function buildIndexData(Store $store, $categoriesIdsChunk, $attributesData)
166166
{
167+
$linkField = $this->categoryMetadata->getLinkField();
168+
167169
$data = [];
168170
foreach ($categoriesIdsChunk as $categoryId) {
169171
try {
172+
$category = $this->categoryRepository->get($categoryId);
173+
$categoryData = $category->getData();
174+
$linkId = $categoryData[$linkField];
175+
170176
$categoryAttributesData = [];
171-
if (isset($attributesData[$categoryId]) && is_array($attributesData[$categoryId])) {
172-
$categoryAttributesData = $attributesData[$categoryId];
177+
if (isset($attributesData[$linkId]) && is_array($attributesData[$linkId])) {
178+
$categoryAttributesData = $attributesData[$linkId];
173179
}
174180
$categoryIndexData = $this->buildCategoryIndexData(
175181
$store,
176-
$categoryId,
182+
$categoryData,
177183
$categoryAttributesData
178184
);
179185
$data[] = $categoryIndexData;
@@ -186,18 +192,16 @@ private function buildIndexData(Store $store, $categoriesIdsChunk, $attributesDa
186192

187193
/**
188194
* @param Store $store
189-
* @param int $categoryId
195+
* @param array $categoryData
190196
* @param array $categoryAttributesData
191197
* @return array
192198
* @throws NoSuchEntityException
193199
*/
194-
private function buildCategoryIndexData(Store $store, $categoryId, array $categoryAttributesData)
200+
private function buildCategoryIndexData(Store $store, array $categoryData, array $categoryAttributesData)
195201
{
196-
$category = $this->categoryRepository->get($categoryId);
197-
$categoryAttributesData = [];
198202
$data = $this->prepareValuesToInsert(
199203
array_merge(
200-
$category->getData(),
204+
$categoryData,
201205
$categoryAttributesData,
202206
['store_id' => $store->getId()]
203207
)

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,16 +340,17 @@ protected function initializeProductData(array $productData, $createNew)
340340
foreach ($productData as $key => $value) {
341341
$product->setData($key, $value);
342342
}
343-
$this->assignProductToWebsites($product);
343+
$this->assignProductToWebsites($product, $createNew);
344344

345345
return $product;
346346
}
347347

348348
/**
349349
* @param \Magento\Catalog\Model\Product $product
350+
* @param bool $createNew
350351
* @return void
351352
*/
352-
private function assignProductToWebsites(\Magento\Catalog\Model\Product $product)
353+
private function assignProductToWebsites(\Magento\Catalog\Model\Product $product, $createNew)
353354
{
354355
$websiteIds = $product->getWebsiteIds();
355356

@@ -362,7 +363,7 @@ private function assignProductToWebsites(\Magento\Catalog\Model\Product $product
362363
);
363364
}
364365

365-
if ($this->storeManager->getStore(true)->getCode() == \Magento\Store\Model\Store::ADMIN_CODE) {
366+
if ($createNew && $this->storeManager->getStore(true)->getCode() == \Magento\Store\Model\Store::ADMIN_CODE) {
366367
$websiteIds = array_keys($this->storeManager->getWebsites());
367368
}
368369

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -672,15 +672,21 @@
672672
</argument>
673673
</arguments>
674674
</type>
675-
<type name="Magento\Eav\Model\EavCustomAttributeTypeLocator">
676-
<arguments>
677-
<argument name="serviceEntityTypeMap" xsi:type="array">
675+
<type name="Magento\Framework\Webapi\ServiceTypeToEntityTypeMap">
676+
<arguments>
677+
<argument name="serviceTypeToEntityTypeMap" xsi:type="array">
678678
<item name="Magento\Catalog\Api\Data\ProductInterface" xsi:type="const">Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE</item>
679+
<item name="Magento\Catalog\Api\Data\CategoryInterface" xsi:type="const">Magento\Catalog\Api\Data\CategoryAttributeInterface::ENTITY_TYPE_CODE</item>
679680
</argument>
680-
<argument name="serviceBackendModelDataInterfaceMap" xsi:type="array">
681-
<item name="Magento\Catalog\Api\Data\ProductInterface" xsi:type="array">
682-
<item name="Magento\Catalog\Model\Product\Attribute\Backend\Media" xsi:type="string">Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface</item>
683-
</item>
681+
</arguments>
682+
</type>
683+
<type name="Magento\Eav\Model\TypeLocator\ComplexType">
684+
<arguments>
685+
<argument name="backendModelToAttributeTypeMap" xsi:type="array">
686+
<item name="Magento\Catalog\Model\Product\Attribute\Backend\Sku" xsi:type="string">string</item>
687+
<item name="Magento\Catalog\Model\Product\Attribute\Backend\Category" xsi:type="string">int[]</item>
688+
<item name="Magento\Catalog\Model\Product\Attribute\Backend\Stock" xsi:type="string">Magento\CatalogInventory\Api\Data\StockItemInterface[]</item>
689+
<item name="Magento\Catalog\Model\Category\Attribute\Backend\Sortby" xsi:type="string">Magento\Eav\Api\Data\AttributeOptionInterface</item>
684690
</argument>
685691
</arguments>
686692
</type>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Cms\Api;
7+
8+
/**
9+
* Command to load the block data by specified identifier
10+
* @api
11+
*/
12+
interface GetBlockByIdentifierInterface
13+
{
14+
/**
15+
* Load block data by given block identifier.
16+
*
17+
* @param string $identifier
18+
* @param int $storeId
19+
* @throws \Magento\Framework\Exception\NoSuchEntityException
20+
* @return \Magento\Cms\Api\Data\BlockInterface
21+
*/
22+
public function execute(string $identifier, int $storeId) : \Magento\Cms\Api\Data\BlockInterface;
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Cms\Api;
7+
8+
/**
9+
* Command to load the page data by specified identifier
10+
* @api
11+
*/
12+
interface GetPageByIdentifierInterface
13+
{
14+
/**
15+
* Load page data by given page identifier.
16+
*
17+
* @param string $identifier
18+
* @param int $storeId
19+
* @throws \Magento\Framework\Exception\NoSuchEntityException
20+
* @return \Magento\Cms\Api\Data\PageInterface
21+
*/
22+
public function execute(string $identifier, int $storeId) : \Magento\Cms\Api\Data\PageInterface;
23+
}

app/code/Magento/Cms/Controller/Adminhtml/Page/PostDataProcessor.php

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
*/
77
namespace Magento\Cms\Controller\Adminhtml\Page;
88

9+
use Magento\Cms\Model\Page\DomValidationState;
10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\Config\Dom\ValidationException;
12+
use Magento\Framework\Config\Dom\ValidationSchemaException;
13+
14+
/**
15+
* Class PostDataProcessor
16+
* @package Magento\Cms\Controller\Adminhtml\Page
17+
*/
918
class PostDataProcessor
1019
{
1120
/**
@@ -23,19 +32,28 @@ class PostDataProcessor
2332
*/
2433
protected $messageManager;
2534

35+
/**
36+
* @var DomValidationState
37+
*/
38+
private $validationState;
39+
2640
/**
2741
* @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter
2842
* @param \Magento\Framework\Message\ManagerInterface $messageManager
2943
* @param \Magento\Framework\View\Model\Layout\Update\ValidatorFactory $validatorFactory
44+
* @param DomValidationState $validationState
3045
*/
3146
public function __construct(
3247
\Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter,
3348
\Magento\Framework\Message\ManagerInterface $messageManager,
34-
\Magento\Framework\View\Model\Layout\Update\ValidatorFactory $validatorFactory
49+
\Magento\Framework\View\Model\Layout\Update\ValidatorFactory $validatorFactory,
50+
DomValidationState $validationState = null
3551
) {
3652
$this->dateFilter = $dateFilter;
3753
$this->messageManager = $messageManager;
3854
$this->validatorFactory = $validatorFactory;
55+
$this->validationState = $validationState
56+
?: ObjectManager::getInstance()->get(DomValidationState::class);
3957
}
4058

4159
/**
@@ -61,27 +79,27 @@ public function filter($data)
6179
* Validate post data
6280
*
6381
* @param array $data
64-
* @return bool Return FALSE if someone item is invalid
82+
* @return bool Return FALSE if some item is invalid
6583
*/
6684
public function validate($data)
6785
{
68-
$errorNo = true;
6986
if (!empty($data['layout_update_xml']) || !empty($data['custom_layout_update_xml'])) {
70-
/** @var $validatorCustomLayout \Magento\Framework\View\Model\Layout\Update\Validator */
71-
$validatorCustomLayout = $this->validatorFactory->create();
72-
if (!empty($data['layout_update_xml']) && !$validatorCustomLayout->isValid($data['layout_update_xml'])) {
73-
$errorNo = false;
74-
}
75-
if (!empty($data['custom_layout_update_xml'])
76-
&& !$validatorCustomLayout->isValid($data['custom_layout_update_xml'])
77-
) {
78-
$errorNo = false;
79-
}
80-
foreach ($validatorCustomLayout->getMessages() as $message) {
81-
$this->messageManager->addError($message);
87+
/** @var $layoutXmlValidator \Magento\Framework\View\Model\Layout\Update\Validator */
88+
$layoutXmlValidator = $this->validatorFactory->create(
89+
[
90+
'validationState' => $this->validationState,
91+
]
92+
);
93+
94+
if (!$this->validateData($data, $layoutXmlValidator)) {
95+
$validatorMessages = $layoutXmlValidator->getMessages();
96+
foreach ($validatorMessages as $message) {
97+
$this->messageManager->addErrorMessage($message);
98+
}
99+
return false;
82100
}
83101
}
84-
return $errorNo;
102+
return true;
85103
}
86104

87105
/**
@@ -108,4 +126,34 @@ public function validateRequireEntry(array $data)
108126
}
109127
return $errorNo;
110128
}
129+
130+
/**
131+
* Validate data, avoid cyclomatic complexity
132+
*
133+
* @param array $data
134+
* @param \Magento\Framework\View\Model\Layout\Update\Validator $layoutXmlValidator
135+
* @return bool
136+
*/
137+
private function validateData($data, $layoutXmlValidator)
138+
{
139+
try {
140+
if (!empty($data['layout_update_xml']) && !$layoutXmlValidator->isValid($data['layout_update_xml'])) {
141+
return false;
142+
}
143+
if (!empty($data['custom_layout_update_xml']) &&
144+
!$layoutXmlValidator->isValid($data['custom_layout_update_xml'])
145+
) {
146+
return false;
147+
}
148+
} catch (ValidationException $e) {
149+
return false;
150+
} catch (ValidationSchemaException $e) {
151+
return false;
152+
} catch (\Exception $e) {
153+
$this->messageManager->addExceptionMessage($e);
154+
return false;
155+
}
156+
157+
return true;
158+
}
111159
}

0 commit comments

Comments
 (0)