From 1a9965cd407e124bbb167292368a5af4230478c9 Mon Sep 17 00:00:00 2001 From: Linus Metzler Date: Wed, 27 Dec 2023 15:25:56 +0100 Subject: [PATCH] Elasticsearch 8 --- .github/workflows/php.yml | 3 +- composer.json | 14 ++- src/Command/Cleanup.php | 4 +- src/Command/Index.php | 2 +- src/Document/AbstractDocument.php | 2 +- src/Document/DocumentNormalizerTrait.php | 8 +- src/Elastica/Client/ElasticsearchClient.php | 18 +++- src/Index/AbstractIndex.php | 3 +- vendor-bin/phpcs/composer.json | 2 +- vendor-bin/phpcs/composer.lock | 94 ++++++++++----------- 10 files changed, 87 insertions(+), 63 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 90355ee..4b8327c 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -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 @@ -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 diff --git a/composer.json b/composer.json index f29b06d..bf6b29d 100644 --- a/composer.json +++ b/composer.json @@ -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": [ diff --git a/src/Command/Cleanup.php b/src/Command/Cleanup.php index b327f02..4486739 100644 --- a/src/Command/Cleanup.php +++ b/src/Command/Cleanup.php @@ -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; @@ -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('%s', $e->getMessage())); } } diff --git a/src/Command/Index.php b/src/Command/Index.php index 023e27f..acef1b1 100644 --- a/src/Command/Index.php +++ b/src/Command/Index.php @@ -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('-> Deleted non-blue/green index to prepare for blue/green usage'); diff --git a/src/Document/AbstractDocument.php b/src/Document/AbstractDocument.php index f5429e0..9734acd 100644 --- a/src/Document/AbstractDocument.php +++ b/src/Document/AbstractDocument.php @@ -206,7 +206,7 @@ private function getDataObjectListingClass(): string $subType = $this->getSubType(); if ($subType === null) { - return DataObject\Listing::class; + return DataObjectListing::class; } $className = $subType . '\Listing'; diff --git a/src/Document/DocumentNormalizerTrait.php b/src/Document/DocumentNormalizerTrait.php index 84508e8..b0a5d8b 100644 --- a/src/Document/DocumentNormalizerTrait.php +++ b/src/Document/DocumentNormalizerTrait.php @@ -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() ) : [] ); @@ -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() ?? [] ) ); diff --git a/src/Elastica/Client/ElasticsearchClient.php b/src/Elastica/Client/ElasticsearchClient.php index f798fab..44e9533 100644 --- a/src/Elastica/Client/ElasticsearchClient.php +++ b/src/Elastica/Client/ElasticsearchClient.php @@ -4,6 +4,7 @@ namespace Valantic\ElasticaBridgeBundle\Elastica\Client; +use Elastic\Elasticsearch\Response\Elasticsearch; use Elastica\Client; /** @@ -11,4 +12,19 @@ * * @see ElasticsearchClientFactory */ -class ElasticsearchClient extends Client {} +class ElasticsearchClient extends Client +{ + /** + * @param array $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; + } +} diff --git a/src/Index/AbstractIndex.php b/src/Index/AbstractIndex.php index 9082421..a17ced8 100644 --- a/src/Index/AbstractIndex.php +++ b/src/Index/AbstractIndex.php @@ -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; @@ -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']) ); diff --git a/vendor-bin/phpcs/composer.json b/vendor-bin/phpcs/composer.json index 777ddc5..dfb2e03 100644 --- a/vendor-bin/phpcs/composer.json +++ b/vendor-bin/phpcs/composer.json @@ -1,5 +1,5 @@ { "require-dev": { - "friendsofphp/php-cs-fixer": "^3.41.1" + "friendsofphp/php-cs-fixer": "^3.47.0" } } diff --git a/vendor-bin/phpcs/composer.lock b/vendor-bin/phpcs/composer.lock index 7b77760..40b7deb 100644 --- a/vendor-bin/phpcs/composer.lock +++ b/vendor-bin/phpcs/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f1ecfb77672ce4bf9dc08b4f044254a1", + "content-hash": "d91338b72831edb74bf93f0de53683f5", "packages": [], "packages-dev": [ { @@ -227,21 +227,22 @@ }, { "name": "friendsofphp/php-cs-fixer", - "version": "v3.41.1", + "version": "v3.47.0", "source": { "type": "git", "url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git", - "reference": "8b6ae8dcbaf23f09680643ab832a4a3a260265f6" + "reference": "184dd992fe49169a18300dba4435212db55220f7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/8b6ae8dcbaf23f09680643ab832a4a3a260265f6", - "reference": "8b6ae8dcbaf23f09680643ab832a4a3a260265f6", + "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/184dd992fe49169a18300dba4435212db55220f7", + "reference": "184dd992fe49169a18300dba4435212db55220f7", "shasum": "" }, "require": { "composer/semver": "^3.4", "composer/xdebug-handler": "^3.0.3", + "ext-filter": "*", "ext-json": "*", "ext-tokenizer": "*", "php": "^7.4 || ^8.0", @@ -266,8 +267,7 @@ "php-cs-fixer/accessible-object": "^1.1", "php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.4", "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.4", - "phpunit/phpunit": "^9.6", - "symfony/phpunit-bridge": "^6.3.8 || ^7.0", + "phpunit/phpunit": "^9.6 || ^10.5.5", "symfony/yaml": "^5.4 || ^6.0 || ^7.0" }, "suggest": { @@ -306,7 +306,7 @@ ], "support": { "issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues", - "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.41.1" + "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.47.0" }, "funding": [ { @@ -314,7 +314,7 @@ "type": "github" } ], - "time": "2023-12-10T19:59:27+00:00" + "time": "2024-01-15T15:35:57+00:00" }, { "name": "psr/container", @@ -471,16 +471,16 @@ }, { "name": "sebastian/diff", - "version": "5.0.3", + "version": "5.1.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "912dc2fbe3e3c1e7873313cc801b100b6c68c87b" + "reference": "fbf413a49e54f6b9b17e12d900ac7f6101591b7f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/912dc2fbe3e3c1e7873313cc801b100b6c68c87b", - "reference": "912dc2fbe3e3c1e7873313cc801b100b6c68c87b", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/fbf413a49e54f6b9b17e12d900ac7f6101591b7f", + "reference": "fbf413a49e54f6b9b17e12d900ac7f6101591b7f", "shasum": "" }, "require": { @@ -493,7 +493,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "5.0-dev" + "dev-main": "5.1-dev" } }, "autoload": { @@ -526,7 +526,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/diff/issues", "security": "https://github.com/sebastianbergmann/diff/security/policy", - "source": "https://github.com/sebastianbergmann/diff/tree/5.0.3" + "source": "https://github.com/sebastianbergmann/diff/tree/5.1.0" }, "funding": [ { @@ -534,20 +534,20 @@ "type": "github" } ], - "time": "2023-05-01T07:48:21+00:00" + "time": "2023-12-22T10:55:06+00:00" }, { "name": "symfony/console", - "version": "v7.0.1", + "version": "v7.0.2", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "cdce5c684b2f920bb1343deecdfba356ffad83d5" + "reference": "f8587c4cdc5acad67af71c37db34ef03af91e59c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/cdce5c684b2f920bb1343deecdfba356ffad83d5", - "reference": "cdce5c684b2f920bb1343deecdfba356ffad83d5", + "url": "https://api.github.com/repos/symfony/console/zipball/f8587c4cdc5acad67af71c37db34ef03af91e59c", + "reference": "f8587c4cdc5acad67af71c37db34ef03af91e59c", "shasum": "" }, "require": { @@ -611,7 +611,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v7.0.1" + "source": "https://github.com/symfony/console/tree/v7.0.2" }, "funding": [ { @@ -627,7 +627,7 @@ "type": "tidelift" } ], - "time": "2023-12-01T15:10:06+00:00" + "time": "2023-12-10T16:54:46+00:00" }, { "name": "symfony/deprecation-contracts", @@ -698,16 +698,16 @@ }, { "name": "symfony/event-dispatcher", - "version": "v7.0.0", + "version": "v7.0.2", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "c459b40ffe67c49af6fd392aac374c9edf8a027e" + "reference": "098b62ae81fdd6cbf941f355059f617db28f4f9a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/c459b40ffe67c49af6fd392aac374c9edf8a027e", - "reference": "c459b40ffe67c49af6fd392aac374c9edf8a027e", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/098b62ae81fdd6cbf941f355059f617db28f4f9a", + "reference": "098b62ae81fdd6cbf941f355059f617db28f4f9a", "shasum": "" }, "require": { @@ -758,7 +758,7 @@ "description": "Provides tools that allow your application components to communicate with each other by dispatching events and listening to them", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/event-dispatcher/tree/v7.0.0" + "source": "https://github.com/symfony/event-dispatcher/tree/v7.0.2" }, "funding": [ { @@ -774,7 +774,7 @@ "type": "tidelift" } ], - "time": "2023-07-27T16:29:09+00:00" + "time": "2023-12-27T22:24:19+00:00" }, { "name": "symfony/event-dispatcher-contracts", @@ -1540,16 +1540,16 @@ }, { "name": "symfony/process", - "version": "v7.0.0", + "version": "v7.0.2", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "13bdb1670c7f510494e04fcb2bfa29af63db9c0d" + "reference": "acd3eb5cb02382c1cb0287ba29b2908cc6ffa83a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/13bdb1670c7f510494e04fcb2bfa29af63db9c0d", - "reference": "13bdb1670c7f510494e04fcb2bfa29af63db9c0d", + "url": "https://api.github.com/repos/symfony/process/zipball/acd3eb5cb02382c1cb0287ba29b2908cc6ffa83a", + "reference": "acd3eb5cb02382c1cb0287ba29b2908cc6ffa83a", "shasum": "" }, "require": { @@ -1581,7 +1581,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v7.0.0" + "source": "https://github.com/symfony/process/tree/v7.0.2" }, "funding": [ { @@ -1597,25 +1597,25 @@ "type": "tidelift" } ], - "time": "2023-11-20T16:43:42+00:00" + "time": "2023-12-24T09:15:37+00:00" }, { "name": "symfony/service-contracts", - "version": "v3.4.0", + "version": "v3.4.1", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "b3313c2dbffaf71c8de2934e2ea56ed2291a3838" + "reference": "fe07cbc8d837f60caf7018068e350cc5163681a0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/b3313c2dbffaf71c8de2934e2ea56ed2291a3838", - "reference": "b3313c2dbffaf71c8de2934e2ea56ed2291a3838", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/fe07cbc8d837f60caf7018068e350cc5163681a0", + "reference": "fe07cbc8d837f60caf7018068e350cc5163681a0", "shasum": "" }, "require": { "php": ">=8.1", - "psr/container": "^2.0" + "psr/container": "^1.1|^2.0" }, "conflict": { "ext-psr": "<1.1|>=2" @@ -1663,7 +1663,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/service-contracts/tree/v3.4.0" + "source": "https://github.com/symfony/service-contracts/tree/v3.4.1" }, "funding": [ { @@ -1679,7 +1679,7 @@ "type": "tidelift" } ], - "time": "2023-07-30T20:28:31+00:00" + "time": "2023-12-26T14:02:43+00:00" }, { "name": "symfony/stopwatch", @@ -1745,16 +1745,16 @@ }, { "name": "symfony/string", - "version": "v7.0.0", + "version": "v7.0.2", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "92bd2bfbba476d4a1838e5e12168bef2fd1e6620" + "reference": "cc78f14f91f5e53b42044d0620961c48028ff9f5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/92bd2bfbba476d4a1838e5e12168bef2fd1e6620", - "reference": "92bd2bfbba476d4a1838e5e12168bef2fd1e6620", + "url": "https://api.github.com/repos/symfony/string/zipball/cc78f14f91f5e53b42044d0620961c48028ff9f5", + "reference": "cc78f14f91f5e53b42044d0620961c48028ff9f5", "shasum": "" }, "require": { @@ -1811,7 +1811,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v7.0.0" + "source": "https://github.com/symfony/string/tree/v7.0.2" }, "funding": [ { @@ -1827,7 +1827,7 @@ "type": "tidelift" } ], - "time": "2023-11-29T08:40:23+00:00" + "time": "2023-12-10T16:54:46+00:00" } ], "aliases": [],