From 65001274e6c72fc0e2ff7981923e30e6a80fb5b5 Mon Sep 17 00:00:00 2001 From: Brett Laishley Date: Mon, 25 Mar 2024 16:07:39 +1030 Subject: [PATCH 1/3] BEG-154: Add ability to disable specific indexers --- Helper/Config.php | 48 ++++++++++++++++++++++ Model/Indexer/Category/CategoryIndexer.php | 3 +- Model/Indexer/Category/ProductIndexer.php | 3 +- Model/Indexer/Product/ProductIndexer.php | 3 +- etc/adminhtml/system.xml | 24 +++++++++++ etc/config.xml | 3 ++ 6 files changed, 81 insertions(+), 3 deletions(-) diff --git a/Helper/Config.php b/Helper/Config.php index c3d465c..b3f17f8 100644 --- a/Helper/Config.php +++ b/Helper/Config.php @@ -13,6 +13,9 @@ class Config { private const XML_PATH_RECACHE_ENABLED = 'system/prerender_io/enabled'; + private const XML_PATH_RECACHE_PRODUCT_ENABLED = 'system/prerender_io/enable_product_indexing'; + private const XML_PATH_RECACHE_PRODUCT_CATEGORY_ENABLED = 'system/prerender_io/enable_product_category_indexing'; + private const XML_PATH_RECACHE_CATEGORY_ENABLED = 'system/prerender_io/enable_category_indexing'; private const XML_PATH_PRERENDER_TOKEN = 'system/prerender_io/token'; private const XML_PATH_PRERENDER_USE_PRODUCT_CANONICAL_URL = 'system/prerender_io/use_product_canonical_url'; @@ -43,6 +46,51 @@ public function isRecacheEnabled(?int $storeId = null): bool ); } + /** + * Return if recaching functionality is enabled for product only indexer + * + * @param int|null $storeId + * @return bool + */ + public function isProductRecacheEnabled(?int $storeId = null): bool + { + return $this->scopeConfig->isSetFlag( + self::XML_PATH_RECACHE_PRODUCT_ENABLED, + ScopeInterface::SCOPE_STORES, + $storeId + ); + } + + /** + * Return if recaching functionality is enabled for product-category mapping indexer + * + * @param int|null $storeId + * @return bool + */ + public function isProductCategoryRecacheEnabled(?int $storeId = null): bool + { + return $this->scopeConfig->isSetFlag( + self::XML_PATH_RECACHE_PRODUCT_CATEGORY_ENABLED, + ScopeInterface::SCOPE_STORES, + $storeId + ); + } + + /** + * Return if recaching functionality is enabled for category only indexer + * + * @param int|null $storeId + * @return bool + */ + public function isCategoryRecacheEnabled(?int $storeId = null): bool + { + return $this->scopeConfig->isSetFlag( + self::XML_PATH_RECACHE_CATEGORY_ENABLED, + ScopeInterface::SCOPE_STORES, + $storeId + ); + } + /** * Return configured Prerender.io token for API calls * diff --git a/Model/Indexer/Category/CategoryIndexer.php b/Model/Indexer/Category/CategoryIndexer.php index 1634db7..0e0e50e 100644 --- a/Model/Indexer/Category/CategoryIndexer.php +++ b/Model/Indexer/Category/CategoryIndexer.php @@ -133,7 +133,8 @@ public function executeByDimensions(array $dimensions, \Traversable $entityIds): } $storeId = (int)$dimensions[StoreDimensionProvider::DIMENSION_NAME]->getValue(); - if (!$this->prerenderConfigHelper->isRecacheEnabled($storeId)) { + if (!$this->prerenderConfigHelper->isRecacheEnabled($storeId) + || !$this->prerenderConfigHelper->isProductCategoryRecacheEnabled($storeId)) { return; } diff --git a/Model/Indexer/Category/ProductIndexer.php b/Model/Indexer/Category/ProductIndexer.php index 9c85fc6..15c0066 100644 --- a/Model/Indexer/Category/ProductIndexer.php +++ b/Model/Indexer/Category/ProductIndexer.php @@ -144,7 +144,8 @@ public function executeByDimensions(array $dimensions, \Traversable $entityIds): } $storeId = (int)$dimensions[StoreDimensionProvider::DIMENSION_NAME]->getValue(); - if (!$this->prerenderConfigHelper->isRecacheEnabled($storeId)) { + if (!$this->prerenderConfigHelper->isRecacheEnabled($storeId) + || !$this->prerenderConfigHelper->isProductCategoryRecacheEnabled($storeId)) { return; } diff --git a/Model/Indexer/Product/ProductIndexer.php b/Model/Indexer/Product/ProductIndexer.php index 0239eb8..429ea4b 100644 --- a/Model/Indexer/Product/ProductIndexer.php +++ b/Model/Indexer/Product/ProductIndexer.php @@ -140,7 +140,8 @@ public function executeByDimensions(array $dimensions, \Traversable $entityIds): } $storeId = (int)$dimensions[StoreDimensionProvider::DIMENSION_NAME]->getValue(); - if (!$this->prerenderConfigHelper->isRecacheEnabled($storeId)) { + if (!$this->prerenderConfigHelper->isRecacheEnabled($storeId) + || !$this->prerenderConfigHelper->isProductCategoryRecacheEnabled($storeId)) { return; } diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 5f3435e..09a8398 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -25,6 +25,30 @@ Ignore the non-canonical URLs which includes category paths for products. Magento\Config\Model\Config\Source\Yesno + + + Product updates will recache PDPs. + Magento\Config\Model\Config\Source\Yesno + + 1 + + + + + Product updates will recache linked category PLPs. + Magento\Config\Model\Config\Source\Yesno + + 1 + + + + + Category updates will recache PLPs. + Magento\Config\Model\Config\Source\Yesno + + 1 + + diff --git a/etc/config.xml b/etc/config.xml index d346dc2..7838f61 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -5,6 +5,9 @@ 0 + 1 + 1 + 1 From 560bb050a9166b66eb8b019ecba50e51055c228c Mon Sep 17 00:00:00 2001 From: Brett Laishley Date: Mon, 25 Mar 2024 16:10:37 +1030 Subject: [PATCH 2/3] BEG-154: Fix typos --- Model/Indexer/Category/CategoryIndexer.php | 2 +- Model/Indexer/Category/ProductIndexer.php | 2 +- Model/Indexer/Product/ProductIndexer.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Model/Indexer/Category/CategoryIndexer.php b/Model/Indexer/Category/CategoryIndexer.php index 0e0e50e..96590f5 100644 --- a/Model/Indexer/Category/CategoryIndexer.php +++ b/Model/Indexer/Category/CategoryIndexer.php @@ -121,7 +121,7 @@ public function execute($ids): void /** * Execute indexing per dimension (store) * - * @param arry $dimensions + * @param array $dimensions * @param \Traversable $entityIds * @throws FileSystemException * @throws RuntimeException diff --git a/Model/Indexer/Category/ProductIndexer.php b/Model/Indexer/Category/ProductIndexer.php index 15c0066..a271d6e 100644 --- a/Model/Indexer/Category/ProductIndexer.php +++ b/Model/Indexer/Category/ProductIndexer.php @@ -132,7 +132,7 @@ public function execute($ids): void /** * Execute indexing per dimension (store) * - * @param arry $dimensions + * @param array $dimensions * @param \Traversable $entityIds * @throws FileSystemException * @throws RuntimeException diff --git a/Model/Indexer/Product/ProductIndexer.php b/Model/Indexer/Product/ProductIndexer.php index 429ea4b..310cd4b 100644 --- a/Model/Indexer/Product/ProductIndexer.php +++ b/Model/Indexer/Product/ProductIndexer.php @@ -128,7 +128,7 @@ public function execute($ids): void /** * Execute indexing per dimension (store) * - * @param arry $dimensions + * @param array $dimensions * @param \Traversable $entityIds * @throws FileSystemException * @throws RuntimeException From 469a6398ff8b490b46c76e2036214992cf3db8a8 Mon Sep 17 00:00:00 2001 From: Brett Laishley Date: Mon, 25 Mar 2024 16:10:55 +1030 Subject: [PATCH 3/3] BEG-154: Update description for global enable/disable toggle --- Helper/Config.php | 2 +- etc/adminhtml/system.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Helper/Config.php b/Helper/Config.php index b3f17f8..873a123 100644 --- a/Helper/Config.php +++ b/Helper/Config.php @@ -32,7 +32,7 @@ public function __construct(ScopeConfigInterface $scopeConfig) } /** - * Return if recaching functionality is enabled or not + * Return if recaching functionality is enabled globally * * @param int|null $storeId * @return bool diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 09a8398..ea3a92d 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -10,8 +10,8 @@ - - Send recache requests to Prerender.io on product changes + + Send recache requests to Prerender.io Magento\Config\Model\Config\Source\Yesno