mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 15:22:17 +02:00
Allow for comparisons of the module's versions in the expression of dependencies. For example one can now say "itop-config-mgmt/>=2.0.2" for a dependency.
SVN:2.0.1[2854]
This commit is contained in:
@@ -173,6 +173,20 @@ class ModuleDiscovery
|
|||||||
protected static function DependencyIsResolved($sDepString, $aOrderedModules)
|
protected static function DependencyIsResolved($sDepString, $aOrderedModules)
|
||||||
{
|
{
|
||||||
$bResult = false;
|
$bResult = false;
|
||||||
|
$aModuleVersions = array();
|
||||||
|
// Separate the module names from their version for an easier comparison later
|
||||||
|
foreach($aOrderedModules as $sModuleId)
|
||||||
|
{
|
||||||
|
if (preg_match('|^([^/]+)/(.*)$|', $sModuleId, $aMatches))
|
||||||
|
{
|
||||||
|
$aModuleVersions[$aMatches[1]] = $aMatches[2];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// No version number found, assume 1.0.0
|
||||||
|
$aModuleVersions[$sModuleId] = '1.0.0';
|
||||||
|
}
|
||||||
|
}
|
||||||
if (preg_match_all('/([^\(\)&| ]+)/', $sDepString, $aMatches))
|
if (preg_match_all('/([^\(\)&| ]+)/', $sDepString, $aMatches))
|
||||||
{
|
{
|
||||||
$aReplacements = array();
|
$aReplacements = array();
|
||||||
@@ -180,17 +194,38 @@ class ModuleDiscovery
|
|||||||
{
|
{
|
||||||
foreach($aMatch as $sModuleId)
|
foreach($aMatch as $sModuleId)
|
||||||
{
|
{
|
||||||
if (in_array($sModuleId, $aOrderedModules))
|
// $sModuleId in the dependency string is made of a <name>/<optional_operator><version>
|
||||||
|
// where the operator is < <= = > >= (by default >=)
|
||||||
|
if(preg_match('|^([^/]+)/(<?>?=?)([^><=]+)$|', $sModuleId, $aModuleMatches))
|
||||||
{
|
{
|
||||||
// module is present
|
$sModuleName = $aModuleMatches[1];
|
||||||
$aReplacements[$sModuleId] = '(true)'; // Add parentheses to protect against invalid condition causing
|
$sOperator = $aModuleMatches[2];
|
||||||
// a function call that results in a runtime fatal error
|
if ($sOperator == '')
|
||||||
}
|
{
|
||||||
else
|
$sOperator = '>=';
|
||||||
{
|
}
|
||||||
// module is not present
|
$sExpectedVersion = $aModuleMatches[3];
|
||||||
$aReplacements[$sModuleId] = '(false)'; // Add parentheses to protect against invalid condition causing
|
if (array_key_exists($sModuleName, $aModuleVersions))
|
||||||
// a function call that results in a runtime fatal error
|
{
|
||||||
|
// module is present, check the version
|
||||||
|
$sCurrentVersion = $aModuleVersions[$sModuleName];
|
||||||
|
if (version_compare($sCurrentVersion, $sExpectedVersion, $sOperator))
|
||||||
|
{
|
||||||
|
$aReplacements[$sModuleId] = '(true)'; // Add parentheses to protect against invalid condition causing
|
||||||
|
// a function call that results in a runtime fatal error
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$aReplacements[$sModuleId] = '(false)'; // 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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user