-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '2.4-develop' of github.com:magento/magento2 into 2.4-de…
…velop
- Loading branch information
Showing
14 changed files
with
320 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
app/code/Magento/Catalog/Model/ProductNotFoundPageCacheTags.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Catalog\Model; | ||
|
||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\Framework\App\RequestInterface; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\PageCache\Model\Spi\PageCacheTagsPreprocessorInterface; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
|
||
/** | ||
* Add product identities to "noroute" page | ||
* | ||
* Ensure that "noroute" page has necessary product tags | ||
* so it can be invalidated once the product becomes visible again | ||
*/ | ||
class ProductNotFoundPageCacheTags implements PageCacheTagsPreprocessorInterface | ||
{ | ||
private const NOROUTE_ACTION_NAME = 'cms_noroute_index'; | ||
/** | ||
* @var ProductRepositoryInterface | ||
*/ | ||
private $productRepository; | ||
/** | ||
* @var StoreManagerInterface | ||
*/ | ||
private $storeManager; | ||
/** | ||
* @var RequestInterface | ||
*/ | ||
private $request; | ||
|
||
/** | ||
* @param RequestInterface $request | ||
* @param ProductRepositoryInterface $productRepository | ||
* @param StoreManagerInterface $storeManager | ||
*/ | ||
public function __construct( | ||
RequestInterface $request, | ||
ProductRepositoryInterface $productRepository, | ||
StoreManagerInterface $storeManager | ||
) { | ||
$this->productRepository = $productRepository; | ||
$this->storeManager = $storeManager; | ||
$this->request = $request; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function process(array $tags): array | ||
{ | ||
if ($this->request->getFullActionName() === self::NOROUTE_ACTION_NAME) { | ||
try { | ||
$productId = (int) $this->request->getParam('id'); | ||
$product = $this->productRepository->getById( | ||
$productId, | ||
false, | ||
$this->storeManager->getStore()->getId() | ||
); | ||
} catch (NoSuchEntityException $e) { | ||
$product = null; | ||
} | ||
if ($product) { | ||
$tags = array_merge($tags, $product->getIdentities()); | ||
} | ||
} | ||
return $tags; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
app/code/Magento/PageCache/Model/PageCacheTagsPreprocessorComposite.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\PageCache\Model; | ||
|
||
use InvalidArgumentException; | ||
use Magento\Framework\App\RequestInterface; | ||
use Magento\PageCache\Model\Spi\PageCacheTagsPreprocessorInterface; | ||
|
||
/** | ||
* Composite page cache preprocessors | ||
*/ | ||
class PageCacheTagsPreprocessorComposite implements PageCacheTagsPreprocessorInterface | ||
{ | ||
/** | ||
* @var PageCacheTagsPreprocessorInterface[][] | ||
*/ | ||
private $preprocessors; | ||
/** | ||
* @var RequestInterface | ||
*/ | ||
private $request; | ||
|
||
/** | ||
* @param RequestInterface $request | ||
* @param PageCacheTagsPreprocessorInterface[][] $preprocessors | ||
*/ | ||
public function __construct( | ||
RequestInterface $request, | ||
array $preprocessors = [] | ||
) { | ||
foreach ($preprocessors as $group) { | ||
foreach ($group as $preprocessor) { | ||
if (!$preprocessor instanceof PageCacheTagsPreprocessorInterface) { | ||
throw new InvalidArgumentException( | ||
sprintf( | ||
'Instance of %s is expected, got %s instead.', | ||
PageCacheTagsPreprocessorInterface::class, | ||
get_class($preprocessor) | ||
) | ||
); | ||
} | ||
} | ||
} | ||
$this->preprocessors = $preprocessors; | ||
$this->request = $request; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function process(array $tags): array | ||
{ | ||
$forwardInfo = $this->request->getBeforeForwardInfo(); | ||
$actionName = $forwardInfo | ||
? implode('_', [$forwardInfo['route_name'], $forwardInfo['controller_name'], $forwardInfo['action_name']]) | ||
: $this->request->getFullActionName(); | ||
if (isset($this->preprocessors[$actionName])) { | ||
foreach ($this->preprocessors[$actionName] as $preprocessor) { | ||
$tags = $preprocessor->process($tags); | ||
} | ||
} | ||
return $tags; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
app/code/Magento/PageCache/Model/Spi/PageCacheTagsPreprocessorInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\PageCache\Model\Spi; | ||
|
||
/** | ||
* Interface for page tags preprocessors | ||
*/ | ||
interface PageCacheTagsPreprocessorInterface | ||
{ | ||
/** | ||
* Change page tags and returned the modified tags | ||
* | ||
* @param array $tags | ||
* @return array | ||
*/ | ||
public function process(array $tags): array; | ||
} |
Oops, something went wrong.