Skip to content

Commit

Permalink
Merge pull request #20 from aligent/feature/BEG-154_Add_admin_configu…
Browse files Browse the repository at this point in the history
…ration_to_disable_indexers

BEG-154: Add admin configuration to disable indexers
  • Loading branch information
aligent-lturner authored Mar 26, 2024
2 parents c1e6de9 + 469a639 commit e2515cd
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 9 deletions.
50 changes: 49 additions & 1 deletion Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -29,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
Expand All @@ -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
*
Expand Down
5 changes: 3 additions & 2 deletions Model/Indexer/Category/CategoryIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
5 changes: 3 additions & 2 deletions Model/Indexer/Category/ProductIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
5 changes: 3 additions & 2 deletions Model/Indexer/Product/ProductIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
28 changes: 26 additions & 2 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<group id="prerender_io" translate="label" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="100">
<label>Prerender.io</label>
<field id="enabled" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Product recaching enabled?</label>
<comment>Send recache requests to Prerender.io on product changes</comment>
<label>Enable prerender.io recaching</label>
<comment>Send recache requests to Prerender.io</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="token" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
Expand All @@ -25,6 +25,30 @@
<comment>Ignore the non-canonical URLs which includes category paths for products.</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="enable_product_indexing" translate="label comment" type="select" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Recache product URLs</label>
<comment>Product updates will recache PDPs.</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<depends>
<field id="enabled">1</field>
</depends>
</field>
<field id="enable_product_category_indexing" translate="label comment" type="select" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Recache product's category URLs</label>
<comment>Product updates will recache linked category PLPs.</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<depends>
<field id="enabled">1</field>
</depends>
</field>
<field id="enable_category_indexing" translate="label comment" type="select" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Recache category URLs</label>
<comment>Category updates will recache PLPs.</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<depends>
<field id="enabled">1</field>
</depends>
</field>
</group>
</section>
</system>
Expand Down
3 changes: 3 additions & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<system>
<prerender_io>
<use_product_canonical_url>0</use_product_canonical_url>
<enable_product_indexing>1</enable_product_indexing>
<enable_product_category_indexing>1</enable_product_category_indexing>
<enable_category_indexing>1</enable_category_indexing>
</prerender_io>
</system>
</default>
Expand Down

0 comments on commit e2515cd

Please sign in to comment.