Skip to content

Commit bd35aae

Browse files
Peter Rauberdaniellienert
authored andcommitted
TASK: Modify to work with Elasticsearch 7
1 parent 6a0651c commit bd35aae

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

Classes/Domain/Factory/DocumentFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Neos\Error\Messages\Error;
2020
use Neos\Error\Messages\Result as ErrorResult;
2121
use Neos\Flow\Annotations as Flow;
22+
use Neos\Utility\Arrays;
2223

2324
/**
2425
* Reconstitute a Document from the ElasticSearch index.
@@ -45,7 +46,7 @@ public function createFromResponse(Model\AbstractType $type, $id = null, Respons
4546
$error = new Error('The received index name "%s" does not match the expected one "%s".', 1340264838, [$content['_index'], $type->getIndex()->getName()]);
4647
$verificationResults->addError($error);
4748
}
48-
if (isset($content['_type']) && $type->getName() !== $content['_type']) {
49+
if ($type->getName() !== Arrays::getValueByPath($content, '_source.neos_type')) {
4950
$error = new Error('The received type name "%s" does not match the expected one "%s".', 1340265103, [$content['_type'], $type->getName()]);
5051
$verificationResults->addError($error);
5152
}

Classes/Domain/Model/AbstractType.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Flowpack\ElasticSearch\Domain\Factory\DocumentFactory;
1818
use Flowpack\ElasticSearch\Transfer\Response;
1919
use Neos\Flow\Annotations as Flow;
20+
use Neos\Utility\TypeHandling;
2021

2122
/**
2223
* An abstract document type. Implement your own or use the GenericType provided with this package.
@@ -81,9 +82,9 @@ public function getIndex(): Index
8182
* @throws \Flowpack\ElasticSearch\Exception
8283
* @throws \Neos\Flow\Http\Exception
8384
*/
84-
public function findDocumentById(string $id): Document
85+
public function findDocumentById(string $id): ?Document
8586
{
86-
$response = $this->request('GET', '/' . $id);
87+
$response = $this->request('GET', '/_doc/' . $id);
8788
if ($response->getStatusCode() !== 200) {
8889
return null;
8990
}

Classes/Domain/Model/Document.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ public function store(): void
9292
{
9393
if ($this->id !== null) {
9494
$method = 'PUT';
95-
$path = '/' . $this->id;
95+
$path = '/_doc/' . $this->id;
9696
} else {
9797
$method = 'POST';
98-
$path = '';
98+
$path = '/_doc/';
9999
}
100100

101101
$response = $this->request($method, $path, [], json_encode($this->getData()));

Classes/Indexer/Object/ObjectIndexer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Flowpack\ElasticSearch\Domain\Model\Client;
1818
use Flowpack\ElasticSearch\Domain\Model\Document;
1919
use Flowpack\ElasticSearch\Domain\Model\GenericType;
20+
use Flowpack\ElasticSearch\Domain\Model\Mapping;
2021
use Neos\Flow\Annotations as Flow;
2122
use Neos\Flow\Persistence\PersistenceManagerInterface;
2223
use Neos\Flow\Reflection\ReflectionService;
@@ -121,7 +122,6 @@ protected function getIndexTypeForObject($object, Client $client = null)
121122
protected function getIndexablePropertiesAndValuesFromObject($object)
122123
{
123124
$className = TypeHandling::getTypeForValue($object);
124-
$data = [];
125125
foreach ($this->indexInformer->getClassProperties($className) as $propertyName) {
126126
if (ObjectAccess::isPropertyGettable($object, $propertyName) === false) {
127127
continue;
@@ -172,6 +172,7 @@ public function objectIndexActionRequired($object, Client $client = null)
172172
$document = $type->findDocumentById($id);
173173
if ($document !== null) {
174174
$objectData = $this->getIndexablePropertiesAndValuesFromObject($object);
175+
$objectData[Mapping::NEOS_TYPE_FIELD] = $type->getName();
175176
if (strcmp(json_encode($objectData), json_encode($document->getData())) === 0) {
176177
$actionType = null;
177178
} else {

0 commit comments

Comments
 (0)