N°2533 Check modules manual install dir on Setup for iTop products

This commit is contained in:
Pierre Goiffon
2019-11-20 12:04:54 +01:00
parent a259be9033
commit 32c5cd245b
3 changed files with 72 additions and 8 deletions

View File

@@ -142,7 +142,7 @@ class RunTimeEnvironment
* @param Config $oConfig Defines the target environment (DB)
* @param mixed $modulesPath Either a single string or an array of absolute paths
* @param bool $bAbortOnMissingDependency ...
* @param array $aModulesToLoad List of modules to search for, defaults to all if ommitted
* @param array $aModulesToLoad List of modules to search for, defaults to all if omitted
*
* @return array Array with the following format:
* array =>

View File

@@ -1466,7 +1466,8 @@ EOF
* @param $oWizard
* @param bool $bAbortOnMissingDependency ...
* @param array $aModulesToLoad List of modules to search for, defaults to all if ommitted
* @return hash
*
* @return array
* @throws Exception
*/
public static function AnalyzeInstallation($oWizard, $bAbortOnMissingDependency = false, $aModulesToLoad = null)
@@ -1557,6 +1558,59 @@ EOF
return $oProductionEnv->GetApplicationVersion($oConfig);
}
/**
* @param array $aModules List of available module codes
*
* @return bool true if we are in a iTop product package (professional, essential, ...)
* @since 2.7.0 N°2533
*/
public static function IsProductVersion($aModules)
{
return array_key_exists('itsm-designer-connector', $aModules);
}
/**
* @param array $aModules Available modules with code as key and metadata array as values
* Same structure as the one returned by {@link \RunTimeEnvironment::AnalyzeInstallation}
* @param string $sExtensionsDir In the setup, get value with the 'extensions_dir' parameter
*
* @return string Error message if has manually installed modules, empty string otherwise
*
* @since 2.7.0 N°2533
*/
public static function CheckManualInstallDirEmpty($aModules, $sExtensionsDir = 'extensions')
{
if (!static::IsProductVersion($aModules))
{
return '';
}
$sManualInstallModulesFullPath = APPROOT.$sExtensionsDir.DIRECTORY_SEPARATOR;
$aManualInstallModules = array_filter($aModules,
static function ($v, $k) use ($sManualInstallModulesFullPath) {
if (!isset($v['root_dir'])) // avoid index undefined for the _Root_ entry
{
return false;
}
// calling realpath to avoid problems with dir separator (almost everywhere we are adding '/' instead of DIRECTORY_SEPARATOR)
$return = utils::RealPath($v['root_dir'], $sManualInstallModulesFullPath);
if ($return === false)
{
return false;
}
return true;
},
ARRAY_FILTER_USE_BOTH);
if (empty($aManualInstallModules))
{
return '';
}
return "Some modules are present in the '$sExtensionsDir' directory, this is not allowed when using ".ITOP_APPLICATION;
}
/**
* Checks if the content of a directory matches the given manifest
* @param string $sBaseDir Path to the root directory of iTop

View File

@@ -1272,6 +1272,7 @@ class WizStepModulesChoice extends WizardStep
if ($sConfigPath !== null) // only called if the config file exists : we are updating a previous installation !
{
$oConfig = new Config($sConfigPath);
utils::SetConfig($oConfig);
$this->bChoicesFromDatabase = $this->oExtensionsMap->LoadChoicesFromDatabase($oConfig);
}
}
@@ -1339,9 +1340,14 @@ class WizStepModulesChoice extends WizardStep
$this->DisplayStep($oPage);
}
/**
* @param \SetupPage $oPage
*
* @throws \Exception
*/
protected function DisplayStep($oPage)
{
// Sanity check (not stopper, to let developpers go further...)
// Sanity check (not stopper, to let developers go further...)
try
{
SetupUtils::AnalyzeInstallation($this->oWizard, true);
@@ -1357,6 +1363,15 @@ class WizStepModulesChoice extends WizardStep
$oPage->add_style("div.choice a { text-decoration:none; font-weight: bold; color: #1C94C4 }");
$oPage->add_style("div.description { margin-left: 2em; }");
$oPage->add_style(".choice-disabled { color: #999; }");
$aModules = SetupUtils::AnalyzeInstallation($this->oWizard);
$sManualInstallError = SetupUtils::CheckManualInstallDirEmpty($aModules,
$this->oWizard->GetParameter('extensions_dir', 'extensions'));
if ($sManualInstallError !== '')
{
$oPage->warning($sManualInstallError);
}
$oPage->add('<table class="module-selection-banner"><tr>');
$sBannerPath = isset($aStepInfo['banner']) ? $aStepInfo['banner'] : '';
if (!empty($sBannerPath))
@@ -1380,12 +1395,7 @@ class WizStepModulesChoice extends WizardStep
$oPage->add('</tr></table>');
// Build the default choices
$aDefaults = array();
$aModules = SetupUtils::AnalyzeInstallation($this->oWizard);
$aDefaults = $this->GetDefaults($aStepInfo, $aModules);
//echo "<pre>aStepInfo:\n ".print_r($aStepInfo, true)."</pre>";
//echo "<pre>aDefaults:\n ".print_r($aDefaults, true)."</pre>";
$index = $this->GetStepIndex();
// retrieve the saved selection