Skip to content

Commit e129a54

Browse files
committed
!!! TASK: Adapt the package to Flow 7.0 interface changes
1 parent 301154e commit e129a54

5 files changed

Lines changed: 48 additions & 38 deletions

File tree

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ addons:
99
- openjdk-8-jre-headless
1010
matrix:
1111
include:
12-
- php: 7.2
12+
- php: 7.3
1313
env: ES=6
14-
- php: 7.2
14+
- php: 7.3
1515
env: ES=7
1616
- php: 7.4
1717
env: ES=6
@@ -23,7 +23,7 @@ cache:
2323
- $HOME/.composer/cache
2424

2525
before_install:
26-
- export NEOS_TARGET_VERSION=5.3
26+
- export NEOS_TARGET_VERSION=6.0
2727
- cd ..
2828
- if [ "$ES" = 6 ]; then wget --no-check-certificate https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.8.6.tar.gz && tar xvfz elasticsearch-6.8.6.tar.gz && mv elasticsearch-6.8.6 elasticsearch; fi
2929
- if [ "$ES" = 7 ]; then wget --no-check-certificate https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.0-linux-x86_64.tar.gz && tar xvfz elasticsearch-7.9.0-linux-x86_64.tar.gz && mv elasticsearch-7.9.0 elasticsearch; fi

Classes/Eel/ElasticSearchQuery.php

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
declare(strict_types=1);
43

54
namespace Flowpack\ElasticSearch\ContentRepositoryAdaptor\Eel;
@@ -15,8 +14,12 @@
1514
*/
1615

1716
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception;
17+
use InvalidArgumentException;
18+
use JsonException;
19+
use Neos\Flow\Persistence\Exception\IllegalObjectTypeException;
1820
use Neos\Flow\Persistence\QueryInterface;
1921
use Neos\ContentRepository\Domain\Model\NodeInterface;
22+
use Neos\Flow\Persistence\QueryResultInterface;
2023

2124
/**
2225
* This ElasticSearchQuery object is just used inside ElasticSearchQueryResult->getQuery(), so that pagination
@@ -49,11 +52,12 @@ public function __construct(ElasticSearchQueryBuilder $elasticSearchQueryBuilder
4952
*
5053
* @param bool $cacheResult If the result cache should be used
5154
* @return ElasticSearchQueryResult The query result
55+
* @throws JsonException
5256
* @api
5357
*/
54-
public function execute($cacheResult = false)
58+
public function execute($cacheResult = false): QueryResultInterface
5559
{
56-
$queryHash = md5($this->queryBuilder->getIndexName() . json_encode($this->queryBuilder->getRequest()));
60+
$queryHash = md5($this->queryBuilder->getIndexName() . json_encode($this->queryBuilder->getRequest(), JSON_THROW_ON_ERROR));
5761
if ($cacheResult === true && isset(self::$runtimeQueryResultCache[$queryHash])) {
5862
return self::$runtimeQueryResultCache[$queryHash];
5963
}
@@ -66,57 +70,59 @@ public function execute($cacheResult = false)
6670
/**
6771
* {@inheritdoc}
6872
*/
69-
public function count()
73+
public function count(): int
7074
{
71-
// FIXME Check that results are fetched!
72-
7375
return $this->queryBuilder->getTotalItems();
7476
}
7577

7678
/**
77-
* {@inheritdoc}
79+
* @param int|null $limit
80+
* @return QueryInterface
81+
* @throws IllegalObjectTypeException
7882
*/
79-
public function setLimit($limit)
83+
public function setLimit(?int $limit): QueryInterface
8084
{
8185
if ($limit < 1 || !is_int($limit)) {
82-
throw new \InvalidArgumentException('Expecting integer greater than zero for limit');
86+
throw new InvalidArgumentException('Expecting integer greater than zero for limit');
8387
}
8488

8589
$this->queryBuilder->limit($limit);
90+
return $this;
8691
}
8792

8893
/**
8994
* {@inheritdoc}
9095
*/
91-
public function getLimit()
96+
public function getLimit(): int
9297
{
9398
return $this->queryBuilder->getLimit();
9499
}
95100

96101
/**
97102
* {@inheritdoc}
98103
*/
99-
public function setOffset($offset)
104+
public function setOffset(?int $offset): QueryInterface
100105
{
101106
if ($offset < 1 || !is_int($offset)) {
102-
throw new \InvalidArgumentException('Expecting integer greater than zero for offset');
107+
throw new InvalidArgumentException('Expecting integer greater than zero for offset', 1605474906);
103108
}
104109

105110
$this->queryBuilder->from($offset);
111+
return $this;
106112
}
107113

108114
/**
109115
* {@inheritdoc}
110116
*/
111-
public function getOffset()
117+
public function getOffset(): int
112118
{
113119
return $this->queryBuilder->getFrom();
114120
}
115121

116122
/**
117123
* {@inheritdoc}
118124
*/
119-
public function getType()
125+
public function getType(): string
120126
{
121127
return NodeInterface::class;
122128
}
@@ -125,7 +131,7 @@ public function getType()
125131
* {@inheritdoc}
126132
* @throws Exception
127133
*/
128-
public function setOrderings(array $orderings)
134+
public function setOrderings(array $orderings): QueryInterface
129135
{
130136
throw new Exception(__FUNCTION__ . ' not implemented', 1421749035);
131137
}
@@ -134,7 +140,7 @@ public function setOrderings(array $orderings)
134140
* {@inheritdoc}
135141
* @throws Exception
136142
*/
137-
public function getOrderings()
143+
public function getOrderings(): array
138144
{
139145
throw new Exception(__FUNCTION__ . ' not implemented', 1421749036);
140146
}
@@ -143,7 +149,7 @@ public function getOrderings()
143149
* {@inheritdoc}
144150
* @throws Exception
145151
*/
146-
public function matching($constraint)
152+
public function matching($constraint): QueryInterface
147153
{
148154
throw new Exception(__FUNCTION__ . ' not implemented', 1421749037);
149155
}
@@ -269,7 +275,7 @@ public function greaterThanOrEqual($propertyName, $operand)
269275
* {@inheritdoc}
270276
* @throws Exception
271277
*/
272-
public function setDistinct($distinct = true)
278+
public function setDistinct(bool $distinct = true): QueryInterface
273279
{
274280
throw new Exception(__FUNCTION__ . ' not implemented', 1421749051);
275281
}
@@ -278,7 +284,7 @@ public function setDistinct($distinct = true)
278284
* {@inheritdoc}
279285
* @throws Exception
280286
*/
281-
public function isDistinct()
287+
public function isDistinct(): bool
282288
{
283289
throw new Exception(__FUNCTION__ . ' not implemented', 1421749052);
284290
}

Classes/Eel/ElasticSearchQueryBuilder.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\ElasticSearchClient;
1919
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception;
2020
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception\QueryBuildingException;
21-
use Flowpack\ElasticSearch\Domain\Model\Index;
22-
use Flowpack\ElasticSearch\Domain\Model\Mapping;
2321
use Neos\Flow\Log\ThrowableStorageInterface;
2422
use Neos\Flow\Log\Utility\LogEnvironment;
2523
use Neos\Flow\Persistence\Exception\IllegalObjectTypeException;
24+
use Neos\Flow\Persistence\QueryResultInterface;
2625
use Psr\Log\LoggerInterface;
2726
use Flowpack\ElasticSearch\Transfer\Exception\ApiException;
2827
use Neos\ContentRepository\Domain\Model\NodeInterface;
@@ -620,20 +619,22 @@ protected function evaluateResult(array $result): SearchResult
620619
/**
621620
* Get a query result object for lazy execution of the query
622621
*
622+
* @param bool $cacheResult
623623
* @return ElasticSearchQueryResult
624-
* @return \Traversable
624+
* @throws \JsonException
625625
* @api
626626
*/
627-
public function execute(): \Traversable
627+
public function execute(bool $cacheResult = true): QueryResultInterface
628628
{
629629
$elasticSearchQuery = new ElasticSearchQuery($this);
630-
return $elasticSearchQuery->execute(true);
630+
return $elasticSearchQuery->execute($cacheResult);
631631
}
632632

633633
/**
634634
* Get a uncached query result object for lazy execution of the query
635635
*
636636
* @return ElasticSearchQueryResult
637+
* @throws \JsonException
637638
* @api
638639
*/
639640
public function executeUncached(): ElasticSearchQueryResult
@@ -662,7 +663,7 @@ public function count(): int
662663
$treatedContent = $response->getTreatedContent();
663664
$count = (int)$treatedContent['count'];
664665

665-
$this->logThisQuery && $this->logger->debug('Count Query Log (' . $this->logMessage . '): ' . 'Indexname: ' . $this->getIndexName() . ' ' . $request . ' -- execution time: ' . (($timeAfterwards - $timeBefore) * 1000) . ' ms -- Total Results: ' . $count, LogEnvironment::fromMethodName(__METHOD__));
666+
$this->logThisQuery && $this->logger->debug('Count Query Log (' . $this->logMessage . '): Indexname: ' . $this->getIndexName() . ' ' . $request . ' -- execution time: ' . (($timeAfterwards - $timeBefore) * 1000) . ' ms -- Total Results: ' . $count, LogEnvironment::fromMethodName(__METHOD__));
666667

667668
return $count;
668669
}
@@ -673,12 +674,13 @@ public function count(): int
673674
* @param string $searchWord
674675
* @param array $options Options to configure the query_string, see https://www.elastic.co/guide/en/elasticsearch/reference/7.6/query-dsl-query-string-query.html
675676
* @return QueryBuilderInterface
677+
* @throws \JsonException
676678
* @api
677679
*/
678680
public function fulltext(string $searchWord, array $options = []): QueryBuilderInterface
679681
{
680682
// We automatically enable result highlighting when doing fulltext searches. It is up to the user to use this information or not use it.
681-
$this->request->fulltext(trim(json_encode($searchWord, JSON_UNESCAPED_UNICODE), '"'), $options);
683+
$this->request->fulltext(trim(json_encode($searchWord, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE), '"'), $options);
682684
$this->request->highlight(150, 2);
683685

684686
return $this;
@@ -926,8 +928,8 @@ public function cacheLifetime(): int
926928
$minTimestamps = array_filter([
927929
$this->getNearestFutureDate('neos_hidden_before_datetime'),
928930
$this->getNearestFutureDate('neos_hidden_after_datetime')
929-
], function ($value) {
930-
return $value != 0;
931+
], static function ($value) {
932+
return $value !== 0;
931933
});
932934

933935
if (empty($minTimestamps)) {
@@ -951,7 +953,7 @@ protected function getNearestFutureDate(string $dateField): int
951953
{
952954
$request = clone $this->request;
953955

954-
$convertDateResultToTimestamp = function (array $dateResult): int {
956+
$convertDateResultToTimestamp = static function (array $dateResult): int {
955957
if (!isset($dateResult['value_as_string'])) {
956958
return 0;
957959
}
@@ -1023,9 +1025,11 @@ protected function convertValue($value)
10231025
}
10241026

10251027
/**
1026-
* Retrieve the indexname
1028+
* Retrieve the indexName
10271029
*
10281030
* @return string
1031+
* @throws Exception
1032+
* @throws Exception\ConfigurationException
10291033
*/
10301034
public function getIndexName(): string
10311035
{

Classes/Eel/ElasticSearchQueryResult.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
declare(strict_types=1);
43

54
namespace Flowpack\ElasticSearch\ContentRepositoryAdaptor\Eel;
@@ -16,6 +15,7 @@
1615

1716
use Neos\ContentRepository\Domain\Model\NodeInterface;
1817
use Neos\Eel\ProtectedContextAwareInterface;
18+
use Neos\Flow\Persistence\QueryInterface;
1919
use Neos\Flow\Persistence\QueryResultInterface;
2020

2121
class ElasticSearchQueryResult implements QueryResultInterface, ProtectedContextAwareInterface
@@ -66,7 +66,7 @@ protected function initialize(): void
6666
/**
6767
* @return ElasticSearchQuery
6868
*/
69-
public function getQuery()
69+
public function getQuery(): QueryInterface
7070
{
7171
return clone $this->elasticSearchQuery;
7272
}
@@ -172,7 +172,7 @@ public function getFirst()
172172
/**
173173
* {@inheritdoc}
174174
*/
175-
public function toArray()
175+
public function toArray(): array
176176
{
177177
$this->initialize();
178178

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
"homepage": "http://flowpack.org/",
66
"license": ["LGPL-3.0-only"],
77
"require": {
8-
"php": "^7.2",
8+
"php": "^7.3",
99
"ext-json": "*",
1010

1111
"flowpack/elasticsearch": " ^5.0 || dev-master",
1212
"neos/content-repository": "^5.0",
1313
"neos/content-repository-search": "^4.0 || dev-master",
1414
"neos/eel": "^6.0",
15-
"neos/flow": "^6.0",
15+
"neos/flow": "^7.0",
1616
"neos/fluid-adaptor": "^6.0",
1717
"neos/utility-arrays": "^6.0"
1818
},

0 commit comments

Comments
 (0)