Skip to content

Commit

Permalink
Merge pull request #8392 from magento-cia/cia-2.4.7-beta2-develop-bug…
Browse files Browse the repository at this point in the history
…fix-07102023

cia-2.4.7-beta2-develop-bugfix-07102023
  • Loading branch information
pawan-adobe-security authored Aug 11, 2023
2 parents 766f08e + 8e0e728 commit 2117252
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
23 changes: 22 additions & 1 deletion app/code/Magento/PageCache/Controller/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\PageCache\Controller;

use Magento\Framework\Serialize\Serializer\Base64Json;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\Validator\RegexFactory;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\View\Layout\LayoutCacheKeyInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;

abstract class Block extends \Magento\Framework\App\Action\Action
{
Expand Down Expand Up @@ -51,21 +54,33 @@ abstract class Block extends \Magento\Framework\App\Action\Action
*/
private const VALIDATION_RULE_PATTERN = '/^[a-z0-9]+[a-z0-9_]*$/i';

/**
* @var ScopeConfigInterface
*/
private $config;

/**
* Handle size system name
*/
private const XML_HANDLES_SIZE = 'system/full_page_cache/handles_size';

/**
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Framework\Translate\InlineInterface $translateInline
* @param Json $jsonSerializer
* @param Base64Json $base64jsonSerializer
* @param LayoutCacheKeyInterface $layoutCacheKey
* @param RegexFactory|null $regexValidatorFactory
* @param ScopeConfigInterface|null $scopeConfig
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\Translate\InlineInterface $translateInline,
Json $jsonSerializer = null,
Base64Json $base64jsonSerializer = null,
LayoutCacheKeyInterface $layoutCacheKey = null,
?RegexFactory $regexValidatorFactory = null
?RegexFactory $regexValidatorFactory = null,
ScopeConfigInterface $scopeConfig = null
) {
parent::__construct($context);
$this->translateInline = $translateInline;
Expand All @@ -77,6 +92,7 @@ public function __construct(
?: ObjectManager::getInstance()->get(LayoutCacheKeyInterface::class);
$this->regexValidatorFactory = $regexValidatorFactory
?: ObjectManager::getInstance()->get(RegexFactory::class);
$this->config = $scopeConfig;
}

/**
Expand All @@ -94,6 +110,11 @@ protected function _getBlocks()
}
$blocks = $this->jsonSerializer->unserialize($blocks);
$handles = $this->base64jsonSerializer->unserialize($handles);

$handleSize = (int) $this->config->getValue(self::XML_HANDLES_SIZE);
$handles = ($handleSize && count($handles) > $handleSize)
? array_splice($handles, 0, $handleSize) : $handles;

if (!$this->validateHandleParam($handles)) {
return [];
}
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/PageCache/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@
<comment>Public content cache lifetime in seconds. If field is empty default value 86400 will be saved. </comment>
<backend_model>Magento\PageCache\Model\System\Config\Backend\Ttl</backend_model>
</field>
<field id="handles_size" type="text" translate="label comment" sortOrder="5" showInDefault="1" canRestore="1">
<label>Handles params size</label>
<comment>Handles params size. For better performance use handles parameter size between 50 and 100. </comment>
</field>
</group>
</section>
</system>
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/PageCache/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<path>varnish4.vcl</path>
</varnish4>
<ttl>86400</ttl>
<handles_size>100</handles_size>
<caching_application>1</caching_application>
<default>
<access_list>localhost</access_list>
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/PageCache/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<type name="Magento\PageCache\Controller\Block">
<arguments>
<argument name="layoutCacheKey" xsi:type="object">Magento\Framework\View\Layout\LayoutCacheKeyInterface</argument>
<argument name="scopeConfig" xsi:type="object">Magento\Framework\App\Config\ScopeConfigInterface\Proxy</argument>
</arguments>
</type>
<type name="Magento\Framework\App\Cache\RuntimeStaleCacheStateModifier">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1933,21 +1933,18 @@ public function testFilterProductsBySingleCategoryId(string $fieldName, string $
$product = $this->productRepository->get($links[$itemIndex]->getSku());
$this->assertEquals($response['products']['items'][$itemIndex]['name'], $product->getName());
$this->assertEquals($response['products']['items'][$itemIndex]['type_id'], $product->getTypeId());
$categoryIds = $product->getCategoryIds();
foreach ($categoryIds as $index => $value) {
$categoryIds[$index] = (int)$value;
}
$categoryInResponse = array_map(
null,
$categoryIds,
$categoryIds = array_map('intval', $product->getCategoryIds());
$this->assertCount(count($categoryIds), $response['products']['items'][$itemIndex]['categories']);
$categoryInResponse = array_combine(
array_column($response['products']['items'][$itemIndex]['categories'], 'id'),
$response['products']['items'][$itemIndex]['categories']
);
foreach ($categoryInResponse as $key => $categoryData) {
$this->assertNotEmpty($categoryData);
foreach ($categoryIds as $categoryId) {
$this->assertArrayHasKey($categoryId, $categoryInResponse);
/** @var CategoryInterface | Category $category */
$category = $this->categoryRepository->get($categoryInResponse[$key][0]);
$category = $this->categoryRepository->get($categoryId);
$this->assertResponseFields(
$categoryInResponse[$key][1],
$categoryInResponse[$categoryId],
[
'name' => $category->getName(),
'id' => $category->getId(),
Expand Down

0 comments on commit 2117252

Please sign in to comment.