EnterReadOnlyMode(); switch ($sStep) { case '': return $this->GetNextStep('log-parameters', 'Log parameters', 0); case 'log-parameters': if (array_key_exists('log-parameters', $this->oParams->Get('optional_steps', []))) { $this->DoLogParameters(); } return $this->GetNextStep('backup', 'Performing a backup of the database', 20); case 'backup': if (array_key_exists('backup', $this->oParams->Get('optional_steps', []))) { $aBackupOptions = $this->oParams->Get('optional_steps')['backup']; // __DB__-%Y-%m-%d $sDestination = $aBackupOptions['destination']; $sSourceConfigFile = $aBackupOptions['configuration_file']; $sMySQLBinDir = $this->oParams->Get('mysql_bindir', null); $this->oRunTimeEnvironment->Backup($this->oConfig, $sDestination, $sSourceConfigFile, $sMySQLBinDir); } return $this->GetNextStep('migrate-before', 'Migrate data before database upgrade', 30); case 'migrate-before': if (array_key_exists('migrate-before', $this->oParams->Get('optional_steps', []))) { $this->oRunTimeEnvironment->MigrateDataBeforeUpdateStructure($this->oParams->Get('mode'), $this->GetConfig()); } return $this->GetNextStep('db-schema', 'Updating database schema', 40); case 'db-schema': $aSelectedModules = $this->oParams->Get('selected_modules', []); $this->DoUpdateDBSchema($this->GetConfig(), $aSelectedModules); return $this->GetNextStep('migrate-after', 'Migrate data after database upgrade', 50); case 'migrate-after': if (array_key_exists('migrate-after', $this->oParams->Get('optional_steps', []))) { $this->oRunTimeEnvironment->MigrateDataAfterUpdateStructure($this->oParams->Get('mode'), $this->GetConfig()); } return $this->GetNextStep('after-db-create', 'Load data after database create', 60); case 'after-db-create': $aAdminParams = $this->oParams->Get('admin_account'); $aSelectedModules = $this->oParams->Get('selected_modules', []); $sMode = $this->oParams->Get('mode'); $this->oRunTimeEnvironment->AfterDBCreate($this->GetConfig(), $sMode, $aSelectedModules, $aAdminParams); return $this->GetNextStep('load-data', 'Loading data', 70); case 'load-data': $aSelectedModules = $this->oParams->Get('selected_modules', []); $bSampleData = ($this->oParams->Get('sample_data', 0) == 1); $this->oRunTimeEnvironment->DoLoadData($this->GetConfig(), $bSampleData, $aSelectedModules); return $this->GetNextStep('create-config', 'Creating the configuration File', 80, 'All data loaded'); case 'create-config': $sDataModelVersion = $this->oParams->Get('datamodel_version', '0.0.0'); $aSelectedModuleCodes = $this->oParams->Get('selected_modules', []); $aSelectedExtensionCodes = $this->oParams->Get('selected_extensions', []); $this->oRunTimeEnvironment->DoCreateConfig( $this->GetConfig(), $sDataModelVersion, $aSelectedModuleCodes, $aSelectedExtensionCodes, $sInstallComment ); return $this->GetNextStep('commit', 'Finalize', 95); case 'commit': $this->oRunTimeEnvironment->Commit(); return $this->GetNextStep('', 'Completed', 100); default: return $this->GetNextStep('', "Unknown setup step '$sStep'.", 100, '', self::ERROR); } } catch (Exception $e) { SetupLog::Exception("$sStep failed", $e); $aResult = $this->GetNextStep('', '', 100, $e->getMessage(), self::ERROR); $aResult['error_code'] = $e->getCode(); return $aResult; } finally { $this->ExitReadOnlyMode(); $fDuration = round(microtime(true) - $fStart, 2); SetupLog::Info("##### STEP {$sStep} duration: {$fDuration}s"); } } protected function EnterReadOnlyMode() { if ($this->oRunTimeEnvironment->GetFinalEnv() != 'production') { return; } if (SetupUtils::IsInReadOnlyMode()) { return; } SetupUtils::EnterReadOnlyMode($this->GetConfig()); } protected function ExitReadOnlyMode() { if ($this->oRunTimeEnvironment->GetFinalEnv() != 'production') { return; } if (!SetupUtils::IsInReadOnlyMode()) { return; } SetupUtils::ExitReadOnlyMode(); } /** * @param \Config $oConfig * @param $aSelectedModules * * @throws \CoreException * @throws \DictExceptionUnknownLanguage * @throws \MySQLException * @throws \MySQLHasGoneAwayException * @throws \OQLException */ protected function DoUpdateDBSchema(Config $oConfig, $aSelectedModules) { $sTargetEnvironment = $this->oRunTimeEnvironment->GetBuildEnv(); $aParamValues = $this->oParams->GetParamForConfigArray(); SetupLog::Info("Update Database Schema for environment '$sTargetEnvironment'."); $sMode = $aParamValues['mode']; $this->oRunTimeEnvironment->UpdateDBSchema($oConfig, $sMode, $aSelectedModules); $oConfig->Set('access_mode', ACCESS_FULL); // Set a DBProperty with a unique ID to identify this instance of iTop $sUUID = DBProperty::GetProperty('database_uuid', ''); if ($sUUID === '') { $sUUID = utils::CreateUUID('database'); DBProperty::SetProperty('database_uuid', $sUUID, 'Installation/upgrade of '.ITOP_APPLICATION, 'Unique ID of this '.ITOP_APPLICATION.' Database'); } SetupLog::Info("Database Schema Successfully Updated for environment '$sTargetEnvironment'."); } }