Jelajahi Sumber

Manage interdependencies between modules, in the setup

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@552 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 15 tahun lalu
induk
melakukan
0999fc952f

+ 1 - 1
modules/itop-change-mgmt-1.0.0/module.itop-change-mgmt.php

@@ -13,7 +13,7 @@ SetupWebPage::AddModule(
 		//
 		'dependencies' => array(
 			'itop-config-mgmt/1.0.0',
-			'itop-ticket/1.0.0',
+			'itop-tickets/1.0.0',
 		),
 		'mandatory' => false,
 		'visible' => true,

+ 0 - 5
modules/itop-config-mgmt-1.0.0/data.sample.business.xml

@@ -22,9 +22,4 @@
 <contact_id>4</contact_id>
 <role>Support Specialist</role>
 </lnkCIToContact>
-<lnkCIToContact alias="lnkCIToContact" id="3">
-<ci_id>8</ci_id>
-<contact_id>6</contact_id>
-<role>Datacenter Network Engineer</role>
-</lnkCIToContact>
 </Set>

+ 0 - 10
modules/itop-config-mgmt-1.0.0/data.sample.contact.xml

@@ -20,16 +20,6 @@
 <first_name>Victor</first_name>
 <employee_id>20100001</employee_id>
 </Person>
-<Person alias="Contact" id="1">
-<name>My last name</name>
-<status>active</status>
-<org_id>1</org_id>
-<email>my.email@foo.org</email>
-<phone></phone>
-<location_id>0</location_id>
-<first_name></first_name>
-<employee_id></employee_id>
-</Person>
 <Person alias="Contact" id="5">
 <name>Verne</name>
 <status>active</status>

+ 1 - 0
modules/itop-knownerror-mgmt-1.0.0/module.itop-knownerror-mgmt.php

@@ -14,6 +14,7 @@ SetupWebPage::AddModule(
 		'dependencies' => array(
 			'itop-config-mgmt/1.0.0',
 			'itop-tickets/1.0.0',
+			'itop-incident-mgmt/1.0.0',
 		),
 		'mandatory' => false,
 		'visible' => true,

+ 1 - 0
modules/itop-problem-mgmt-1.0.0/module.itop-problem-mgmt.php

@@ -14,6 +14,7 @@ SetupWebPage::AddModule(
 		'dependencies' => array(
 			'itop-config-mgmt/1.0.0',
 			'itop-tickets/1.0.0',
+			'itop-incident-mgmt/1.0.0',
 		),
 		'mandatory' => false,
 		'visible' => true,

+ 1 - 1
modules/itop-service-mgmt-1.0.0/module.itop-service-mgmt.php

@@ -12,7 +12,7 @@ SetupWebPage::AddModule(
 		// Setup
 		//
 		'dependencies' => array(
-			//'itop-service-mgmt/1.0.0',
+			'itop-config-mgmt/1.0.0',
 		),
 		'mandatory' => false,
 		'visible' => true,

+ 1 - 0
modules/itop-tickets-1.0.0/module.itop-tickets.php

@@ -12,6 +12,7 @@ SetupWebPage::AddModule(
 		// Setup
 		//
 		'dependencies' => array(
+			'itop-config-mgmt/1.0.0',
 		),
 		'mandatory' => true,
 		'visible' => true,

+ 2 - 2
setup/index.php

@@ -538,7 +538,7 @@ function GetAvailableModules(SetupWebpage $oP)
 {
 	clearstatcache();
 	ListModuleFiles('../modules/', $oP);
-	return SetupWebPage::GetModules();
+	return $oP->GetModules();
 }
 
 /**
@@ -756,6 +756,7 @@ function ModulesSelection(SetupWebPage $oP, $aParamValues, $iCurrentStep, $oConf
 	$sRedStar = '<span class="hilite">*</span>';
 	$oP->set_title("Selection of the iTop Modules\n");
 	$oP->add("<h2>Customize your iTop installation to fit your needs</h2>\n");
+	$aAvailableModules = GetAvailableModules($oP);
 	
 	// Form goes here
 	$oP->add("<fieldset><legend>Select the iTop modules you want to install:</legend>\n");
@@ -768,7 +769,6 @@ function ModulesSelection(SetupWebPage $oP, $aParamValues, $iCurrentStep, $oConf
 		// Make sure it gets initialized as an array
 		$aSelectedModules = array();
 	}
-	$aAvailableModules = GetAvailableModules($oP);
 	foreach($aAvailableModules as $sModuleId => $aModule)
 	{
 		$sModuleLabel = $aModule['label'];

+ 47 - 2
setup/setuppage.class.inc.php

@@ -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