(Retrofit from trunk) Small setup refactoring for getting ready for the Hub.

SVN:2.4[5271]
This commit is contained in:
Denis Flaven
2018-01-17 10:13:14 +00:00
parent f237a98c1d
commit c081b89f03
6 changed files with 250 additions and 171 deletions

View File

@@ -67,6 +67,16 @@ class iTopExtension
*/
public $aModules;
/**
* @var string[]
*/
public $aModuleVersion;
/**
* @var string
*/
public $sSourceDir;
public function __construct()
{
$this->sCode = '';
@@ -78,6 +88,8 @@ class iTopExtension
$this->bMarkedAsChosen = false;
$this->sVersion = ITOP_VERSION;
$this->sInstalledVersion = '';
$this->aModuleVersion = array();
$this->sSourceDir = '';
$this->bVisible = true;
}
}
@@ -240,6 +252,7 @@ class iTopExtensionsMap
$oExtension->sMoreInfoUrl = $oXml->Get('more_info_url');
$oExtension->sVersion = $oXml->Get('version');
$oExtension->sSource = $sSource;
$oExtension->sSourceDir = $sSearchDir;
$sParentExtensionId = $sExtensionId = $oExtension->sCode.'/'.$oExtension->sVersion;
$this->AddExtension($oExtension);
@@ -274,7 +287,8 @@ class iTopExtensionsMap
{
// Already inside an extension, let's add this module the list of modules belonging to this extension
$this->aExtensions[$sParentExtensionId]->aModules[] = $sModuleName;
}
$this->aExtensions[$sParentExtensionId]->aModuleVersion[$sModuleName] = $sModuleVersion;
}
else
{
// Not already inside an folder containing an 'extension.xml' file
@@ -299,10 +313,10 @@ class iTopExtensionsMap
$oExtension->bMandatory = $aModuleInfo[2]['mandatory'];
$oExtension->sMoreInfoUrl = $aModuleInfo[2]['doc.more_information'];
$oExtension->aModules = array($sModuleName);
$oExtension->aModuleVersion[$sModuleName] = $sModuleVersion;
$oExtension->sSourceDir = $sSearchDir;
$oExtension->bVisible = $bVisible;
$this->AddExtension($oExtension);
$this->AddExtension($oExtension);
}
}
}
@@ -479,6 +493,34 @@ class iTopExtensionsMap
return true;
}
/**
* Find is a single-module extension is contained within another extension
* @param iTopExtension $oExtension
* @return NULL|iTopExtension
*/
public function IsExtensionObsoletedByAnother(iTopExtension $oExtension)
{
// Complex extensions (more than 1 module) are never considered as obsolete
if (count($oExtension->aModules) != 1) return null;
foreach($this->GetAllExtensions() as $oOtherExtension)
{
if (($oOtherExtension->sSourceDir != $oExtension->sSourceDir) && ($oOtherExtension->sSource != iTopExtension::SOURCE_WIZARD))
{
if (array_key_exists($oExtension->sCode, $oOtherExtension->aModuleVersion) &&
(version_compare($oOtherExtension->aModuleVersion[$oExtension->sCode], $oExtension->sVersion, '>=')) )
{
// Found another extension containing a more recent version of the extension/module
return $oOtherExtension;
}
}
}
// No match at all
return null;
}
/**
* Search for multi-module extensions that are NOT deployed as an extension (i.e. shipped with an extension.xml file)
* but as a bunch of un-related modules based on the signature of some well-known extensions. If such an extension is found,