oWizard->SetParameter('mode', 'upgrade'); $this->oWizard->SetParameter('upgrade_type', $sUpgradeType); $bDisplayLicense = $this->oWizard->GetParameter('display_license'); switch ($sUpgradeType) { case 'keep-previous': $sSourceDir = utils::ReadParam('relative_source_dir', '', false, 'raw_data'); $this->oWizard->SetParameter('source_dir', $this->oWizard->GetParameter('previous_version_dir').'/'.$sSourceDir); $this->oWizard->SetParameter('datamodel_version', utils::ReadParam('datamodel_previous_version', '', false, 'raw_data')); break; case 'use-compatible': $sDataModelPath = utils::ReadParam('datamodel_path', '', false, 'raw_data'); $this->oWizard->SetParameter('source_dir', $sDataModelPath); $this->oWizard->SaveParameter('datamodel_version', ''); break; default: // Do nothing, maybe the user pressed the Back button } if ($bDisplayLicense) { $aRet = new WizardState(WizStepLicense2::class); } else { $aRet = new WizardState(WizStepUpgradeMiscParams::class); } return $aRet; } /** * @param WebPage $oPage * * @throws Exception */ public function Display(WebPage $oPage) { $oPage->add_style( <<bCanMoveForward = true; $bDisplayLicense = true; $sPreviousVersionDir = $this->oWizard->GetParameter('previous_version_dir', ''); $aInstalledInfo = SetupUtils::GetApplicationVersion($this->oWizard); if ($aInstalledInfo === false) { throw(new Exception('No previous version of '.ITOP_APPLICATION.' found in the supplied database. The upgrade cannot continue.')); } elseif (strcasecmp($aInstalledInfo['product_name'], ITOP_APPLICATION) != 0) { $oPage->p("Warning: The installed products seem different. Are you sure that you want to upgrade {$aInstalledInfo['product_name']} with ".ITOP_APPLICATION."?"); } $sInstalledVersion = $aInstalledInfo['product_version']; $sInstalledDataModelVersion = $aInstalledInfo['datamodel_version']; $oPage->add("

Information about the upgrade from version $sInstalledVersion to ".ITOP_VERSION_FULL."

"); if ($sInstalledVersion == ITOP_VERSION_FULL) { // Reinstalling the same version let's skip the license agreement... $bDisplayLicense = false; } $this->oWizard->SetParameter('display_license', $bDisplayLicense); // Remember for later $sCompatibleDMDir = SetupUtils::GetLatestDataModelDir(); if ($sCompatibleDMDir === false) { // No compatible version exists... cannot upgrade. Either it is too old, or too new (downgrade !) $this->bCanMoveForward = false; $oPage->p("No datamodel directory found."); } else { $sUpgradeDMVersion = SetupUtils::GetDataModelVersion($sCompatibleDMDir); $sPreviousSourceDir = isset($aInstalledInfo['source_dir']) ? $aInstalledInfo['source_dir'] : 'modules'; $aChanges = false; if (is_dir($sPreviousVersionDir)) { // Check if the previous version is a "genuine" one or not... $aChanges = SetupUtils::CheckVersion($sInstalledDataModelVersion, $sPreviousVersionDir.'/'.$sPreviousSourceDir); } if (($aChanges !== false) && ((count($aChanges['added']) > 0) || (count($aChanges['removed']) > 0) || (count($aChanges['modified']) > 0))) { // Some changes were detected, prompt the user to keep or discard them $oPage->p(" Some modifications were detected between the ".ITOP_APPLICATION." version in '$sPreviousVersionDir' and a genuine $sInstalledVersion version."); $oPage->p("What do you want to do?"); $aWritableDirs = ['modules', 'portal']; $aErrors = SetupUtils::CheckWritableDirs($aWritableDirs); $sChecked = ($this->oWizard->GetParameter('upgrade_type') == 'keep-previous') ? ' checked ' : ''; $sDisabled = (count($aErrors) > 0) ? ' disabled ' : ''; $oPage->p(''); $oPage->add(''); $oPage->add(''); if (count($aErrors) > 0) { $oPage->p("Cannot copy the installed version due to the following access rights issue(s):"); foreach ($aErrors as $sDir => $oCheckResult) { $oPage->p(' '.$oCheckResult->sLabel); } } $sChecked = ($this->oWizard->GetParameter('upgrade_type') == 'use-compatible') ? ' checked ' : ''; $oPage->p(''); $oPage->add(''); $oPage->add(''); $oPage->add('
Details of the modifications
'); if (count($aChanges['added']) > 0) { $oPage->add('
    New files added:'); foreach ($aChanges['added'] as $sFilePath => $void) { $oPage->add('
  • '.$sFilePath.'
  • '); } $oPage->add('
'); } if (count($aChanges['removed']) > 0) { $oPage->add('
    Deleted files:'); foreach ($aChanges['removed'] as $sFilePath => $void) { $oPage->add('
  • '.$sFilePath.'
  • '); } $oPage->add('
'); } if (count($aChanges['modified']) > 0) { $oPage->add('
    Modified files:'); foreach ($aChanges['modified'] as $sFilePath => $void) { $oPage->add('
  • '.$sFilePath.'
  • '); } $oPage->add('
'); } $oPage->add('
'); } else { // No changes detected... or no way to tell because of the lack of a manifest or previous source dir // Use the "compatible" datamodel as-is. $sCompatibleDMDirToDisplay = utils::HtmlEntities($sCompatibleDMDir); $sUpgradeDMVersionToDisplay = utils::HtmlEntities($sUpgradeDMVersion); $oPage->add( <<The datamodel will be upgraded from version $sInstalledDataModelVersion to version $sUpgradeDMVersion. HTML ); } $oPage->add_ready_script( <<oWizard->GetParameter('db_name', '').$this->oWizard->GetParameter('db_prefix', ''), $this->oWizard->GetParameter('db_server', ''), $this->oWizard->GetParameter('db_user', ''), $this->oWizard->GetParameter('db_pwd', ''), $this->oWizard->GetParameter('db_tls_enabled', ''), $this->oWizard->GetParameter('db_tls_ca', '') ); if ($oMutex->IsLocked()) { $oPage->add('
'.ITOP_APPLICATION.' cron process is being executed on the target database. '.ITOP_APPLICATION.' cron process will be stopped during the setup execution.
'); } } } public function CanMoveForward() { return $this->bCanMoveForward; } /** * Tells whether the "Next" button should be enabled interactively * @return string A piece of javascript code returning either true or false */ public function JSCanMoveForward() { return << 0); return bRet; EOF ; } }