2
2
3
3
namespace Algolia \AlgoliaSearch \Helper ;
4
4
5
- use Algolia \AlgoliaSearch \Api \Data \IndexOptionsInterface ;
6
5
use Algolia \AlgoliaSearch \Api \SearchClient ;
7
6
use Algolia \AlgoliaSearch \Exceptions \AlgoliaException ;
8
7
use Algolia \AlgoliaSearch \Exceptions \ExceededRetriesException ;
9
- use Algolia \AlgoliaSearch \Model \IndexOptions ;
10
8
use Algolia \AlgoliaSearch \Model \Search \ListIndicesResponse ;
11
9
use Algolia \AlgoliaSearch \Service \AlgoliaConnector ;
10
+ use Algolia \AlgoliaSearch \Service \IndexOptionsBuilder ;
12
11
use Magento \Framework \App \Helper \AbstractHelper ;
13
12
use Exception ;
14
13
use Magento \Framework \App \Helper \Context ;
@@ -22,7 +21,8 @@ class AlgoliaHelper extends AbstractHelper
22
21
{
23
22
public function __construct (
24
23
Context $ context ,
25
- protected AlgoliaConnector $ algoliaConnector
24
+ protected AlgoliaConnector $ algoliaConnector ,
25
+ protected IndexOptionsBuilder $ indexOptionsBuilder
26
26
){
27
27
parent ::__construct ($ context );
28
28
}
@@ -67,7 +67,7 @@ public function listIndexes(?int $storeId = null)
67
67
*/
68
68
public function query (string $ indexName , string $ q , array $ params , ?int $ storeId = null ): array
69
69
{
70
- $ indexOptions = $ this ->convertToIndexOptions ($ indexName , $ storeId );
70
+ $ indexOptions = $ this ->indexOptionsBuilder -> convertToIndexOptions ($ indexName , $ storeId );
71
71
72
72
return $ this ->algoliaConnector ->query ($ indexOptions , $ q , $ params );
73
73
}
@@ -77,11 +77,11 @@ public function query(string $indexName, string $q, array $params, ?int $storeId
77
77
* @param array $objectIds
78
78
* @param int|null $storeId
79
79
* @return array<string, mixed>
80
- * @throws AlgoliaException|NoSuchEntityException
80
+ * @throws AlgoliaException
81
81
*/
82
82
public function getObjects (string $ indexName , array $ objectIds , ?int $ storeId = null ): array
83
83
{
84
- $ indexOptions = $ this ->convertToIndexOptions ($ indexName , $ storeId );
84
+ $ indexOptions = $ this ->indexOptionsBuilder -> convertToIndexOptions ($ indexName , $ storeId );
85
85
86
86
return $ this ->algoliaConnector ->getObjects ($ indexOptions , $ objectIds );
87
87
}
@@ -103,7 +103,7 @@ public function setSettings(
103
103
string $ mergeSettingsFrom = '' ,
104
104
?int $ storeId = null
105
105
) {
106
- $ indexOptions = $ this ->convertToIndexOptions ($ indexName , $ storeId );
106
+ $ indexOptions = $ this ->indexOptionsBuilder -> convertToIndexOptions ($ indexName , $ storeId );
107
107
108
108
$ this ->algoliaConnector ->setSettings (
109
109
$ indexOptions ,
@@ -122,7 +122,7 @@ public function setSettings(
122
122
*/
123
123
public function deleteIndex (string $ indexName , ?int $ storeId = null ): void
124
124
{
125
- $ indexOptions = $ this ->convertToIndexOptions ($ indexName , $ storeId );
125
+ $ indexOptions = $ this ->indexOptionsBuilder -> convertToIndexOptions ($ indexName , $ storeId );
126
126
127
127
$ this ->algoliaConnector ->deleteIndex ($ indexOptions );
128
128
}
@@ -132,11 +132,11 @@ public function deleteIndex(string $indexName, ?int $storeId = null): void
132
132
* @param string $indexName
133
133
* @param int|null $storeId
134
134
* @return void
135
- * @throws AlgoliaException
135
+ * @throws AlgoliaException|NoSuchEntityException
136
136
*/
137
137
public function deleteObjects (array $ ids , string $ indexName , ?int $ storeId = null ): void
138
138
{
139
- $ indexOptions = $ this ->convertToIndexOptions ($ indexName , $ storeId );
139
+ $ indexOptions = $ this ->indexOptionsBuilder -> convertToIndexOptions ($ indexName , $ storeId );
140
140
141
141
$ this ->algoliaConnector ->deleteObjects ($ ids , $ indexOptions );
142
142
}
@@ -150,8 +150,8 @@ public function deleteObjects(array $ids, string $indexName, ?int $storeId = nul
150
150
*/
151
151
public function moveIndex (string $ fromIndexName , string $ toIndexName , ?int $ storeId = null ): void
152
152
{
153
- $ fromIndexOptions = $ this ->convertToIndexOptions ($ fromIndexName , $ storeId );
154
- $ toIndexOptions = $ this ->convertToIndexOptions ($ toIndexName , $ storeId );
153
+ $ fromIndexOptions = $ this ->indexOptionsBuilder -> convertToIndexOptions ($ fromIndexName , $ storeId );
154
+ $ toIndexOptions = $ this ->indexOptionsBuilder -> convertToIndexOptions ($ toIndexName , $ storeId );
155
155
156
156
$ this ->algoliaConnector ->moveIndex ($ fromIndexOptions , $ toIndexOptions );
157
157
}
@@ -176,7 +176,7 @@ public function generateSearchSecuredApiKey(string $key, array $params = [], ?in
176
176
*/
177
177
public function getSettings (string $ indexName , ?int $ storeId = null ): array
178
178
{
179
- $ indexOptions = $ this ->convertToIndexOptions ($ indexName , $ storeId );
179
+ $ indexOptions = $ this ->indexOptionsBuilder -> convertToIndexOptions ($ indexName , $ storeId );
180
180
181
181
return $ this ->algoliaConnector ->getSettings ($ indexOptions );
182
182
}
@@ -192,7 +192,7 @@ public function getSettings(string $indexName, ?int $storeId = null): array
192
192
*/
193
193
public function saveObjects (string $ indexName , array $ objects , bool $ isPartialUpdate = false , ?int $ storeId = null ): void
194
194
{
195
- $ indexOptions = $ this ->convertToIndexOptions ($ indexName , $ storeId );
195
+ $ indexOptions = $ this ->indexOptionsBuilder -> convertToIndexOptions ($ indexName , $ storeId );
196
196
197
197
$ this ->algoliaConnector ->saveObjects ($ indexOptions , $ objects , $ isPartialUpdate );
198
198
}
@@ -207,7 +207,7 @@ public function saveObjects(string $indexName, array $objects, bool $isPartialUp
207
207
*/
208
208
public function saveRule (array $ rule , string $ indexName , bool $ forwardToReplicas = false , ?int $ storeId = null ): void
209
209
{
210
- $ indexOptions = $ this ->convertToIndexOptions ($ indexName , $ storeId );
210
+ $ indexOptions = $ this ->indexOptionsBuilder -> convertToIndexOptions ($ indexName , $ storeId );
211
211
212
212
$ this ->algoliaConnector ->saveRule ($ rule , $ indexOptions , $ forwardToReplicas );
213
213
}
@@ -223,7 +223,7 @@ public function saveRule(array $rule, string $indexName, bool $forwardToReplicas
223
223
*/
224
224
public function saveRules (string $ indexName , array $ rules , bool $ forwardToReplicas = false , ?int $ storeId = null ): void
225
225
{
226
- $ indexOptions = $ this ->convertToIndexOptions ($ indexName , $ storeId );
226
+ $ indexOptions = $ this ->indexOptionsBuilder -> convertToIndexOptions ($ indexName , $ storeId );
227
227
228
228
$ this ->algoliaConnector ->saveRules ($ indexOptions , $ rules , $ forwardToReplicas );
229
229
}
@@ -243,7 +243,7 @@ public function deleteRule(
243
243
?int $ storeId = null
244
244
) : void
245
245
{
246
- $ indexOptions = $ this ->convertToIndexOptions ($ indexName , $ storeId );
246
+ $ indexOptions = $ this ->indexOptionsBuilder -> convertToIndexOptions ($ indexName , $ storeId );
247
247
248
248
$ this ->algoliaConnector ->deleteRule ($ indexOptions , $ objectID , $ forwardToReplicas );
249
249
}
@@ -258,8 +258,8 @@ public function deleteRule(
258
258
*/
259
259
public function copySynonyms (string $ fromIndexName , string $ toIndexName , ?int $ storeId = null ): void
260
260
{
261
- $ fromIndexOptions = $ this ->convertToIndexOptions ($ fromIndexName , $ storeId );
262
- $ toIndexOptions = $ this ->convertToIndexOptions ($ toIndexName , $ storeId );
261
+ $ fromIndexOptions = $ this ->indexOptionsBuilder -> convertToIndexOptions ($ fromIndexName , $ storeId );
262
+ $ toIndexOptions = $ this ->indexOptionsBuilder -> convertToIndexOptions ($ toIndexName , $ storeId );
263
263
264
264
$ this ->algoliaConnector ->copySynonyms ($ fromIndexOptions , $ toIndexOptions );
265
265
}
@@ -274,8 +274,8 @@ public function copySynonyms(string $fromIndexName, string $toIndexName, ?int $s
274
274
*/
275
275
public function copyQueryRules (string $ fromIndexName , string $ toIndexName , ?int $ storeId = null ): void
276
276
{
277
- $ fromIndexOptions = $ this ->convertToIndexOptions ($ fromIndexName , $ storeId );
278
- $ toIndexOptions = $ this ->convertToIndexOptions ($ toIndexName , $ storeId );
277
+ $ fromIndexOptions = $ this ->indexOptionsBuilder -> convertToIndexOptions ($ fromIndexName , $ storeId );
278
+ $ toIndexOptions = $ this ->indexOptionsBuilder -> convertToIndexOptions ($ toIndexName , $ storeId );
279
279
280
280
$ this ->algoliaConnector ->copyQueryRules ($ fromIndexOptions , $ toIndexOptions );
281
281
}
@@ -290,7 +290,7 @@ public function copyQueryRules(string $fromIndexName, string $toIndexName, ?int
290
290
*/
291
291
public function searchRules (string $ indexName , array $ searchRulesParams = null , ?int $ storeId = null )
292
292
{
293
- $ indexOptions = $ this ->convertToIndexOptions ($ indexName , $ storeId );
293
+ $ indexOptions = $ this ->indexOptionsBuilder -> convertToIndexOptions ($ indexName , $ storeId );
294
294
295
295
return $ this ->algoliaConnector ->searchRules ($ indexOptions , $ searchRulesParams );
296
296
}
@@ -303,7 +303,7 @@ public function searchRules(string $indexName, array $searchRulesParams = null,
303
303
*/
304
304
public function clearIndex (string $ indexName , ?int $ storeId = null ): void
305
305
{
306
- $ indexOptions = $ this ->convertToIndexOptions ($ indexName , $ storeId );
306
+ $ indexOptions = $ this ->indexOptionsBuilder -> convertToIndexOptions ($ indexName , $ storeId );
307
307
308
308
$ this ->algoliaConnector ->clearIndex ($ indexOptions );
309
309
}
@@ -338,22 +338,4 @@ public function getLastTaskId(?int $storeId = null): int
338
338
{
339
339
return $ this ->algoliaConnector ->getLastTaskId ($ storeId );
340
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
- }
359
341
}
0 commit comments