From f79a78e4c5c37de476727dbee018c5d852abe1bf Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Wed, 19 Oct 2016 11:50:04 +0200 Subject: [PATCH] Restore merge exceptions and add structure factory method --- .../SearchEngine/Elastic/Structure/Field.php | 4 ++-- .../Elastic/Structure/GlobalStructure.php | 22 ++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Structure/Field.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Structure/Field.php index 9c364a8843..cd8629cd91 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Structure/Field.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Structure/Field.php @@ -205,7 +205,7 @@ class Field implements Typed // type so we reject only those with different types. if (($type = $other->getType()) !== $this->type) { - //throw new MergeException(sprintf("Field %s can't be merged, incompatible types (%s vs %s)", $name, $type, $this->type)); + throw new MergeException(sprintf("Field %s can't be merged, incompatible types (%s vs %s)", $name, $type, $this->type)); } if ($other->isPrivate() !== $this->is_private) { @@ -217,7 +217,7 @@ class Field implements Typed } if ($other->getFacetValuesLimit() !== $this->facet) { - //throw new MergeException(sprintf("Field %s can't be merged, incompatible facet eligibility", $name)); + throw new MergeException(sprintf("Field %s can't be merged, incompatible facet eligibility", $name)); } $thesaurus_roots = null; diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Structure/GlobalStructure.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Structure/GlobalStructure.php index 239072f1b5..2016e134b3 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Structure/GlobalStructure.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Structure/GlobalStructure.php @@ -46,7 +46,7 @@ final class GlobalStructure implements Structure /** * @param \databox[] $databoxes - * @return self + * @return GlobalStructure */ public static function createFromDataboxes(array $databoxes) { @@ -66,6 +66,26 @@ final class GlobalStructure implements Structure return new self($fields, $flags, MetadataHelper::createTags()); } + /** + * @param \databox $databox + * @return GlobalStructure + */ + public static function createFromDatabox(\databox $databox) + { + $fields = []; + $flags = []; + + foreach ($databox->get_meta_structure() as $fieldStructure) { + $fields[] = Field::createFromLegacyField($fieldStructure); + } + + foreach ($databox->getStatusStructure() as $status) { + $flags[] = Flag::createFromLegacyStatus($status); + } + + return new self($fields, $flags, MetadataHelper::createTags()); + } + /** * GlobalStructure constructor. * @param Field[] $fields