diff --git a/setup/runtimeenv.class.inc.php b/setup/runtimeenv.class.inc.php index 7d405724a..2a14c82f0 100644 --- a/setup/runtimeenv.class.inc.php +++ b/setup/runtimeenv.class.inc.php @@ -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 => diff --git a/setup/setuputils.class.inc.php b/setup/setuputils.class.inc.php index 71c3cbac0..4a42909e2 100644 --- a/setup/setuputils.class.inc.php +++ b/setup/setuputils.class.inc.php @@ -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 diff --git a/setup/wizardsteps.class.inc.php b/setup/wizardsteps.class.inc.php index 49e9712ac..e06ec3e3d 100644 --- a/setup/wizardsteps.class.inc.php +++ b/setup/wizardsteps.class.inc.php @@ -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(''); $sBannerPath = isset($aStepInfo['banner']) ? $aStepInfo['banner'] : ''; if (!empty($sBannerPath)) @@ -1380,12 +1395,7 @@ class WizStepModulesChoice extends WizardStep $oPage->add('
'); // Build the default choices - $aDefaults = array(); - $aModules = SetupUtils::AnalyzeInstallation($this->oWizard); $aDefaults = $this->GetDefaults($aStepInfo, $aModules); - //echo "
aStepInfo:\n ".print_r($aStepInfo, true)."
"; - //echo "
aDefaults:\n ".print_r($aDefaults, true)."
"; - $index = $this->GetStepIndex(); // retrieve the saved selection