mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-12 23:14:18 +01:00
Enhancement: the expression of dependencies between modules can now use a complex boolean expression with a combination of "logical or" (||) and "logical and" (&&) instead of just a module name.
SVN:trunk[2708]
This commit is contained in:
@@ -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'<br/>";
|
||||
}
|
||||
}
|
||||
return $bResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search (on the disk) for all defined iTop modules, load them and returns the list (as an array)
|
||||
|
||||
Reference in New Issue
Block a user