Skip to content

Commit e6a98c4

Browse files
author
Oleksandr Gorkun
committed
Merge branch '2.4.0-develop' of https://github.com/magento/magento2ce into MC-33823
� Conflicts: � dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Category/Tree.php � dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Create.php � dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Create/Coupons.php � dev/tests/functional/tests/app/Magento/Wishlist/Test/Block/Adminhtml/Customer/Edit/Tab/Wishlist/Grid.php
2 parents ae758df + 07b53eb commit e6a98c4

File tree

3,415 files changed

+2733
-224785
lines changed

Some content is hidden

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

3,415 files changed

+2733
-224785
lines changed

.php_cs.dist

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010

1111
$finder = PhpCsFixer\Finder::create()
1212
->name('*.phtml')
13-
->exclude('dev/tests/functional/generated')
14-
->exclude('dev/tests/functional/var')
15-
->exclude('dev/tests/functional/vendor')
1613
->exclude('dev/tests/integration/tmp')
1714
->exclude('dev/tests/integration/var')
1815
->exclude('lib/internal/Cm')

app/code/Magento/Backend/App/AbstractAction.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Magento\Framework\Data\Form\FormKey\Validator as FormKeyValidator;
1717
use Magento\Framework\Locale\ResolverInterface;
1818
use Magento\Framework\View\Element\AbstractBlock;
19+
use Magento\Framework\Encryption\Helper\Security;
1920

2021
/**
2122
* Generic backend controller
@@ -386,7 +387,7 @@ protected function _validateSecretKey()
386387
}
387388

388389
$secretKey = $this->getRequest()->getParam(UrlInterface::SECRET_KEY_PARAM_NAME, null);
389-
if (!$secretKey || $secretKey != $this->_backendUrl->getSecretKey()) {
390+
if (!$secretKey || !Security::compareStrings($secretKey, $this->_backendUrl->getSecretKey())) {
390391
return false;
391392
}
392393
return true;

app/code/Magento/Backend/Test/Mftf/Test/AdminLoginSuccessfulTest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<group value="login"/>
2121
</annotations>
2222

23+
2324
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
2425
<actionGroup ref="AssertAdminSuccessLoginActionGroup" stepKey="assertLoggedIn"/>
2526
<actionGroup ref="AdminLogoutActionGroup" stepKey="logoutFromAdmin"/>

app/code/Magento/CardinalCommerce/Model/JwtManagement.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\CardinalCommerce\Model;
99

1010
use Magento\Framework\Serialize\Serializer\Json;
11+
use Magento\Framework\Encryption\Helper\Security;
1112

1213
/**
1314
* JSON Web Token management.
@@ -62,7 +63,8 @@ public function decode(string $jwt, string $key): array
6263
$payload = $this->json->unserialize($payloadJson);
6364

6465
$signature = $this->urlSafeB64Decode($signatureB64);
65-
if ($signature !== $this->sign($headB64 . '.' . $payloadB64, $key, $header['alg'])) {
66+
67+
if (!Security::compareStrings($signature, $this->sign($headB64 . '.' . $payloadB64, $key, $header['alg']))) {
6668
throw new \InvalidArgumentException('JWT signature verification failed');
6769
}
6870

app/code/Magento/Catalog/Block/Product/ListProduct.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -358,18 +358,16 @@ public function getIdentities()
358358

359359
$category = $this->getLayer()->getCurrentCategory();
360360
if ($category) {
361-
$identities[] = Product::CACHE_PRODUCT_CATEGORY_TAG . '_' . $category->getId();
361+
$identities[] = [Product::CACHE_PRODUCT_CATEGORY_TAG . '_' . $category->getId()];
362362
}
363363

364364
//Check if category page shows only static block (No products)
365-
if ($category->getData('display_mode') == Category::DM_PAGE) {
366-
return $identities;
367-
}
368-
369-
foreach ($this->_getProductCollection() as $item) {
370-
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
371-
$identities = array_merge($identities, $item->getIdentities());
365+
if ($category->getData('display_mode') != Category::DM_PAGE) {
366+
foreach ($this->_getProductCollection() as $item) {
367+
$identities[] = $item->getIdentities();
368+
}
372369
}
370+
$identities = array_merge(...$identities);
373371

374372
return $identities;
375373
}
@@ -382,7 +380,7 @@ public function getIdentities()
382380
*/
383381
public function getAddToCartPostParams(Product $product)
384382
{
385-
$url = $this->getAddToCartUrl($product);
383+
$url = $this->getAddToCartUrl($product, ['_escape' => false]);
386384
return [
387385
'action' => $url,
388386
'data' => [

app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77
namespace Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute;
88

99
use Magento\AsynchronousOperations\Api\Data\OperationInterface;
10+
use Magento\Catalog\Model\ProductFactory;
1011
use Magento\Catalog\Api\Data\ProductAttributeInterface;
1112
use Magento\Eav\Model\Config;
1213
use Magento\Framework\App\Action\HttpPostActionInterface;
1314
use Magento\Backend\App\Action;
1415
use Magento\Framework\App\ObjectManager;
16+
use Magento\Framework\Exception\LocalizedException;
1517
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1618

1719
/**
18-
* Class used for saving mass updated products attributes.
20+
* Class responsible for saving product attributes.
1921
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2022
*/
2123
class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute implements HttpPostActionInterface
@@ -60,6 +62,11 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribut
6062
*/
6163
private $eavConfig;
6264

65+
/**
66+
* @var ProductFactory
67+
*/
68+
private $productFactory;
69+
6370
/**
6471
* @param Action\Context $context
6572
* @param \Magento\Catalog\Helper\Product\Edit\Action\Attribute $attributeHelper
@@ -71,6 +78,7 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribut
7178
* @param int $bulkSize
7279
* @param TimezoneInterface $timezone
7380
* @param Config $eavConfig
81+
* @param ProductFactory $productFactory
7482
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
7583
*/
7684
public function __construct(
@@ -83,7 +91,8 @@ public function __construct(
8391
\Magento\Authorization\Model\UserContextInterface $userContext,
8492
int $bulkSize = 100,
8593
TimezoneInterface $timezone = null,
86-
Config $eavConfig = null
94+
Config $eavConfig = null,
95+
ProductFactory $productFactory = null
8796
) {
8897
parent::__construct($context, $attributeHelper);
8998
$this->bulkManagement = $bulkManagement;
@@ -96,6 +105,7 @@ public function __construct(
96105
->get(TimezoneInterface::class);
97106
$this->eavConfig = $eavConfig ?: ObjectManager::getInstance()
98107
->get(Config::class);
108+
$this->productFactory = $productFactory ?? ObjectManager::getInstance()->get(ProductFactory::class);
99109
}
100110

101111
/**
@@ -121,9 +131,10 @@ public function execute()
121131
$attributesData = $this->sanitizeProductAttributes($attributesData);
122132

123133
try {
134+
$this->validateProductAttributes($attributesData);
124135
$this->publish($attributesData, $websiteRemoveData, $websiteAddData, $storeId, $websiteId, $productIds);
125136
$this->messageManager->addSuccessMessage(__('Message is added to queue'));
126-
} catch (\Magento\Framework\Exception\LocalizedException $e) {
137+
} catch (LocalizedException $e) {
127138
$this->messageManager->addErrorMessage($e->getMessage());
128139
} catch (\Exception $e) {
129140
$this->messageManager->addExceptionMessage(
@@ -152,10 +163,12 @@ private function sanitizeProductAttributes($attributesData)
152163
}
153164

154165
$attribute = $this->eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $attributeCode);
166+
155167
if (!$attribute->getAttributeId()) {
156168
unset($attributesData[$attributeCode]);
157169
continue;
158170
}
171+
159172
if ($attribute->getBackendType() === 'datetime') {
160173
if (!empty($value)) {
161174
$filterInput = new \Zend_Filter_LocalizedToNormalized(['date_format' => $dateFormat]);
@@ -183,6 +196,25 @@ private function sanitizeProductAttributes($attributesData)
183196
return $attributesData;
184197
}
185198

199+
/**
200+
* Validate product attributes data.
201+
*
202+
* @param array $attributesData
203+
*
204+
* @return void
205+
* @throws LocalizedException
206+
*/
207+
private function validateProductAttributes(array $attributesData): void
208+
{
209+
$product = $this->productFactory->create();
210+
$product->setData($attributesData);
211+
212+
foreach (array_keys($attributesData) as $attributeCode) {
213+
$attribute = $this->eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $attributeCode);
214+
$attribute->getBackend()->validate($product);
215+
}
216+
}
217+
186218
/**
187219
* Schedule new bulk
188220
*
@@ -192,7 +224,7 @@ private function sanitizeProductAttributes($attributesData)
192224
* @param int $storeId
193225
* @param int $websiteId
194226
* @param array $productIds
195-
* @throws \Magento\Framework\Exception\LocalizedException
227+
* @throws LocalizedException
196228
*
197229
* @return void
198230
*/
@@ -246,7 +278,7 @@ private function publish(
246278
$this->userContext->getUserId()
247279
);
248280
if (!$result) {
249-
throw new \Magento\Framework\Exception\LocalizedException(
281+
throw new LocalizedException(
250282
__('Something went wrong while processing the request.')
251283
);
252284
}

app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public function execute()
224224
return $this->returnResult('catalog/*/', [], ['error' => true]);
225225
}
226226
// entity type check
227-
if ($model->getEntityTypeId() != $this->_entityTypeId) {
227+
if ($model->getEntityTypeId() != $this->_entityTypeId || array_key_exists('backend_model', $data)) {
228228
$this->messageManager->addErrorMessage(__('We can\'t update the attribute.'));
229229
$this->_session->setAttributeData($data);
230230
return $this->returnResult('catalog/*/', [], ['error' => true]);
@@ -261,6 +261,8 @@ public function execute()
261261
unset($data['apply_to']);
262262
}
263263

264+
unset($data['entity_type_id']);
265+
264266
$model->addData($data);
265267

266268
if (!$attributeId) {

app/code/Magento/Catalog/Model/Template/Filter.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
/**
1616
* Work with catalog(store, website) urls
17-
*
18-
* @package Magento\Catalog\Model\Template
1917
*/
2018
class Filter extends \Magento\Framework\Filter\Template
2119
{
@@ -30,6 +28,7 @@ class Filter extends \Magento\Framework\Filter\Template
3028
* Whether to allow SID in store directive: NO
3129
*
3230
* @var bool
31+
* @deprecated SID query parameter is not used in URLs anymore.
3332
*/
3433
protected $_useSessionInUrl = false;
3534

@@ -81,10 +80,14 @@ public function setUseAbsoluteLinks($flag)
8180
*
8281
* @param bool $flag
8382
* @return $this
83+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
84+
* @deprecated SID query parameter is not used in URLs anymore.
8485
*/
8586
public function setUseSessionInUrl($flag)
8687
{
87-
$this->_useSessionInUrl = $flag;
88+
// phpcs:disable Magento2.Functions.DiscouragedFunction
89+
trigger_error('Session ID is not used as URL parameter anymore.', E_USER_DEPRECATED);
90+
8891
return $this;
8992
}
9093

@@ -126,6 +129,7 @@ public function viewDirective($construction)
126129
*/
127130
public function mediaDirective($construction)
128131
{
132+
// phpcs:disable Magento2.Functions.DiscouragedFunction
129133
$params = $this->getParameters(html_entity_decode($construction[2], ENT_QUOTES));
130134
return $this->_storeManager->getStore()
131135
->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . $params['url'];

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public function testGetAddToCartPostParams()
235235
->willReturn(true);
236236
$this->cartHelperMock->expects($this->any())
237237
->method('getAddUrl')
238-
->with($this->productMock, [])
238+
->with($this->productMock, ['_escape' => false])
239239
->willReturn($url);
240240
$this->productMock->expects($this->once())
241241
->method('getEntityId')

app/code/Magento/Checkout/Controller/Sidebar/RemoveItem.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
use Magento\Framework\Exception\LocalizedException;
2020
use Psr\Log\LoggerInterface;
2121

22+
/**
23+
* Controller for removing quote item from shopping cart.
24+
*/
2225
class RemoveItem extends Action implements HttpPostActionInterface
2326
{
2427
/**
@@ -96,6 +99,9 @@ public function execute()
9699
$this->sidebar->removeQuoteItem($itemId);
97100
} catch (LocalizedException $e) {
98101
$error = $e->getMessage();
102+
} catch (\Zend_Db_Exception $e) {
103+
$this->logger->critical($e);
104+
$error = __('An unspecified error occurred. Please contact us for assistance.');
99105
} catch (Exception $e) {
100106
$this->logger->critical($e);
101107
$error = $e->getMessage();

0 commit comments

Comments
 (0)