Skip to content
Snippets Groups Projects

Fix dev

Merged Christian Mahnke requested to merge fix-dev into dev
@@ -10,7 +10,7 @@ use FOS\ElasticaBundle\Elastica\Client;
class ChildCollectionsMappingTransformer extends GeonamesEnrichTransformer
{
protected array $fieldMappings;
protected array $nestedMappings;
protected array $nestedMappings = [];
public function __construct(Client $client, string $geonamesIndex, array $settings)
{
@@ -77,37 +77,39 @@ class ChildCollectionsMappingTransformer extends GeonamesEnrichTransformer
$filteredFields = self::filterFields($fields, self::extractFilterFields($entityFieldMappings));
//Filter nested
$filteredNestedDocs = [];
foreach ($filteredFields as $key => $mapping) {
if (isset($mapping['type']) && in_array($mapping['type'], ['nested', 'object']) && isset($mapping['properties']) && !empty($mapping['properties']) && array_key_exists($key, $this->nestedMappings)) {
unset($filteredFields[$key]);
$path = '';
if (isset($mapping['property_path'])) {
$path = $mapping['property_path'];
} else {
$path = $key;
}
$filteredNestedFields = self::filterFields($mapping['properties'], self::extractFilterFields($this->nestedMappings[$key]));
$values = $this->propertyAccessor->getValue($entity, $path);
if (!is_array($values)) {
$values = [$values];
}
foreach ($values as $value) {
$nestedDoc = $this->transformNested($value, $filteredNestedFields)[0];
// Add our own stuff
$additionalValues = $this->extractAdditionalValues($value, $this->nestedMappings[$key]);
foreach (array_keys($additionalValues) as $entity) {
foreach ($additionalValues[$entity] as $field => $content) {
if ($nestedDoc->has($field)) {
$nestedDoc->remove($field);
}
if (!empty($content)) {
$nestedDoc->set($field, $this->normalizeValue($content));
} else {
$nestedDoc->set($field, '');
if (!empty($this->nestedMappings)) {
foreach ($filteredFields as $key => $mapping) {
if (isset($mapping['type']) && in_array($mapping['type'], ['nested', 'object']) && isset($mapping['properties']) && !empty($mapping['properties']) && array_key_exists($key, $this->nestedMappings)) {
unset($filteredFields[$key]);
$path = '';
if (isset($mapping['property_path'])) {
$path = $mapping['property_path'];
} else {
$path = $key;
}
$filteredNestedFields = self::filterFields($mapping['properties'], self::extractFilterFields($this->nestedMappings[$key]));
$values = $this->propertyAccessor->getValue($entity, $path);
if (!is_array($values)) {
$values = [$values];
}
foreach ($values as $value) {
$nestedDoc = $this->transformNested($value, $filteredNestedFields)[0];
// Add our own stuff
$additionalValues = $this->extractAdditionalValues($value, $this->nestedMappings[$key]);
foreach (array_keys($additionalValues) as $entity) {
foreach ($additionalValues[$entity] as $field => $content) {
if ($nestedDoc->has($field)) {
$nestedDoc->remove($field);
}
if (!empty($content)) {
$nestedDoc->set($field, $this->normalizeValue($content));
} else {
$nestedDoc->set($field, '');
}
}
}
$filteredNestedDocs[$key][] = $nestedDoc;
}
$filteredNestedDocs[$key][] = $nestedDoc;
}
}
}
Loading