3
3
namespace Algolia \AlgoliaSearch \Setup \Patch \Data ;
4
4
5
5
use Algolia \AlgoliaSearch \Api \Product \ReplicaManagerInterface ;
6
+ use Algolia \AlgoliaSearch \Helper \ConfigHelper ;
6
7
use Algolia \AlgoliaSearch \Helper \Configuration \ConfigChecker ;
7
8
use Magento \Framework \App \Config \ConfigResource \ConfigInterface ;
8
9
use Magento \Framework \App \Config \ScopeConfigInterface ;
@@ -23,32 +24,50 @@ public function __construct(
23
24
)
24
25
{}
25
26
26
- /**
27
- * @inheritDoc
28
- */
29
- public static function getDependencies ()
30
- {
31
- return [];
32
- }
33
-
34
27
/**
35
28
* @inheritDoc
36
29
*/
37
30
public function apply (): PatchInterface
38
31
{
39
32
$ this ->moduleDataSetup ->getConnection ()->startSetup ();
40
33
41
- // do stuff
34
+ $ this ->configChecker ->checkAndApplyAllScopes (ConfigHelper::USE_VIRTUAL_REPLICA_ENABLED , [$ this , 'migrateSetting ' ]);
35
+
36
+ // rebuild everything after
42
37
43
38
$ this ->moduleDataSetup ->getConnection ()->endSetup ();
44
39
45
40
return $ this ;
46
41
}
47
42
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
+
48
67
/**
49
68
* @inheritDoc
50
69
*/
51
- public function getAliases ()
70
+ public function getAliases (): array
52
71
{
53
72
return [];
54
73
}
0 commit comments