Skip to content

Commit a42b061

Browse files
authored
N°9010 fix flags when extension is missing
1 parent c4d7c89 commit a42b061

File tree

2 files changed

+70
-4
lines changed

2 files changed

+70
-4
lines changed

setup/wizardsteps/WizStepModulesChoice.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -666,14 +666,26 @@ protected function GetStepInfo($idx = null)
666666
public function ComputeChoiceFlags(array $aChoice, string $sChoiceId, array $aSelectedComponents, bool $bAllDisabled, bool $bDisableUninstallCheck, bool $bUpgradeMode)
667667
{
668668
$oITopExtension = $this->oExtensionsMap->GetFromExtensionCode($aChoice['extension_code']);
669+
//If the extension is missing from disk, it won't exist in the ExtensionsMap, thus returning null
669670
$bCanBeUninstalled = isset($aChoice['uninstallable']) ? $aChoice['uninstallable'] === true || $aChoice['uninstallable'] === 'yes' : $oITopExtension->CanBeUninstalled();
670671
$bSelected = isset($aSelectedComponents[$sChoiceId]) && ($aSelectedComponents[$sChoiceId] == $sChoiceId);
671-
$bMandatory = (isset($aChoice['mandatory']) && $aChoice['mandatory']) || $bUpgradeMode && $oITopExtension->bInstalled && !$bCanBeUninstalled && !$bDisableUninstallCheck;
672-
673672
$bMissingFromDisk = isset($aChoice['missing']) && $aChoice['missing'] === true;
673+
$bMandatory = (isset($aChoice['mandatory']) && $aChoice['mandatory']);
674674
$bInstalled = $bMissingFromDisk || $oITopExtension->bInstalled;
675-
$bDisabled = $bMandatory || $bAllDisabled || $bMissingFromDisk;
676-
$bChecked = $bMandatory || $bSelected;
675+
676+
$bChecked = $bSelected;
677+
$bDisabled = false;
678+
if ($bMissingFromDisk) {
679+
$bDisabled = true;
680+
$bChecked = false;
681+
}
682+
elseif($bMandatory || $bInstalled && !$bCanBeUninstalled){
683+
$bDisabled = true;
684+
$bChecked = true;
685+
}
686+
if($bAllDisabled){
687+
$bDisabled = true;
688+
}
677689

678690
if (isset($aChoice['sub_options'])) {
679691
$aOptions = $aChoice['sub_options']['options'] ?? [];

tests/php-unit-tests/unitary-tests/setup/WizStepModulesChoiceTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,60 @@ public function ProviderComputeChoiceFlags()
6767
'checked' => true,
6868
],
6969
],
70+
'A missing extension should be disabled and unchecked' => [
71+
'aExtensionsOnDiskOrDb' => [
72+
],
73+
'aWizardStepDefinition' => [
74+
'extension_code' => 'itop-ext1',
75+
'mandatory' => false,
76+
'missing' => true,
77+
'uninstallable' => true,
78+
],
79+
'bCurrentSelected' => false,
80+
'aExpectedFlags' => [
81+
'uninstallable' => true,
82+
'missing' => true,
83+
'installed' => true,
84+
'disabled' => true,
85+
'checked' => false,
86+
],
87+
],
88+
'A missing extension should always be disabled and unchecked, even when mandatory' => [
89+
'aExtensionsOnDiskOrDb' => [
90+
],
91+
'aWizardStepDefinition' => [
92+
'extension_code' => 'itop-ext1',
93+
'mandatory' => true,
94+
'missing' => true,
95+
'uninstallable' => true,
96+
],
97+
'bCurrentSelected' => false,
98+
'aExpectedFlags' => [
99+
'uninstallable' => true,
100+
'missing' => true,
101+
'installed' => true,
102+
'disabled' => true,
103+
'checked' => false,
104+
],
105+
],
106+
'A missing extension should always be disabled and unchecked, even when non-uninstallable' => [
107+
'aExtensionsOnDiskOrDb' => [
108+
],
109+
'aWizardStepDefinition' => [
110+
'extension_code' => 'itop-ext1',
111+
'mandatory' => true,
112+
'missing' => true,
113+
'uninstallable' => false,
114+
],
115+
'bCurrentSelected' => false,
116+
'aExpectedFlags' => [
117+
'uninstallable' => false,
118+
'missing' => true,
119+
'installed' => true,
120+
'disabled' => true,
121+
'checked' => false,
122+
],
123+
],
70124
'An installed but not selected extension should not be checked and be enabled' => [
71125
'aExtensionsOnDiskOrDb' => [
72126
'itop-ext1' => [

0 commit comments

Comments
 (0)