Skip to content

Commit

Permalink
Elasticsearch 8
Browse files Browse the repository at this point in the history
  • Loading branch information
limenet committed Jan 16, 2024
1 parent 75b3687 commit 1a9965c
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 63 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
php: [ '8.1', '8.2' ]
pimcore: [ '^11.0' ]
stability: [ prefer-lowest, prefer-stable ]
elastica: [ '^7.1', '8.x-dev' ]

steps:
- name: Checkout code
Expand All @@ -34,7 +33,7 @@ jobs:

- name: Install dependencies
run: |
composer require "pimcore/pimcore:${{ matrix.pimcore }}" "ruflin/elastica:${{ matrix.elastica }}" --no-interaction --no-update
composer require "pimcore/pimcore:${{ matrix.pimcore }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: List installed dependencies
Expand Down
14 changes: 10 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,31 @@
"version": "3.1.1",
"description": "Elastica bridge for Pimcore",
"type": "pimcore-bundle",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/pawelkeska/Elastica"
}
],
"require": {
"php": "^8.1",
"ext-json": "*",
"pimcore/pimcore": "^11.0",
"psr/log": "^3.0",
"ruflin/elastica": "^7.1 || 8.x-dev",
"ruflin/elastica": "dev-feature/up_to_elasticsearch_8",
"symfony/console": "^6.2",
"symfony/lock": "^6.2"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8.2",
"phpstan/extension-installer": "^1.3.1",
"phpstan/phpstan": "^1.10.49",
"phpstan/phpstan": "^1.10.56",
"phpstan/phpstan-deprecation-rules": "^1.1.4",
"phpstan/phpstan-strict-rules": "^1.5.2",
"rector/rector": "^0.18.12",
"rector/rector": "^0.18.13",
"roave/security-advisories": "dev-latest",
"sentry/sentry": "^3.22.1",
"symfony/http-client": "^6.4.0"
"symfony/http-client": "^6.4.2"
},
"license": "MIT",
"authors": [
Expand Down
4 changes: 2 additions & 2 deletions src/Command/Cleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Valantic\ElasticaBridgeBundle\Command;

use Elastica\Exception\ResponseException;
use Elastic\Elasticsearch\Exception\ElasticsearchException;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -62,7 +62,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

try {
$client->delete();
} catch (ResponseException $e) {
} catch (ElasticsearchException $e) {
$this->output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private function ensureCorrectBlueGreenIndexSetup(IndexInterface $indexConfig):
// In case an index with the same name as the blue/green alias exists, delete it
if (
$nonAliasIndex->exists()
&& !$this->esClient->request('_alias/' . $indexConfig->getName(), Request::HEAD)->isOk()
&& !$this->esClient->request(Request::HEAD, '_alias/' . $indexConfig->getName())->asBool()
) {
$nonAliasIndex->delete();
$this->output->writeln('<comment>-> Deleted non-blue/green index to prepare for blue/green usage</comment>');
Expand Down
2 changes: 1 addition & 1 deletion src/Document/AbstractDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private function getDataObjectListingClass(): string
$subType = $this->getSubType();

if ($subType === null) {
return DataObject\Listing::class;
return DataObjectListing::class;
}

$className = $subType . '\Listing';
Expand Down
8 changes: 5 additions & 3 deletions src/Document/DocumentNormalizerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ protected function editables(Document\Page $document): array
$data = [];
$editableNames = array_merge(
array_map(fn (Document\Editable $editable): string => $editable->getName(), $document->getEditables()),
$document->getContentMasterDocument() instanceof Document\PageSnippet
$document->getContentMainDocument() instanceof Document\PageSnippet
? array_map(
fn (Document\Editable $editable): string => $editable->getName(),
$document->getContentMasterDocument()->getEditables()
$document->getContentMainDocument()->getEditables()
)
: []
);
Expand Down Expand Up @@ -84,7 +84,9 @@ protected function editableRelation(
[$contents->getId()],
array_map(
fn (Concrete $obj): int => $obj->getId(),
$contents->getChildren([AbstractObject::OBJECT_TYPE_OBJECT])
$contents
->getChildren([AbstractObject::OBJECT_TYPE_OBJECT])
->getData() ?? []
)
);

Expand Down
18 changes: 17 additions & 1 deletion src/Elastica/Client/ElasticsearchClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,27 @@

namespace Valantic\ElasticaBridgeBundle\Elastica\Client;

use Elastic\Elasticsearch\Response\Elasticsearch;
use Elastica\Client;

/**
* When typehinted, this class provides an Elastica client pre-configured with port and host.
*
* @see ElasticsearchClientFactory
*/
class ElasticsearchClient extends Client {}
class ElasticsearchClient extends Client
{
/**
* @param array<string,string> $headers
*/
public function request(string $method, string $url, array $headers = [], mixed $body = null): Elasticsearch
{
$result = $this->sendRequest($this->createRequest($method, $url, $headers, $body));

if (!$result instanceof Elasticsearch) {
throw new \RuntimeException();
}

return $result;
}
}
3 changes: 2 additions & 1 deletion src/Index/AbstractIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Valantic\ElasticaBridgeBundle\Index;

use Elastica\Index;
use Elastica\Request;
use Pimcore\Model\Element\AbstractElement;
use Valantic\ElasticaBridgeBundle\Document\DocumentInterface;
use Valantic\ElasticaBridgeBundle\Elastica\Client\ElasticsearchClient;
Expand Down Expand Up @@ -113,7 +114,7 @@ final public function getBlueGreenActiveSuffix(): IndexBlueGreenSuffix
}

$aliases = array_filter(
$this->client->request('_aliases')->getData(),
json_decode((string) $this->client->request(Request::GET, '_aliases')->getBody(), true, flags: \JSON_THROW_ON_ERROR),
fn (array $datum): bool => array_key_exists($this->getName(), $datum['aliases'])
);

Expand Down
2 changes: 1 addition & 1 deletion vendor-bin/phpcs/composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.41.1"
"friendsofphp/php-cs-fixer": "^3.47.0"
}
}
Loading

0 comments on commit 1a9965c

Please sign in to comment.