mirror of
https://github.com/Combodo/iTop.git
synced 2026-08-12 16:58:18 +02:00
N°9904 - Add explanation message when "Check compatibility" button is not available
This commit is contained in:
@@ -51,6 +51,8 @@ class WizStepModulesChoice extends AbstractWizStepInstall
|
||||
private array $aAnalyzeInstallationModules = [];
|
||||
private ?MissingDependencyException $oMissingDependencyException = null;
|
||||
|
||||
private array $aFlagsByChoiceId = [];
|
||||
|
||||
public function __construct(WizardController $oWizard, $sCurrentState, bool $bOverWriteConfig = true)
|
||||
{
|
||||
parent::__construct($oWizard, $sCurrentState);
|
||||
@@ -290,6 +292,34 @@ class WizStepModulesChoice extends AbstractWizStepInstall
|
||||
$oPage->warning($sManualInstallError);
|
||||
}
|
||||
|
||||
// Build the default choices
|
||||
$aDefaults = $this->GetDefaults($aStepInfo, $this->aAnalyzeInstallationModules);
|
||||
$index = $this->GetStepIndex();
|
||||
|
||||
// retrieve the saved selection
|
||||
// use json_encode:decode to store a hash array: step_id => array(input_name => selected_input_id)
|
||||
$aParameters = json_decode($this->oWizard->GetParameter('selected_components', '{}'), true);
|
||||
if (!isset($aParameters[$index])) {
|
||||
$aParameters[$index] = $aDefaults;
|
||||
}
|
||||
$aSelectedComponents = $aParameters[$index];
|
||||
|
||||
$bDisableUninstallCheck = (bool)$this->oWizard->GetParameter('force-uninstall', false);
|
||||
|
||||
$aOptions = $aStepInfo['options'] ?? [];
|
||||
foreach ($aOptions as $index => $aChoice) {
|
||||
$sChoiceId = self::$SEP.$index;
|
||||
$this->ComputeChoiceFlags($aChoice, $sChoiceId, $aSelectedComponents, false, $bDisableUninstallCheck);
|
||||
}
|
||||
|
||||
if (!$this->bCanMoveForward) {
|
||||
if (SetupUtils::IsConnectableToITopHub($this->aAnalyzeInstallationModules)) {
|
||||
$oPage->error('Due to some inconsistencies the upgrade can\'t continue. You must deactivate "consistency protections" in the previous steps and restore a consistent environment.');
|
||||
} else {
|
||||
$oPage->error('Due to some inconsistencies the upgrade can\'t continue, please contact Combodo support.');
|
||||
}
|
||||
}
|
||||
|
||||
$oPage->add('<div class="module-selection-banner">');
|
||||
$sBannerPath = isset($aStepInfo['banner']) ? $aStepInfo['banner'] : '';
|
||||
if (!empty($sBannerPath)) {
|
||||
@@ -308,18 +338,6 @@ class WizStepModulesChoice extends AbstractWizStepInstall
|
||||
$oPage->add('<span>'.$sDescription.'</span>');
|
||||
$oPage->add('</div>');
|
||||
|
||||
// Build the default choices
|
||||
$aDefaults = $this->GetDefaults($aStepInfo, $this->aAnalyzeInstallationModules);
|
||||
$index = $this->GetStepIndex();
|
||||
|
||||
// retrieve the saved selection
|
||||
// use json_encode:decode to store a hash array: step_id => array(input_name => selected_input_id)
|
||||
$aParameters = json_decode($this->oWizard->GetParameter('selected_components', '{}'), true);
|
||||
if (!isset($aParameters[$index])) {
|
||||
$aParameters[$index] = $aDefaults;
|
||||
}
|
||||
$aSelectedComponents = $aParameters[$index];
|
||||
|
||||
$oPage->add('<div class="module-selection-body">');
|
||||
$this->DisplayOptions($oPage, $aStepInfo, $aSelectedComponents, $aDefaults);
|
||||
$oPage->add('</div>');
|
||||
@@ -742,8 +760,12 @@ EOF
|
||||
return $this->aSteps[$index] ?? null;
|
||||
}
|
||||
|
||||
public function ComputeChoiceFlags(array $aChoice, string $sChoiceId, array $aSelectedComponents, bool $bAllDisabled, bool $bDisableUninstallCheck, bool $bUpgradeMode)
|
||||
public function ComputeChoiceFlags(array $aChoice, string $sChoiceId, array $aSelectedComponents, bool $bAllDisabled, bool $bDisableUninstallCheck)
|
||||
{
|
||||
if (array_key_exists($sChoiceId, $this->aFlagsByChoiceId)) {
|
||||
return $this->aFlagsByChoiceId[$sChoiceId];
|
||||
}
|
||||
|
||||
$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();
|
||||
@@ -784,7 +806,7 @@ EOF
|
||||
$aOptions = $aChoice['sub_options']['options'] ?? [];
|
||||
foreach ($aOptions as $index => $aSubChoice) {
|
||||
$sSubChoiceId = $sChoiceId.self::$SEP.$index;
|
||||
$aSubFlags = $this->ComputeChoiceFlags($aSubChoice, $sSubChoiceId, $aSelectedComponents, $bAllDisabled, $bDisableUninstallCheck, $bUpgradeMode);
|
||||
$aSubFlags = $this->ComputeChoiceFlags($aSubChoice, $sSubChoiceId, $aSelectedComponents, $bAllDisabled, $bDisableUninstallCheck);
|
||||
if ($aSubFlags['checked']) {
|
||||
$bChecked = true;
|
||||
if ($aSubFlags['disabled']) {
|
||||
@@ -796,7 +818,7 @@ EOF
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
$aFlags = [
|
||||
'uninstallable' => $bCanBeUninstalled,
|
||||
'dependency_issue' => $bDependencyIssue,
|
||||
'mandatory' => $bMandatory,
|
||||
@@ -805,6 +827,11 @@ EOF
|
||||
'disabled' => $bDisabled,
|
||||
'checked' => $bChecked,
|
||||
];
|
||||
|
||||
$this->bCanMoveForward = $this->bCanMoveForward && $this->CanMoveForwardFromChoiceFlags($aFlags, $bDisableUninstallCheck);
|
||||
$this->aFlagsByChoiceId[$sChoiceId] = $aFlags;
|
||||
|
||||
return $aFlags;
|
||||
}
|
||||
|
||||
public function DisplayOptions($oPage, $aStepInfo, $aSelectedComponents, $aDefaults, $sParentId = '', $bAllDisabled = false)
|
||||
@@ -816,16 +843,7 @@ EOF
|
||||
|
||||
foreach ($aOptions as $index => $aChoice) {
|
||||
$sChoiceId = $sParentId.self::$SEP.$index;
|
||||
$aFlags = $this->ComputeChoiceFlags($aChoice, $sChoiceId, $aSelectedComponents, $bAllDisabled, $bDisableUninstallCheck, $this->bUpgrade);
|
||||
|
||||
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;
|
||||
}
|
||||
$aFlags = $this->ComputeChoiceFlags($aChoice, $sChoiceId, $aSelectedComponents, $bAllDisabled, $bDisableUninstallCheck);
|
||||
|
||||
$this->DisplayChoice($oPage, $aChoice, $aSelectedComponents, $aDefaults, $sChoiceId, $sChoiceId, $aFlags);
|
||||
}
|
||||
@@ -864,7 +882,7 @@ EOF
|
||||
$bSelected = ($sChoiceId === $sChoiceIdNone);
|
||||
}
|
||||
|
||||
$aFlags = $this->ComputeChoiceFlags($aChoice, $sChoiceId, $aSelectedComponents, $bAllDisabled, $bDisableUninstallCheck, $this->bUpgrade);
|
||||
$aFlags = $this->ComputeChoiceFlags($aChoice, $sChoiceId, $aSelectedComponents, $bAllDisabled, $bDisableUninstallCheck);
|
||||
//ComputeChoiceFlags does not completely compute alternative flags
|
||||
$aFlags['disabled'] = $bDisabled;
|
||||
$aFlags['checked'] = $bSelected;
|
||||
@@ -872,6 +890,32 @@ EOF
|
||||
}
|
||||
}
|
||||
|
||||
protected function CanMoveForwardFromChoiceFlags(array $aFlags, bool $bDisableUninstallCheck): bool
|
||||
{
|
||||
// The user can force to move forward with the "force-uninstall" option
|
||||
if ($bDisableUninstallCheck) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($aFlags['checked']) {
|
||||
// An extension cannot be installed if it has a dependency issue
|
||||
if ($aFlags['disabled'] && $aFlags['dependency_issue']) {
|
||||
return false;
|
||||
}
|
||||
} elseif ($aFlags['installed']) {
|
||||
// An extension cannot be uninstalled if it is not uninstallable
|
||||
if (!$aFlags['uninstallable']) {
|
||||
return false;
|
||||
}
|
||||
// An extension cannot be uninstalled if it is mandatory
|
||||
if ($aFlags['mandatory']) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function DisplayChoice($oPage, $aChoice, $aSelectedComponents, $aDefaults, $sChoiceName, $sChoiceId, $aFlags, $sInputType = 'checkbox')
|
||||
{
|
||||
$sMoreInfo = (isset($aChoice['more_info']) && ($aChoice['more_info'] != '')) ? '
|
||||
|
||||
@@ -592,7 +592,7 @@ class WizStepModulesChoiceTest extends ItopTestCase
|
||||
public function testComputeChoiceFlags($aExtensionsOnDiskOrDb, $aWizardStepDefinition, $bIsCurrentSelected, $bDisableUninstallChecks, $aExpectedFlags)
|
||||
{
|
||||
$this->oWizStepModulesChoiceFake->setExtensionMap(iTopExtensionsMapFake::createFromArray($aExtensionsOnDiskOrDb));
|
||||
$aFlags = $this->oWizStepModulesChoiceFake->ComputeChoiceFlags($aWizardStepDefinition, '_0', $bIsCurrentSelected ? ['_0' => '_0'] : [], false, $bDisableUninstallChecks, true);
|
||||
$aFlags = $this->oWizStepModulesChoiceFake->ComputeChoiceFlags($aWizardStepDefinition, '_0', $bIsCurrentSelected ? ['_0' => '_0'] : [], false, $bDisableUninstallChecks);
|
||||
$this->assertEquals($aExpectedFlags, $aFlags);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user