public static function GetMySQLVersion($sDBServer, $sDBUser, $sDBPwd) { $oDBSource = new CMDBSource(); $oDBSource->Init($sDBServer, $sDBUser, $sDBPwd); $sDBVersion = $oDBSource->GetDBVersion(); return $sDBVersion; }
public function GetApplicationVersion(Config $oConfig) { $aResult = false; try { require_once APPROOT . '/core/cmdbsource.class.inc.php'; CMDBSource::Init($oConfig->GetDBHost(), $oConfig->GetDBUser(), $oConfig->GetDBPwd(), $oConfig->GetDBName()); CMDBSource::SetCharacterSet($oConfig->GetDBCharacterSet(), $oConfig->GetDBCollation()); $sSQLQuery = "SELECT * FROM " . $oConfig->GetDBSubname() . "priv_module_install"; $aSelectInstall = CMDBSource::QueryToArray($sSQLQuery); } catch (MySQLException $e) { // No database or erroneous information $this->log_error('Can not connect to the database: host: ' . $oConfig->GetDBHost() . ', user:'******', pwd:' . $oConfig->GetDBPwd() . ', db name:' . $oConfig->GetDBName()); $this->log_error('Exception ' . $e->getMessage()); return false; } // Scan the list of installed modules to get the version of the 'ROOT' module which holds the main application version foreach ($aSelectInstall as $aInstall) { $sModuleVersion = $aInstall['version']; if ($sModuleVersion == '') { // Though the version cannot be empty in iTop 2.0, it used to be possible // therefore we have to put something here or the module will not be considered // as being installed $sModuleVersion = '0.0.0'; } if ($aInstall['parent_id'] == 0) { if ($aInstall['name'] == DATAMODEL_MODULE) { $aResult['datamodel_version'] = $sModuleVersion; $aComments = json_decode($aInstall['comment'], true); if (is_array($aComments)) { $aResult = array_merge($aResult, $aComments); } } else { $aResult['product_name'] = $aInstall['name']; $aResult['product_version'] = $sModuleVersion; } } } if (!array_key_exists('datamodel_version', $aResult)) { // Versions prior to 2.0 did not record the version of the datamodel // so assume that the datamodel version is equal to the application version $aResult['datamodel_version'] = $aResult['product_version']; } $this->log_info("GetApplicationVersion returns: product_name: " . $aResult['product_name'] . ', product_version: ' . $aResult['product_version']); return $aResult; }
public static function LoadConfig($oConfiguration, $bAllowCache = false) { self::$m_oConfig = $oConfiguration; // Set log ASAP if (self::$m_oConfig->GetLogGlobal()) { if (self::$m_oConfig->GetLogIssue()) { self::$m_bLogIssue = true; IssueLog::Enable(APPROOT . 'log/error.log'); } self::$m_bLogNotification = self::$m_oConfig->GetLogNotification(); self::$m_bLogWebService = self::$m_oConfig->GetLogWebService(); ToolsLog::Enable(APPROOT . 'log/tools.log'); } else { self::$m_bLogIssue = false; self::$m_bLogNotification = false; self::$m_bLogWebService = false; } ExecutionKPI::EnableDuration(self::$m_oConfig->Get('log_kpi_duration')); ExecutionKPI::EnableMemory(self::$m_oConfig->Get('log_kpi_memory')); ExecutionKPI::SetAllowedUser(self::$m_oConfig->Get('log_kpi_user_id')); self::$m_bSkipCheckToWrite = self::$m_oConfig->Get('skip_check_to_write'); self::$m_bSkipCheckExtKeys = self::$m_oConfig->Get('skip_check_ext_keys'); self::$m_bUseAPCCache = $bAllowCache && self::$m_oConfig->Get('apc_cache.enabled') && function_exists('apc_fetch') && function_exists('apc_store'); DBSearch::EnableQueryCache(self::$m_oConfig->GetQueryCacheEnabled(), self::$m_bUseAPCCache, self::$m_oConfig->Get('apc_cache.query_ttl')); DBSearch::EnableQueryTrace(self::$m_oConfig->GetLogQueries()); DBSearch::EnableQueryIndentation(self::$m_oConfig->Get('query_indentation_enabled')); DBSearch::EnableOptimizeQuery(self::$m_oConfig->Get('query_optimization_enabled')); // PHP timezone first... // $sPHPTimezone = self::$m_oConfig->Get('timezone'); if ($sPHPTimezone == '') { // Leave as is... up to the admin to set a value somewhere... //$sPHPTimezone = date_default_timezone_get(); } else { date_default_timezone_set($sPHPTimezone); } // Note: load the dictionary as soon as possible, because it might be // needed when some error occur $sAppIdentity = 'itop-' . MetaModel::GetEnvironmentId(); $bDictInitializedFromData = false; if (!self::$m_bUseAPCCache || !Dict::InCache($sAppIdentity)) { $bDictInitializedFromData = true; foreach (self::$m_oConfig->GetDictionaries() as $sModule => $sToInclude) { self::IncludeModule('dictionaries', $sToInclude); } } // Set the language... after the dictionaries have been loaded! Dict::SetDefaultLanguage(self::$m_oConfig->GetDefaultLanguage()); // Romain: this is the only way I've found to cope with the fact that // classes have to be derived from cmdbabstract (to be editable in the UI) require_once APPROOT . '/application/cmdbabstract.class.inc.php'; foreach (self::$m_oConfig->GetAppModules() as $sModule => $sToInclude) { self::IncludeModule('application', $sToInclude); } foreach (self::$m_oConfig->GetDataModels() as $sModule => $sToInclude) { self::IncludeModule('business', $sToInclude); } foreach (self::$m_oConfig->GetWebServiceCategories() as $sModule => $sToInclude) { self::IncludeModule('webservice', $sToInclude); } foreach (self::$m_oConfig->GetAddons() as $sModule => $sToInclude) { self::IncludeModule('addons', $sToInclude); } $sServer = self::$m_oConfig->GetDBHost(); $sUser = self::$m_oConfig->GetDBUser(); $sPwd = self::$m_oConfig->GetDBPwd(); $sSource = self::$m_oConfig->GetDBName(); $sTablePrefix = self::$m_oConfig->GetDBSubname(); $sCharacterSet = self::$m_oConfig->GetDBCharacterSet(); $sCollation = self::$m_oConfig->GetDBCollation(); if (self::$m_bUseAPCCache) { $oKPI = new ExecutionKPI(); // Note: For versions of APC older than 3.0.17, fetch() accepts only one parameter // $sOqlAPCCacheId = 'itop-' . MetaModel::GetEnvironmentId() . '-metamodel'; $result = apc_fetch($sOqlAPCCacheId); if (is_array($result)) { // todo - verifier que toutes les classes mentionnees ici sont chargees dans InitClasses() self::$m_aExtensionClasses = $result['m_aExtensionClasses']; self::$m_Category2Class = $result['m_Category2Class']; self::$m_aRootClasses = $result['m_aRootClasses']; self::$m_aParentClasses = $result['m_aParentClasses']; self::$m_aChildClasses = $result['m_aChildClasses']; self::$m_aClassParams = $result['m_aClassParams']; self::$m_aAttribDefs = $result['m_aAttribDefs']; self::$m_aAttribOrigins = $result['m_aAttribOrigins']; self::$m_aExtKeyFriends = $result['m_aExtKeyFriends']; self::$m_aIgnoredAttributes = $result['m_aIgnoredAttributes']; self::$m_aFilterDefs = $result['m_aFilterDefs']; self::$m_aFilterOrigins = $result['m_aFilterOrigins']; self::$m_aListInfos = $result['m_aListInfos']; self::$m_aListData = $result['m_aListData']; self::$m_aRelationInfos = $result['m_aRelationInfos']; self::$m_aStates = $result['m_aStates']; self::$m_aStimuli = $result['m_aStimuli']; self::$m_aTransitions = $result['m_aTransitions']; self::$m_aHighlightScales = $result['m_aHighlightScales']; } $oKPI->ComputeAndReport('Metamodel APC (fetch + read)'); } if (count(self::$m_aAttribDefs) == 0) { // The includes have been included, let's browse the existing classes and // develop some data based on the proposed model $oKPI = new ExecutionKPI(); self::InitClasses($sTablePrefix); $oKPI->ComputeAndReport('Initialization of Data model structures'); if (self::$m_bUseAPCCache) { $oKPI = new ExecutionKPI(); $aCache = array(); $aCache['m_aExtensionClasses'] = self::$m_aExtensionClasses; $aCache['m_Category2Class'] = self::$m_Category2Class; $aCache['m_aRootClasses'] = self::$m_aRootClasses; // array of "classname" => "rootclass" $aCache['m_aParentClasses'] = self::$m_aParentClasses; // array of ("classname" => array of "parentclass") $aCache['m_aChildClasses'] = self::$m_aChildClasses; // array of ("classname" => array of "childclass") $aCache['m_aClassParams'] = self::$m_aClassParams; // array of ("classname" => array of class information) $aCache['m_aAttribDefs'] = self::$m_aAttribDefs; // array of ("classname" => array of attributes) $aCache['m_aAttribOrigins'] = self::$m_aAttribOrigins; // array of ("classname" => array of ("attcode"=>"sourceclass")) $aCache['m_aExtKeyFriends'] = self::$m_aExtKeyFriends; // array of ("classname" => array of ("indirect ext key attcode"=> array of ("relative ext field"))) $aCache['m_aIgnoredAttributes'] = self::$m_aIgnoredAttributes; //array of ("classname" => array of ("attcode") $aCache['m_aFilterDefs'] = self::$m_aFilterDefs; // array of ("classname" => array filterdef) $aCache['m_aFilterOrigins'] = self::$m_aFilterOrigins; // array of ("classname" => array of ("attcode"=>"sourceclass")) $aCache['m_aListInfos'] = self::$m_aListInfos; // array of ("listcode" => various info on the list, common to every classes) $aCache['m_aListData'] = self::$m_aListData; // array of ("classname" => array of "listcode" => list) $aCache['m_aRelationInfos'] = self::$m_aRelationInfos; // array of ("relcode" => various info on the list, common to every classes) $aCache['m_aStates'] = self::$m_aStates; // array of ("classname" => array of "statecode"=>array('label'=>..., attribute_inherit=> attribute_list=>...)) $aCache['m_aStimuli'] = self::$m_aStimuli; // array of ("classname" => array of ("stimuluscode"=>array('label'=>...))) $aCache['m_aTransitions'] = self::$m_aTransitions; // array of ("classname" => array of ("statcode_from"=>array of ("stimuluscode" => array('target_state'=>..., 'actions'=>array of handlers procs, 'user_restriction'=>TBD))) $aCache['m_aHighlightScales'] = self::$m_aHighlightScales; // array of ("classname" => array of higlightcodes))) apc_store($sOqlAPCCacheId, $aCache); $oKPI->ComputeAndReport('Metamodel APC (store)'); } } if (self::$m_bUseAPCCache && $bDictInitializedFromData) { Dict::InitCache($sAppIdentity); } self::$m_sDBName = $sSource; self::$m_sTablePrefix = $sTablePrefix; CMDBSource::Init($sServer, $sUser, $sPwd); // do not select the DB (could not exist) CMDBSource::SetCharacterSet($sCharacterSet, $sCollation); // Later when timezone implementation is correctly done: CMDBSource::SetTimezone($sDBTimezone); }
protected function DoPrepare() { $sDBHost = $this->GetDBHost(); $sDBUser = $this->GetDBUser(); $sDBPwd = $this->GetDBPwd(); $sDBName = $this->GetDBName(); CMDBSource::Init($sDBHost, $sDBUser, $sDBPwd); CMDBSource::SetCharacterSet(); if (CMDBSource::IsDB($sDBName)) { CMDBSource::DropDB($sDBName); } CMDBSource::CreateDB($sDBName); }