diff --git a/setup/unattended-install/InstallationFileService.php b/setup/unattended-install/InstallationFileService.php index 301fd8ba2..77dad4cbd 100644 --- a/setup/unattended-install/InstallationFileService.php +++ b/setup/unattended-install/InstallationFileService.php @@ -21,6 +21,7 @@ class InstallationFileService { private $sInstallationPath; private $aSelectedModules; private $aSelectedExtensions; + private $aAfterComputationSelectedExtensions; private $aUnSelectedModules; private $aAutoSelectModules; private $bInstallationOptionalChoicesChecked; @@ -37,6 +38,7 @@ class InstallationFileService { $this->aUnSelectedModules = []; $this->sTargetEnvironment = $sTargetEnvironment; $this->aSelectedExtensions = $aSelectedExtensions; + $this->aAfterComputationSelectedExtensions = (count($aSelectedExtensions)==0) ? [] : $aSelectedExtensions; $this->bInstallationOptionalChoicesChecked = $bInstallationOptionalChoicesChecked; } @@ -51,6 +53,10 @@ class InstallationFileService { $this->oProductionEnv = $oProductionEnv; } + public function GetAfterComputationSelectedExtensions(): array { + return $this->aAfterComputationSelectedExtensions; + } + public function GetAutoSelectModules(): array { return $this->aAutoSelectModules; } @@ -146,10 +152,13 @@ class InstallationFileService { $sMandatory = $aChoiceInfo["mandatory"] ?? "false"; $aCurrentModules = $aChoiceInfo["modules"] ?? []; + $sExtensionCode = $aChoiceInfo["extension_code"] ?? null; if (0 === count($this->aSelectedExtensions)){ $bSelected = $bAllChecked || $sDefault === "true" || $sMandatory === "true"; + if ($bSelected){ + $this->aAfterComputationSelectedExtensions[]= $sExtensionCode; + } } else { - $sExtensionCode = $aChoiceInfo["extension_code"] ?? null; $bSelected = $sMandatory === "true" || (null !== $sExtensionCode && in_array($sExtensionCode, $this->aSelectedExtensions)); } diff --git a/setup/unattended-install/unattended-install.php b/setup/unattended-install/unattended-install.php index 10dc03fc0..5a630381d 100644 --- a/setup/unattended-install/unattended-install.php +++ b/setup/unattended-install/unattended-install.php @@ -63,7 +63,8 @@ if (! is_null($sInstallationXmlPath) && is_file($sInstallationXmlPath)) { $sInstallationBaseName = basename($sInstallationXmlPath); $aSelectedExtensionsFromXmlSetup = $oParams->Get('selected_extensions', []); - if (count($aSelectedExtensionsFromXmlSetup) !== 0) { + $bInstallationChoicesProvided = count($aSelectedExtensionsFromXmlSetup) !== 0; + if ($bInstallationChoicesProvided) { $sMsg = "Modules to install computed based on $sInstallationBaseName file and installation choices (listed in section `selected_extensions` of $sXmlSetupBaseName file)"; echo "$sMsg:\n".implode(',', $aSelectedExtensionsFromXmlSetup)."\n\n"; SetupLog::Info($sMsg, null, $aSelectedExtensionsFromXmlSetup); @@ -75,11 +76,21 @@ if (! is_null($sInstallationXmlPath) && is_file($sInstallationXmlPath)) { $oInstallationFileService = new InstallationFileService($sInstallationXmlPath, $sTargetEnvironment, $aSelectedExtensionsFromXmlSetup); $oInstallationFileService->Init(); + + $aComputedExtensions = $oInstallationFileService->GetAfterComputationSelectedExtensions(); + if (! $bInstallationChoicesProvided) { + $sMsg = "Computed installation choices"; + echo "$sMsg:\n".implode(',', $aComputedExtensions)."\n\n"; + SetupLog::Info($sMsg, null, $aComputedExtensions); + } + $aSelectedExtensions = array_keys($aComputedExtensions); + $oParams->Set('selected_extensions', $aSelectedExtensions); + $aComputedModules = $oInstallationFileService->GetSelectedModules(); $aSelectedModules = array_keys($aComputedModules); $oParams->Set('selected_modules', $aSelectedModules); - $sMsg = "Modules to install computed"; + $sMsg = "Computed modules to install"; } else { $aSelectedModules = $oParams->Get('selected_modules', []); $sMsg = "Modules to install listed in $sXmlSetupBaseName (selected_modules section)"; diff --git a/tests/php-unit-tests/unitary-tests/setup/unattended-install/InstallationFileServiceTest.php b/tests/php-unit-tests/unitary-tests/setup/unattended-install/InstallationFileServiceTest.php index 272e913e2..9aefa4237 100644 --- a/tests/php-unit-tests/unitary-tests/setup/unattended-install/InstallationFileServiceTest.php +++ b/tests/php-unit-tests/unitary-tests/setup/unattended-install/InstallationFileServiceTest.php @@ -195,12 +195,34 @@ class InstallationFileServiceTest extends ItopTestCase { sort($aExpectedUnselectedModules); sort($aUnselectedModules); $this->assertEquals($aExpectedUnselectedModules, $aUnselectedModules); + + $aGetAfterComputationSelectedExtensions = $oInstallationFileService->GetAfterComputationSelectedExtensions(); + sort($aGetAfterComputationSelectedExtensions); + $aExpectedExtensions = [ + 'itop-change-mgmt-simple', + 'itop-config-mgmt-core', + 'itop-config-mgmt-datacenter', + 'itop-config-mgmt-end-user', + 'itop-config-mgmt-storage', + 'itop-config-mgmt-virtualization', + 'itop-service-mgmt-enterprise', + 'itop-ticket-mgmt-simple-ticket', + 'itop-ticket-mgmt-simple-ticket-enhanced-portal', + ]; + if ($bInstallationOptionalChoicesChecked){ + $aExpectedExtensions []= "itop-problem-mgmt"; + $aExpectedExtensions []= 'itop-kown-error-mgmt'; + } + sort($aExpectedExtensions); + $this->assertEquals($aExpectedExtensions, $aGetAfterComputationSelectedExtensions); + + $this->ValidateNonItilExtensionComputation($oInstallationFileService, $bInstallationOptionalChoicesChecked); } /** * @dataProvider ItilExtensionProvider */ - public function testProcessInstallationChoicesWithItilChoices(array $aSelectedExtensions, bool $bKnownMgtSelected) { + public function testProcessInstallationChoicesWithItilChoices(array $aSelectedExtensions, bool $bKnownMgtSelected, bool $bCoreMgtSelected) { $sPath = $this->GetInstallationPath(); $oInstallationFileService = new \InstallationFileService($sPath, 'production', $aSelectedExtensions, false); $oProductionEnv = $this->createMock(\RunTimeEnvironment::class); @@ -255,6 +277,8 @@ class InstallationFileServiceTest extends ItopTestCase { sort($aExpectedUnselectedModules); sort($aUnselectedModules); $this->assertEquals($aExpectedUnselectedModules, $aUnselectedModules); + + $this->ValidateItilExtensionComputation($oInstallationFileService, $bKnownMgtSelected, $bCoreMgtSelected); } public function GetDefaultModulesProvider() { @@ -334,6 +358,55 @@ class InstallationFileServiceTest extends ItopTestCase { $this->checkModuleList("unvisible", $aUnvisibleModules, $aSelectedModules); $this->checkModuleList("auto-select", $aAutoSelectedModules, $aSelectedModules); $this->assertEquals([], $aSelectedModules, "there should be no more modules remaining apart from below lists"); + + $this->ValidateNonItilExtensionComputation($oInstallationFileService, $bInstallationOptionalChoicesChecked); + } + + private function ValidateNonItilExtensionComputation($oInstallationFileService, bool $bInstallationOptionalChoicesChecked) { + $aGetAfterComputationSelectedExtensions = $oInstallationFileService->GetAfterComputationSelectedExtensions(); + sort($aGetAfterComputationSelectedExtensions); + $aExpectedExtensions = [ + 'itop-change-mgmt-simple', + 'itop-config-mgmt-core', + 'itop-config-mgmt-datacenter', + 'itop-config-mgmt-end-user', + 'itop-config-mgmt-storage', + 'itop-config-mgmt-virtualization', + 'itop-service-mgmt-enterprise', + 'itop-ticket-mgmt-simple-ticket', + 'itop-ticket-mgmt-simple-ticket-enhanced-portal', + ]; + if ($bInstallationOptionalChoicesChecked){ + $aExpectedExtensions []= "itop-problem-mgmt"; + $aExpectedExtensions []= 'itop-kown-error-mgmt'; + } + sort($aExpectedExtensions); + $this->assertEquals($aExpectedExtensions, $aGetAfterComputationSelectedExtensions); + } + + private function ValidateItilExtensionComputation($oInstallationFileService, bool $bKnownMgtSelected, bool $bCoreMgtSelected) { + $aGetAfterComputationSelectedExtensions = $oInstallationFileService->GetAfterComputationSelectedExtensions(); + sort($aGetAfterComputationSelectedExtensions); + $aExpectedExtensions = [ + 'itop-change-mgmt-itil', + 'itop-config-mgmt-datacenter', + 'itop-config-mgmt-end-user', + 'itop-config-mgmt-storage', + 'itop-config-mgmt-virtualization', + 'itop-service-mgmt-enterprise', + 'itop-ticket-mgmt-itil', + 'itop-ticket-mgmt-itil-enhanced-portal', + 'itop-ticket-mgmt-itil-incident', + 'itop-ticket-mgmt-itil-user-request', + ]; + if ($bCoreMgtSelected){ + $aExpectedExtensions []= 'itop-config-mgmt-core'; + } + if ($bKnownMgtSelected){ + $aExpectedExtensions []= 'itop-kown-error-mgmt'; + } + sort($aExpectedExtensions); + $this->assertEquals($aExpectedExtensions, $aGetAfterComputationSelectedExtensions); } private function GetSelectedItilExtensions(bool $coreExtensionIncluded, bool $bKnownMgtIncluded) : array { @@ -367,18 +440,22 @@ class InstallationFileServiceTest extends ItopTestCase { 'all itil extensions + INCLUDING known-error-mgt' => [ 'aSelectedExtensions' => $this->GetSelectedItilExtensions(true, true), 'bKnownMgtSelected' => true, + 'bCoreMgtSelected' => true, ], 'all itil extensions WITHOUT known-error-mgt' => [ 'aSelectedExtensions' => $this->GetSelectedItilExtensions(true, false), 'bKnownMgtSelected' => false, + 'bCoreMgtSelected' => true, ], 'all itil extensions WITHOUT core mandatory ones + INCLUDING known-error-mgt' => [ 'aSelectedExtensions' => $this->GetSelectedItilExtensions(false, true), 'bKnownMgtSelected' => true, + 'bCoreMgtSelected' => false, ], 'all itil extensions WITHOUT core mandatory ones and WITHOUT known-error-mgt' => [ 'aSelectedExtensions' => $this->GetSelectedItilExtensions(false, false), 'bKnownMgtSelected' => false, + 'bCoreMgtSelected' => false, ], ]; } @@ -386,7 +463,7 @@ class InstallationFileServiceTest extends ItopTestCase { /** * @dataProvider ItilExtensionProvider */ - public function testGetAllSelectedModules_withItilExtensions(array $aSelectedExtensions, bool $bKnownMgtSelected) { + public function testGetAllSelectedModules_withItilExtensions(array $aSelectedExtensions, bool $bKnownMgtSelected, bool $bCoreMgtSelected) { $sPath = $this->GetInstallationPath(); $oInstallationFileService = new \InstallationFileService($sPath, 'production', $aSelectedExtensions); @@ -448,6 +525,8 @@ class InstallationFileServiceTest extends ItopTestCase { $this->checkModuleList("unvisible", $aUnvisibleModules, $aSelectedModules); $this->checkModuleList("auto-select", $aAutoSelectedModules, $aSelectedModules); $this->assertEquals([], $aSelectedModules, "there should be no more modules remaining apart from below lists"); + + $this->ValidateItilExtensionComputation($oInstallationFileService, $bKnownMgtSelected, $bCoreMgtSelected); } private function checkModuleList(string $sModuleCategory, array $aExpectedModuleList, array &$aSelectedModules) {