From f0ae02fd8e52e4f229ba3d99354512140ed60ac9 Mon Sep 17 00:00:00 2001 From: Denis Flaven Date: Thu, 6 Dec 2012 17:51:52 +0000 Subject: [PATCH] Integration of the "bridge" module and new mechanism for auto_select modules. SVN:trunk[2544] --- ...ule.itop-bridge-virtualization-storage.php | 2 +- .../datamodel.itop-virtualization-mgmt.xml | 36 +++++++++++++------ setup/setuputils.class.inc.php | 29 +++++++++++++++ setup/wizardsteps.class.inc.php | 35 ++++++++++++++++++ 4 files changed, 90 insertions(+), 12 deletions(-) diff --git a/datamodels/2.x/itop-bridge-virtualization-storage/module.itop-bridge-virtualization-storage.php b/datamodels/2.x/itop-bridge-virtualization-storage/module.itop-bridge-virtualization-storage.php index fcdd0f52a..609532a16 100644 --- a/datamodels/2.x/itop-bridge-virtualization-storage/module.itop-bridge-virtualization-storage.php +++ b/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 diff --git a/datamodels/2.x/itop-virtualization-mgmt/datamodel.itop-virtualization-mgmt.xml b/datamodels/2.x/itop-virtualization-mgmt/datamodel.itop-virtualization-mgmt.xml index fe494f494..6579d2f67 100644 --- a/datamodels/2.x/itop-virtualization-mgmt/datamodel.itop-virtualization-mgmt.xml +++ b/datamodels/2.x/itop-virtualization-mgmt/datamodel.itop-virtualization-mgmt.xml @@ -48,7 +48,31 @@ - + + + true + public + Overload-DBObject + "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); + } + }]]> + +
@@ -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); } diff --git a/setup/setuputils.class.inc.php b/setup/setuputils.class.inc.php index 77864f04f..c5daef4fc 100644 --- a/setup/setuputils.class.inc.php +++ b/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)); + } } \ No newline at end of file diff --git a/setup/wizardsteps.class.inc.php b/setup/wizardsteps.class.inc.php index 92fb75862..9341e9648 100644 --- a/setup/wizardsteps.class.inc.php +++ b/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 .= '
  • Warning: auto_select failed with exception ('.$e->getMessage().') for module "'.$sModuleId.'"
  • '; + $bSelected = false; + } + if ($bSelected) + { + $aModules[$sModuleId] = true; // store the Id of the selected module + $bModuleAdded = true; + } + } + } + } + while($bModuleAdded); + } + return $sDisplayChoices; }