소스 검색

Fixed an issue revealed by fix [2201], occurring when filtering on organization (context) - the fix is not complete (see Trac #588)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2204 a333f486-631f-4898-b8df-5754b55c2be0
romainq 12 년 전
부모
커밋
fc65906a86
2개의 변경된 파일36개의 추가작업 그리고 20개의 파일을 삭제
  1. 12 1
      application/displayblock.class.inc.php
  2. 24 19
      core/dbobjectsearch.class.php

+ 12 - 1
application/displayblock.class.inc.php

@@ -44,6 +44,7 @@ class DisplayBlock
 {
 	const TAG_BLOCK = 'itopblock';
 	protected $m_oFilter;
+	protected $m_aConditions; // Conditions added to the filter -> avoid duplicate conditions
 	protected $m_sStyle;
 	protected $m_bAsynchronous;
 	protected $m_aParams;
@@ -51,7 +52,8 @@ class DisplayBlock
 	
 	public function __construct(DBObjectSearch $oFilter, $sStyle = 'list', $bAsynchronous = false, $aParams = array(), $oSet = null)
 	{
-		$this->m_oFilter = $oFilter;
+		$this->m_oFilter = clone $oFilter;
+		$this->m_aConditions = array();
 		$this->m_sStyle = $sStyle;
 		$this->m_bAsynchronous = $bAsynchronous;
 		$this->m_aParams = $aParams;
@@ -1015,6 +1017,15 @@ EOF
 	 */
 	protected function AddCondition($sFilterCode, $condition)
 	{
+		// Workaround to an issue revealed whenever a condition on org_id is applied twice (with a hierarchy of organizations)
+		// Moreover, it keeps the query as simple as possible
+		if (isset($this->m_aConditions[$sFilterCode]) && $condition == $this->m_aConditions[$sFilterCode])
+		{
+			// Skip
+			return;
+		}
+		$this->m_aConditions[$sFilterCode] = $condition;
+
 		$sClass = $this->m_oFilter->GetClass();
 		$bConditionAdded = false;
 		

+ 24 - 19
core/dbobjectsearch.class.php

@@ -548,24 +548,38 @@ class DBObjectSearch
 	{
 		if ($bTranslateMainAlias)
 		{
-			$sOrigAlias = $this->GetClassAlias();
+			$sOrigAlias = $this->GetFirstJoinedClassAlias();
 			if (array_key_exists($sOrigAlias, $aClassAliases))
 			{
-				$sNewAlias = MetaModel::GenerateUniqueAlias($aClassAliases, $sOrigAlias, $this->GetClass());
-//echo "<p>Generating a new alias for $sOrigAlias (already used). It is now: $sNewAlias</p>\n";
-				$this->m_aSelectedClasses[$sNewAlias] = $this->GetClass();
-				unset($this->m_aSelectedClasses[$sOrigAlias]);
-	
-				$this->m_aClasses[$sNewAlias] = $this->GetClass();
-				unset($this->m_aClasses[$sOrigAlias]);
+				$sNewAlias = MetaModel::GenerateUniqueAlias($aClassAliases, $sOrigAlias, $this->GetFirstJoinedClass());
+				if (isset($this->m_aSelectedClasses[$sOrigAlias]))
+				{
+					$this->m_aSelectedClasses[$sNewAlias] = $this->GetFirstJoinedClass();
+					unset($this->m_aSelectedClasses[$sOrigAlias]);
+				}
+
+				// TEMPORARY ALGORITHM (m_aClasses is not correctly updated, it is not possible to add a subtree onto a subnode)
+				// Replace the element at the same position (unset + set is not enough because the hash array is ordered)
+				$aPrevList = $this->m_aClasses;
+				$this->m_aClasses = array();
+				foreach ($aPrevList as $sSomeAlias => $sSomeClass)
+				{
+					if ($sSomeAlias == $sOrigAlias)
+					{
+						$this->m_aClasses[$sNewAlias] = $sSomeClass; // note: GetFirstJoinedClass now returns '' !!!
+					}
+					else
+					{
+						$this->m_aClasses[$sSomeAlias] = $sSomeClass;
+					}
+				}
 	
 				// Translate the condition expression with the new alias
 				$aAliasTranslation[$sOrigAlias]['*'] = $sNewAlias;
 			}
 	
-//echo "<p>Adding the alias ".$this->GetClass()." as ".$this->GetClassAlias()."</p>\n";
 			// add the alias into the filter aliases list
-			$aClassAliases[$this->GetClassAlias()] = $this->GetClass();
+			$aClassAliases[$this->GetFirstJoinedClassAlias()] = $this->GetFirstJoinedClass();
 		}
 		
 		foreach($this->m_aPointingTo as $sExtKeyAttCode=>$aPointingTo)
@@ -598,7 +612,6 @@ class DBObjectSearch
 
 	protected function AddCondition_PointingTo_InNameSpace(DBObjectSearch $oFilter, $sExtKeyAttCode, &$aClassAliases, &$aAliasTranslation, $iOperatorCode)
 	{
-//echo "<p style=\"color:green\">Calling: AddCondition_PointingTo_InNameSpace([<pre>".print_r($aClassAliases, true)."</pre></br>], [<pre>".print_r($aAliasTranslation, true)."</pre>]);</p>";
 		if (!MetaModel::IsValidKeyAttCode($this->GetClass(), $sExtKeyAttCode))
 		{
 			throw new CoreWarning("The attribute code '$sExtKeyAttCode' is not an external key of the class '{$this->GetClass()}' - the condition will be ignored");
@@ -620,27 +633,19 @@ class DBObjectSearch
 			{
 				if (array_key_exists($oFilter->GetClassAlias(), $this->m_aPointingTo[$sExtKeyAttCode][$iOperatorCode]))
 				{
-//echo "<p style=\"color:red\">[".__LINE__."]this->m_aPointingTo[$sExtKeyAttCode][$iOperatorCode][".$oFilter->GetFirstJoinedClassAlias()."]:<pre>\n".print_r($this->m_aPointingTo[$sExtKeyAttCode][$iOperatorCode], true)."</pre>;</p>";
 					$bSamePointingTo = true;
 				}
 			}
 		}
 
-//echo "<p style=\"color:red\">[".__LINE__."]Calling: AddToNameSpace([".implode(',', $aClassAliases)."], [".implode(',', $aAliasTranslation)."]);</p>";
 		if ($bSamePointingTo)
 		{
-//echo "<p style=\"color:red\">[".__LINE__."]AddPointingTo: Merging filters for [$sExtKeyAttCode][$iOperatorCode][".$oFilter->GetClassAlias()."]</p>";
 			// Same ext key, alias and same operator, merge the filters together
-//			$sAlias = $oFilter->GetClassAlias();
-//echo "<p style=\"color:red\">[".__LINE__."]before: AddToNameSpace(aClassAliases[<pre>\n".print_r($aClassAliases, true)."</pre>], aAliasTranslation[<pre>\n".print_r($aAliasTranslation, true)."</pre>]);</p>";
 			$oFilter->AddToNamespace($aClassAliases, $aAliasTranslation, true /* Don't translate the main alias */);
-//echo "<p style=\"color:blue\">[".__LINE__."]after: AddToNameSpace(aClassAliases[<pre>\n".print_r($aClassAliases, true)."</pre>], aAliasTranslation[<pre>\n".print_r($aAliasTranslation, true)."</pre>]);</p>";
-//			$this->m_aPointingTo[$sExtKeyAttCode][$iOperatorCode][$sAlias]->MergeWith($oFilter, $aClassAliases, $aAliasTranslation);
 			$this->m_aPointingTo[$sExtKeyAttCode][$iOperatorCode][$oFilter->GetClassAlias()] = $oFilter;
 		}
 		else
 		{
-//echo "<p style=\"color:red\">[".__LINE__."]AddPointingTo: Adding a new PointingTo filter for [$sExtKeyAttCode][$iOperatorCode][".$oFilter->GetClassAlias()."]</p>";
 			$oFilter->AddToNamespace($aClassAliases, $aAliasTranslation);
 			$this->m_aPointingTo[$sExtKeyAttCode][$iOperatorCode][$oFilter->GetClassAlias()] = $oFilter;
 		}