mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-25 19:48:49 +02:00
N°9144 Split wizard steps files
This commit is contained in:
254
setup/wizardsteps/WizStepInstallOrUpgrade.php
Normal file
254
setup/wizardsteps/WizStepInstallOrUpgrade.php
Normal file
@@ -0,0 +1,254 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2026 Combodo SAS
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
use Combodo\iTop\Application\WebPage\WebPage;
|
||||
|
||||
/**
|
||||
* Second step of the iTop Installation Wizard: Install or Upgrade
|
||||
*/
|
||||
class WizStepInstallOrUpgrade extends WizardStep
|
||||
{
|
||||
public function GetTitle()
|
||||
{
|
||||
return 'Install or Upgrade choice';
|
||||
}
|
||||
|
||||
public function GetPossibleSteps()
|
||||
{
|
||||
return ['WizStepDetectedInfo', 'WizStepLicense'];
|
||||
}
|
||||
|
||||
public function ProcessParams($bMoveForward = true)
|
||||
{
|
||||
$sNextStep = '';
|
||||
$sInstallMode = utils::ReadParam('install_mode');
|
||||
|
||||
$this->oWizard->SaveParameter('previous_version_dir', '');
|
||||
$this->oWizard->SaveParameter('db_server', '');
|
||||
$this->oWizard->SaveParameter('db_user', '');
|
||||
$this->oWizard->SaveParameter('db_pwd', '');
|
||||
$this->oWizard->SaveParameter('db_name', '');
|
||||
$this->oWizard->SaveParameter('db_prefix', '');
|
||||
$this->oWizard->SaveParameter('db_backup', false);
|
||||
$this->oWizard->SaveParameter('db_backup_path', '');
|
||||
$this->oWizard->SaveParameter('db_tls_enabled', false);
|
||||
$this->oWizard->SaveParameter('db_tls_ca', '');
|
||||
|
||||
if ($sInstallMode == 'install') {
|
||||
$this->oWizard->SetParameter('install_mode', 'install');
|
||||
$sFullSourceDir = SetupUtils::GetLatestDataModelDir();
|
||||
$this->oWizard->SetParameter('source_dir', $sFullSourceDir);
|
||||
$this->oWizard->SetParameter('datamodel_version', SetupUtils::GetDataModelVersion($sFullSourceDir));
|
||||
$sNextStep = 'WizStepLicense';
|
||||
} else {
|
||||
$this->oWizard->SetParameter('install_mode', 'upgrade');
|
||||
$sNextStep = 'WizStepDetectedInfo';
|
||||
|
||||
}
|
||||
return ['class' => $sNextStep, 'state' => ''];
|
||||
}
|
||||
|
||||
public function Display(WebPage $oPage)
|
||||
{
|
||||
$sInstallMode = $this->oWizard->GetParameter('install_mode', '');
|
||||
$sDBServer = $this->oWizard->GetParameter('db_server', '');
|
||||
$sDBUser = $this->oWizard->GetParameter('db_user', '');
|
||||
$sDBPwd = $this->oWizard->GetParameter('db_pwd', '');
|
||||
$sDBName = $this->oWizard->GetParameter('db_name', '');
|
||||
$sDBPrefix = $this->oWizard->GetParameter('db_prefix', '');
|
||||
$bDBBackup = $this->oWizard->GetParameter('db_backup', false);
|
||||
$sDBBackupPath = $this->oWizard->GetParameter('db_backup_path', '');
|
||||
$sTlsEnabled = $this->oWizard->GetParameter('db_tls_enabled', false);
|
||||
$sTlsCA = $this->oWizard->GetParameter('db_tls_ca', '');
|
||||
$sMySQLBinDir = $this->oWizard->GetParameter('mysql_bindir', null);
|
||||
$sPreviousVersionDir = '';
|
||||
if ($sInstallMode == '') {
|
||||
$sDBBackupPath = utils::GetDataPath().'backups/manual/setup-'.date('Y-m-d_H_i');
|
||||
$bDBBackup = true;
|
||||
$aPreviousInstance = SetupUtils::GetPreviousInstance(APPROOT);
|
||||
if ($aPreviousInstance['found']) {
|
||||
$sInstallMode = 'upgrade';
|
||||
$sDBServer = $aPreviousInstance['db_server'];
|
||||
$sDBUser = $aPreviousInstance['db_user'];
|
||||
$sDBPwd = $aPreviousInstance['db_pwd'];
|
||||
$sDBName = $aPreviousInstance['db_name'];
|
||||
$sDBPrefix = $aPreviousInstance['db_prefix'];
|
||||
$sTlsEnabled = $aPreviousInstance['db_tls_enabled'];
|
||||
$sTlsCA = $aPreviousInstance['db_tls_ca'];
|
||||
$this->oWizard->SaveParameter('graphviz_path', $aPreviousInstance['graphviz_path']);
|
||||
$sMySQLBinDir = $aPreviousInstance['mysql_bindir'];
|
||||
$this->oWizard->SaveParameter('mysql_bindir', $aPreviousInstance['mysql_bindir']);
|
||||
$sPreviousVersionDir = APPROOT;
|
||||
} else {
|
||||
$sInstallMode = 'install';
|
||||
}
|
||||
}
|
||||
$sPreviousVersionDir = $this->oWizard->GetParameter('previous_version_dir', $sPreviousVersionDir);
|
||||
|
||||
$sUpgradeInfoStyle = '';
|
||||
if ($sInstallMode == 'install') {
|
||||
$sUpgradeInfoStyle = ' style="display: none;" ';
|
||||
}
|
||||
$oPage->add('<div class="setup-content-title">What do you want to do?</div>');
|
||||
$sChecked = ($sInstallMode == 'install') ? ' checked ' : '';
|
||||
$oPage->p('<input id="radio_install" type="radio" name="install_mode" value="install" '.$sChecked.'/><label for="radio_install"> Install a new '.ITOP_APPLICATION.'</label>');
|
||||
$sChecked = ($sInstallMode == 'upgrade') ? ' checked ' : '';
|
||||
$sDisabled = (($sInstallMode == 'install') && (empty($sPreviousVersionDir))) ? ' disabled' : '';
|
||||
$oPage->p('<input id="radio_update" type="radio" name="install_mode" value="upgrade" '.$sChecked.$sDisabled.'/><label for="radio_update"> Upgrade an existing '.ITOP_APPLICATION.' instance</label>');
|
||||
|
||||
$sUpgradeDir = utils::HtmlEntities($sPreviousVersionDir);
|
||||
$oPage->add(
|
||||
<<<HTML
|
||||
<div id="upgrade_info"'.$sUpgradeInfoStyle.'>
|
||||
<div class="setup-disk-location--input--container">Location on the disk:<input id="previous_version_dir_display" type="text" value="$sUpgradeDir" class="ibo-input" disabled>
|
||||
<input type="hidden" name="previous_version_dir" value="$sUpgradeDir"></div>
|
||||
HTML
|
||||
);
|
||||
|
||||
SetupUtils::DisplayDBParameters(
|
||||
$oPage,
|
||||
false,
|
||||
$sDBServer,
|
||||
$sDBUser,
|
||||
$sDBPwd,
|
||||
$sDBName,
|
||||
$sDBPrefix,
|
||||
$sTlsEnabled,
|
||||
$sTlsCA,
|
||||
null
|
||||
);
|
||||
|
||||
$aBackupChecks = SetupUtils::CheckBackupPrerequisites($sDBBackupPath, $sMySQLBinDir);
|
||||
$bCanBackup = true;
|
||||
$sMySQLDumpMessage = '';
|
||||
foreach ($aBackupChecks as $oCheck) {
|
||||
switch ($oCheck->iSeverity) {
|
||||
case CheckResult::ERROR:
|
||||
$bCanBackup = false;
|
||||
$sMySQLDumpMessage .= '<div class="message message-error"><span class="message-title">Error:</span>'.$oCheck->sLabel.'</div>';
|
||||
break;
|
||||
case CheckResult::TRACE:
|
||||
SetupLog::Ok($oCheck->sLabel);
|
||||
break;
|
||||
default:
|
||||
$sMySQLDumpMessage .= '<div class="message message-valid"><span class="message-title">Success:</span>'.$oCheck->sLabel.'</div>';
|
||||
break;
|
||||
}
|
||||
}
|
||||
$sChecked = ($bCanBackup && $bDBBackup) ? ' checked ' : '';
|
||||
$sDisabled = $bCanBackup ? '' : ' disabled ';
|
||||
$oPage->add('<input id="db_backup" type="checkbox" name="db_backup" '.$sChecked.$sDisabled.' value="1"/><label for="db_backup">Backup the '.ITOP_APPLICATION.' database before upgrading</label>');
|
||||
$oPage->add('<div class="setup-backup--input--container">Save the backup to:<input id="db_backup_path" class="ibo-input" type="text" name="db_backup_path" '.$sDisabled.'value="'.utils::EscapeHtml($sDBBackupPath).'"/></div>');
|
||||
$fFreeSpace = SetupUtils::CheckDiskSpace($sDBBackupPath);
|
||||
$sMessage = '';
|
||||
if ($fFreeSpace !== false) {
|
||||
$sMessage .= SetupUtils::HumanReadableSize($fFreeSpace).' free in '.dirname($sDBBackupPath);
|
||||
}
|
||||
$oPage->add($sMySQLDumpMessage.'<span id="backup_info" style="font-size:small;color:#696969;">'.$sMessage.'</span>');
|
||||
$oPage->add('</div>');
|
||||
$sAuthentToken = $this->oWizard->GetParameter('authent', '');
|
||||
$oPage->add('<input type="hidden" id="authent_token" value="'.$sAuthentToken.'"/>');
|
||||
//$oPage->add('</fieldset>');
|
||||
$oPage->add_ready_script(
|
||||
<<<JS
|
||||
$("#radio_update").on('change', function() { if (this.checked ) { $('#upgrade_info').show(); WizardUpdateButtons(); } else { $('#upgrade_info').hide(); } });
|
||||
$("#radio_install").on('change', function() { if (this.checked ) { $('#upgrade_info').hide(); WizardUpdateButtons(); } else { $('#upgrade_info').show(); } });
|
||||
$("#db_backup_path").on('change keyup', function() { WizardAsyncAction('check_backup', { db_backup_path: $('#db_backup_path').val() }); });
|
||||
JS
|
||||
);
|
||||
}
|
||||
|
||||
public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
|
||||
{
|
||||
switch ($sCode) {
|
||||
case 'check_path':
|
||||
$sPreviousVersionDir = $aParameters['previous_version_dir'];
|
||||
$aPreviousInstance = SetupUtils::GetPreviousInstance($sPreviousVersionDir);
|
||||
if ($aPreviousInstance['found']) {
|
||||
$sDBServer = utils::EscapeHtml($aPreviousInstance['db_server']);
|
||||
$sDBUser = utils::EscapeHtml($aPreviousInstance['db_user']);
|
||||
$sDBPwd = utils::EscapeHtml($aPreviousInstance['db_pwd']);
|
||||
$sDBName = utils::EscapeHtml($aPreviousInstance['db_name']);
|
||||
$sDBPrefix = utils::EscapeHtml($aPreviousInstance['db_prefix']);
|
||||
$oPage->add_ready_script(
|
||||
<<<EOF
|
||||
$("#db_server").val('$sDBServer');
|
||||
$("#db_user").val('$sDBUser');
|
||||
$("#db_pwd").val('$sDBPwd');
|
||||
$("#db_name").val('$sDBName');
|
||||
$("#db_prefix").val('$sDBPrefix');
|
||||
$("#db_pwd").trigger('change'); // Forces check of the DB connection
|
||||
EOF
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'check_db':
|
||||
SetupUtils::AsyncCheckDB($oPage, $aParameters);
|
||||
break;
|
||||
|
||||
case 'check_backup':
|
||||
$sDBBackupPath = $aParameters['db_backup_path'];
|
||||
$fFreeSpace = SetupUtils::CheckDiskSpace($sDBBackupPath);
|
||||
if ($fFreeSpace !== false) {
|
||||
$sMessage = utils::EscapeHtml(SetupUtils::HumanReadableSize($fFreeSpace).' free in '.dirname($sDBBackupPath));
|
||||
$oPage->add_ready_script(
|
||||
<<<EOF
|
||||
$("#backup_info").html('$sMessage');
|
||||
EOF
|
||||
);
|
||||
} else {
|
||||
$oPage->add_ready_script(
|
||||
<<<EOF
|
||||
$("#backup_info").html('');
|
||||
EOF
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
<<<EOF
|
||||
if ($("#radio_install").prop("checked"))
|
||||
{
|
||||
ValidateField("db_name", false);
|
||||
ValidateField("db_new_name", false);
|
||||
ValidateField("db_prefix", false);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var bRet = ($("#wiz_form").data("db_connection") !== "error");
|
||||
bRet = ValidateField("db_name", true) && bRet;
|
||||
bRet = ValidateField("db_new_name", true) && bRet;
|
||||
bRet = ValidateField("db_prefix", true) && bRet;
|
||||
|
||||
return bRet;
|
||||
}
|
||||
EOF
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user