Skip to content

Commit cbe1ea8

Browse files
GaryPEGEOTJulien Mariller
andauthored
build!: Upgrade ruflin/elastica to v8 (#194)
BREAKING CHANGE: `JoliCode\Elastically\Transport\HttpClientTransport` has been removed, Closes #186 --------- Co-authored-by: Julien Mariller <[email protected]>
1 parent d504a7f commit cbe1ea8

20 files changed

+60
-353
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
9+
## 2.0.0
10+
11+
### Added
12+
13+
- Updated `ruflin/elastica` to v8 (Breaking Change)
14+
- Dropped `HttpClientTransport` (Breaking Change)
915

1016
## 1.9.1
1117

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ test: ## Run test suite
22
./vendor/bin/simple-phpunit
33

44
start: ## Start testing tools (Elasticsearch)
5-
docker run --rm -d --name "elastically_es" -p 9999:9200 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch-oss:7.8.0
5+
docker run --rm -d --name "elastically_es" -p 9999:9200 -e "discovery.type=single-node" -e "xpack.security.enabled=false" -e "action.destructive_requires_name=false" -it -m 1GB docker.elastic.co/elasticsearch/elasticsearch:8.14.2
66

77
start_opensearch: ## Start testing tools (OpenSearch)
88
docker run --rm -d --name "elastically_es" -p 9999:9200 -e "discovery.type=single-node" -e "plugins.security.disabled=true" opensearchproject/opensearch:2.3.0

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ elastically:
253253
client:
254254
host: '%env(ELASTICSEARCH_HOST)%'
255255
# If you want to use the Symfony HttpClient (you MUST create this service)
256-
#transport: 'JoliCode\Elastically\Transport\HttpClientTransport'
257256
258257
# Path to the mapping directory (in YAML)
259258
mapping_directory: '%kernel.project_dir%/config/elasticsearch'

UPGRADE.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Upgrade guide
22

3+
## From v1.9.0 to v2.0.0
4+
5+
HttpClientTransport has been removed:
6+
```diff
7+
JoliCode\Elastically\Client:
8+
arguments:
9+
$config:
10+
host: '%env(ELASTICSEARCH_HOST)%'
11+
port: '%env(ELASTICSEARCH_PORT)%'
12+
- transport: '@JoliCode\Elastically\Transport\HttpClientTransport'
13+
+ transport_client:
14+
+ client: '@my_custom_psr18_client' # An instance of Symfony\Component\HttpClient\Psr18Client (Or any PSR 18 compliant one)
15+
```
16+
317
## From v1.3.0 to v1.4.0
418

519
If you're using Symfony, here are the changes to apply:

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
"require": {
1818
"php": ">=8.0",
1919
"ext-json": "*",
20+
"nyholm/psr7": "^1.8",
2021
"phpdocumentor/reflection-docblock": "^4.4|^5.0",
21-
"ruflin/elastica": "^7.0",
22+
"ruflin/elastica": "^8.0",
2223
"symfony/deprecation-contracts": "^2.4 || ^3.0",
2324
"symfony/property-access": "^5.4 || ^6.0 || ^7.0",
2425
"symfony/property-info": "^5.4 || ^6.0 || ^7.0",
26+
"symfony/psr-http-message-bridge": "^7.1",
2527
"symfony/serializer": "^5.4 || ^6.0 || ^7.0",
2628
"symfony/yaml": "^5.4 || ^6.0 || ^7.0"
2729
},

src/Bridge/Symfony/DependencyInjection/Configuration.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public function getConfigTreeBuilder(): TreeBuilder
3232
->info('All options for the Elastica client constructor')
3333
->example([
3434
'host' => '%env(ELASTICSEARCH_HOST)%',
35-
'transport' => 'JoliCode\Elastically\Transport\HttpClientTransport',
3635
])
3736
->normalizeKeys(false)
3837
->defaultValue([])

src/Bridge/Symfony/DependencyInjection/ElasticallyExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ private function buildConnection(string $name, array $config, bool $isDefaultCon
6767
$container->setDefinition("elastically.{$name}.result_set_builder", $resultSetBuilder);
6868

6969
$client = new ChildDefinition('elastically.abstract.client');
70-
if (\array_key_exists('client', $config) && \array_key_exists('transport', $config['client'])) {
71-
$config['client']['transport'] = new Reference($config['client']['transport']);
70+
if ($transportClient = $config['client']['transport_config']['http_client'] ?? null) {
71+
$config['client']['transport_config']['http_client'] = new Reference($transportClient);
7272
}
7373
$client->replaceArgument('$config', $config['client'] ?? []);
7474
$client->replaceArgument('$resultSetBuilder', new Reference("elastically.{$name}.result_set_builder"));

src/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class Client extends ElasticaClient
3131
private ResultSetBuilder $resultSetBuilder;
3232
private IndexNameMapper $indexNameMapper;
3333

34-
public function __construct($config = [], ?callable $callback = null, ?LoggerInterface $logger = null, ?ResultSetBuilder $resultSetBuilder = null, ?IndexNameMapper $indexNameMapper = null)
34+
public function __construct($config = [], ?LoggerInterface $logger = null, ?ResultSetBuilder $resultSetBuilder = null, ?IndexNameMapper $indexNameMapper = null)
3535
{
36-
parent::__construct($config, $callback, $logger);
36+
parent::__construct($config, $logger);
3737

3838
// BC Layer, to remove in 2.0
3939
$this->factory = new Factory($config);

src/Factory.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public function buildClient(): Client
6565
return $this->client ??= new Client(
6666
$this->config,
6767
null,
68-
null,
6968
$this->buildBuilder(),
7069
$this->buildIndexNameMapper()
7170
);

src/IndexBuilder.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
use Elastica\Exception\ExceptionInterface;
1515
use Elastica\Exception\RuntimeException;
1616
use Elastica\Reindex;
17-
use Elastica\Request;
1817
use Elastica\Response;
1918
use Elastica\Task;
20-
use Elasticsearch\Endpoints\Cluster\State;
2119
use JoliCode\Elastically\Mapping\MappingProviderInterface;
2220

2321
class IndexBuilder
@@ -64,7 +62,9 @@ public function markAsLive(Index $index, string $indexName): Response
6462
$data['actions'][] = ['remove' => ['index' => $indexPrefixedName . '*', 'alias' => $indexPrefixedName]];
6563
$data['actions'][] = ['add' => ['index' => $index->getName(), 'alias' => $indexPrefixedName]];
6664

67-
return $this->client->request('_aliases', Request::POST, $data);
65+
return $this->client->toElasticaResponse(
66+
$this->client->indices()->updateAliases(['index' => $indexName, 'body' => $data])
67+
);
6868
}
6969

7070
/**
@@ -119,13 +119,11 @@ public function purgeOldIndices(string $indexName, bool $dryRun = false): array
119119
{
120120
$indexName = $this->indexNameMapper->getPrefixedIndex($indexName);
121121

122-
$stateRequest = new State();
123-
$stateRequest->setParams([
122+
$state = $this->client->cluster()->state([
124123
'filter_path' => 'metadata.indices.*.state,metadata.indices.*.aliases',
125124
]);
126125

127-
$indexes = $this->client->requestEndpoint($stateRequest);
128-
$indexes = $indexes->getData();
126+
$indexes = $this->client->toElasticaResponse($state)->getData();
129127
$indexes = $indexes['metadata']['indices'];
130128

131129
foreach ($indexes as $realIndexName => &$data) {

0 commit comments

Comments
 (0)