From cb57335c0bd34a87e200e5eaed6245f61a8c2e20 Mon Sep 17 00:00:00 2001 From: Denis Flaven Date: Thu, 27 Sep 2012 10:53:45 +0000 Subject: [PATCH] Work in progress on the 2.0 setup/ the "install from scratch" is complete. SVN:trunk[2219] --- setup/parameters.class.inc.php | 53 ++++ setup/setuputils.class.inc.php | 47 +++- setup/wizardsteps.class.inc.php | 439 ++++++++++++++++++++++++++++---- 3 files changed, 482 insertions(+), 57 deletions(-) diff --git a/setup/parameters.class.inc.php b/setup/parameters.class.inc.php index 24b06b41d..c49889f21 100644 --- a/setup/parameters.class.inc.php +++ b/setup/parameters.class.inc.php @@ -37,6 +37,59 @@ class PHPParameters extends Parameters $this->aData = $ITOP_PARAMS; } } + + public function ToXML(DOMNode $oRoot, $data = null, $sNodeName = null) + { + if ($data === null) + { + $data = $this->aData; + } + + if (is_array($data)) + { + if ($oRoot instanceof DOMDocument) + { + $oNode = $oRoot->createElement($sNodeName); + } + else + { + $oNode = $oRoot->ownerDocument->createElement($sNodeName); + } + $oRoot->appendChild($oNode); + + $aKeys = array_keys($data); + $bNumericKeys = true; + foreach($aKeys as $idx => $subkey) + { + if(((int)$subkey) !== $subkey) + { + $bNumericKeys = false; + break; + } + } + if ($bNumericKeys) + { + $oNode->setAttribute("type", "array"); + foreach($data as $key => $value) + { + $this->ToXML($oNode, $value , 'item'); + } + } + else + { + foreach($data as $key => $value) + { + $this->ToXML($oNode, $value , $key); + } + } + } + else + { + $oNode = $oRoot->ownerDocument->createElement($sNodeName, $data); + $oRoot->appendChild($oNode); + } + return $oNode; + } } class XMLParameters extends Parameters diff --git a/setup/setuputils.class.inc.php b/setup/setuputils.class.inc.php index c2740bc91..a584eae2b 100644 --- a/setup/setuputils.class.inc.php +++ b/setup/setuputils.class.inc.php @@ -667,8 +667,29 @@ function ValidateField(sFieldId, bUsed) { if (sValue.match(/^[A-Za-z][A-Za-z0-9_]*$/)) { - $("#v_"+sFieldId).html(""); - return true; + var bCollision = false; + if (sFieldId == 'db_new_name') + { + // check that the "new name" does not correspond to an existing database + var sNewName = $('#db_new_name').val(); + $('#db_name option').each( function() { + if ($(this).attr('value') == sNewName) + { + bCollision = true; + } + }); + } + + if (bCollision) + { + $("#v_"+sFieldId).html(''); + return false; + } + else + { + $("#v_"+sFieldId).html(""); + return true; + } } else { @@ -883,4 +904,26 @@ EOF return $sHtml; } + + public static function AnalyzeInstallation($oWizard) + { + require_once(APPROOT.'/setup/moduleinstaller.class.inc.php'); + $oConfig = new Config(); + + $aParamValues = array( + 'db_server' => $oWizard->GetParameter('db_server', ''), + 'db_user' => $oWizard->GetParameter('db_user', ''), + 'db_pwd' => $oWizard->GetParameter('db_server', ''), + 'db_name' => $oWizard->GetParameter('db_name', ''), + 'db_prefix' => $oWizard->GetParameter('db_prefix', ''), + 'source_dir' => APPROOT.'datamodel', + ); + $oConfig->UpdateFromParams($aParamValues, 'datamodel'); + + $oProductionEnv = new RunTimeEnvironment(); + $oConfig = new Config(); + $aAvailableModules = $oProductionEnv->AnalyzeInstallation($oConfig, 'datamodel'); + + return $aAvailableModules; + } } \ No newline at end of file diff --git a/setup/wizardsteps.class.inc.php b/setup/wizardsteps.class.inc.php index eb1ab618f..aa821718f 100644 --- a/setup/wizardsteps.class.inc.php +++ b/setup/wizardsteps.class.inc.php @@ -230,17 +230,33 @@ class WizStepInstallOrUpgrade extends WizardStep $oPage->add('Location on the disk:'); SetupUtils::DisplayDBParameters($oPage, false, $sDBServer, $sDBUser, $sDBPwd, $sDBName, $sDBPrefix); - $sChecked = ($bDBBackup == 'install') ? ' checked ' : ''; - $oPage->add('Backup the '.ITOP_APPLICATION.' database before upgrading'); - $oPage->add('Save the backup to:'); + $aBackupChecks = SetupUtils::CheckBackupPrerequisites($sDBBackupPath); + $bCanBackup = true; + $sMySQLDumpMessage = ''; + foreach($aBackupChecks as $oCheck) + { + if ($oCheck->iSeverity == CheckResult::ERROR) + { + $bCanBackup = false; + $sMySQLDumpMessage .= '  Warning: '.$oCheck->sLabel; + } + else + { + $sMySQLDumpMessage .= ' '.$oCheck->sLabel.' '; + } + } + $sChecked = ($bCanBackup && ($bDBBackup == 'install')) ? ' checked ' : ''; + $sDisabled = $bCanBackup ? '' : ' disabled '; + $oPage->add(' Backup the '.ITOP_APPLICATION.' database before upgrading'); + $oPage->add('Save the backup to: '); $fFreeSpace = SetupUtils::CheckDiskSpace($sDBBackupPath); $sMessage = ''; if ($fFreeSpace !== false) { - $sMessage = SetupUtils::HumanReadableSize($fFreeSpace).' free in '.dirname($sDBBackupPath); + $sMessage .= SetupUtils::HumanReadableSize($fFreeSpace).' free in '.dirname($sDBBackupPath); } - $oPage->add(' '); - $oPage->add(''.$sMessage.''); + $oPage->add(''); + $oPage->add($sMySQLDumpMessage.'
'.$sMessage.''); $oPage->add(''); //$oPage->add(''); $oPage->add_ready_script( @@ -615,8 +631,8 @@ class WizStepAdminAccount extends WizardStep $oPage->add('
'); $oPage->add('Administrator Account'); $oPage->add(''); - $oPage->add(''); - $oPage->add(''); + $oPage->add(''); + $oPage->add(''); $oPage->add(''); $sSourceDir = APPROOT.'dictionaries/'; $aLanguages = SetupUtils::GetAvailableLanguages($sSourceDir); @@ -625,8 +641,48 @@ class WizStepAdminAccount extends WizardStep $oPage->add(''); $oPage->add('
Login:
Password:
Login:
Password:
Confirm password:
'); $oPage->add('
'); + $oPage->add_ready_script( +<<'); + } + else + { + $("#v_admin_user").html(''); + } + + bPasswordsMatch = ($('#admin_pwd').val() == $('#confirm_pwd').val()); + if (!bPasswordsMatch) + { + $('#v_admin_pwd').html(''); + } + else + { + $('#v_admin_pwd').html(''); + } + bRet = bPasswordsMatch && bRet; + + return bRet; +EOF + ; + }} /** * Miscellaneous Parameters (URL, Sample Data) @@ -670,7 +726,8 @@ class WizStepMiscParams extends WizardStep $oPage->add('
'); $oPage->add('Application URL'); $oPage->add(''); - $oPage->add(''); + $oPage->add(''); + $oPage->add(''); $oPage->add('
URL:
URL:
Change the value above if the end-users will be accessing the application by another path due to a specific configuration of the web server.
'); $oPage->add('
'); $oPage->add('
'); @@ -682,6 +739,33 @@ class WizStepMiscParams extends WizardStep $oPage->p('
'); + $oPage->add_ready_script( +<<'); + } + else + { + $("#v_application_url").html(''); + } + return bRet; +EOF + ; } } @@ -704,7 +788,7 @@ class WizStepModulesChoice extends WizardStep public function ProcessParams($bMoveForward = true) { - // Accumualtes the selected modules: + // Accumulates the selected modules: $index = $this->GetStepIndex(); // use json_encode:decode to store a hash array: step_id => array(input_name => selected_input_id) @@ -727,12 +811,15 @@ class WizStepModulesChoice extends WizardStep { // Exiting this step of the wizard, let's convert the selection into a list of modules $aModules = array(); + $sDisplayChoices = '
    '; for($i = 0; $i <= $index; $i++) { $aStepInfo = $this->GetStepInfo($i); - $this->GetSelectedModules($aStepInfo, $aSelectedChoices[$i], $aModules); + $sDisplayChoices .= $this->GetSelectedModules($aStepInfo, $aSelectedChoices[$i], $aModules); } + $sDisplayChoices .= '
'; $this->oWizard->SetParameter('selected_modules', json_encode(array_keys($aModules))); + $this->oWizard->SetParameter('display_choices', $sDisplayChoices); return array('class' => 'WizStepSummary', 'state' => ''); } @@ -749,6 +836,7 @@ class WizStepModulesChoice extends WizardStep $aStepInfo = $this->GetStepInfo(); $oPage->add_style("div.choice { margin: 0.5em;}"); $oPage->add_style("div.description { margin-left: 2em; }"); + $oPage->add_style(".choice-disabled { color: #999; }"); $oPage->add(''); $sBannerPath = isset($aStepInfo['banner']) ? $aStepInfo['banner'] : ''; if (!empty($sBannerPath)) @@ -788,6 +876,62 @@ class WizStepModulesChoice extends WizardStep $oPage->add('
'); $this->DisplayOptions($oPage, $aStepInfo, $aSelectedComponents); $oPage->add('
'); + + $oPage->add_script( +<<add_ready_script( +<<
'); + $oPage->add(""); + $oPage->add(""); + $oPage->add(""); + $oPage->add('
'); + $sForm = '
'; + $sForm .= ''; + $sForm .= ''; + $sForm .= "

"; + $sForm .= '
'; $oPage->add(''); + $sForm = addslashes($sForm); + $oPage->add_ready_script("$('#wiz_form').after('$sForm');"); } public function CanMoveForward()