From 94f9b16c03c4f9a232f677212aecde616b09b95e Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 24 Jun 2020 15:18:11 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B02589=20-=20Infinite=20loops=20when=20log?= =?UTF-8?q?ging=20with=20a=20Contact=20having=20a=20non=20empty=20TagSet?= =?UTF-8?q?=20field=20Add=20ListParameters=20to=20DBSearch=20for=20nested?= =?UTF-8?q?=20queries?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/dbobjectsearch.class.php | 5 ++++ core/dbsearch.class.php | 2 ++ core/dbunionsearch.class.php | 10 +++++++ core/oql/expression.class.inc.php | 2 +- test/core/ExpressionTest.php | 47 +++++++++++++++++++++++++++++++ test/core/OQLTest.php | 1 + 6 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 test/core/ExpressionTest.php diff --git a/core/dbobjectsearch.class.php b/core/dbobjectsearch.class.php index bd461b0228..0dba2f23c9 100644 --- a/core/dbobjectsearch.class.php +++ b/core/dbobjectsearch.class.php @@ -2097,4 +2097,9 @@ static public function GetPolymorphicExpression($sClass, $sAttCode) } return $oExpression; } + + public function ListParameters() + { + return $this->GetCriteria()->ListParameters(); + } } diff --git a/core/dbsearch.class.php b/core/dbsearch.class.php index 66884183ef..c4e9d6a122 100644 --- a/core/dbsearch.class.php +++ b/core/dbsearch.class.php @@ -1230,6 +1230,8 @@ public abstract function GetSQLQueryStructure( */ public abstract function GetCriteria(); + public abstract function ListParameters(); + /** * Shortcut to add efficient IN condition * diff --git a/core/dbunionsearch.class.php b/core/dbunionsearch.class.php index adcd76c512..3d659bbf85 100644 --- a/core/dbunionsearch.class.php +++ b/core/dbunionsearch.class.php @@ -728,4 +728,14 @@ public function AddConditionForInOperatorUsingParam($sFilterCode, $aValues, $bPo $oSearch->AddConditionExpression($oInCondition); } } + + public function ListParameters() + { + $aParameters = array(); + foreach ($this->aSearches as $oSearch) + { + $aParameters = array_merge($aParameters, $oSearch->ListParameters()); + } + return $aParameters; + } } diff --git a/core/oql/expression.class.inc.php b/core/oql/expression.class.inc.php index 5bce60fb85..8b2e43e271 100644 --- a/core/oql/expression.class.inc.php +++ b/core/oql/expression.class.inc.php @@ -2624,7 +2624,7 @@ public function ListConstantFields() public function ListParameters() { - return array(); + return $this->m_oValue->ListParameters(); } public function RenameParam($sOldName, $sNewName) diff --git a/test/core/ExpressionTest.php b/test/core/ExpressionTest.php new file mode 100644 index 0000000000..2ceef39441 --- /dev/null +++ b/test/core/ExpressionTest.php @@ -0,0 +1,47 @@ +ListParameters(); + $aResult = array(); + foreach ($aParameters as $oVarExpr) + { + /** var \VariableExpression $oVarExpr */ + $aResult[] = $oVarExpr->RenderExpression(); + } + $this->debug($aResult); + $this->assertSame(array_diff($aExpected, $aResult), array_diff($aResult, $aExpected)); + } + + public function ListParametersProvider() + { + return array( + array('1', array()), + array(':id = 2', array(':id')), + array('expiration_date < DATE_SUB(NOW(), INTERVAL :expiration_days DAY)', array(':expiration_days')), + array('id IN (SELECT Organization WHERE :id = 2)', array(':id')), + array('id IN (:id, 2)', array(':id')), + array("B.name LIKE :name", array(':name')), + array("name REGEXP :regexp", array(':regexp')), + array(" t.agent_id = :current_contact_id", array(':current_contact_id')), + array("INET_ATON(dev.managementip) > INET_ATON('10.22.32.224') AND INET_ATON(:ip) < INET_ATON('10.22.32.255')", array(':ip')), + ); + } +} diff --git a/test/core/OQLTest.php b/test/core/OQLTest.php index e1f74f8795..eb7bf7230f 100644 --- a/test/core/OQLTest.php +++ b/test/core/OQLTest.php @@ -402,6 +402,7 @@ public function testMakeSelectQuery($sOQL, $sExpectedExceptionClass = '') } catch (Exception $e) { + $this->debug($e->getMessage()); $sExceptionClass = get_class($e); }