From be37b12f4e5da7552cd6e9ad7983d0710c9c94ef Mon Sep 17 00:00:00 2001 From: Eric Espie Date: Tue, 30 Jun 2026 17:30:23 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B09711=20-=20Store=20setup=20parameters=20?= =?UTF-8?q?in=20session?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/log.class.inc.php | 7 + .../DataFeatureRemovalController.php | 6 +- lib/autoload.php | 5 +- lib/composer/autoload_classmap.php | 4 +- lib/composer/autoload_static.php | 4 +- lib/composer/platform_check.php | 5 +- setup/setuputils.class.inc.php | 3 + setup/wizardcontroller.class.inc.php | 164 ++++++------------ setup/wizardsteps/WizStepDone.php | 3 + .../wizardsteps/WizStepLandingBeforeAudit.php | 11 ++ setup/wizardsteps/WizStepWelcome.php | 2 + setup/wizardsteps/WizardStep.php | 9 - .../Helper => Service/Session}/Session.php | 22 +-- sources/Service/Session/SessionParameters.php | 96 ++++++++++ sources/alias.php | 3 + 15 files changed, 205 insertions(+), 139 deletions(-) rename sources/{Application/Helper => Service/Session}/Session.php (90%) create mode 100644 sources/Service/Session/SessionParameters.php diff --git a/core/log.class.inc.php b/core/log.class.inc.php index deb4349751..285a94cf3f 100644 --- a/core/log.class.inc.php +++ b/core/log.class.inc.php @@ -614,6 +614,13 @@ class LogChannels * @since 3.2.0 */ public const SECURITY = 'Security'; + + /** + * For Session parameters + * + * @Since 3.3.0 + */ + public const SESSION_PARAMETERS = 'SessionParameters'; } abstract class LogAPI diff --git a/datamodels/2.x/combodo-data-feature-removal/src/Controller/DataFeatureRemovalController.php b/datamodels/2.x/combodo-data-feature-removal/src/Controller/DataFeatureRemovalController.php index 53c67d856d..39d3776511 100644 --- a/datamodels/2.x/combodo-data-feature-removal/src/Controller/DataFeatureRemovalController.php +++ b/datamodels/2.x/combodo-data-feature-removal/src/Controller/DataFeatureRemovalController.php @@ -19,6 +19,7 @@ use Combodo\iTop\DataFeatureRemoval\Helper\DataFeatureRemovalLog; use Combodo\iTop\DataFeatureRemoval\Service\DataCleanupService; use Combodo\iTop\DataFeatureRemoval\Service\DataFeatureRemoverExtensionService; use Combodo\iTop\DataFeatureRemoval\Service\StaticDeletionPlan; +use Combodo\iTop\Service\Session\SessionParameters; use Combodo\iTop\Setup\FeatureRemoval\DryRemovalRuntimeEnvironment; use Combodo\iTop\Setup\FeatureRemoval\SetupAudit; use ContextTag; @@ -180,7 +181,7 @@ class DataFeatureRemovalController extends Controller ]; foreach ($aHiddenInputs as $sInputName => $sInputValue) { - $aParams['aSetupParams']["_params[$sInputName]"] = $sInputValue; + $aParams['aSetupParams'][$sInputName] = $sInputValue; } [$aParams['aDeletionPlanSummary'], $aParams['iQueryCount'], $aParams['bDeletionPossible']] = $this->GetDeletionPlanSummaryTable($aGetRemovedClasses); @@ -189,6 +190,9 @@ class DataFeatureRemovalController extends Controller Session::Set('aDeletionExecutionSummary', serialize($this->aDeletionExecutionSummary)); if (!$aParams['bDeletionNeeded']) { + // Erase session setup parameters + SetupUtils::EraseSetupToken(); + (new SessionParameters(SetupUtils::SESSION_PARAMETERS_NAME))->Erase(); SetupUtils::CreateSetupToken(); } diff --git a/lib/autoload.php b/lib/autoload.php index 1b6f5ac129..9861c4c24c 100644 --- a/lib/autoload.php +++ b/lib/autoload.php @@ -14,10 +14,7 @@ if (PHP_VERSION_ID < 50600) { echo $err; } } - trigger_error( - $err, - E_USER_ERROR - ); + throw new RuntimeException($err); } require_once __DIR__ . '/composer/autoload_real.php'; diff --git a/lib/composer/autoload_classmap.php b/lib/composer/autoload_classmap.php index a51c3ba362..d76a0fa5d7 100644 --- a/lib/composer/autoload_classmap.php +++ b/lib/composer/autoload_classmap.php @@ -137,7 +137,6 @@ return array( 'Combodo\\iTop\\Application\\Helper\\FormHelper' => $baseDir . '/sources/Application/Helper/FormHelper.php', 'Combodo\\iTop\\Application\\Helper\\ImportHelper' => $baseDir . '/sources/Application/Helper/ImportHelper.php', 'Combodo\\iTop\\Application\\Helper\\SearchHelper' => $baseDir . '/sources/Application/Helper/SearchHelper.php', - 'Combodo\\iTop\\Application\\Helper\\Session' => $baseDir . '/sources/Application/Helper/Session.php', 'Combodo\\iTop\\Application\\Helper\\SynchroReplicaHelper' => $baseDir . '/sources/Application/Helper/SynchroReplicaHelper.php', 'Combodo\\iTop\\Application\\Helper\\WebResourcesHelper' => $baseDir . '/sources/Application/Helper/WebResourcesHelper.php', 'Combodo\\iTop\\Application\\Newsroom\\iTopNewsroomProvider' => $baseDir . '/sources/Application/Newsroom/iTopNewsroomProvider.php', @@ -640,6 +639,8 @@ return array( 'Combodo\\iTop\\Service\\Router\\Exception\\RouteNotFoundException' => $baseDir . '/sources/Service/Router/Exception/RouteNotFoundException.php', 'Combodo\\iTop\\Service\\Router\\Exception\\RouterException' => $baseDir . '/sources/Service/Router/Exception/RouterException.php', 'Combodo\\iTop\\Service\\Router\\Router' => $baseDir . '/sources/Service/Router/Router.php', + 'Combodo\\iTop\\Service\\Session\\Session' => $baseDir . '/sources/Service/Session/Session.php', + 'Combodo\\iTop\\Service\\Session\\SessionParameters' => $baseDir . '/sources/Service/Session/SessionParameters.php', 'Combodo\\iTop\\Service\\Startup\\StartupService' => $baseDir . '/sources/Service/Startup/StartupService.php', 'Combodo\\iTop\\Service\\SummaryCard\\SummaryCardService' => $baseDir . '/sources/Service/SummaryCard/SummaryCardService.php', 'Combodo\\iTop\\Service\\TemporaryObjects\\TemporaryObjectConfig' => $baseDir . '/sources/Service/TemporaryObjects/TemporaryObjectConfig.php', @@ -1423,6 +1424,7 @@ return array( 'ReportValue' => $baseDir . '/core/bulkchange.class.inc.php', 'RestDelete' => $baseDir . '/core/restservices.class.inc.php', 'RestResult' => $baseDir . '/application/applicationextension/rest/RestResult.php', + 'RestResultWithObjectSets' => $baseDir . '/core/restservices.class.inc.php', 'RestResultWithObjects' => $baseDir . '/core/restservices.class.inc.php', 'RestResultWithRelations' => $baseDir . '/core/restservices.class.inc.php', 'RestUtils' => $baseDir . '/application/applicationextension/rest/RestUtils.php', diff --git a/lib/composer/autoload_static.php b/lib/composer/autoload_static.php index db32c807e5..910956cab3 100644 --- a/lib/composer/autoload_static.php +++ b/lib/composer/autoload_static.php @@ -538,7 +538,6 @@ class ComposerStaticInitfc0e9e9dea11dcbb6272414776c30685 'Combodo\\iTop\\Application\\Helper\\FormHelper' => __DIR__ . '/../..' . '/sources/Application/Helper/FormHelper.php', 'Combodo\\iTop\\Application\\Helper\\ImportHelper' => __DIR__ . '/../..' . '/sources/Application/Helper/ImportHelper.php', 'Combodo\\iTop\\Application\\Helper\\SearchHelper' => __DIR__ . '/../..' . '/sources/Application/Helper/SearchHelper.php', - 'Combodo\\iTop\\Application\\Helper\\Session' => __DIR__ . '/../..' . '/sources/Application/Helper/Session.php', 'Combodo\\iTop\\Application\\Helper\\SynchroReplicaHelper' => __DIR__ . '/../..' . '/sources/Application/Helper/SynchroReplicaHelper.php', 'Combodo\\iTop\\Application\\Helper\\WebResourcesHelper' => __DIR__ . '/../..' . '/sources/Application/Helper/WebResourcesHelper.php', 'Combodo\\iTop\\Application\\Newsroom\\iTopNewsroomProvider' => __DIR__ . '/../..' . '/sources/Application/Newsroom/iTopNewsroomProvider.php', @@ -1041,6 +1040,8 @@ class ComposerStaticInitfc0e9e9dea11dcbb6272414776c30685 'Combodo\\iTop\\Service\\Router\\Exception\\RouteNotFoundException' => __DIR__ . '/../..' . '/sources/Service/Router/Exception/RouteNotFoundException.php', 'Combodo\\iTop\\Service\\Router\\Exception\\RouterException' => __DIR__ . '/../..' . '/sources/Service/Router/Exception/RouterException.php', 'Combodo\\iTop\\Service\\Router\\Router' => __DIR__ . '/../..' . '/sources/Service/Router/Router.php', + 'Combodo\\iTop\\Service\\Session\\Session' => __DIR__ . '/../..' . '/sources/Service/Session/Session.php', + 'Combodo\\iTop\\Service\\Session\\SessionParameters' => __DIR__ . '/../..' . '/sources/Service/Session/SessionParameters.php', 'Combodo\\iTop\\Service\\Startup\\StartupService' => __DIR__ . '/../..' . '/sources/Service/Startup/StartupService.php', 'Combodo\\iTop\\Service\\SummaryCard\\SummaryCardService' => __DIR__ . '/../..' . '/sources/Service/SummaryCard/SummaryCardService.php', 'Combodo\\iTop\\Service\\TemporaryObjects\\TemporaryObjectConfig' => __DIR__ . '/../..' . '/sources/Service/TemporaryObjects/TemporaryObjectConfig.php', @@ -1824,6 +1825,7 @@ class ComposerStaticInitfc0e9e9dea11dcbb6272414776c30685 'ReportValue' => __DIR__ . '/../..' . '/core/bulkchange.class.inc.php', 'RestDelete' => __DIR__ . '/../..' . '/core/restservices.class.inc.php', 'RestResult' => __DIR__ . '/../..' . '/application/applicationextension/rest/RestResult.php', + 'RestResultWithObjectSets' => __DIR__ . '/../..' . '/core/restservices.class.inc.php', 'RestResultWithObjects' => __DIR__ . '/../..' . '/core/restservices.class.inc.php', 'RestResultWithRelations' => __DIR__ . '/../..' . '/core/restservices.class.inc.php', 'RestUtils' => __DIR__ . '/../..' . '/application/applicationextension/rest/RestUtils.php', diff --git a/lib/composer/platform_check.php b/lib/composer/platform_check.php index bb733000d3..f6cf0ea27c 100644 --- a/lib/composer/platform_check.php +++ b/lib/composer/platform_check.php @@ -36,8 +36,7 @@ if ($issues) { echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL; } } - trigger_error( - 'Composer detected issues in your platform: ' . implode(' ', $issues), - E_USER_ERROR + throw new \RuntimeException( + 'Composer detected issues in your platform: ' . implode(' ', $issues) ); } diff --git a/setup/setuputils.class.inc.php b/setup/setuputils.class.inc.php index 53c95f0ad9..ec3077d63b 100644 --- a/setup/setuputils.class.inc.php +++ b/setup/setuputils.class.inc.php @@ -103,6 +103,9 @@ class CheckResult */ class SetupUtils { + // Name of the parameter array in session for setup + public const SESSION_PARAMETERS_NAME = 'setup_params'; + // -- Minimum versions (requirements : forbids installation if not met) public const PHP_MIN_VERSION = '8.2.0'; public const MYSQL_MIN_VERSION = '5.7.0'; // 5.6 is no longer supported diff --git a/setup/wizardcontroller.class.inc.php b/setup/wizardcontroller.class.inc.php index 76ba0bd587..71c1e03db5 100644 --- a/setup/wizardcontroller.class.inc.php +++ b/setup/wizardcontroller.class.inc.php @@ -1,21 +1,11 @@ +/** + * @copyright Copyright (C) 2010-2026 Combodo SAS + * @license http://opensource.org/licenses/AGPL-3.0 + */ + +use Combodo\iTop\Service\Session\SessionParameters; require_once(APPROOT.'setup/setuputils.class.inc.php'); require_once(APPROOT.'setup/parameters.class.inc.php'); @@ -26,14 +16,12 @@ require_once(APPROOT.'setup/extensionsmap.class.inc.php'); /** * Engine for displaying the various pages of a "wizard" * Each "step" of the wizard must be implemented as - * separate class derived from WizardStep. each 'step' can also have its own + * separate classes derived from WizardStep. Each 'step' can also have its own * internal 'state' for developing complex wizards. * The WizardController provides the "<< Back" feature by storing a stack * of the previous screens. The WizardController also maintains from page * to page a list of "parameters" to be dispayed/edited by each of the steps. * - * @copyright Copyright (C) 2010-2024 Combodo SAS - * @license http://opensource.org/licenses/AGPL-3.0 */ class WizardController @@ -41,37 +29,42 @@ class WizardController protected $aWizardSteps; protected $sInitialStepClass; protected $sInitialState; - protected $aParameters; + protected SessionParameters $oSessionParameters; /** - * Initiailization of the wizard controller + * Initialization of the wizard controller * @param string $sInitialStepClass Class of the initial step/page of the wizard * @param string $sInitialState Initial state of the initial page (if this class manages states) */ - public function __construct($sInitialStepClass, $sInitialState = '') + public function __construct(string $sInitialStepClass, string $sInitialState = '') { $this->sInitialStepClass = $sInitialStepClass; $this->sInitialState = $sInitialState; - $this->aParameters = []; - $this->aWizardSteps = []; + $this->oSessionParameters = new SessionParameters(SetupUtils::SESSION_PARAMETERS_NAME); + $this->oSessionParameters->LogParameters(); + $this->aWizardSteps = $this->GetParameter('_steps', []); } /** * Pushes information about the current step onto the stack * @param array $aStepInfo Array('class' => , 'state' => ) */ - protected function PushStep($aStepInfo) + protected function PushStep(array $aStepInfo): void { - array_push($this->aWizardSteps, $aStepInfo); + $this->aWizardSteps[] = $aStepInfo; + $this->SetParameter('_steps', $this->aWizardSteps); } /** * Removes information about the previous step from the stack * @return array{'class': string, 'state': string} */ - protected function PopStep() + protected function PopStep(): array { - return array_pop($this->aWizardSteps); + $aStep = array_pop($this->aWizardSteps); + $this->SetParameter('_steps', $this->aWizardSteps); + + return $aStep; } /** @@ -79,13 +72,9 @@ class WizardController * @param string $sParamCode The code identifying this parameter * @param mixed $defaultValue The default value of the parameter in case it was not set */ - public function GetParameter($sParamCode, $defaultValue = '') + public function GetParameter(string $sParamCode, mixed $defaultValue = ''): mixed { - if (array_key_exists($sParamCode, $this->aParameters)) { - return $this->aParameters[$sParamCode]; - } - - return $defaultValue; + return $this->oSessionParameters->GetParameter($sParamCode, $defaultValue); } /** @@ -115,9 +104,9 @@ class WizardController * @param string $sParamCode The code identifying this parameter * @param mixed $value The value to store */ - public function SetParameter($sParamCode, $value) + public function SetParameter(string $sParamCode, mixed $value): void { - $this->aParameters[$sParamCode] = $value; + $this->oSessionParameters->SetParameter($sParamCode, $value); } /** @@ -126,17 +115,30 @@ class WizardController * @param mixed $defaultValue The default value for the parameter * @param string $sSanitizationFilter A 'sanitization' fitler. Default is 'raw_data', which means no filtering */ - public function SaveParameter($sParamCode, $defaultValue, $sSanitizationFilter = 'raw_data') + public function SaveParameter(string $sParamCode, mixed $defaultValue, string $sSanitizationFilter = 'raw_data'): void { - $value = utils::ReadParam($sParamCode, $defaultValue, false, $sSanitizationFilter); - $this->aParameters[$sParamCode] = $value; + $this->oSessionParameters->SetParameterFromParams($sParamCode, $defaultValue, $sSanitizationFilter); + } + + /** + * Stores the value of the page's parameter in a "persistent" parameter in the wizard's context + * @param string $sParamCode The code identifying this parameter + * @param mixed $defaultValue The default value for the parameter + * @param string $sSanitizationFilter A 'sanitization' fitler. Default is 'raw_data', which means no filtering + */ + public function SavePostedParameter(string $sParamCode, mixed $defaultValue = '', string $sSanitizationFilter = 'raw_data'): void + { + $this->oSessionParameters->SetParameterFromPostedParams($sParamCode, $defaultValue, $sSanitizationFilter); } /** * Starts the wizard by displaying it in its initial state + * + * @throws \Exception */ - public function Start() + public function Start(): void { + $this->EraseParameters(); $sCurrentStepClass = $this->sInitialStepClass; $oStep = $this->GetWizardStep($sCurrentStepClass, $this->sInitialState); $this->DisplayStep($oStep); @@ -145,7 +147,7 @@ class WizardController * Progress towards the next step of the wizard * @throws Exception */ - protected function Next() + protected function Next(): void { $sCurrentStepClass = utils::ReadParam('_class', $this->sInitialStepClass); $sCurrentState = utils::ReadParam('_state', $this->sInitialState); @@ -169,8 +171,10 @@ class WizardController /** * Move one step back + * + * @throws \Exception */ - protected function Back() + protected function Back(): void { // let the current step save its parameters $sCurrentStepClass = utils::ReadParam('_class', $this->sInitialStepClass); @@ -208,11 +212,7 @@ class WizardController // to store the parameters $oPage->add(''); $oPage->add(''); - foreach ($this->aParameters as $sCode => $value) { - $oPage->add(''); - } - - $oPage->add(''); + // $oPage->add(''); $oPage->add(''); if (count($this->aWizardSteps) > 0) { if ($oStep->CanMoveBackward()) { @@ -267,7 +267,7 @@ EOF * Make the wizard run: 'Start', 'Next' or 'Back' depending WizardUpdateButtons(); * on the page's parameters */ - public function Run() + public function Run(): void { /** * @since 3.2.0 Add the ContextTag init @@ -276,8 +276,8 @@ EOF $oContextTag = new ContextTag(ContextTag::TAG_SETUP); $sOperation = utils::ReadParam('operation'); - $this->aParameters = utils::ReadParam('_params', [], false, 'raw_data'); - $this->SetWizardSteps(json_decode(utils::ReadParam('_steps', '[]', false, 'raw_data'), true)); + // $this->aParameters = utils::ReadParam('_params', [], false, 'raw_data'); + // $this->SetWizardSteps(json_decode(utils::ReadParam('_steps', '[]', false, 'raw_data'), true)); switch ($sOperation) { case 'next': @@ -293,65 +293,6 @@ EOF } } - /** - * Provides information about the structure/workflow of the wizard by listing - * the possible list of 'steps' and their dependencies - * @param string $sStep Name of the class to start from (used for recursion) - * @param array $aAllSteps List of steps (used for recursion) - */ - public function DumpStructure($sStep = '', $aAllSteps = null) - { - if ($aAllSteps == null) { - $aAllSteps = []; - } - if ($sStep == '') { - $sStep = $this->sInitialStepClass; - } - - $oStep = $this->GetWizardStep($sStep); - $aAllSteps[$sStep] = $oStep->GetPossibleSteps(); - foreach ($aAllSteps[$sStep] as $sNextStep) { - if (!array_key_exists($sNextStep, $aAllSteps)) { - $aAllSteps = $this->DumpStructure($sNextStep, $aAllSteps); - } - } - - return $aAllSteps; - } - - /** - * Dump the wizard's structure as a string suitable to produce a chart - * using graphviz's "dot" program - * @return string The 'dot' formatted output - */ - public function DumpStructureAsDot() - { - $aAllSteps = $this->DumpStructure(); - $sOutput = "digraph finite_state_machine {\n"; - //$sOutput .= "\trankdir=LR;"; - $sOutput .= "\tsize=\"10,12\"\n"; - - $aDeadEnds = [$this->sInitialStepClass]; - foreach ($aAllSteps as $sStep => $aNextSteps) { - if (count($aNextSteps) == 0) { - $aDeadEnds[] = $sStep; - } - } - $sOutput .= "\tnode [shape = doublecircle]; ".implode(' ', $aDeadEnds).";\n"; - $sOutput .= "\tnode [shape = box];\n"; - foreach ($aAllSteps as $sStep => $aNextSteps) { - $oStep = $this->GetWizardStep($sStep); - $sOutput .= "\t$sStep [ label = \"".$oStep->GetTitle()."\"];\n"; - if (count($aNextSteps) > 0) { - foreach ($aNextSteps as $sNextStep) { - $sOutput .= "\t$sStep -> $sNextStep;\n"; - } - } - } - $sOutput .= "}\n"; - return $sOutput; - } - public function SetWizardSteps(array $aWizardSteps): void { $this->aWizardSteps = $aWizardSteps; @@ -371,4 +312,9 @@ EOF } return new $sCurrentStepClass($this, $sCurrentState); } + + public function EraseParameters() + { + $this->oSessionParameters->Erase(); + } } diff --git a/setup/wizardsteps/WizStepDone.php b/setup/wizardsteps/WizStepDone.php index 9353bf2212..61e4c09f0b 100644 --- a/setup/wizardsteps/WizStepDone.php +++ b/setup/wizardsteps/WizStepDone.php @@ -19,6 +19,7 @@ */ use Combodo\iTop\Application\WebPage\WebPage; +use Combodo\iTop\Service\Session\SessionParameters; /** * Summary of the installation tasks @@ -132,6 +133,7 @@ class WizStepDone extends WizardStep if (false === $bHasBackup) { SetupUtils::EraseSetupToken(); + $this->oWizard->EraseParameters(); } } @@ -152,6 +154,7 @@ class WizStepDone extends WizardStep public function AsyncAction(WebPage $oPage, $sCode, $aParameters) { SetupUtils::EraseSetupToken(); + $this->oWizard->EraseParameters(); // For security reasons: add the extension now so that this action can be used to read *only* .tar.gz files from the disk... $sBackupFile = $aParameters['backup'].'.tar.gz'; if (file_exists($sBackupFile)) { diff --git a/setup/wizardsteps/WizStepLandingBeforeAudit.php b/setup/wizardsteps/WizStepLandingBeforeAudit.php index 691f851212..fa15ed2fec 100644 --- a/setup/wizardsteps/WizStepLandingBeforeAudit.php +++ b/setup/wizardsteps/WizStepLandingBeforeAudit.php @@ -61,6 +61,17 @@ class WizStepLandingBeforeAudit extends WizStepModulesChoice $this->oWizard->SetParameter('selected_extensions', json_encode($aExtensionsFromDatabase)); $adModulesFromDatabase = ModuleInstallationRepository::GetInstance()->ReadComputeInstalledModules($oConfig); $this->oWizard->SetParameter('selected_modules', json_encode(array_keys($adModulesFromDatabase))); + } else { + $this->oWizard->SavePostedParameter('selected_modules'); + $this->oWizard->SavePostedParameter('selected_extensions'); + $this->oWizard->SavePostedParameter('added_extensions'); + $this->oWizard->SavePostedParameter('removed_extensions'); + $this->oWizard->SavePostedParameter('extensions_not_uninstallable'); + $this->oWizard->SavePostedParameter('copy_setup_files'); + $this->oWizard->SavePostedParameter('force-uninstall'); + $this->oWizard->SavePostedParameter('use_symbolic_links'); + $this->oWizard->SavePostedParameter('return_application'); + $this->oWizard->SavePostedParameter('target_env'); } $aWizardSteps = $this->GetWizardSteps(); diff --git a/setup/wizardsteps/WizStepWelcome.php b/setup/wizardsteps/WizStepWelcome.php index 31ad75f12f..0d9f16808b 100644 --- a/setup/wizardsteps/WizStepWelcome.php +++ b/setup/wizardsteps/WizStepWelcome.php @@ -18,6 +18,8 @@ * You should have received a copy of the GNU Affero General Public License */ +use Combodo\iTop\Service\Session\SessionParameters; + /** * First step of the iTop Installation Wizard: Welcome screen, requirements */ diff --git a/setup/wizardsteps/WizardStep.php b/setup/wizardsteps/WizardStep.php index a953c52756..fe5714cf40 100644 --- a/setup/wizardsteps/WizardStep.php +++ b/setup/wizardsteps/WizardStep.php @@ -187,15 +187,6 @@ abstract class WizardStep return 'return true;'; } - /** - * Tells whether this step of the wizard requires that the configuration file be writable - * @return bool True if the wizard will possibly need to modify the configuration at some point - */ - public function RequiresWritableConfig() - { - return true; - } - /** * Overload this function to implement asynchronous action(s) (AJAX) * @param string $sCode The code of the action (if several actions need to be distinguished) diff --git a/sources/Application/Helper/Session.php b/sources/Service/Session/Session.php similarity index 90% rename from sources/Application/Helper/Session.php rename to sources/Service/Session/Session.php index ae800cf22b..5ab8cc1faf 100644 --- a/sources/Application/Helper/Session.php +++ b/sources/Service/Session/Session.php @@ -1,11 +1,11 @@ sSessionArrayName = $sParamsName; + $this->aParameters = Session::Get($this->sSessionArrayName, []); + IssueLog::Enable(APPROOT.'log/error.log'); + } + + /** + * Reads a "persistent" parameter from the wizard's context + * @param string $sParamCode The code identifying this parameter + * @param mixed $defaultValue The default value of the parameter in case it was not set + */ + public function GetParameter(string $sParamCode, mixed $defaultValue = '') + { + if (array_key_exists($sParamCode, $this->aParameters)) { + return $this->aParameters[$sParamCode]; + } + + return $defaultValue; + } + + /** + * Stores a "persistent" parameter in the wizard's context + * + * @param string $sParamCode The code identifying this parameter + * @param mixed $value The value to store + */ + public function SetParameter($sParamCode, $value): void + { + $this->aParameters[$sParamCode] = $value; + $this->Save(); + } + + /** + * Stores the value of the page's parameter in a "persistent" parameter in the wizard's context + * @param string $sParamCode The code identifying this parameter + * @param mixed $defaultValue The default value for the parameter + * @param string $sSanitizationFilter A 'sanitization' fitler. Default is 'raw_data', which means no filtering + */ + public function SetParameterFromPostedParams(string $sParamCode, mixed $defaultValue, string $sSanitizationFilter = 'raw_data'): void + { + $value = utils::ReadPostedParam($sParamCode, $defaultValue, $sSanitizationFilter); + $this->aParameters[$sParamCode] = $value; + $this->Save(); + } + + /** + * Stores the value of the page's parameter in a "persistent" parameter in the wizard's context + * @param string $sParamCode The code identifying this parameter + * @param mixed $defaultValue The default value for the parameter + * @param string $sSanitizationFilter A 'sanitization' fitler. Default is 'raw_data', which means no filtering + */ + public function SetParameterFromParams(string $sParamCode, mixed $defaultValue, string $sSanitizationFilter = 'raw_data'): void + { + $value = utils::ReadParam($sParamCode, $defaultValue, false, $sSanitizationFilter); + $this->aParameters[$sParamCode] = $value; + $this->Save(); + } + + private function Save(): void + { + Session::Set($this->sSessionArrayName, $this->aParameters); + } + + public function Erase(): void + { + $this->aParameters = []; + $this->Save(); + $this->LogParameters(); + } + + public function LogParameters(): void + { + IssueLog::Debug('---------------------------------', LogChannels::SESSION_PARAMETERS); + IssueLog::Debug(json_encode(Session::Get($this->sSessionArrayName, []), JSON_PRETTY_PRINT), LogChannels::SESSION_PARAMETERS); + IssueLog::Debug('---------------------------------', LogChannels::SESSION_PARAMETERS); + } +} diff --git a/sources/alias.php b/sources/alias.php index 56dc31c5b6..2157938c89 100644 --- a/sources/alias.php +++ b/sources/alias.php @@ -121,3 +121,6 @@ class_alias(\Combodo\iTop\PropertyType\ValueType\Leaf\ValueTypeText::class, 'Com class_alias(\Combodo\iTop\PropertyType\Serializer\XMLFormat\XMLFormatCSV::class, 'Combodo-XMLFormat-CSV'); class_alias(\Combodo\iTop\PropertyType\Serializer\XMLFormat\XMLFormatValueAsId::class, 'Combodo-XMLFormat-ValueAsId'); class_alias(\Combodo\iTop\PropertyType\Serializer\XMLFormat\XMLFormatFlatArray::class, 'Combodo-XMLFormat-FlatArray'); + +// Moved classes +class_alias(\Combodo\iTop\Service\Session\Session::class, '\Combodo\iTop\Application\Helper\Session');