浏览代码

Exclude magic parameters when listing query parameters (refactoring from run_query) This enables the use of magic parameters in the exports. The issue was less exposed in iTop 2.2.0 because only one single magic parameter was available.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@3948 a333f486-631f-4898-b8df-5754b55c2be0
romainq 9 年之前
父节点
当前提交
3c7638bf00
共有 4 个文件被更改,包括 44 次插入32 次删除
  1. 39 2
      core/dbobjectsearch.class.php
  2. 1 1
      core/dbsearch.class.php
  3. 4 4
      core/dbunionsearch.class.php
  4. 0 25
      pages/run_query.php

+ 39 - 2
core/dbobjectsearch.class.php

@@ -728,11 +728,48 @@ class DBObjectSearch extends DBSearch
 		return $this->m_aParams;
 	}
 
-	public function GetQueryParams()
+	public function GetQueryParams($bExcludeMagicParams = true)
 	{
 		$aParams = array();
 		$this->m_oSearchCondition->Render($aParams, true);
-		return $aParams;
+
+		if ($bExcludeMagicParams)
+		{
+			$aRet = array();
+
+			// Make the list of acceptable arguments... could be factorized with run_query, into oSearch->GetQueryParams($bExclude magic params)
+			$aNakedMagicArguments = array();
+			foreach (MetaModel::PrepareQueryArguments(array()) as $sArgName => $value)
+			{
+				$iPos = strpos($sArgName, '->object()');
+				if ($iPos === false)
+				{
+					$aNakedMagicArguments[$sArgName] = $value;
+				}
+				else
+				{
+					$aNakedMagicArguments[substr($sArgName, 0, $iPos)] = true;
+				}
+			}
+			foreach ($aParams as $sParam => $foo)
+			{
+				$iPos = strpos($sParam, '->');
+				if ($iPos === false)
+				{
+					$sRefName = $sParam;
+				}
+				else
+				{
+					$sRefName = substr($sParam, 0, $iPos);
+				}
+				if (!array_key_exists($sRefName, $aNakedMagicArguments))
+				{
+					$aRet[$sParam] = $foo;
+				}
+			}
+		}
+
+		return $aRet;
 	}
 
 	public function ListConstantFields()

+ 1 - 1
core/dbsearch.class.php

@@ -130,7 +130,7 @@ abstract class DBSearch
 
 	abstract public function SetInternalParams($aParams);
 	abstract public function GetInternalParams();
-	abstract public function GetQueryParams();
+	abstract public function GetQueryParams($bExcludeMagicParams = true);
 	abstract public function ListConstantFields();
 	
 	/**

+ 4 - 4
core/dbunionsearch.class.php

@@ -1,5 +1,5 @@
 <?php
-// Copyright (C) 2015 Combodo SARL
+// Copyright (C) 2015-2016 Combodo SARL
 //
 //   This file is part of iTop.
 //
@@ -20,7 +20,7 @@
 /**
  * A union of DBObjectSearches 
  *
- * @copyright   Copyright (C) 2015 Combodo SARL
+ * @copyright   Copyright (C) 2015-2016 Combodo SARL
  * @license     http://opensource.org/licenses/AGPL-3.0
  */
  
@@ -326,12 +326,12 @@ class DBUnionSearch extends DBSearch
 		return $aParams;
 	}
 
-	public function GetQueryParams()
+	public function GetQueryParams($bExcludeMagicParams = true)
 	{
 		$aParams = array();
 		foreach ($this->aSearches as $oSearch)
 		{
-			$aParams = array_merge($oSearch->GetQueryParams(), $aParams);
+			$aParams = array_merge($oSearch->GetQueryParams($bExcludeMagicParams), $aParams);
 		}
 		return $aParams;
 	}

+ 0 - 25
pages/run_query.php

@@ -143,36 +143,11 @@ try
 			}
 		}
 
-		$aNakedMagicArguments = array();
-		foreach (MetaModel::PrepareQueryArguments(array()) as $sArgName => $value)
-		{
-			$iPos = strpos($sArgName, '->object()');
-			if ($iPos === false)
-			{
-				$aNakedMagicArguments[$sArgName] = $value;
-			}
-			else
-			{
-				$aNakedMagicArguments[substr($sArgName, 0, $iPos)] = true;
-			}
-		}
 		if ($oFilter)
 		{
 			$aArgs = array();
 			foreach($oFilter->GetQueryParams() as $sParam => $foo)
 			{
-				// Skip magic parameters
-				$iPos = strpos($sParam, '->');
-				if ($iPos === false)
-				{
-					$sRefName = $sParam;
-				}
-				else
-				{
-					$sRefName = substr($sParam, 0, $iPos);
-				}
-				if (array_key_exists($sRefName, $aNakedMagicArguments)) continue;
-
 				$value = utils::ReadParam('arg_'.$sParam, null, true, 'raw_data');
 				if (!is_null($value))
 				{