(Retrofit from trunk) Preparing for the Hub: better decouple the RunTimeEnvironment from the list of directories to scan/install in order to support installation from the Hub.

SVN:2.4[5274]
This commit is contained in:
Denis Flaven
2018-01-17 10:22:14 +00:00
parent 4ee6e6f915
commit 6e4836f5e0
2 changed files with 52 additions and 3 deletions

View File

@@ -666,6 +666,28 @@ class iTopExtensionsMap
($this->aExtensions[$sModuleIdToFind]->sInstalledVersion !== '') );
}
/**
* Tells if the given module name is "chosen" since it is part of a "chosen" extension (in the specified source dir)
* @param string $sModuleNameToFind
* @param string $sInSourceOnly
* @return boolean
*/
public function ModuleIsChosenAsPartOfAnExtension($sModuleNameToFind, $sInSourceOnly = iTopExtension::SOURCE_REMOTE)
{
$bChosen = false;
foreach($this->GetAllExtensions() as $oExtension)
{
if (($oExtension->sSource == $sInSourceOnly) &&
($oExtension->bMarkedAsChosen == true) &&
(array_key_exists($sModuleNameToFind, $oExtension->aModuleVersion)))
{
return true;
}
}
return false;
}
/**
* Replace a given set of stand-alone modules by one single "extension"
* @param string[] $aModules

View File

@@ -358,6 +358,26 @@ class RunTimeEnvironment
@chmod($sTargetConfigFile, 0440); // Read-only for owner and group, nothing for others
}
/**
* Return an array with extra directories to scan for extensions/modules to install
* @return string[]
*/
protected function GetExtraDirsToScan()
{
// Do nothing, overload this method if needed
return array();
}
/**
* Decide whether or not the given extension is selected for installation
* @param iTopExtension $oExtension
* @return boolean
*/
protected function IsExtensionSelected(iTopExtension $oExtension)
{
return ($oExtension->sSource == iTopExtension::SOURCE_REMOTE);
}
/**
* Get the installed modules (only the installed ones)
*/
@@ -378,7 +398,10 @@ class RunTimeEnvironment
{
$aDirsToCompile[] = $sExtraDir;
}
$aExtraDirs = $this->GetExtraDirsToScan($aDirsToCompile);
$aDirsToCompile = array_merge($aDirsToCompile, $aExtraDirs);
$aRet = array();
// Determine the installed modules and extensions
@@ -393,10 +416,14 @@ class RunTimeEnvironment
// target environment (data/<target-env>-modules)
// The actual choices will be recorded by RecordInstallation below
$this->oExtensionsMap = new iTopExtensionsMap($this->sTargetEnv);
foreach($aExtraDirs as $sDir)
{
$this->oExtensionsMap->ReadDir($sDir, iTopExtension::SOURCE_REMOTE);
}
$this->oExtensionsMap->LoadChoicesFromDatabase($oSourceConfig);
foreach($this->oExtensionsMap->GetAllExtensions() as $oExtension)
{
if($oExtension->sSource == iTopExtension::SOURCE_REMOTE)
if($this->IsExtensionSelected($oExtension))
{
$this->oExtensionsMap->MarkAsChosen($oExtension->sCode);
}
@@ -426,7 +453,7 @@ class RunTimeEnvironment
{
$sModule = $oModule->GetName();
$sModuleRootDir = $oModule->GetRootDir();
$bIsExtra = (strpos($sModuleRootDir, $sExtraDir) !== false);
$bIsExtra = $this->oExtensionsMap->ModuleIsChosenAsPartOfAnExtension($sModule, iTopExtension::SOURCE_REMOTE);
if (array_key_exists($sModule, $aAvailableModules))
{
if (($aAvailableModules[$sModule]['version_db'] != '') || $bIsExtra && !$oModule->IsAutoSelect()) //Extra modules are always unless they are 'AutoSelect'