2
2
3
3
namespace Algolia \AlgoliaSearch \Helper ;
4
4
5
+ use Algolia \AlgoliaSearch \Api \Data \IndexOptionsInterface ;
5
6
use Algolia \AlgoliaSearch \Api \SearchClient ;
6
7
use Algolia \AlgoliaSearch \Exceptions \AlgoliaException ;
7
8
use Algolia \AlgoliaSearch \Exceptions \ExceededRetriesException ;
9
+ use Algolia \AlgoliaSearch \Model \IndexOptions ;
8
10
use Algolia \AlgoliaSearch \Model \Search \ListIndicesResponse ;
9
11
use Algolia \AlgoliaSearch \Service \AlgoliaConnector ;
10
12
use Magento \Framework \App \Helper \AbstractHelper ;
11
13
use Exception ;
12
14
use Magento \Framework \App \Helper \Context ;
13
15
use Magento \Framework \App \RequestInterface ;
16
+ use Magento \Framework \Exception \NoSuchEntityException ;
14
17
15
18
/**
16
19
* @deprecated (will be removed in v3.16.0)
@@ -59,24 +62,28 @@ public function listIndexes(?int $storeId = null)
59
62
* @param array $params
60
63
* @param int|null $storeId
61
64
* @return array<string, mixed>
62
- * @throws AlgoliaException
65
+ * @throws AlgoliaException|NoSuchEntityException
63
66
* @internal This method is currently unstable and should not be used. It may be revisited ar fixed in a future version.
64
67
*/
65
68
public function query (string $ indexName , string $ q , array $ params , ?int $ storeId = null ): array
66
69
{
67
- return $ this ->algoliaConnector ->query ($ indexName , $ q , $ params , $ storeId );
70
+ $ indexOptions = $ this ->convertToIndexOptions ($ indexName , $ storeId );
71
+
72
+ return $ this ->algoliaConnector ->query ($ indexOptions , $ q , $ params );
68
73
}
69
74
70
75
/**
71
76
* @param string $indexName
72
77
* @param array $objectIds
73
78
* @param int|null $storeId
74
79
* @return array<string, mixed>
75
- * @throws AlgoliaException
80
+ * @throws AlgoliaException|NoSuchEntityException
76
81
*/
77
82
public function getObjects (string $ indexName , array $ objectIds , ?int $ storeId = null ): array
78
83
{
79
- return $ this ->algoliaConnector ->getObjects ($ indexName , $ objectIds , $ storeId );
84
+ $ indexOptions = $ this ->convertToIndexOptions ($ indexName , $ storeId );
85
+
86
+ return $ this ->algoliaConnector ->getObjects ($ indexOptions , $ objectIds );
80
87
}
81
88
82
89
/**
@@ -86,7 +93,7 @@ public function getObjects(string $indexName, array $objectIds, ?int $storeId =
86
93
* @param bool $mergeSettings
87
94
* @param string $mergeSettingsFrom
88
95
* @param int|null $storeId
89
- * @throws AlgoliaException
96
+ * @throws AlgoliaException|NoSuchEntityException
90
97
*/
91
98
public function setSettings (
92
99
$ indexName ,
@@ -96,25 +103,28 @@ public function setSettings(
96
103
string $ mergeSettingsFrom = '' ,
97
104
?int $ storeId = null
98
105
) {
106
+ $ indexOptions = $ this ->convertToIndexOptions ($ indexName , $ storeId );
107
+
99
108
$ this ->algoliaConnector ->setSettings (
100
- $ indexName ,
109
+ $ indexOptions ,
101
110
$ settings ,
102
111
$ forwardToReplicas ,
103
112
$ mergeSettings ,
104
- $ mergeSettingsFrom ,
105
- $ storeId
113
+ $ mergeSettingsFrom
106
114
);
107
115
}
108
116
109
117
/**
110
118
* @param string $indexName
111
119
* @param int|null $storeId
112
120
* @return void
113
- * @throws AlgoliaException
121
+ * @throws AlgoliaException|NoSuchEntityException
114
122
*/
115
123
public function deleteIndex (string $ indexName , ?int $ storeId = null ): void
116
124
{
117
- $ this ->algoliaConnector ->deleteIndex ($ indexName , $ storeId );
125
+ $ indexOptions = $ this ->convertToIndexOptions ($ indexName , $ storeId );
126
+
127
+ $ this ->algoliaConnector ->deleteIndex ($ indexOptions );
118
128
}
119
129
120
130
/**
@@ -126,19 +136,24 @@ public function deleteIndex(string $indexName, ?int $storeId = null): void
126
136
*/
127
137
public function deleteObjects (array $ ids , string $ indexName , ?int $ storeId = null ): void
128
138
{
129
- $ this ->algoliaConnector ->deleteObjects ($ ids , $ indexName , $ storeId );
139
+ $ indexOptions = $ this ->convertToIndexOptions ($ indexName , $ storeId );
140
+
141
+ $ this ->algoliaConnector ->deleteObjects ($ ids , $ indexOptions );
130
142
}
131
143
132
144
/**
133
145
* @param string $fromIndexName
134
146
* @param string $toIndexName
135
147
* @param int|null $storeId
136
148
* @return void
137
- * @throws AlgoliaException
149
+ * @throws AlgoliaException|NoSuchEntityException
138
150
*/
139
151
public function moveIndex (string $ fromIndexName , string $ toIndexName , ?int $ storeId = null ): void
140
152
{
141
- $ this ->algoliaConnector ->moveIndex ($ fromIndexName , $ toIndexName , $ storeId );
153
+ $ fromIndexOptions = $ this ->convertToIndexOptions ($ fromIndexName , $ storeId );
154
+ $ toIndexOptions = $ this ->convertToIndexOptions ($ toIndexName , $ storeId );
155
+
156
+ $ this ->algoliaConnector ->moveIndex ($ fromIndexOptions , $ toIndexOptions );
142
157
}
143
158
144
159
/**
@@ -157,11 +172,13 @@ public function generateSearchSecuredApiKey(string $key, array $params = [], ?in
157
172
* @param string $indexName
158
173
* @param int|null $storeId
159
174
* @return array<string, mixed>
160
- * @throws AlgoliaException
175
+ * @throws AlgoliaException|NoSuchEntityException
161
176
*/
162
177
public function getSettings (string $ indexName , ?int $ storeId = null ): array
163
178
{
164
- return $ this ->algoliaConnector ->getSettings ($ indexName , $ storeId );
179
+ $ indexOptions = $ this ->convertToIndexOptions ($ indexName , $ storeId );
180
+
181
+ return $ this ->algoliaConnector ->getSettings ($ indexOptions );
165
182
}
166
183
167
184
/**
@@ -175,7 +192,9 @@ public function getSettings(string $indexName, ?int $storeId = null): array
175
192
*/
176
193
public function saveObjects (string $ indexName , array $ objects , bool $ isPartialUpdate = false , ?int $ storeId = null ): void
177
194
{
178
- $ this ->algoliaConnector ->saveObjects ($ indexName , $ objects , $ isPartialUpdate , $ storeId );
195
+ $ indexOptions = $ this ->convertToIndexOptions ($ indexName , $ storeId );
196
+
197
+ $ this ->algoliaConnector ->saveObjects ($ indexOptions , $ objects , $ isPartialUpdate );
179
198
}
180
199
181
200
/**
@@ -184,11 +203,13 @@ public function saveObjects(string $indexName, array $objects, bool $isPartialUp
184
203
* @param bool $forwardToReplicas
185
204
* @param int|null $storeId
186
205
* @return void
187
- * @throws AlgoliaException
206
+ * @throws AlgoliaException|NoSuchEntityException
188
207
*/
189
208
public function saveRule (array $ rule , string $ indexName , bool $ forwardToReplicas = false , ?int $ storeId = null ): void
190
209
{
191
- $ this ->algoliaConnector ->saveRule ($ rule , $ indexName , $ forwardToReplicas , $ storeId );
210
+ $ indexOptions = $ this ->convertToIndexOptions ($ indexName , $ storeId );
211
+
212
+ $ this ->algoliaConnector ->saveRule ($ rule , $ indexOptions , $ forwardToReplicas );
192
213
}
193
214
194
215
/**
@@ -197,10 +218,14 @@ public function saveRule(array $rule, string $indexName, bool $forwardToReplicas
197
218
* @param bool $forwardToReplicas
198
219
* @param int|null $storeId
199
220
* @return void
221
+ * @throws AlgoliaException
222
+ * @throws NoSuchEntityException
200
223
*/
201
224
public function saveRules (string $ indexName , array $ rules , bool $ forwardToReplicas = false , ?int $ storeId = null ): void
202
225
{
203
- $ this ->algoliaConnector ->saveRules ($ indexName , $ rules , $ forwardToReplicas , $ storeId );
226
+ $ indexOptions = $ this ->convertToIndexOptions ($ indexName , $ storeId );
227
+
228
+ $ this ->algoliaConnector ->saveRules ($ indexOptions , $ rules , $ forwardToReplicas );
204
229
}
205
230
206
231
/**
@@ -209,7 +234,7 @@ public function saveRules(string $indexName, array $rules, bool $forwardToReplic
209
234
* @param bool $forwardToReplicas
210
235
* @param int|null $storeId
211
236
* @return void
212
- * @throws AlgoliaException
237
+ * @throws AlgoliaException|NoSuchEntityException
213
238
*/
214
239
public function deleteRule (
215
240
string $ indexName ,
@@ -218,7 +243,9 @@ public function deleteRule(
218
243
?int $ storeId = null
219
244
) : void
220
245
{
221
- $ this ->algoliaConnector ->deleteRule ($ indexName , $ objectID , $ forwardToReplicas , $ storeId );
246
+ $ indexOptions = $ this ->convertToIndexOptions ($ indexName , $ storeId );
247
+
248
+ $ this ->algoliaConnector ->deleteRule ($ indexOptions , $ objectID , $ forwardToReplicas );
222
249
}
223
250
224
251
/**
@@ -227,11 +254,14 @@ public function deleteRule(
227
254
* @param int|null $storeId
228
255
* @return void
229
256
* @throws AlgoliaException
230
- * @throws ExceededRetriesException
257
+ * @throws ExceededRetriesException|NoSuchEntityException
231
258
*/
232
259
public function copySynonyms (string $ fromIndexName , string $ toIndexName , ?int $ storeId = null ): void
233
260
{
234
- $ this ->algoliaConnector ->copySynonyms ($ fromIndexName , $ toIndexName , $ storeId );
261
+ $ fromIndexOptions = $ this ->convertToIndexOptions ($ fromIndexName , $ storeId );
262
+ $ toIndexOptions = $ this ->convertToIndexOptions ($ toIndexName , $ storeId );
263
+
264
+ $ this ->algoliaConnector ->copySynonyms ($ fromIndexOptions , $ toIndexOptions );
235
265
}
236
266
237
267
/**
@@ -240,11 +270,14 @@ public function copySynonyms(string $fromIndexName, string $toIndexName, ?int $s
240
270
* @param int|null $storeId
241
271
* @return void
242
272
* @throws AlgoliaException
243
- * @throws ExceededRetriesException
273
+ * @throws ExceededRetriesException|NoSuchEntityException
244
274
*/
245
275
public function copyQueryRules (string $ fromIndexName , string $ toIndexName , ?int $ storeId = null ): void
246
276
{
247
- $ this ->algoliaConnector ->copyQueryRules ($ fromIndexName , $ toIndexName , $ storeId );
277
+ $ fromIndexOptions = $ this ->convertToIndexOptions ($ fromIndexName , $ storeId );
278
+ $ toIndexOptions = $ this ->convertToIndexOptions ($ toIndexName , $ storeId );
279
+
280
+ $ this ->algoliaConnector ->copyQueryRules ($ fromIndexOptions , $ toIndexOptions );
248
281
}
249
282
250
283
/**
@@ -253,22 +286,26 @@ public function copyQueryRules(string $fromIndexName, string $toIndexName, ?int
253
286
* @param int|null $storeId
254
287
* @return array
255
288
*
256
- * @throws AlgoliaException
289
+ * @throws AlgoliaException|NoSuchEntityException
257
290
*/
258
- public function searchRules (string $ indexName , array $ searchRulesParams = null , ?int $ storeId = null )
291
+ public function searchRules (string $ indexName , array $ searchRulesParams = null , ?int $ storeId = null )
259
292
{
260
- return $ this ->algoliaConnector ->searchRules ($ indexName , $ searchRulesParams , $ storeId );
293
+ $ indexOptions = $ this ->convertToIndexOptions ($ indexName , $ storeId );
294
+
295
+ return $ this ->algoliaConnector ->searchRules ($ indexOptions , $ searchRulesParams );
261
296
}
262
297
263
298
/**
264
299
* @param string $indexName
265
300
* @param int|null $storeId
266
301
* @return void
267
- * @throws AlgoliaException
302
+ * @throws AlgoliaException|NoSuchEntityException
268
303
*/
269
304
public function clearIndex (string $ indexName , ?int $ storeId = null ): void
270
305
{
271
- $ this ->algoliaConnector ->clearIndex ($ indexName , $ storeId );
306
+ $ indexOptions = $ this ->convertToIndexOptions ($ indexName , $ storeId );
307
+
308
+ $ this ->algoliaConnector ->clearIndex ($ indexOptions );
272
309
}
273
310
274
311
/**
@@ -301,4 +338,22 @@ public function getLastTaskId(?int $storeId = null): int
301
338
{
302
339
return $ this ->algoliaConnector ->getLastTaskId ($ storeId );
303
340
}
341
+
342
+ /**
343
+ * Automatically converts information related to an index into a IndexOptions objects
344
+ * This ensures compatibility of this deprecated class with the new method signatures of AlgoliaConnector
345
+ *
346
+ * @param string|null $indexName
347
+ * @param int|null $storeId
348
+ * @param bool|null $isTmp
349
+ * @return IndexOptions
350
+ */
351
+ protected function convertToIndexOptions (?string $ indexName = null , ?int $ storeId = null , ?bool $ isTmp = false ): IndexOptions
352
+ {
353
+ return new IndexOptions ([
354
+ IndexOptionsInterface::ENFORCED_INDEX_NAME => $ indexName ,
355
+ IndexOptionsInterface::STORE_ID => $ storeId ,
356
+ IndexOptionsInterface::IS_TMP => $ isTmp
357
+ ]);
358
+ }
304
359
}
0 commit comments