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

SVN:trunk[2544]
This commit is contained in:
Denis Flaven
2012-12-06 17:51:52 +00:00
parent aa6cfc205e
commit f0ae02fd8e
4 changed files with 90 additions and 12 deletions

View File

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

View File

@@ -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);
}

View File

@@ -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));
}
}

View File

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