From 54cc0132b76fa70dcd88623f8e175b9530a66e6d Mon Sep 17 00:00:00 2001 From: Mathieu Darse Date: Tue, 10 Nov 2015 11:51:57 +0100 Subject: [PATCH] Cast metadata tags values according to type --- .../Record/Hydrator/MetadataHydrator.php | 46 ++++++++++++------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/Record/Hydrator/MetadataHydrator.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/Record/Hydrator/MetadataHydrator.php index 54759bdd0c..e3b94e626d 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/Record/Hydrator/MetadataHydrator.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/Record/Hydrator/MetadataHydrator.php @@ -76,23 +76,7 @@ SQL; case 'caption': // Sanitize fields $value = StringHelper::crlfNormalize($value); - switch ($this->structure->typeOf($key)) { - case Mapping::TYPE_DATE: - $value = $this->helper->sanitizeDate($value); - break; - - case Mapping::TYPE_FLOAT: - case Mapping::TYPE_DOUBLE: - $value = (float) $value; - break; - - case Mapping::TYPE_INTEGER: - case Mapping::TYPE_LONG: - case Mapping::TYPE_SHORT: - case Mapping::TYPE_BYTE: - $value = (int) $value; - break; - } + $value = $this->sanitizeValue($value, $this->structure->typeOf($key)); // Private caption fields are kept apart $type = $metadata['private'] ? 'private_caption' : 'caption'; // Caption are multi-valued @@ -110,6 +94,10 @@ SQL; case 'exif': // EXIF data is single-valued + $tag = $this->structure->getMetadataTagByName($key); + if ($tag) { + $value = $this->sanitizeValue($value, $tag->getType()); + } $record['exif'][$key] = $value; break; @@ -119,4 +107,28 @@ SQL; } } } + + private function sanitizeValue($value, $type) + { + switch ($type) { + case Mapping::TYPE_DATE: + return $this->helper->sanitizeDate($value); + + case Mapping::TYPE_FLOAT: + case Mapping::TYPE_DOUBLE: + return (float) $value; + + case Mapping::TYPE_INTEGER: + case Mapping::TYPE_LONG: + case Mapping::TYPE_SHORT: + case Mapping::TYPE_BYTE: + return (int) $value; + + case Mapping::TYPE_BOOLEAN: + return (bool) $value; + + default: + return $value; + } + } }