diff --git a/setup/modulediscovery.class.inc.php b/setup/modulediscovery.class.inc.php index 9e28bbce3..14c1a79d0 100644 --- a/setup/modulediscovery.class.inc.php +++ b/setup/modulediscovery.class.inc.php @@ -124,7 +124,7 @@ class ModuleDiscovery $bDependenciesSolved = true; foreach($aRemainingDeps as $sDepId) { - if (!in_array($sDepId, $aOrderedModules)) + if (!self::DependencyIsResolved($sDepId, $aOrderedModules)) { $bDependenciesSolved = false; } @@ -167,6 +167,41 @@ class ModuleDiscovery } return $aResult; } + + protected static function DependencyIsResolved($sDepString, $aOrderedModules) + { + $bResult = false; + if (preg_match_all('/([^\(\)&| ]+)/', $sDepString, $aMatches)) + { + $aReplacements = array(); + foreach($aMatches as $aMatch) + { + foreach($aMatch as $sModuleId) + { + if (in_array($sModuleId, $aOrderedModules)) + { + // module is present + $aReplacements[$sModuleId] = '(true)'; // Add parentheses to protect against invalid condition causing + // a function call that results in a runtime fatal error + } + else + { + // module is not present + $aReplacements[$sModuleId] = '(false)'; // Add parentheses to protect against invalid condition causing + // a function call that results in a runtime fatal error + } + } + } + $sBooleanExpr = str_replace(array_keys($aReplacements), array_values($aReplacements), $sDepString); + $bOk = @eval('$bResult = '.$sBooleanExpr.'; return true;'); + if($bOk == false) + { + SetupPage::log_warning("Eval of $sRelDir/$sFile returned false"); + echo "Failed to parse the boolean Expression = '$sBooleanExpr'
"; + } + } + return $bResult; + } /** * Search (on the disk) for all defined iTop modules, load them and returns the list (as an array)