diff --git a/setup/wizardsteps/WizStepModulesChoice.php b/setup/wizardsteps/WizStepModulesChoice.php index e8cd00093..0baa691c2 100644 --- a/setup/wizardsteps/WizStepModulesChoice.php +++ b/setup/wizardsteps/WizStepModulesChoice.php @@ -666,14 +666,26 @@ EOF public function ComputeChoiceFlags(array $aChoice, string $sChoiceId, array $aSelectedComponents, bool $bAllDisabled, bool $bDisableUninstallCheck, bool $bUpgradeMode) { $oITopExtension = $this->oExtensionsMap->GetFromExtensionCode($aChoice['extension_code']); + //If the extension is missing from disk, it won't exist in the ExtensionsMap, thus returning null $bCanBeUninstalled = isset($aChoice['uninstallable']) ? $aChoice['uninstallable'] === true || $aChoice['uninstallable'] === 'yes' : $oITopExtension->CanBeUninstalled(); $bSelected = isset($aSelectedComponents[$sChoiceId]) && ($aSelectedComponents[$sChoiceId] == $sChoiceId); - $bMandatory = (isset($aChoice['mandatory']) && $aChoice['mandatory']) || $bUpgradeMode && $oITopExtension->bInstalled && !$bCanBeUninstalled && !$bDisableUninstallCheck; - $bMissingFromDisk = isset($aChoice['missing']) && $aChoice['missing'] === true; + $bMandatory = (isset($aChoice['mandatory']) && $aChoice['mandatory']); $bInstalled = $bMissingFromDisk || $oITopExtension->bInstalled; - $bDisabled = $bMandatory || $bAllDisabled || $bMissingFromDisk; - $bChecked = $bMandatory || $bSelected; + + $bChecked = $bSelected; + $bDisabled = false; + if ($bMissingFromDisk) { + $bDisabled = true; + $bChecked = false; + } + elseif($bMandatory || $bInstalled && !$bCanBeUninstalled){ + $bDisabled = true; + $bChecked = true; + } + if($bAllDisabled){ + $bDisabled = true; + } if (isset($aChoice['sub_options'])) { $aOptions = $aChoice['sub_options']['options'] ?? []; diff --git a/tests/php-unit-tests/unitary-tests/setup/WizStepModulesChoiceTest.php b/tests/php-unit-tests/unitary-tests/setup/WizStepModulesChoiceTest.php index 742cf00bc..9d21471de 100644 --- a/tests/php-unit-tests/unitary-tests/setup/WizStepModulesChoiceTest.php +++ b/tests/php-unit-tests/unitary-tests/setup/WizStepModulesChoiceTest.php @@ -67,6 +67,60 @@ class WizStepModulesChoiceTest extends ItopTestCase 'checked' => true, ], ], + 'A missing extension should be disabled and unchecked' => [ + 'aExtensionsOnDiskOrDb' => [ + ], + 'aWizardStepDefinition' => [ + 'extension_code' => 'itop-ext1', + 'mandatory' => false, + 'missing' => true, + 'uninstallable' => true, + ], + 'bCurrentSelected' => false, + 'aExpectedFlags' => [ + 'uninstallable' => true, + 'missing' => true, + 'installed' => true, + 'disabled' => true, + 'checked' => false, + ], + ], + 'A missing extension should always be disabled and unchecked, even when mandatory' => [ + 'aExtensionsOnDiskOrDb' => [ + ], + 'aWizardStepDefinition' => [ + 'extension_code' => 'itop-ext1', + 'mandatory' => true, + 'missing' => true, + 'uninstallable' => true, + ], + 'bCurrentSelected' => false, + 'aExpectedFlags' => [ + 'uninstallable' => true, + 'missing' => true, + 'installed' => true, + 'disabled' => true, + 'checked' => false, + ], + ], + 'A missing extension should always be disabled and unchecked, even when non-uninstallable' => [ + 'aExtensionsOnDiskOrDb' => [ + ], + 'aWizardStepDefinition' => [ + 'extension_code' => 'itop-ext1', + 'mandatory' => true, + 'missing' => true, + 'uninstallable' => false, + ], + 'bCurrentSelected' => false, + 'aExpectedFlags' => [ + 'uninstallable' => false, + 'missing' => true, + 'installed' => true, + 'disabled' => true, + 'checked' => false, + ], + ], 'An installed but not selected extension should not be checked and be enabled' => [ 'aExtensionsOnDiskOrDb' => [ 'itop-ext1' => [