Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
function MakeDictionaryTemplate($sModules = '', $sLanguage = 'EN US')
{
    $sRes = '';
    Dict::SetDefaultLanguage($sLanguage);
    $aAvailableLanguages = Dict::GetLanguages();
    $sDesc = $aAvailableLanguages[$sLanguage]['description'];
    $sLocalizedDesc = $aAvailableLanguages[$sLanguage]['localized_description'];
    $sRes .= "// Dictionary conventions\n";
    $sRes .= htmlentities("// Class:<class_name>\n", ENT_QUOTES, 'UTF-8');
    $sRes .= htmlentities("// Class:<class_name>+\n", ENT_QUOTES, 'UTF-8');
    $sRes .= htmlentities("// Class:<class_name>/Attribute:<attribute_code>\n", ENT_QUOTES, 'UTF-8');
    $sRes .= htmlentities("// Class:<class_name>/Attribute:<attribute_code>+\n", ENT_QUOTES, 'UTF-8');
    $sRes .= htmlentities("// Class:<class_name>/Attribute:<attribute_code>/Value:<value>\n", ENT_QUOTES, 'UTF-8');
    $sRes .= htmlentities("// Class:<class_name>/Attribute:<attribute_code>/Value:<value>+\n", ENT_QUOTES, 'UTF-8');
    $sRes .= htmlentities("// Class:<class_name>/Stimulus:<stimulus_code>\n", ENT_QUOTES, 'UTF-8');
    $sRes .= htmlentities("// Class:<class_name>/Stimulus:<stimulus_code>+\n", ENT_QUOTES, 'UTF-8');
    $sRes .= "\n";
    // Note: I did not use EnumCategories(), because a given class maybe found in several categories
    // Need to invent the "module", to characterize the origins of a class
    if (strlen($sModules) == 0) {
        $aModules = array('bizmodel', 'core/cmdb', 'gui', 'application', 'addon/userrights', 'monitoring');
    } else {
        $aModules = explode(', ', $sModules);
    }
    $sRes .= "//////////////////////////////////////////////////////////////////////\n";
    $sRes .= "// Note: The classes have been grouped by categories: " . implode(', ', $aModules) . "\n";
    $sRes .= "//////////////////////////////////////////////////////////////////////\n";
    foreach ($aModules as $sCategory) {
        $sRes .= "//////////////////////////////////////////////////////////////////////\n";
        $sRes .= "// Classes in '{$sCategory}'\n";
        $sRes .= "//////////////////////////////////////////////////////////////////////\n";
        $sRes .= "//\n";
        $sRes .= "\n";
        foreach (MetaModel::GetClasses($sCategory) as $sClass) {
            if (!MetaModel::HasTable($sClass)) {
                continue;
            }
            $bNotInDico = false;
            $bNotImportant = true;
            $sClassRes = "//\n";
            $sClassRes .= "// Class: {$sClass}\n";
            $sClassRes .= "//\n";
            $sClassRes .= "\n";
            $sClassRes .= "Dict::Add('{$sLanguage}', '{$sDesc}', '{$sLocalizedDesc}', array(\n";
            $sClassRes .= MakeDictEntry("Class:{$sClass}", MetaModel::GetName_Obsolete($sClass), $sClass, $bNotInDico);
            $sClassRes .= MakeDictEntry("Class:{$sClass}+", MetaModel::GetClassDescription_Obsolete($sClass), '', $bNotImportant);
            foreach (MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef) {
                if ($sAttCode == 'friendlyname') {
                    continue;
                }
                // Skip this attribute if not originaly defined in this class
                if (MetaModel::GetAttributeOrigin($sClass, $sAttCode) != $sClass) {
                    continue;
                }
                $sClassRes .= MakeDictEntry("Class:{$sClass}/Attribute:{$sAttCode}", $oAttDef->GetLabel_Obsolete(), $sAttCode, $bNotInDico);
                $sClassRes .= MakeDictEntry("Class:{$sClass}/Attribute:{$sAttCode}+", $oAttDef->GetDescription_Obsolete(), '', $bNotImportant);
                if ($oAttDef instanceof AttributeEnum) {
                    if (MetaModel::GetStateAttributeCode($sClass) == $sAttCode) {
                        foreach (MetaModel::EnumStates($sClass) as $sStateCode => $aStateData) {
                            if (array_key_exists('label', $aStateData)) {
                                $sValue = $aStateData['label'];
                            } else {
                                $sValue = MetaModel::GetStateLabel($sClass, $sStateCode);
                            }
                            if (array_key_exists('description', $aStateData)) {
                                $sValuePlus = $aStateData['description'];
                            } else {
                                $sValuePlus = MetaModel::GetStateDescription($sClass, $sStateCode);
                            }
                            $sClassRes .= MakeDictEntry("Class:{$sClass}/Attribute:{$sAttCode}/Value:{$sStateCode}", $sValue, '', $bNotInDico);
                            $sClassRes .= MakeDictEntry("Class:{$sClass}/Attribute:{$sAttCode}/Value:{$sStateCode}+", $sValuePlus, '', $bNotImportant);
                        }
                    } else {
                        foreach ($oAttDef->GetAllowedValues() as $sKey => $value) {
                            $sClassRes .= MakeDictEntry("Class:{$sClass}/Attribute:{$sAttCode}/Value:{$sKey}", $value, '', $bNotInDico);
                            $sClassRes .= MakeDictEntry("Class:{$sClass}/Attribute:{$sAttCode}/Value:{$sKey}+", $value, '', $bNotImportant);
                        }
                    }
                }
            }
            foreach (MetaModel::EnumStimuli($sClass) as $sStimulusCode => $oStimulus) {
                $sClassRes .= MakeDictEntry("Class:{$sClass}/Stimulus:{$sStimulusCode}", $oStimulus->GetLabel_Obsolete(), '', $bNotInDico);
                $sClassRes .= MakeDictEntry("Class:{$sClass}/Stimulus:{$sStimulusCode}+", $oStimulus->GetDescription_Obsolete(), '', $bNotImportant);
            }
            $sClassRes .= "));\n";
            $sClassRes .= "\n";
            $sRes .= $sClassRes;
        }
    }
    return $sRes;
}