Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BEG-154: Add admin configuration to disable indexers #20

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading