-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeleteSynonymRuleAdaptor.php
More file actions
40 lines (30 loc) · 1.36 KB
/
DeleteSynonymRuleAdaptor.php
File metadata and controls
40 lines (30 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
namespace SilverStripe\ForagerBifrost\Adaptors\Requests;
use SilverStripe\Forager\Interfaces\Requests\DeleteSynonymRuleAdaptor as DeleteSynonymRuleAdaptorInterface;
use SilverStripe\Forager\Service\IndexConfiguration;
use Silverstripe\Search\Client\Client;
use Silverstripe\Search\Client\Exception\SynonymRuleDeleteNotFoundException;
use Silverstripe\Search\Client\Exception\SynonymRuleDeleteUnprocessableEntityException;
class DeleteSynonymRuleAdaptor implements DeleteSynonymRuleAdaptorInterface
{
private ?Client $client = null;
private static array $dependencies = [
'client' => '%$' . Client::class . '.managementClient',
];
public function setClient(?Client $client): void
{
$this->client = $client;
}
/**
* @throws SynonymRuleDeleteNotFoundException
* @throws SynonymRuleDeleteUnprocessableEntityException
*/
public function process(int|string $synonymCollectionId, int|string $synonymRuleId): bool
{
// Silverstripe Search simply uses the engine name as the Synonym Collection ID
$engineName = IndexConfiguration::singleton()->environmentizeIndex($synonymCollectionId);
// Should either be successful or throw an exception, which we'll let fly
$response = $this->client->synonymRuleDelete($synonymRuleId, $engineName);
return $response->getSuccess();
}
}