public function CompileFrom($sSourceEnv, $bUseSymLinks = false) { $oSourceConfig = new Config(utils::GetConfigFilePath($sSourceEnv)); $sSourceDir = $oSourceConfig->Get('source_dir'); $sSourceDirFull = APPROOT . $sSourceDir; // Do load the required modules // $oFactory = new ModelFactory($sSourceDirFull); foreach ($this->GetMFModulesToCompile($sSourceEnv, $sSourceDir) as $oModule) { $sModule = $oModule->GetName(); $oFactory->LoadModule($oModule); if ($oFactory->HasLoadErrors()) { break; } } if ($oFactory->HasLoadErrors()) { foreach ($oFactory->GetLoadErrors() as $sModuleId => $aErrors) { echo "<h3>Module: " . $sModuleId . "</h3>\n"; foreach ($aErrors as $oXmlError) { echo "<p>File: " . $oXmlError->file . " Line:" . $oXmlError->line . " Message:" . $oXmlError->message . "</p>\n"; } } } else { $oFactory->ApplyChanges(); //$oFactory->Dump(); $sTargetDir = APPROOT . 'env-' . $this->sTargetEnv; self::MakeDirSafe($sTargetDir); $oMFCompiler = new MFCompiler($oFactory); $oMFCompiler->Compile($sTargetDir, null, $bUseSymLinks); require_once APPROOT . '/core/dict.class.inc.php'; MetaModel::ResetCache(md5(APPROOT) . '-' . $this->sTargetEnv); } }
function InitDataModel($sConfigFileName, $bModelOnly = true) { require_once APPROOT . '/core/log.class.inc.php'; require_once APPROOT . '/core/kpi.class.inc.php'; require_once APPROOT . '/core/coreexception.class.inc.php'; require_once APPROOT . '/core/dict.class.inc.php'; require_once APPROOT . '/core/attributedef.class.inc.php'; require_once APPROOT . '/core/filterdef.class.inc.php'; require_once APPROOT . '/core/stimulus.class.inc.php'; require_once APPROOT . '/core/MyHelpers.class.inc.php'; require_once APPROOT . '/core/expression.class.inc.php'; require_once APPROOT . '/core/cmdbsource.class.inc.php'; require_once APPROOT . '/core/sqlquery.class.inc.php'; require_once APPROOT . '/core/dbobject.class.php'; if (file_exists(APPROOT . '/core/dbsearch.class.php')) { // iTop 2.2.0 or newer require_once APPROOT . '/core/dbsearch.class.php'; } else { // Pre 2.2 require_once APPROOT . '/core/dbobjectsearch.class.php'; } require_once APPROOT . '/core/dbobjectset.class.php'; require_once APPROOT . '/application/cmdbabstract.class.inc.php'; require_once APPROOT . '/core/userrights.class.inc.php'; require_once APPROOT . '/setup/moduleinstallation.class.inc.php'; MetaModel::ResetCache(); MetaModel::Startup($sConfigFileName, $bModelOnly, false); }
protected static function DoCreateConfig($sMode, $sModulesDir, $sDBServer, $sDBUser, $sDBPwd, $sDBName, $sDBPrefix, $sUrl, $sLanguage, $aSelectedModules, $sTargetEnvironment, $bOldAddon, $sSourceDir, $sPreviousConfigFile, $sDataModelVersion, $sGraphvizPath) { $aParamValues = array('mode' => $sMode, 'db_server' => $sDBServer, 'db_user' => $sDBUser, 'db_pwd' => $sDBPwd, 'db_name' => $sDBName, 'new_db_name' => $sDBName, 'db_prefix' => $sDBPrefix, 'application_path' => $sUrl, 'language' => $sLanguage, 'graphviz_path' => $sGraphvizPath, 'selected_modules' => implode(',', $aSelectedModules)); $bPreserveModuleSettings = false; if ($sMode == 'upgrade') { try { $oOldConfig = new Config($sPreviousConfigFile); $oConfig = clone $oOldConfig; $bPreserveModuleSettings = true; } catch (Exception $e) { // In case the previous configuration is corrupted... start with a blank new one $oConfig = new Config(); } } else { $oConfig = new Config(); // To preserve backward compatibility while upgrading to 2.0.3 (when tracking_level_linked_set_default has been introduced) // the default value on upgrade differs from the default value at first install $oConfig->Set('tracking_level_linked_set_default', LINKSET_TRACKING_NONE, 'first_install'); } // Migration: force utf8_unicode_ci as the collation to make the global search // NON case sensitive $oConfig->SetDBCollation('utf8_unicode_ci'); // Final config update: add the modules $oConfig->UpdateFromParams($aParamValues, $sModulesDir, $bPreserveModuleSettings); if ($bOldAddon) { // Old version of the add-on for backward compatibility with pre-2.0 data models $oConfig->SetAddons(array('user rights' => 'addons/userrights/userrightsprofile.db.class.inc.php')); } $oConfig->Set('source_dir', $sSourceDir); // Have it work fine even if the DB has been set in read-only mode for the users $iPrevAccessMode = $oConfig->Get('access_mode'); $oConfig->Set('access_mode', ACCESS_FULL); // Record which modules are installed... $oProductionEnv = new RunTimeEnvironment($sTargetEnvironment); $oProductionEnv->InitDataModel($oConfig, true); // load data model and connect to the database $aAvailableModules = $oProductionEnv->AnalyzeInstallation(MetaModel::GetConfig(), APPROOT . $sModulesDir); if (!$oProductionEnv->RecordInstallation($oConfig, $sDataModelVersion, $aSelectedModules, $sModulesDir)) { throw new Exception("Failed to record the installation information"); } // Restore the previous access mode $oConfig->Set('access_mode', $iPrevAccessMode); // Make sure the root configuration directory exists if (!file_exists(APPCONF)) { mkdir(APPCONF); chmod(APPCONF, 0770); // RWX for owner and group, nothing for others SetupPage::log_info("Created configuration directory: " . APPCONF); } // Write the final configuration file $sConfigFile = APPCONF . ($sTargetEnvironment == '' ? 'production' : $sTargetEnvironment) . '/' . ITOP_CONFIG_FILE; $sConfigDir = dirname($sConfigFile); @mkdir($sConfigDir); @chmod($sConfigDir, 0770); // RWX for owner and group, nothing for others $oConfig->WriteToFile($sConfigFile); // try to make the final config file read-only @chmod($sConfigFile, 0444); // Read-only for owner and group, nothing for others // Ready to go !! require_once APPROOT . 'core/dict.class.inc.php'; MetaModel::ResetCache(); }