diff --git a/setup/wizardsteps/WizStepModulesChoice.php b/setup/wizardsteps/WizStepModulesChoice.php index 9afb266cb..91b3873a7 100644 --- a/setup/wizardsteps/WizStepModulesChoice.php +++ b/setup/wizardsteps/WizStepModulesChoice.php @@ -758,11 +758,19 @@ EOF if ($bMissingFromDisk) { $bDisabled = true; $bChecked = false; + } elseif ($bDependencyIssue && ($oITopExtension->sSource !== iTopExtension::SOURCE_WIZARD || !$bMandatory)) { + // If the extension is not installed, the user cannot select it + // If the extension is installed and mandatory or not uninstallable, the user cannot unselect it + // Unless the user uses the "force-uninstall" option + $bDisabled = (!$bInstalled || $bMandatory || !$bCanBeUninstalled) && !$bDisableUninstallCheck; + // If the extension is a remote extension and not be installed means the user previously uninstalled it + // Otherwise, it will be checked if it is mandatory or if it was selected by the user + if ($oITopExtension->sSource !== iTopExtension::SOURCE_REMOTE || $bInstalled) { + $bChecked = $bMandatory ?: $bSelected; + } } elseif ($bMandatory) { $bDisabled = true; $bChecked = true; - } elseif ($bDependencyIssue) { - $bDisabled = !$bDisableUninstallCheck; } elseif ($bInstalled && !$bCanBeUninstalled && !$bDisableUninstallCheck) { $bChecked = true; $bDisabled = true; @@ -810,10 +818,12 @@ EOF $sChoiceId = $sParentId.self::$SEP.$index; $aFlags = $this->ComputeChoiceFlags($aChoice, $sChoiceId, $aSelectedComponents, $bAllDisabled, $bDisableUninstallCheck, $this->bUpgrade); - if ($aFlags['disabled'] && !$aFlags['checked'] && !$bDisableUninstallCheck && (!$aFlags['uninstallable'] || $aFlags['mandatory'])) { - $this->bCanMoveForward = false;//Disable "Next" - } elseif (!$bDisableUninstallCheck && $aFlags['dependency_issue']) { - //If there is a dependency issue, the user cannot move forward without forced uninstall + if (!$aFlags['checked'] && $aFlags['installed'] && !$bDisableUninstallCheck && (!$aFlags['uninstallable'] || $aFlags['mandatory'])) { + // If the user cannot uninstall a mandatory extension, he cannot move forward unless he uses the "force-uninstall" option + // The same applies if the extension is not uninstallable (i.e. a product extension) + $this->bCanMoveForward = false; + } elseif ($aFlags['checked'] && $aFlags['disabled'] && $aFlags['dependency_issue'] && !$bDisableUninstallCheck) { + // If there is a dependency issue on a selected and disabled extension, the user cannot move forward unless he uses the "force-uninstall" option $this->bCanMoveForward = false; } diff --git a/tests/php-unit-tests/unitary-tests/setup/WizStepModulesChoiceTest.php b/tests/php-unit-tests/unitary-tests/setup/WizStepModulesChoiceTest.php index c3a2084da..d9ae25d2e 100644 --- a/tests/php-unit-tests/unitary-tests/setup/WizStepModulesChoiceTest.php +++ b/tests/php-unit-tests/unitary-tests/setup/WizStepModulesChoiceTest.php @@ -421,7 +421,7 @@ class WizStepModulesChoiceTest extends ItopTestCase 'mandatory' => false, ], ], - 'An installed non mandatory extension with missing dependencies and without force uninstall should be not checked and disabled' => [ + 'An installed non mandatory extension with missing dependencies and without force uninstall should be not checked and enabled' => [ 'aExtensionsOnDiskOrDb' => [ 'itop-ext1' => [ 'installed' => true, @@ -442,6 +442,33 @@ class WizStepModulesChoiceTest extends ItopTestCase 'uninstallable' => true, 'missing' => false, 'installed' => true, + 'disabled' => false, + 'checked' => false, + 'dependency_issue' => true, + 'mandatory' => false, + ], + ], + 'An installed non mandatory and not uninstallable extension with missing dependencies and without force uninstall should be not checked and disabled' => [ + 'aExtensionsOnDiskOrDb' => [ + 'itop-ext1' => [ + 'installed' => true, + 'missing_dependencies' => [ + 'itop-ext1-1', + ], + ], + ], + 'aWizardStepDefinition' => [ + 'extension_code' => 'itop-ext1', + 'mandatory' => false, + 'uninstallable' => false, + 'missing_dependencies' => true, + ], + 'bCurrentSelected' => false, + 'bDisableUninstallChecks' => false, + 'aExpectedFlags' => [ + 'uninstallable' => false, + 'missing' => false, + 'installed' => true, 'disabled' => true, 'checked' => false, 'dependency_issue' => true, @@ -518,7 +545,7 @@ class WizStepModulesChoiceTest extends ItopTestCase 'missing_dependencies' => true, ], 'bCurrentSelected' => false, - 'bDisableUninstallChecks' => true, + 'bDisableUninstallChecks' => false, 'aExpectedFlags' => [ 'uninstallable' => true, 'missing' => false, @@ -545,7 +572,7 @@ class WizStepModulesChoiceTest extends ItopTestCase 'missing_dependencies' => true, ], 'bCurrentSelected' => false, - 'bDisableUninstallChecks' => true, + 'bDisableUninstallChecks' => false, 'aExpectedFlags' => [ 'uninstallable' => true, 'missing' => false,