From 2073e8c10cfdc2bb05ef64317faae32425113cb5 Mon Sep 17 00:00:00 2001 From: Lenaick Date: Wed, 19 Aug 2026 16:03:25 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B09861=20-=20Check=20user=20can=20go=20to?= =?UTF-8?q?=20audit=20step=20only=20when=20keep=20current=20choice=20butto?= =?UTF-8?q?n=20has=20been=20clicked=20(#1013)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * N°9861 - Check user can go to audit step only when keep current choice button has been clicked * Rename variable to improve clarity --- setup/wizardcontroller.class.inc.php | 11 ++++------- setup/wizardsteps/WizStepLandingBeforeAudit.php | 10 +++++++--- .../unitary-tests/setup/WizStepModulesChoiceTest.php | 4 ---- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/setup/wizardcontroller.class.inc.php b/setup/wizardcontroller.class.inc.php index 3c6511aad3..737159a923 100644 --- a/setup/wizardcontroller.class.inc.php +++ b/setup/wizardcontroller.class.inc.php @@ -57,9 +57,9 @@ class WizardController /** * Removes information about the previous step from the stack - * @return array{'class': string, 'state': string} + * @return null|array{'class': string, 'state': string} */ - public function PopStep(): array + public function PopStep(): ?array { $aStep = array_pop($this->aWizardSteps); $this->SetParameter('_steps', $this->aWizardSteps); @@ -343,11 +343,8 @@ EOF */ public function GetLatestWizardStateFromStepClass(string $sStepClass): WizardState { - $iCountModulesChoiceSteps = count(array_filter($this->aWizardSteps, fn (array $step): bool => $step['class'] === $sStepClass && $step['state'] !== '')); - $sStepState = $iCountModulesChoiceSteps > 0 ? (string) ($iCountModulesChoiceSteps - 1) : ''; - - // Pop the latest step from the stack, since we are going back to it - $this->PopStep(); + $iStepStateOccurrences = count(array_filter($this->aWizardSteps, fn (array $step): bool => $step['class'] === $sStepClass && $step['state'] !== '')); + $sStepState = $iStepStateOccurrences > 0 ? (string) ($iStepStateOccurrences - 1) : ''; return new WizardState($sStepClass, $sStepState); } diff --git a/setup/wizardsteps/WizStepLandingBeforeAudit.php b/setup/wizardsteps/WizStepLandingBeforeAudit.php index a22ec3ead8..c77db51359 100644 --- a/setup/wizardsteps/WizStepLandingBeforeAudit.php +++ b/setup/wizardsteps/WizStepLandingBeforeAudit.php @@ -82,15 +82,19 @@ class WizStepLandingBeforeAudit extends WizStepModulesChoice } $bForceUninstall = (bool)$this->oWizard->GetParameter('force-uninstall', false); - if (!$bForceUninstall) { + if ($bSkipWizard && !$bForceUninstall) { // Check if the current choices allow going to the data audit step $aOptions = $this->oExtensionsMap->GetAllExtensionsOptionInfo(); foreach ($aOptions as $index => $aChoice) { $sChoiceId = self::$SEP.$index; - $aFlags = $this->ComputeChoiceFlags($aChoice, $sChoiceId, $aSelectedComponents, false, false, true); + $oLatestWizardState = $this->oWizard->GetLatestWizardStateFromStepClass(WizStepModulesChoice::class); + $aFlags = $this->ComputeChoiceFlags($aChoice, $sChoiceId, $aSelectedComponents[$oLatestWizardState->GetState()], false, false); if (!$this->CanMoveForwardFromChoiceFlags($aFlags)) { + // Pop the latest step from the stack, since we are going back to it + $this->oWizard->PopStep(); + // If the user has selected incompatible modules, we need to go back to the extension choices step, which is the last module choices step in the wizard - return $this->oWizard->GetLatestWizardStateFromStepClass(WizStepModulesChoice::class); + return $oLatestWizardState; } } } diff --git a/tests/php-unit-tests/unitary-tests/setup/WizStepModulesChoiceTest.php b/tests/php-unit-tests/unitary-tests/setup/WizStepModulesChoiceTest.php index e7ebe6148a..0528cea376 100644 --- a/tests/php-unit-tests/unitary-tests/setup/WizStepModulesChoiceTest.php +++ b/tests/php-unit-tests/unitary-tests/setup/WizStepModulesChoiceTest.php @@ -1715,13 +1715,9 @@ HTML, ['class' => 'WizStepModulesChoice', 'state' => '4'], ['class' => 'WizStepModulesChoice', 'state' => '5'], ]; - $this->oWizard->SetParameter('_steps', $aSteps); $this->oWizard->SetWizardSteps($aSteps); $oWizardState = $this->oWizard->GetLatestWizardStateFromStepClass($sStepClass); $this->assertEquals(new WizardState($sStepClass, $sExpectedState), $oWizardState); - - $aNewSteps = $this->oWizard->GetParameter('_steps', []); - $this->assertCount(count($aSteps) - 1, $aNewSteps); } }