mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 11:08:45 +02:00
Manage interdependencies between modules, in the setup
SVN:trunk[552]
This commit is contained in:
@@ -283,9 +283,54 @@ table.formTable {
|
||||
}
|
||||
}
|
||||
}
|
||||
public static function GetModules()
|
||||
public function GetModules()
|
||||
{
|
||||
return self::$m_aModules;
|
||||
// Order the modules to take into account their inter-dependencies
|
||||
$aDependencies = array();
|
||||
foreach(self::$m_aModules as $sId => $aModule)
|
||||
{
|
||||
$aDependencies[$sId] = $aModule['dependencies'];
|
||||
}
|
||||
$aOrderedModules = array();
|
||||
$iLoopCount = 1;
|
||||
while(($iLoopCount < count(self::$m_aModules)) && (count($aDependencies) > 0) )
|
||||
{
|
||||
foreach($aDependencies as $sId => $aRemainingDeps)
|
||||
{
|
||||
$bDependenciesSolved = true;
|
||||
foreach($aRemainingDeps as $sDepId)
|
||||
{
|
||||
if (!in_array($sDepId, $aOrderedModules))
|
||||
{
|
||||
$bDependenciesSolved = false;
|
||||
}
|
||||
}
|
||||
if ($bDependenciesSolved)
|
||||
{
|
||||
$aOrderedModules[] = $sId;
|
||||
unset($aDependencies[$sId]);
|
||||
}
|
||||
}
|
||||
$iLoopCount++;
|
||||
}
|
||||
if (count($aDependencies) >0)
|
||||
{
|
||||
$sHtml = "<ul><b>Warning: the following modules have unmet dependencies, and have been ignored:</b>\n";
|
||||
foreach($aDependencies as $sId => $aDeps)
|
||||
{
|
||||
$aModule = self::$m_aModules[$sId];
|
||||
$sHtml.= "<li>{$aModule['label']} (id: $sId), depends on: ".implode(', ', $aDeps)."</li>";
|
||||
}
|
||||
$sHtml .= "</ul>\n";
|
||||
$this->warning($sHtml);
|
||||
}
|
||||
// Return the ordered list, so that the dependencies are met...
|
||||
$aResult = array();
|
||||
foreach($aOrderedModules as $sId)
|
||||
{
|
||||
$aResult[$sId] = self::$m_aModules[$sId];
|
||||
}
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
} // End of class
|
||||
|
||||
Reference in New Issue
Block a user