From 21aed2d2e14d2bbad5bf17a034bc01c019258611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Espi=C3=A9?= Date: Wed, 2 May 2018 08:11:28 +0000 Subject: [PATCH] Advanced Search: Fix missing query internal params SVN:trunk[5762] --- core/oql/expression.class.inc.php | 18 +++++++++++++++++- .../criteriontosearchform.class.inc.php | 4 ++-- .../search/searchform.class.inc.php | 18 ++++++++++++++---- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/core/oql/expression.class.inc.php b/core/oql/expression.class.inc.php index 59ce6c5cb..7f2d032a8 100644 --- a/core/oql/expression.class.inc.php +++ b/core/oql/expression.class.inc.php @@ -44,7 +44,15 @@ abstract class Expression */ abstract public function Translate($aTranslationData, $bMatchAll = true, $bMarkFieldsAsResolved = true); - // recursive rendering (aArgs used as input by default, or used as output if bRetrofitParams set to True + /** + * recursive rendering + * + * @param array $aArgs used as input by default, or used as output if bRetrofitParams set to True + * @param bool $bRetrofitParams + * + * @return array|string + * @throws \MissingQueryArgument + */ abstract public function Render(&$aArgs = null, $bRetrofitParams = false); /** @@ -1259,6 +1267,14 @@ class VariableExpression extends UnaryExpression } // recursive rendering + + /** + * @param null $aArgs + * @param bool $bRetrofitParams + * + * @return array|string + * @throws \MissingQueryArgument + */ public function Render(&$aArgs = null, $bRetrofitParams = false) { if (is_null($aArgs)) diff --git a/sources/application/search/criterionconversion/criteriontosearchform.class.inc.php b/sources/application/search/criterionconversion/criteriontosearchform.class.inc.php index 20b9e813f..ce196da40 100644 --- a/sources/application/search/criterionconversion/criteriontosearchform.class.inc.php +++ b/sources/application/search/criterionconversion/criteriontosearchform.class.inc.php @@ -167,10 +167,10 @@ class CriterionToSearchForm extends CriterionConversionAbstract { if (!is_null($aPrevCriterion)) { - if (array_key_exists('ref', $aPrevCriterion)) + if (array_key_exists('ref', $aPrevCriterion) && array_key_exists('widget', $aPrevCriterion)) { // If previous has ref, the current has ref as the array is sorted with all without ref first - if (strcmp($aPrevCriterion['ref'], $aCurrCriterion['ref']) == 0) + if (($aPrevCriterion['ref'] == $aCurrCriterion['ref']) && ($aPrevCriterion['widget'] == $aCurrCriterion['widget'])) { // Same attribute, try to merge if (array_key_exists('widget', $aCurrCriterion)) diff --git a/sources/application/search/searchform.class.inc.php b/sources/application/search/searchform.class.inc.php index 4cb08c65a..e720d26a3 100644 --- a/sources/application/search/searchform.class.inc.php +++ b/sources/application/search/searchform.class.inc.php @@ -39,6 +39,7 @@ use Expression; use FieldExpression; use IssueLog; use MetaModel; +use MissingQueryArgument; use TrueExpression; use utils; use WebPage; @@ -468,6 +469,7 @@ class SearchForm * @param bool $bIsRemovable * * @return array + * @throws \MissingQueryArgument */ public function GetCriterion($oSearch, $aFields, $aArgs = array(), $bIsRemovable = true) { @@ -478,12 +480,20 @@ class SearchForm { $oExpression = $oSearch->GetCriteria(); + $aArgs = MetaModel::PrepareQueryArguments($aArgs, $oSearch->GetInternalParams()); + if (!empty($aArgs)) { - $aArgs = MetaModel::PrepareQueryArguments($aArgs); - - $sOQL = $oExpression->Render($aArgs); - $oExpression = Expression::FromOQL($sOQL); + try + { + $sOQL = $oExpression->Render($aArgs); + $oExpression = Expression::FromOQL($sOQL); + } + catch (MissingQueryArgument $e) + { + IssueLog::Error("Search form disabled: \"".$oSearch->ToOQL()."\" Error: ".$e->getMessage()); + throw $e; + } } $aORExpressions = Expression::Split($oExpression, 'OR');