12
12
use Magento \Framework \App \Helper \Context ;
13
13
use Magento \Framework \App \RequestInterface ;
14
14
15
+ /**
16
+ * @deprecated (will be removed in v3.16.0)
17
+ */
15
18
class AlgoliaHelper extends AbstractHelper
16
19
{
17
- /**
18
- * @var string Case-sensitive object ID key
19
- */
20
- public const ALGOLIA_API_OBJECT_ID = 'objectID ' ;
21
-
22
- /**
23
- * @var string
24
- */
25
- public const ALGOLIA_API_INDEX_NAME = 'indexName ' ;
26
-
27
- /**
28
- * @var string
29
- */
30
- public const ALGOLIA_API_TASK_ID = 'taskID ' ;
31
-
32
- /**
33
- * @var int
34
- */
35
- public const ALGOLIA_DEFAULT_SCOPE = 0 ;
36
-
37
20
public function __construct (
38
21
Context $ context ,
39
22
protected AlgoliaConnector $ algoliaConnector
@@ -49,40 +32,14 @@ public function getRequest(): RequestInterface
49
32
return $ this ->_getRequest ();
50
33
}
51
34
52
- /**
53
- * Ensure AlgoliaConnector targets the application configured on a particular store
54
- *
55
- * @param int|null $storeId
56
- * @return void
57
- */
58
- protected function handleStoreContext (int |null $ storeId ): void
59
- {
60
- if (!is_null ($ storeId )) {
61
- $ this ->algoliaConnector ->setStoreId ($ storeId );
62
- }
63
- }
64
-
65
- /**
66
- * Restore AlgoliaConnector default Scope
67
- *
68
- * @return void
69
- */
70
- protected function restoreDefaultScope (): void
71
- {
72
- $ this ->algoliaConnector ->setStoreId (self ::ALGOLIA_DEFAULT_SCOPE );
73
- }
74
-
75
35
/**
76
36
* @param int|null $storeId
77
37
* @return SearchClient
78
38
* @throws AlgoliaException
79
39
*/
80
- public function getClient (int $ storeId = null ): SearchClient
40
+ public function getClient (? int $ storeId = null ): SearchClient
81
41
{
82
- $ this ->handleStoreContext ($ storeId );
83
- $ client = $ this ->algoliaConnector ->getClient ();
84
- $ this ->restoreDefaultScope ();
85
- return $ client ;
42
+ return $ this ->algoliaConnector ->getClient ($ storeId );
86
43
}
87
44
88
45
/**
@@ -91,12 +48,9 @@ public function getClient(int $storeId = null): SearchClient
91
48
* @return ListIndicesResponse|array<string,mixed>
92
49
* @throws AlgoliaException
93
50
*/
94
- public function listIndexes (int $ storeId = null )
51
+ public function listIndexes (? int $ storeId = null )
95
52
{
96
- $ this ->handleStoreContext ($ storeId );
97
- $ indexes = $ this ->algoliaConnector ->listIndexes ();
98
- $ this ->restoreDefaultScope ();
99
- return $ indexes ;
53
+ return $ this ->algoliaConnector ->listIndexes ($ storeId );
100
54
}
101
55
102
56
/**
@@ -108,12 +62,9 @@ public function listIndexes(int $storeId = null)
108
62
* @throws AlgoliaException
109
63
* @internal This method is currently unstable and should not be used. It may be revisited ar fixed in a future version.
110
64
*/
111
- public function query (string $ indexName , string $ q , array $ params , int $ storeId = null ): array
65
+ public function query (string $ indexName , string $ q , array $ params , ? int $ storeId = null ): array
112
66
{
113
- $ this ->handleStoreContext ($ storeId );
114
- $ result = $ this ->algoliaConnector ->query ($ indexName , $ q , $ params );
115
- $ this ->restoreDefaultScope ();
116
- return $ result ;
67
+ return $ this ->algoliaConnector ->query ($ indexName , $ q , $ params , $ storeId );
117
68
}
118
69
119
70
/**
@@ -123,12 +74,9 @@ public function query(string $indexName, string $q, array $params, int $storeId
123
74
* @return array<string, mixed>
124
75
* @throws AlgoliaException
125
76
*/
126
- public function getObjects (string $ indexName , array $ objectIds , int $ storeId = null ): array
77
+ public function getObjects (string $ indexName , array $ objectIds , ? int $ storeId = null ): array
127
78
{
128
- $ this ->handleStoreContext ($ storeId );
129
- $ result = $ this ->algoliaConnector ->getObjects ($ indexName , $ objectIds );
130
- $ this ->restoreDefaultScope ();
131
- return $ result ;
79
+ return $ this ->algoliaConnector ->getObjects ($ indexName , $ objectIds , $ storeId );
132
80
}
133
81
134
82
/**
@@ -146,17 +94,16 @@ public function setSettings(
146
94
bool $ forwardToReplicas = false ,
147
95
bool $ mergeSettings = false ,
148
96
string $ mergeSettingsFrom = '' ,
149
- int $ storeId = null
97
+ ? int $ storeId = null
150
98
) {
151
- $ this ->handleStoreContext ($ storeId );
152
99
$ this ->algoliaConnector ->setSettings (
153
100
$ indexName ,
154
101
$ settings ,
155
102
$ forwardToReplicas ,
156
103
$ mergeSettings ,
157
- $ mergeSettingsFrom
104
+ $ mergeSettingsFrom ,
105
+ $ storeId
158
106
);
159
- $ this ->restoreDefaultScope ();
160
107
}
161
108
162
109
/**
@@ -165,11 +112,9 @@ public function setSettings(
165
112
* @return void
166
113
* @throws AlgoliaException
167
114
*/
168
- public function deleteIndex (string $ indexName , int $ storeId = null ): void
115
+ public function deleteIndex (string $ indexName , ? int $ storeId = null ): void
169
116
{
170
- $ this ->handleStoreContext ($ storeId );
171
- $ this ->algoliaConnector ->deleteIndex ($ indexName );
172
- $ this ->restoreDefaultScope ();
117
+ $ this ->algoliaConnector ->deleteIndex ($ indexName , $ storeId );
173
118
}
174
119
175
120
/**
@@ -179,11 +124,9 @@ public function deleteIndex(string $indexName, int $storeId = null): void
179
124
* @return void
180
125
* @throws AlgoliaException
181
126
*/
182
- public function deleteObjects (array $ ids , string $ indexName , int $ storeId = null ): void
127
+ public function deleteObjects (array $ ids , string $ indexName , ? int $ storeId = null ): void
183
128
{
184
- $ this ->handleStoreContext ($ storeId );
185
- $ this ->algoliaConnector ->deleteObjects ($ ids , $ indexName );
186
- $ this ->restoreDefaultScope ();
129
+ $ this ->algoliaConnector ->deleteObjects ($ ids , $ indexName , $ storeId );
187
130
}
188
131
189
132
/**
@@ -193,11 +136,9 @@ public function deleteObjects(array $ids, string $indexName, int $storeId = null
193
136
* @return void
194
137
* @throws AlgoliaException
195
138
*/
196
- public function moveIndex (string $ fromIndexName , string $ toIndexName , int $ storeId = null ): void
139
+ public function moveIndex (string $ fromIndexName , string $ toIndexName , ? int $ storeId = null ): void
197
140
{
198
- $ this ->handleStoreContext ($ storeId );
199
- $ this ->algoliaConnector ->moveIndex ($ fromIndexName , $ toIndexName );
200
- $ this ->restoreDefaultScope ();
141
+ $ this ->algoliaConnector ->moveIndex ($ fromIndexName , $ toIndexName , $ storeId );
201
142
}
202
143
203
144
/**
@@ -207,12 +148,9 @@ public function moveIndex(string $fromIndexName, string $toIndexName, int $store
207
148
* @return string
208
149
* @throws AlgoliaException
209
150
*/
210
- public function generateSearchSecuredApiKey (string $ key , array $ params = [], int $ storeId = null ): string
151
+ public function generateSearchSecuredApiKey (string $ key , array $ params = [], ? int $ storeId = null ): string
211
152
{
212
- $ this ->handleStoreContext ($ storeId );
213
- $ apiKey = $ this ->algoliaConnector ->generateSearchSecuredApiKey ($ key , $ params );
214
- $ this ->restoreDefaultScope ();
215
- return $ apiKey ;
153
+ return $ this ->algoliaConnector ->generateSearchSecuredApiKey ($ key , $ params , $ storeId );
216
154
}
217
155
218
156
/**
@@ -221,12 +159,9 @@ public function generateSearchSecuredApiKey(string $key, array $params = [], int
221
159
* @return array<string, mixed>
222
160
* @throws AlgoliaException
223
161
*/
224
- public function getSettings (string $ indexName , int $ storeId = null ): array
162
+ public function getSettings (string $ indexName , ? int $ storeId = null ): array
225
163
{
226
- $ this ->handleStoreContext ($ storeId );
227
- $ settings = $ this ->algoliaConnector ->getSettings ($ indexName );
228
- $ this ->restoreDefaultScope ();
229
- return $ settings ;
164
+ return $ this ->algoliaConnector ->getSettings ($ indexName , $ storeId );
230
165
}
231
166
232
167
/**
@@ -238,39 +173,34 @@ public function getSettings(string $indexName, int $storeId = null): array
238
173
* @return void
239
174
* @throws Exception
240
175
*/
241
- public function saveObjects (string $ indexName , array $ objects , bool $ isPartialUpdate = false , int $ storeId = null ): void
176
+ public function saveObjects (string $ indexName , array $ objects , bool $ isPartialUpdate = false , ? int $ storeId = null ): void
242
177
{
243
- $ this ->handleStoreContext ($ storeId );
244
- $ this ->algoliaConnector ->saveObjects ($ indexName , $ objects , $ isPartialUpdate );
245
- $ this ->restoreDefaultScope ();
178
+ $ this ->algoliaConnector ->saveObjects ($ indexName , $ objects , $ isPartialUpdate , $ storeId );
246
179
}
247
180
248
181
/**
249
182
* @param array<string, mixed> $rule
250
183
* @param string $indexName
251
184
* @param bool $forwardToReplicas
185
+ * @param int|null $storeId
252
186
* @return void
253
187
* @throws AlgoliaException
254
188
*/
255
- public function saveRule (array $ rule , string $ indexName , bool $ forwardToReplicas = false , int $ storeId = null ): void
189
+ public function saveRule (array $ rule , string $ indexName , bool $ forwardToReplicas = false , ? int $ storeId = null ): void
256
190
{
257
- $ this ->handleStoreContext ($ storeId );
258
- $ this ->algoliaConnector ->saveRule ($ rule , $ indexName , $ forwardToReplicas );
259
- $ this ->restoreDefaultScope ();
191
+ $ this ->algoliaConnector ->saveRule ($ rule , $ indexName , $ forwardToReplicas , $ storeId );
260
192
}
261
193
262
194
/**
263
195
* @param string $indexName
264
196
* @param array $rules
265
197
* @param bool $forwardToReplicas
266
- * @param null $storeId
198
+ * @param int| null $storeId
267
199
* @return void
268
200
*/
269
- public function saveRules (string $ indexName , array $ rules , bool $ forwardToReplicas = false , $ storeId = null ): void
201
+ public function saveRules (string $ indexName , array $ rules , bool $ forwardToReplicas = false , ? int $ storeId = null ): void
270
202
{
271
- $ this ->handleStoreContext ($ storeId );
272
- $ this ->algoliaConnector ->saveRules ($ indexName , $ rules , $ forwardToReplicas );
273
- $ this ->restoreDefaultScope ();
203
+ $ this ->algoliaConnector ->saveRules ($ indexName , $ rules , $ forwardToReplicas , $ storeId );
274
204
}
275
205
276
206
/**
@@ -285,12 +215,10 @@ public function deleteRule(
285
215
string $ indexName ,
286
216
string $ objectID ,
287
217
bool $ forwardToReplicas = false ,
288
- int $ storeId = null
218
+ ? int $ storeId = null
289
219
) : void
290
220
{
291
- $ this ->handleStoreContext ($ storeId );
292
- $ this ->algoliaConnector ->deleteRule ($ indexName , $ objectID , $ forwardToReplicas );
293
- $ this ->restoreDefaultScope ();
221
+ $ this ->algoliaConnector ->deleteRule ($ indexName , $ objectID , $ forwardToReplicas , $ storeId );
294
222
}
295
223
296
224
/**
@@ -301,11 +229,9 @@ public function deleteRule(
301
229
* @throws AlgoliaException
302
230
* @throws ExceededRetriesException
303
231
*/
304
- public function copySynonyms (string $ fromIndexName , string $ toIndexName , int $ storeId = null ): void
232
+ public function copySynonyms (string $ fromIndexName , string $ toIndexName , ? int $ storeId = null ): void
305
233
{
306
- $ this ->handleStoreContext ($ storeId );
307
- $ this ->algoliaConnector ->copySynonyms ($ fromIndexName , $ toIndexName );
308
- $ this ->restoreDefaultScope ();
234
+ $ this ->algoliaConnector ->copySynonyms ($ fromIndexName , $ toIndexName , $ storeId );
309
235
}
310
236
311
237
/**
@@ -316,11 +242,9 @@ public function copySynonyms(string $fromIndexName, string $toIndexName, int $st
316
242
* @throws AlgoliaException
317
243
* @throws ExceededRetriesException
318
244
*/
319
- public function copyQueryRules (string $ fromIndexName , string $ toIndexName , int $ storeId = null ): void
245
+ public function copyQueryRules (string $ fromIndexName , string $ toIndexName , ? int $ storeId = null ): void
320
246
{
321
- $ this ->handleStoreContext ($ storeId );
322
- $ this ->algoliaConnector ->copyQueryRules ($ fromIndexName , $ toIndexName );
323
- $ this ->restoreDefaultScope ();
247
+ $ this ->algoliaConnector ->copyQueryRules ($ fromIndexName , $ toIndexName , $ storeId );
324
248
}
325
249
326
250
/**
@@ -331,22 +255,20 @@ public function copyQueryRules(string $fromIndexName, string $toIndexName, int $
331
255
*
332
256
* @throws AlgoliaException
333
257
*/
334
- public function searchRules (string $ indexName , array $ searchRulesParams = null , int $ storeId = null )
258
+ public function searchRules (string $ indexName , array $ searchRulesParams = null , ? int $ storeId = null )
335
259
{
336
- $ this ->handleStoreContext ($ storeId );
337
- $ rules = $ this ->algoliaConnector ->searchRules ($ indexName , $ searchRulesParams );
338
- $ this ->restoreDefaultScope ();
339
- return $ rules ;
260
+ return $ this ->algoliaConnector ->searchRules ($ indexName , $ searchRulesParams , $ storeId );
340
261
}
341
262
342
263
/**
343
264
* @param string $indexName
265
+ * @param int|null $storeId
344
266
* @return void
345
267
* @throws AlgoliaException
346
268
*/
347
- public function clearIndex (string $ indexName ): void
269
+ public function clearIndex (string $ indexName, ? int $ storeId = null ): void
348
270
{
349
- $ this ->algoliaConnector ->clearIndex ($ indexName );
271
+ $ this ->algoliaConnector ->clearIndex ($ indexName, $ storeId );
350
272
}
351
273
352
274
/**
@@ -357,11 +279,9 @@ public function clearIndex(string $indexName): void
357
279
* @throws AlgoliaException
358
280
* @throws ExceededRetriesException
359
281
*/
360
- public function waitLastTask (int $ storeId = null , string $ lastUsedIndexName = null , int $ lastTaskId = null ): void
282
+ public function waitLastTask (? int $ storeId = null , ? string $ lastUsedIndexName = null , ? int $ lastTaskId = null ): void
361
283
{
362
- $ this ->handleStoreContext ($ storeId );
363
- $ this ->algoliaConnector ->waitLastTask ($ lastUsedIndexName , $ lastTaskId );
364
- $ this ->restoreDefaultScope ();
284
+ $ this ->algoliaConnector ->waitLastTask ($ storeId , $ lastUsedIndexName , $ lastTaskId );
365
285
}
366
286
367
287
/**
@@ -374,14 +294,10 @@ public function castProductObject(&$productData): void
374
294
}
375
295
376
296
/**
377
- * @param int|null $storeId
378
297
* @return int
379
298
*/
380
- public function getLastTaskId (int $ storeId = null ): int
299
+ public function getLastTaskId (): int
381
300
{
382
- $ this ->handleStoreContext ($ storeId );
383
- $ lastTaskId = $ this ->algoliaConnector ->getLastTaskId ();
384
- $ this ->restoreDefaultScope ();
385
- return $ lastTaskId ;
301
+ return $ this ->algoliaConnector ->getLastTaskId ();
386
302
}
387
303
}
0 commit comments