瀏覽代碼

Integration of the "bridge" module and new mechanism for auto_select modules.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2544 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 12 年之前
父節點
當前提交
96f8c55494

+ 1 - 1
datamodels/2.x/itop-bridge-virtualization-storage/module.itop-bridge-virtualization-storage.php

@@ -15,7 +15,7 @@ SetupWebPage::AddModule(
 		'dependencies' => array(
 		),
 		'mandatory' => false,
-		'visible' => false,
+		'visible' => true, // To prevent auto-install but shall not be listed in the install wizard
 		'auto_select' => 'SetupInfo::ModuleIsSelected("itop-storage-mgmt") && SetupInfo::ModuleIsSelected("itop-virtualization-mgmt")',
 
 		// Components

+ 25 - 11
datamodels/2.x/itop-virtualization-mgmt/datamodel.itop-virtualization-mgmt.xml

@@ -48,7 +48,31 @@
           <duplicates/>
         </field>
       </fields>
-      <methods/>
+      <methods>
+        <method id="GetRelationQueries">
+          <static>true</static>
+          <access>public</access>
+          <type>Overload-DBObject</type>
+          <code><![CDATA[ public static function GetRelationQueries($sRelCode)
+  {
+    switch ($sRelCode)
+    {
+      case 'depends on':
+      $aRels = array(
+      );
+      if (class_exists('LogicalVolume'))
+      {
+        $aRels["logicalvolume"] = array("sQuery"=>"SELECT LogicalVolume AS lv JOIN lnkVirtualDeviceToVolume AS l1 ON l1.volume_id=lv.id  WHERE l1.virtualdevice_id = :this->id", "bPropagate"=>true, "iDistance"=>5);
+      }
+      return array_merge($aRels, parent::GetRelationQueries($sRelCode));
+      break;
+      
+      default:
+      return parent::GetRelationQueries($sRelCode);     
+    }
+  }]]></code>
+        </method>
+      </methods>
       <presentation>
         <details>
           <items>
@@ -174,16 +198,6 @@
       return array_merge($aRels, parent::GetRelationQueries($sRelCode));
       break;
       
-      case 'depends on':
-      $aRels = array(
-      );
-      if (class_exists('LogicalVolume'))
-      {
-        $aRels["logicalvolume"] = array("sQuery"=>"SELECT LogicalVolume AS lv JOIN lnkVirtualDeviceToVolume AS l1 ON l1.volume_id=lv.id  WHERE l1.virtualdevice_id = :this->id", "bPropagate"=>true, "iDistance"=>5);
-      }
-      return array_merge($aRels, parent::GetRelationQueries($sRelCode));
-      break;
-      
       default:
       return parent::GetRelationQueries($sRelCode);     
     }

+ 29 - 0
setup/setuputils.class.inc.php

@@ -1254,4 +1254,33 @@ EOF
 		}
 		return false;
 	}
+}
+/**
+ * Helper class to write rules (as PHP expressions) in the 'auto_select' field of the 'module'
+ */
+class SetupInfo
+{
+	static $aSelectedModules = array();
+	
+	/**
+	 * Called by the setup process to initializes the list of selected modules. Do not call this method
+	 * from an 'auto_select' rule
+	 * @param hash $aModules
+	 * @return void
+	 */
+	static function SetSelectedModules($aModules)
+	{
+		self::$aSelectedModules = $aModules;
+	}
+	
+	/**
+	 * Returns true if a module is selected (as a consequence of the end-user's choices,
+	 * or because the module is hidden, or mandatory, or because of a previous auto_select rule)
+	 * @param string $sModuleId The identifier of the module (without the version number. Example: itop-config-mgmt)
+	 * @return boolean True if the module is already selected, false otherwise
+	 */
+	static function ModuleIsSelected($sModuleId)
+	{
+		return (array_key_exists($sModuleId, self::$aSelectedModules));
+	}
 }

+ 35 - 0
setup/wizardsteps.class.inc.php

@@ -1384,6 +1384,41 @@ EOF
 			}
 			$index++;
 		}
+		if ($sParentId == '')
+		{
+			// Last pass (after all the user's choices are turned into "selected" modules):
+			// Process 'auto_select' modules for modules that are not already selected
+			$aAvailableModules = SetupUtils::AnalyzeInstallation($this->oWizard);
+			do
+			{
+				// Loop while new modules are added...
+				$bModuleAdded = false;
+				foreach($aAvailableModules as $sModuleId => $aModule)
+				{
+					if (($sModuleId != ROOT_MODULE) && !array_key_exists($sModuleId, $aModules) && isset($aModule['auto_select']))
+					{
+						try
+						{
+							$bSelected = false;
+							SetupInfo::SetSelectedModules($aModules);
+							eval('$bSelected = ('.$aModule['auto_select'].');');
+						}
+						catch(Exception $e)
+						{
+							$sDisplayChoices .= '<li><b>Warning: auto_select failed with exception ('.$e->getMessage().') for module "'.$sModuleId.'"</b></li>';
+							$bSelected = false;
+						}
+						if ($bSelected)
+						{
+							$aModules[$sModuleId] = true; // store the Id of the selected module
+							$bModuleAdded  = true;
+						}
+					}
+				}
+			}
+			while($bModuleAdded);	
+		}
+		
 		return $sDisplayChoices;
 	}