Skip to content

Commit 46d1adc

Browse files
committed
MAGE-1260: bring back AlgoliaHelper with new deprecated comment
1 parent 661a205 commit 46d1adc

File tree

1 file changed

+350
-0
lines changed

1 file changed

+350
-0
lines changed

Helper/AlgoliaHelper.php

Lines changed: 350 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,350 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Helper;
4+
5+
use Algolia\AlgoliaSearch\Api\SearchClient;
6+
use Algolia\AlgoliaSearch\Exceptions\AlgoliaException;
7+
use Algolia\AlgoliaSearch\Exceptions\ExceededRetriesException;
8+
use Algolia\AlgoliaSearch\Model\Search\ListIndicesResponse;
9+
use Algolia\AlgoliaSearch\Service\AlgoliaConnector;
10+
use Algolia\AlgoliaSearch\Service\IndexOptionsBuilder;
11+
use Magento\Framework\App\Helper\AbstractHelper;
12+
use Exception;
13+
use Magento\Framework\App\Helper\Context;
14+
use Magento\Framework\App\RequestInterface;
15+
use Magento\Framework\Exception\NoSuchEntityException;
16+
17+
/**
18+
* @deprecated (will be removed from the codebase in v3.17.0)
19+
*/
20+
class AlgoliaHelper extends AbstractHelper
21+
{
22+
public function __construct(
23+
Context $context,
24+
protected AlgoliaConnector $algoliaConnector,
25+
protected IndexOptionsBuilder $indexOptionsBuilder
26+
){
27+
parent::__construct($context);
28+
}
29+
30+
/**
31+
* @return RequestInterface
32+
*/
33+
public function getRequest(): RequestInterface
34+
{
35+
return $this->_getRequest();
36+
}
37+
38+
/**
39+
* @param int|null $storeId
40+
* @return SearchClient
41+
* @throws AlgoliaException
42+
*/
43+
public function getClient(?int $storeId = null): SearchClient
44+
{
45+
return $this->algoliaConnector->getClient($storeId);
46+
}
47+
48+
/**
49+
* @param int|null $storeId
50+
*
51+
* @return ListIndicesResponse|array<string,mixed>
52+
* @throws AlgoliaException
53+
*/
54+
public function listIndexes(?int $storeId = null)
55+
{
56+
return $this->algoliaConnector->listIndexes($storeId);
57+
}
58+
59+
/**
60+
* @param string $indexName
61+
* @param string $q
62+
* @param array $params
63+
* @param int|null $storeId
64+
* @return array<string, mixed>
65+
* @throws AlgoliaException|NoSuchEntityException
66+
* @internal This method is currently unstable and should not be used. It may be revisited ar fixed in a future version.
67+
*/
68+
public function query(string $indexName, string $q, array $params, ?int $storeId = null): array
69+
{
70+
$indexOptions = $this->indexOptionsBuilder->buildWithEnforcedIndex($indexName, $storeId);
71+
72+
return $this->algoliaConnector->query($indexOptions, $q, $params);
73+
}
74+
75+
/**
76+
* @param string $indexName
77+
* @param array $objectIds
78+
* @param int|null $storeId
79+
* @return array<string, mixed>
80+
* @throws AlgoliaException|NoSuchEntityException
81+
*/
82+
public function getObjects(string $indexName, array $objectIds, ?int $storeId = null): array
83+
{
84+
$indexOptions = $this->indexOptionsBuilder->buildWithEnforcedIndex($indexName, $storeId);
85+
86+
return $this->algoliaConnector->getObjects($indexOptions, $objectIds);
87+
}
88+
89+
/**
90+
* @param $indexName
91+
* @param $settings
92+
* @param bool $forwardToReplicas
93+
* @param bool $mergeSettings
94+
* @param string $mergeSettingsFrom
95+
* @param int|null $storeId
96+
* @throws AlgoliaException|NoSuchEntityException
97+
*/
98+
public function setSettings(
99+
$indexName,
100+
$settings,
101+
bool $forwardToReplicas = false,
102+
bool $mergeSettings = false,
103+
string $mergeSettingsFrom = '',
104+
?int $storeId = null
105+
) {
106+
$indexOptions = $this->indexOptionsBuilder->buildWithEnforcedIndex($indexName, $storeId);
107+
108+
$this->algoliaConnector->setSettings(
109+
$indexOptions,
110+
$settings,
111+
$forwardToReplicas,
112+
$mergeSettings,
113+
$mergeSettingsFrom
114+
);
115+
}
116+
117+
/**
118+
* @param string $indexName
119+
* @param int|null $storeId
120+
* @return void
121+
* @throws AlgoliaException|NoSuchEntityException
122+
*/
123+
public function deleteIndex(string $indexName, ?int $storeId = null): void
124+
{
125+
$indexOptions = $this->indexOptionsBuilder->buildWithEnforcedIndex($indexName, $storeId);
126+
127+
$this->algoliaConnector->deleteIndex($indexOptions);
128+
}
129+
130+
/**
131+
* @param array $ids
132+
* @param string $indexName
133+
* @param int|null $storeId
134+
* @return void
135+
* @throws AlgoliaException|NoSuchEntityException
136+
*/
137+
public function deleteObjects(array $ids, string $indexName, ?int $storeId = null): void
138+
{
139+
$indexOptions = $this->indexOptionsBuilder->buildWithEnforcedIndex($indexName, $storeId);
140+
141+
$this->algoliaConnector->deleteObjects($ids, $indexOptions);
142+
}
143+
144+
/**
145+
* @param string $fromIndexName
146+
* @param string $toIndexName
147+
* @param int|null $storeId
148+
* @return void
149+
* @throws AlgoliaException|NoSuchEntityException
150+
*/
151+
public function moveIndex(string $fromIndexName, string $toIndexName, ?int $storeId = null): void
152+
{
153+
$fromIndexOptions = $this->indexOptionsBuilder->buildWithEnforcedIndex($fromIndexName, $storeId);
154+
$toIndexOptions = $this->indexOptionsBuilder->buildWithEnforcedIndex($toIndexName, $storeId);
155+
156+
$this->algoliaConnector->moveIndex($fromIndexOptions, $toIndexOptions);
157+
}
158+
159+
/**
160+
* @param string $key
161+
* @param array $params
162+
* @param int|null $storeId
163+
* @return string
164+
* @throws AlgoliaException
165+
*/
166+
public function generateSearchSecuredApiKey(string $key, array $params = [], ?int $storeId = null): string
167+
{
168+
return $this->algoliaConnector->generateSearchSecuredApiKey($key, $params, $storeId);
169+
}
170+
171+
/**
172+
* @param string $indexName
173+
* @param int|null $storeId
174+
* @return array<string, mixed>
175+
* @throws AlgoliaException|NoSuchEntityException
176+
*/
177+
public function getSettings(string $indexName, ?int $storeId = null): array
178+
{
179+
$indexOptions = $this->indexOptionsBuilder->buildWithEnforcedIndex($indexName, $storeId);
180+
181+
return $this->algoliaConnector->getSettings($indexOptions);
182+
}
183+
184+
/**
185+
* Save objects to index (upserts records)
186+
* @param string $indexName
187+
* @param array $objects
188+
* @param bool $isPartialUpdate
189+
* @param int|null $storeId
190+
* @return void
191+
* @throws Exception
192+
*/
193+
public function saveObjects(string $indexName, array $objects, bool $isPartialUpdate = false, ?int $storeId = null): void
194+
{
195+
$indexOptions = $this->indexOptionsBuilder->buildWithEnforcedIndex($indexName, $storeId);
196+
197+
$this->algoliaConnector->saveObjects($indexOptions, $objects, $isPartialUpdate);
198+
}
199+
200+
/**
201+
* @param array<string, mixed> $rule
202+
* @param string $indexName
203+
* @param bool $forwardToReplicas
204+
* @param int|null $storeId
205+
* @return void
206+
* @throws AlgoliaException|NoSuchEntityException
207+
*/
208+
public function saveRule(array $rule, string $indexName, bool $forwardToReplicas = false, ?int $storeId = null): void
209+
{
210+
$indexOptions = $this->indexOptionsBuilder->buildWithEnforcedIndex($indexName, $storeId);
211+
212+
$this->algoliaConnector->saveRule($rule, $indexOptions, $forwardToReplicas);
213+
}
214+
215+
/**
216+
* @param string $indexName
217+
* @param array $rules
218+
* @param bool $forwardToReplicas
219+
* @param int|null $storeId
220+
* @return void
221+
* @throws AlgoliaException
222+
* @throws NoSuchEntityException
223+
*/
224+
public function saveRules(string $indexName, array $rules, bool $forwardToReplicas = false, ?int $storeId = null): void
225+
{
226+
$indexOptions = $this->indexOptionsBuilder->buildWithEnforcedIndex($indexName, $storeId);
227+
228+
$this->algoliaConnector->saveRules($indexOptions, $rules, $forwardToReplicas);
229+
}
230+
231+
/**
232+
* @param string $indexName
233+
* @param string $objectID
234+
* @param bool $forwardToReplicas
235+
* @param int|null $storeId
236+
* @return void
237+
* @throws AlgoliaException|NoSuchEntityException
238+
*/
239+
public function deleteRule(
240+
string $indexName,
241+
string $objectID,
242+
bool $forwardToReplicas = false,
243+
?int $storeId = null
244+
) : void
245+
{
246+
$indexOptions = $this->indexOptionsBuilder->buildWithEnforcedIndex($indexName, $storeId);
247+
248+
$this->algoliaConnector->deleteRule($indexOptions, $objectID, $forwardToReplicas);
249+
}
250+
251+
/**
252+
* @throws AlgoliaException|NoSuchEntityException
253+
*/
254+
public function clearSynonyms(string $indexName, bool $forwardToReplicas = false, ?int $storeId = null): void
255+
{
256+
$indexOptions = $this->indexOptionsBuilder->buildWithEnforcedIndex($indexName, $storeId);
257+
$this->algoliaConnector->clearSynonyms($indexOptions, $forwardToReplicas);
258+
}
259+
260+
/**
261+
* @param string $fromIndexName
262+
* @param string $toIndexName
263+
* @param int|null $storeId
264+
* @return void
265+
* @throws AlgoliaException
266+
* @throws ExceededRetriesException|NoSuchEntityException
267+
*/
268+
public function copySynonyms(string $fromIndexName, string $toIndexName, ?int $storeId = null): void
269+
{
270+
$fromIndexOptions = $this->indexOptionsBuilder->buildWithEnforcedIndex($fromIndexName, $storeId);
271+
$toIndexOptions = $this->indexOptionsBuilder->buildWithEnforcedIndex($toIndexName, $storeId);
272+
273+
$this->algoliaConnector->copySynonyms($fromIndexOptions, $toIndexOptions);
274+
}
275+
276+
/**
277+
* @param string $fromIndexName
278+
* @param string $toIndexName
279+
* @param int|null $storeId
280+
* @return void
281+
* @throws AlgoliaException
282+
* @throws ExceededRetriesException|NoSuchEntityException
283+
*/
284+
public function copyQueryRules(string $fromIndexName, string $toIndexName, ?int $storeId = null): void
285+
{
286+
$fromIndexOptions = $this->indexOptionsBuilder->buildWithEnforcedIndex($fromIndexName, $storeId);
287+
$toIndexOptions = $this->indexOptionsBuilder->buildWithEnforcedIndex($toIndexName, $storeId);
288+
289+
$this->algoliaConnector->copyQueryRules($fromIndexOptions, $toIndexOptions);
290+
}
291+
292+
/**
293+
* @param string $indexName
294+
* @param array|null $searchRulesParams
295+
* @param int|null $storeId
296+
* @return array
297+
*
298+
* @throws AlgoliaException|NoSuchEntityException
299+
*/
300+
public function searchRules(string $indexName, array $searchRulesParams = null, ?int $storeId = null)
301+
{
302+
$indexOptions = $this->indexOptionsBuilder->buildWithEnforcedIndex($indexName, $storeId);
303+
304+
return $this->algoliaConnector->searchRules($indexOptions, $searchRulesParams);
305+
}
306+
307+
/**
308+
* @param string $indexName
309+
* @param int|null $storeId
310+
* @return void
311+
* @throws AlgoliaException|NoSuchEntityException
312+
*/
313+
public function clearIndex(string $indexName, ?int $storeId = null): void
314+
{
315+
$indexOptions = $this->indexOptionsBuilder->buildWithEnforcedIndex($indexName, $storeId);
316+
317+
$this->algoliaConnector->clearIndex($indexOptions);
318+
}
319+
320+
/**
321+
* @param int|null $storeId
322+
* @param string|null $lastUsedIndexName
323+
* @param int|null $lastTaskId
324+
* @return void
325+
* @throws AlgoliaException
326+
* @throws ExceededRetriesException
327+
*/
328+
public function waitLastTask(?int $storeId = null, ?string $lastUsedIndexName = null, ?int $lastTaskId = null): void
329+
{
330+
$this->algoliaConnector->waitLastTask($storeId, $lastUsedIndexName, $lastTaskId);
331+
}
332+
333+
/**
334+
* @param $productData
335+
* @return void
336+
*/
337+
public function castProductObject(&$productData): void
338+
{
339+
$this->algoliaConnector->castProductObject($productData);
340+
}
341+
342+
/**
343+
* @param int|null $storeId
344+
* @return int
345+
*/
346+
public function getLastTaskId(?int $storeId = null): int
347+
{
348+
return $this->algoliaConnector->getLastTaskId($storeId);
349+
}
350+
}

0 commit comments

Comments
 (0)