Skip to content

Commit e2515cd

Browse files
Merge pull request #20 from aligent/feature/BEG-154_Add_admin_configuration_to_disable_indexers
BEG-154: Add admin configuration to disable indexers
2 parents c1e6de9 + 469a639 commit e2515cd

File tree

6 files changed

+87
-9
lines changed

6 files changed

+87
-9
lines changed

Helper/Config.php

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
class Config
1414
{
1515
private const XML_PATH_RECACHE_ENABLED = 'system/prerender_io/enabled';
16+
private const XML_PATH_RECACHE_PRODUCT_ENABLED = 'system/prerender_io/enable_product_indexing';
17+
private const XML_PATH_RECACHE_PRODUCT_CATEGORY_ENABLED = 'system/prerender_io/enable_product_category_indexing';
18+
private const XML_PATH_RECACHE_CATEGORY_ENABLED = 'system/prerender_io/enable_category_indexing';
1619
private const XML_PATH_PRERENDER_TOKEN = 'system/prerender_io/token';
1720
private const XML_PATH_PRERENDER_USE_PRODUCT_CANONICAL_URL = 'system/prerender_io/use_product_canonical_url';
1821

@@ -29,7 +32,7 @@ public function __construct(ScopeConfigInterface $scopeConfig)
2932
}
3033

3134
/**
32-
* Return if recaching functionality is enabled or not
35+
* Return if recaching functionality is enabled globally
3336
*
3437
* @param int|null $storeId
3538
* @return bool
@@ -43,6 +46,51 @@ public function isRecacheEnabled(?int $storeId = null): bool
4346
);
4447
}
4548

49+
/**
50+
* Return if recaching functionality is enabled for product only indexer
51+
*
52+
* @param int|null $storeId
53+
* @return bool
54+
*/
55+
public function isProductRecacheEnabled(?int $storeId = null): bool
56+
{
57+
return $this->scopeConfig->isSetFlag(
58+
self::XML_PATH_RECACHE_PRODUCT_ENABLED,
59+
ScopeInterface::SCOPE_STORES,
60+
$storeId
61+
);
62+
}
63+
64+
/**
65+
* Return if recaching functionality is enabled for product-category mapping indexer
66+
*
67+
* @param int|null $storeId
68+
* @return bool
69+
*/
70+
public function isProductCategoryRecacheEnabled(?int $storeId = null): bool
71+
{
72+
return $this->scopeConfig->isSetFlag(
73+
self::XML_PATH_RECACHE_PRODUCT_CATEGORY_ENABLED,
74+
ScopeInterface::SCOPE_STORES,
75+
$storeId
76+
);
77+
}
78+
79+
/**
80+
* Return if recaching functionality is enabled for category only indexer
81+
*
82+
* @param int|null $storeId
83+
* @return bool
84+
*/
85+
public function isCategoryRecacheEnabled(?int $storeId = null): bool
86+
{
87+
return $this->scopeConfig->isSetFlag(
88+
self::XML_PATH_RECACHE_CATEGORY_ENABLED,
89+
ScopeInterface::SCOPE_STORES,
90+
$storeId
91+
);
92+
}
93+
4694
/**
4795
* Return configured Prerender.io token for API calls
4896
*

Model/Indexer/Category/CategoryIndexer.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function execute($ids): void
121121
/**
122122
* Execute indexing per dimension (store)
123123
*
124-
* @param arry $dimensions
124+
* @param array $dimensions
125125
* @param \Traversable $entityIds
126126
* @throws FileSystemException
127127
* @throws RuntimeException
@@ -133,7 +133,8 @@ public function executeByDimensions(array $dimensions, \Traversable $entityIds):
133133
}
134134
$storeId = (int)$dimensions[StoreDimensionProvider::DIMENSION_NAME]->getValue();
135135

136-
if (!$this->prerenderConfigHelper->isRecacheEnabled($storeId)) {
136+
if (!$this->prerenderConfigHelper->isRecacheEnabled($storeId)
137+
|| !$this->prerenderConfigHelper->isProductCategoryRecacheEnabled($storeId)) {
137138
return;
138139
}
139140

Model/Indexer/Category/ProductIndexer.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function execute($ids): void
132132
/**
133133
* Execute indexing per dimension (store)
134134
*
135-
* @param arry $dimensions
135+
* @param array $dimensions
136136
* @param \Traversable $entityIds
137137
* @throws FileSystemException
138138
* @throws RuntimeException
@@ -144,7 +144,8 @@ public function executeByDimensions(array $dimensions, \Traversable $entityIds):
144144
}
145145
$storeId = (int)$dimensions[StoreDimensionProvider::DIMENSION_NAME]->getValue();
146146

147-
if (!$this->prerenderConfigHelper->isRecacheEnabled($storeId)) {
147+
if (!$this->prerenderConfigHelper->isRecacheEnabled($storeId)
148+
|| !$this->prerenderConfigHelper->isProductCategoryRecacheEnabled($storeId)) {
148149
return;
149150
}
150151

Model/Indexer/Product/ProductIndexer.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function execute($ids): void
128128
/**
129129
* Execute indexing per dimension (store)
130130
*
131-
* @param arry $dimensions
131+
* @param array $dimensions
132132
* @param \Traversable $entityIds
133133
* @throws FileSystemException
134134
* @throws RuntimeException
@@ -140,7 +140,8 @@ public function executeByDimensions(array $dimensions, \Traversable $entityIds):
140140
}
141141
$storeId = (int)$dimensions[StoreDimensionProvider::DIMENSION_NAME]->getValue();
142142

143-
if (!$this->prerenderConfigHelper->isRecacheEnabled($storeId)) {
143+
if (!$this->prerenderConfigHelper->isRecacheEnabled($storeId)
144+
|| !$this->prerenderConfigHelper->isProductCategoryRecacheEnabled($storeId)) {
144145
return;
145146
}
146147

etc/adminhtml/system.xml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
<group id="prerender_io" translate="label" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="100">
1111
<label>Prerender.io</label>
1212
<field id="enabled" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
13-
<label>Product recaching enabled?</label>
14-
<comment>Send recache requests to Prerender.io on product changes</comment>
13+
<label>Enable prerender.io recaching</label>
14+
<comment>Send recache requests to Prerender.io</comment>
1515
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
1616
</field>
1717
<field id="token" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
@@ -25,6 +25,30 @@
2525
<comment>Ignore the non-canonical URLs which includes category paths for products.</comment>
2626
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
2727
</field>
28+
<field id="enable_product_indexing" translate="label comment" type="select" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
29+
<label>Recache product URLs</label>
30+
<comment>Product updates will recache PDPs.</comment>
31+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
32+
<depends>
33+
<field id="enabled">1</field>
34+
</depends>
35+
</field>
36+
<field id="enable_product_category_indexing" translate="label comment" type="select" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1">
37+
<label>Recache product's category URLs</label>
38+
<comment>Product updates will recache linked category PLPs.</comment>
39+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
40+
<depends>
41+
<field id="enabled">1</field>
42+
</depends>
43+
</field>
44+
<field id="enable_category_indexing" translate="label comment" type="select" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="1">
45+
<label>Recache category URLs</label>
46+
<comment>Category updates will recache PLPs.</comment>
47+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
48+
<depends>
49+
<field id="enabled">1</field>
50+
</depends>
51+
</field>
2852
</group>
2953
</section>
3054
</system>

etc/config.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
<system>
66
<prerender_io>
77
<use_product_canonical_url>0</use_product_canonical_url>
8+
<enable_product_indexing>1</enable_product_indexing>
9+
<enable_product_category_indexing>1</enable_product_category_indexing>
10+
<enable_category_indexing>1</enable_category_indexing>
811
</prerender_io>
912
</system>
1013
</default>

0 commit comments

Comments
 (0)