From 85dd5448fe62d46cf432b99aaee5508382611681 Mon Sep 17 00:00:00 2001 From: Timothee Date: Fri, 23 Jan 2026 12:01:14 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B09144=20WIP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- datamodels/2.x/installation.xml | 1 + .../ModelReflectionSerializer.php | 4 +- setup/wizardsteps.class.inc.php | 356 +++++++++++++++++- 3 files changed, 350 insertions(+), 11 deletions(-) diff --git a/datamodels/2.x/installation.xml b/datamodels/2.x/installation.xml index a3e53c2d0..fed17ad67 100755 --- a/datamodels/2.x/installation.xml +++ b/datamodels/2.x/installation.xml @@ -223,6 +223,7 @@ itop-problem-mgmt + no diff --git a/setup/feature_removal/ModelReflectionSerializer.php b/setup/feature_removal/ModelReflectionSerializer.php index ba4f8bc51..0425d2fe5 100644 --- a/setup/feature_removal/ModelReflectionSerializer.php +++ b/setup/feature_removal/ModelReflectionSerializer.php @@ -40,8 +40,8 @@ class ModelReflectionSerializer exec(sprintf("$sPHPExec %s/get_model_reflection.php --env='%s'", __DIR__, $sEnv), $sOutput, $iRes); if ($iRes != 0) { - $this->LogErrorWithProperLogger("Cannot get classes", null, ['env' => $sEnv, 'code' => $iRes, "output" => $sOutput]); - throw new CoreException("Cannot get classes"); + $this->LogErrorWithProperLogger("Cannot get classes1", null, ['env' => $sEnv, 'code' => $iRes, "output" => $sOutput]); + throw new CoreException("Cannot get classes2"); } $aClasses = json_decode($sOutput[0] ?? null, true); diff --git a/setup/wizardsteps.class.inc.php b/setup/wizardsteps.class.inc.php index f8c947f85..ad65ebdd3 100644 --- a/setup/wizardsteps.class.inc.php +++ b/setup/wizardsteps.class.inc.php @@ -1381,7 +1381,7 @@ class WizStepModulesChoice extends WizardStep public function GetPossibleSteps() { - return ['WizStepModulesChoice', 'WizStepSummary']; + return ['WizStepModulesChoice', 'WizStepAudit']; } public function GetAddedAndRemovedExtensions($aSelectedExtensions) @@ -1442,7 +1442,14 @@ class WizStepModulesChoice extends WizardStep $this->oWizard->SetParameter('extensions_added', json_encode($aExtensionsAdded)); $this->oWizard->SetParameter('removed_extensions', json_encode($aExtensionsRemoved)); $this->oWizard->SetParameter('extensions_not_uninstallable', json_encode(array_keys($aExtensionsNotUninstallable))); - return ['class' => 'WizStepSummary', 'state' => '']; + $sMode = $this->oWizard->GetParameter('mode', 'install'); + if ($sMode == 'install') { + return ['class' => 'WizStepAudit', 'state' => '']; + } + else { + return ['class' => 'WizStepAudit', 'state' => '']; + } + } } @@ -1930,7 +1937,7 @@ EOF ]; } } - +var_dump($this->aSteps[$index]); return $this->aSteps[$index] ?? null; } @@ -2107,6 +2114,107 @@ EOF } +class WizStepAudit extends WizardStep +{ + public function GetTitle() + { + return 'Checking upgrade'; + + } + + public function GetPossibleSteps() + { + return ['WizStepSummary']; + } + + public function GetNextButtonLabel() + { + return 'Next'; + } + + public function CanMoveForward() + { + return true; + + } + + public function ProcessParams($bMoveForward = true) + { + return ['class' => 'WizStepSummary', 'state' => '']; + } + + public function Display(WebPage $oPage) + { + $oPage->add('

Progress bar

'); + } + + public function AsyncAction(WebPage $oPage, $sCode, $aParameters) + { + $oParameters = new PHPParameters(); + $sStep = $aParameters['installer_step']; + $sJSONParameters = $aParameters['installer_config']; + $oParameters->LoadFromHash(json_decode($sJSONParameters, true /* bAssoc */)); + $oInstaller = new ApplicationInstaller($oParameters); + $aRes = $oInstaller->ExecuteStep($sStep); + if (($aRes['status'] != ApplicationInstaller::ERROR) && ($aRes['next-step'] != '')) { + // Tell the web page to move the progress bar and to launch the next step + $sMessage = addslashes(utils::EscapeHtml($aRes['next-step-label'])); + $oPage->add_ready_script( + <<{$aRes['next-step-label']}'); + ExecuteStep('{$aRes['next-step']}'); +EOF + ); + } elseif ($aRes['status'] != ApplicationInstaller::ERROR) { + // Installation complete, move to the next step of the wizard + $oPage->add_ready_script( + <<', $sMessage); + $oPage->add_ready_script( + << 'WizStepDone', 'state' => '']; + return ['class' => 'WizStepBuild', 'state' => '']; } public function Display(WebPage $oPage) @@ -2290,6 +2398,234 @@ class WizStepSummary extends WizardStep $oPage->add(''); // params_summary $oPage->add(''); + if (!$this->CheckDependencies()) { + $oPage->error($this->sDependencyIssue); + } + + $oPage->add_ready_script( + <<oWizard->GetParameter('install_mode', 'install'); + $aSelectedModules = json_decode($this->oWizard->GetParameter('selected_modules'), true); + $aSelectedExtensions = json_decode($this->oWizard->GetParameter('selected_extensions'), true); + $sBackupDestination = ''; + $sPreviousConfigurationFile = ''; + $sDBName = $this->oWizard->GetParameter('db_name'); + if ($sMode == 'upgrade') { + $sPreviousVersionDir = $this->oWizard->GetParameter('previous_version_dir', ''); + if (!empty($sPreviousVersionDir)) { + $aPreviousInstance = SetupUtils::GetPreviousInstance($sPreviousVersionDir); + if ($aPreviousInstance['found']) { + $sPreviousConfigurationFile = $aPreviousInstance['configuration_file']; + } + } + + if ($this->oWizard->GetParameter('db_backup', false)) { + $sBackupDestination = $this->oWizard->GetParameter('db_backup_path', ''); + } + } else { + + $sDBNewName = $this->oWizard->GetParameter('db_new_name', ''); + if ($sDBNewName != '') { + $sDBName = $sDBNewName; // Database will be created + } + } + + $sSourceDir = $this->oWizard->GetParameter('source_dir'); + $aCopies = []; + if (($sMode == 'upgrade') && ($this->oWizard->GetParameter('upgrade_type') == 'keep-previous')) { + $sPreviousVersionDir = $this->oWizard->GetParameter('previous_version_dir'); + $aCopies[] = ['source' => $sSourceDir, 'destination' => 'modules']; // Source is an absolute path, destination is relative to APPROOT + $aCopies[] = ['source' => $sPreviousVersionDir.'/portal', 'destination' => 'portal']; // Source is an absolute path, destination is relative to APPROOT + $sSourceDir = APPROOT.'modules'; + } + + $aInstallParams = [ + 'mode' => $sMode, + 'preinstall' => [ + 'copies' => $aCopies, + // 'backup' => see below + ], + 'source_dir' => str_replace(APPROOT, '', $sSourceDir), + 'datamodel_version' => $this->oWizard->GetParameter('datamodel_version'), //TODO: let the installer compute this automatically... + 'previous_configuration_file' => $sPreviousConfigurationFile, + 'extensions_dir' => 'extensions', + 'target_env' => 'production', + 'workspace_dir' => '', + 'database' => [ + 'server' => $this->oWizard->GetParameter('db_server'), + 'user' => $this->oWizard->GetParameter('db_user'), + 'pwd' => $this->oWizard->GetParameter('db_pwd'), + 'name' => $sDBName, + 'db_tls_enabled' => $this->oWizard->GetParameter('db_tls_enabled'), + 'db_tls_ca' => $this->oWizard->GetParameter('db_tls_ca'), + 'prefix' => $this->oWizard->GetParameter('db_prefix'), + ], + 'url' => $this->oWizard->GetParameter('application_url'), + 'graphviz_path' => $this->oWizard->GetParameter('graphviz_path'), + 'admin_account' => [ + 'user' => $this->oWizard->GetParameter('admin_user'), + 'pwd' => $this->oWizard->GetParameter('admin_pwd'), + 'language' => $this->oWizard->GetParameter('admin_language'), + ], + 'language' => $this->oWizard->GetParameter('default_language'), + 'selected_modules' => $aSelectedModules, + 'selected_extensions' => $aSelectedExtensions, + 'sample_data' => ($this->oWizard->GetParameter('sample_data', '') == 'yes') ? true : false , + 'old_addon' => $this->oWizard->GetParameter('old_addon', false), // whether or not to use the "old" userrights profile addon + 'options' => json_decode($this->oWizard->GetParameter('misc_options', '[]'), true), + 'mysql_bindir' => $this->oWizard->GetParameter('mysql_bindir'), + ]; + + if ($sBackupDestination != '') { + $aInstallParams['preinstall']['backup'] = [ + 'destination' => $sBackupDestination, + 'configuration_file' => $sPreviousConfigurationFile, + ]; + } + + return $aInstallParams; + } + + public function AsyncAction(WebPage $oPage, $sCode, $aParameters) + { + $oParameters = new PHPParameters(); + $sStep = $aParameters['installer_step']; + $sJSONParameters = $aParameters['installer_config']; + $oParameters->LoadFromHash(json_decode($sJSONParameters, true /* bAssoc */)); + $oInstaller = new ApplicationInstaller($oParameters); + $aRes = $oInstaller->ExecuteStep($sStep); + if (($aRes['status'] != ApplicationInstaller::ERROR) && ($aRes['next-step'] != '')) { + // Tell the web page to move the progress bar and to launch the next step + $sMessage = addslashes(utils::EscapeHtml($aRes['next-step-label'])); + $oPage->add_ready_script( + <<{$aRes['next-step-label']}'); + ExecuteStep('{$aRes['next-step']}'); +EOF + ); + } elseif ($aRes['status'] != ApplicationInstaller::ERROR) { + // Installation complete, move to the next step of the wizard + $oPage->add_ready_script( + <<', $sMessage); + $oPage->add_ready_script( + <<bDependencyCheck)) { + $aSelectedModules = json_decode($this->oWizard->GetParameter('selected_modules'), true); + $this->bDependencyCheck = true; + try { + SetupUtils::AnalyzeInstallation($this->oWizard, true, $aSelectedModules); + } catch (MissingDependencyException $e) { + $this->bDependencyCheck = false; + $this->sDependencyIssue = $e->getHtmlDesc(); + } + } + return $this->bDependencyCheck; + } + + public function GetTitle() + { + return 'Building iTop'; + } + + public function GetPossibleSteps() + { + return ['WizStepDone']; + } + + /** + * Returns the label for the " Next >> " button + * @return string The label for the button + */ + public function GetNextButtonLabel() + { + return 'Install'; + } + + public function CanMoveForward() + { + if ($this->CheckDependencies()) { + return true; + } else { + return false; + } + } + + public function ProcessParams($bMoveForward = true) + { + return ['class' => 'WizStepDone', 'state' => '']; + } + + public function Display(WebPage $oPage) + { + + $aInstallParams = $this->BuildConfig(); + $oPage->add('
Progress of the installation'); $oPage->add('
'); $oPage->LinkScriptFromAppRoot('setup/jquery.progression.js'); @@ -2312,9 +2648,11 @@ class WizStepSummary extends WizardStep $("#params_summary div").addClass('closed'); $("#params_summary .title").on('click', function() { $(this).parent().toggleClass('closed'); } ); $("#btn_next").on("click.install", function(event) { - $('#summary').hide(); - $('#installation_progress').show(); - $(this).prop('disabled', true); event.preventDefault(); ExecuteStep(""); + $('#summary').hide(); + $('#installation_progress').show(); + $(this).prop('disabled', true); + event.preventDefault(); + ExecuteStep(""); }); $("#wiz_form").data("installation_status", "not started") JS @@ -2323,7 +2661,7 @@ JS /** * Prepare the parameters to execute the installation asynchronously - * @return Hash A big hash array that can be converted to XML or JSON with all the needed parameters + * @return array A big hash array that can be converted to XML or JSON with all the needed parameters */ protected function BuildConfig() {