Browse Source

Form : Fixed dependancies check in Form::Finalize()

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@3955 a333f486-631f-4898-b8df-5754b55c2be0
glajarige 9 years ago
parent
commit
fc896e312b
1 changed files with 15 additions and 3 deletions
  1. 15 3
      sources/form/form.class.inc.php

+ 15 - 3
sources/form/form.class.inc.php

@@ -406,14 +406,26 @@ class Form
 		// Clone the dependency data : $aDependencies will be truncated as the fields are added to the list
 		$aDependencies = $this->aDependencies;
 		$bMadeProgress = true; // Safety net in case of circular references
+
+		foreach ($aDependencies as $sImpactedBy => $aSomeFields)
+		{
+			foreach ($aSomeFields as $i => $sSomeId)
+			{
+				if (!array_key_exists($sSomeId, $this->aFields))
+				{
+					throw new Exception('Missing dependancy : Field ' . $sImpactedBy . ' expecting field ' . $sSomeId . ' which is not in the Form');
+				}
+			}
+		}
+
 		while ($bMadeProgress && count($aFieldList) < count($this->aFields))
 		{
 			$bMadeProgress = false;
 			foreach ($this->aFields as $sId => $oField)
 			{
-				if (array_key_exists($sId, $aFieldList)) continue;
+				if (array_key_exists($sId, $aFieldList))
+					continue;
 				if (isset($aDependencies[$sId]) && count($aDependencies[$sId]) > 0) continue;
-
 				// Add the field at the end of the list
 				$aFieldList[$sId] = $oField;
 				$bMadeProgress = true;
@@ -433,7 +445,7 @@ class Form
 		}
 		if (!$bMadeProgress)
 		{
-			throw new Exception('Unmet dependencies: '.implode(', ', array_keys($aDependencies)));
+			throw new Exception('Unmet dependencies (might be a circular reference) : ' . implode(', ', array_keys($aDependencies)));
 		}
 		foreach ($aFieldList as $sId => $oField)
 		{