Skip to content

Commit 1046a2f

Browse files
committed
MAGE-848 Implement ConfigChecker callback
1 parent bb6b8e9 commit 1046a2f

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

Helper/ConfigHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class ConfigHelper
141141
protected const IS_LOOKING_SIMILAR_ENABLED_IN_PDP = 'algoliasearch_recommend/recommend/looking_similar/is_looking_similar_enabled_on_pdp';
142142
protected const IS_LOOKING_SIMILAR_ENABLED_IN_SHOPPING_CART = 'algoliasearch_recommend/recommend/looking_similar/is_looking_similar_enabled_on_cart_page';
143143
protected const LOOKING_SIMILAR_TITLE = 'algoliasearch_recommend/recommend/looking_similar/title';
144-
protected const USE_VIRTUAL_REPLICA_ENABLED = 'algoliasearch_instant/instant/use_virtual_replica'; //legacy config
144+
public const USE_VIRTUAL_REPLICA_ENABLED = 'algoliasearch_instant/instant/use_virtual_replica'; //legacy config
145145
protected const AUTOCOMPLETE_KEYBORAD_NAVIAGATION = 'algoliasearch_autocomplete/autocomplete/navigator';
146146
protected const FREQUENTLY_BOUGHT_TOGETHER_TITLE = 'algoliasearch_recommend/recommend/frequently_bought_together/title';
147147
protected const RELATED_PRODUCTS_TITLE = 'algoliasearch_recommend/recommend/related_product/title';

Setup/Patch/Data/MigrateVirtualReplicaConfigPatch.php

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Algolia\AlgoliaSearch\Setup\Patch\Data;
44

55
use Algolia\AlgoliaSearch\Api\Product\ReplicaManagerInterface;
6+
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
67
use Algolia\AlgoliaSearch\Helper\Configuration\ConfigChecker;
78
use Magento\Framework\App\Config\ConfigResource\ConfigInterface;
89
use Magento\Framework\App\Config\ScopeConfigInterface;
@@ -23,32 +24,50 @@ public function __construct(
2324
)
2425
{}
2526

26-
/**
27-
* @inheritDoc
28-
*/
29-
public static function getDependencies()
30-
{
31-
return [];
32-
}
33-
3427
/**
3528
* @inheritDoc
3629
*/
3730
public function apply(): PatchInterface
3831
{
3932
$this->moduleDataSetup->getConnection()->startSetup();
4033

41-
// do stuff
34+
$this->configChecker->checkAndApplyAllScopes(ConfigHelper::USE_VIRTUAL_REPLICA_ENABLED, [$this, 'migrateSetting']);
35+
36+
// rebuild everything after
4237

4338
$this->moduleDataSetup->getConnection()->endSetup();
4439

4540
return $this;
4641
}
4742

43+
public function migrateSetting(string $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, int $scopeId = 0): void
44+
{
45+
$value = (bool) $this->scopeConfig->getValue(ConfigHelper::USE_VIRTUAL_REPLICA_ENABLED, $scope, $scopeId);
46+
// not enabled moving on...
47+
if (!$value) {
48+
return;
49+
}
50+
51+
// TODO...
52+
// retrieve the sorting config
53+
// turn on virtual replicas for all attributes
54+
// run the validator, throw ReplicaExceedsException if needed
55+
56+
//if all is copacetic then save the new sorting config
57+
}
58+
59+
/**
60+
* @inheritDoc
61+
*/
62+
public static function getDependencies(): array
63+
{
64+
return [];
65+
}
66+
4867
/**
4968
* @inheritDoc
5069
*/
51-
public function getAliases()
70+
public function getAliases(): array
5271
{
5372
return [];
5473
}

0 commit comments

Comments
 (0)