Get('target_env', 'production'); $oRunTimeEnvironment = new RunTimeEnvironment($sEnvironment, false); } $this->oRunTimeEnvironment = $oRunTimeEnvironment; $this->oParams = $oParams; $aParamValues = $oParams->GetParamForConfigArray(); $this->oConfig = new Config(); $this->oConfig->UpdateFromParams($aParamValues); utils::SetConfig($this->oConfig); } public function LogStep($sStep, $aResult) { $this->aStepsHistory[] = ['step' => $sStep, 'result' => $aResult]; } public function GetHistory() { return $this->aStepsHistory; } /** * Runs all the installation steps in one go and directly outputs * some information about the progress and the success of the various * sequential steps. * * @param bool $bVerbose * @param string|null $sMessage * @param string|null $sComment * * @return boolean True if the installation was successful, false otherwise */ public function ExecuteAllSteps(bool $bVerbose = true, ?string &$sMessage = null, ?string $sComment = null) { $sStep = ''; $sStepLabel = ''; $iOverallStatus = self::OK; do { if ($bVerbose) { if ($sStep != '') { echo "$sStepLabel\n"; echo "Executing '$sStep'\n"; } else { echo "Starting...\n"; } } $aRes = $this->ExecuteStep($sStep, $sComment); $this->LogStep($sStep, $aRes); $sStep = $aRes['next-step']; $sStepLabel = $aRes['next-step-label']; $sMessage = $aRes['message']; if ($bVerbose) { switch ($aRes['status']) { case self::OK: echo "Ok. ".$aRes['percentage-completed']." % done.\n"; break; case self::ERROR: $iOverallStatus = self::ERROR; echo "Error: ".$aRes['message']."\n"; break; case self::WARNING: $iOverallStatus = self::WARNING; echo "Warning: ".$aRes['message']."\n"; echo $aRes['percentage-completed']." % done.\n"; break; case self::INFO: echo "Info: ".$aRes['message']."\n"; echo $aRes['percentage-completed']." % done.\n"; break; } } else { switch ($aRes['status']) { case self::ERROR: $iOverallStatus = self::ERROR; break; case self::WARNING: $iOverallStatus = self::WARNING; break; } } } while (($aRes['status'] != self::ERROR) && ($aRes['next-step'] != '')); return ($iOverallStatus == self::OK); } protected function GetNextStep(string $sNextStep, string $sNextStepLabel, int $iPercentComplete, string $sMessage = '', int $iStatus = self::OK): array { return [ 'status' => $iStatus, 'message' => $sMessage, 'next-step' => $sNextStep, 'next-step-label' => $sNextStepLabel, 'percentage-completed' => $iPercentComplete, ]; } protected function DoLogParameters($sPrefix = 'install-', $sOperation = 'Installation') { // Log the parameters... $oDoc = new DOMDocument('1.0', 'UTF-8'); $oDoc->preserveWhiteSpace = false; $oDoc->formatOutput = true; $this->oParams->ToXML($oDoc, null, 'installation'); $sXML = $oDoc->saveXML(); $sSafeXml = preg_replace('|([^<]*)|', '**removed**', $sXML); SetupLog::Info('======= '.$sOperation." starts =======\nParameters:\n$sSafeXml\n"); // Save the response file as a stand-alone file as well $sFileName = $sPrefix.date('Y-m-d'); $index = 0; while (file_exists(APPROOT.'log/'.$sFileName.'.xml')) { $index++; $sFileName = $sPrefix.date('Y-m-d').'-'.$index; } file_put_contents(APPROOT.'log/'.$sFileName.'.xml', $sSafeXml); } protected function GetConfig() { $sTargetEnvironment = $this->oRunTimeEnvironment->GetBuildEnv(); $sConfigFile = APPCONF.$sTargetEnvironment.'/'.ITOP_CONFIG_FILE; try { $oConfig = new Config($sConfigFile); } catch (Exception $e) { return null; } $aParamValues = $this->oParams->GetParamForConfigArray(); $oConfig->UpdateFromParams($aParamValues); return $oConfig; } /** * Executes the next step of the installation and reports about the progress * and the next step to perform * * @param string $sStep The identifier of the step to execute * @param string|null $sInstallComment * * @return array (status => , message => , percentage-completed => , next-step => , next-step-label => ) */ abstract public function ExecuteStep($sStep = '', $sInstallComment = null): array; }