$sOSVersion = PHP_OS; $sWebServerVersion = $_SERVER["SERVER_SOFTWARE"]; $sModules = implode(', ', get_loaded_extensions()); // Get the datamodel directory $oFilter = DBObjectSearch::FromOQL('SELECT ModuleInstallation WHERE name="datamodel"'); $oSet = new DBObjectSet($oFilter, array('installed' => false)); // Most recent first $oLastInstall = $oSet->Fetch(); $sLastInstallDate = $oLastInstall->Get('installed'); $sDataModelVersion = $oLastInstall->Get('version'); $aDataModelInfo = json_decode($oLastInstall->Get('comment'), true); $sDataModelSourceDir = $aDataModelInfo['source_dir']; require_once APPROOT . 'setup/runtimeenv.class.inc.php'; $sCurrEnv = utils::GetCurrentEnvironment(); $oRuntimeEnv = new RunTimeEnvironment($sCurrEnv); $aAvailableModules = $oRuntimeEnv->AnalyzeInstallation(MetaModel::GetConfig(), array(APPROOT . $sDataModelSourceDir, APPROOT . 'extensions')); require_once APPROOT . 'setup/setuputils.class.inc.php'; $aLicenses = SetupUtils::GetLicenses(); $aItopSettings = array('cron_max_execution_time', 'timezone'); $aPHPSettings = array('memory_limit', 'max_execution_time', 'upload_max_filesize', 'post_max_size'); $aMySQLSettings = array('max_allowed_packet', 'key_buffer_size', 'query_cache_size'); $aMySQLStatuses = array('Key_read_requests', 'Key_reads'); if (extension_loaded('suhosin')) { $aPHPSettings[] = 'suhosin.post.max_vars'; $aPHPSettings[] = 'suhosin.get.max_value_length'; } $aMySQLVars = array(); foreach (CMDBSource::QueryToArray('SHOW VARIABLES') as $aRow) { $aMySQLVars[$aRow['Variable_name']] = $aRow['Value']; } $aMySQLStats = array();
/** * * @param bool $bAbortOnMissingDependency ... * @param array $aModulesToLoad List of modules to search for, defaults to all if ommitted */ public static function AnalyzeInstallation($oWizard, $bAbortOnMissingDependency = false, $aModulesToLoad = null) { require_once APPROOT . '/setup/moduleinstaller.class.inc.php'; $oConfig = new Config(); $sSourceDir = $oWizard->GetParameter('source_dir', ''); if (strpos($sSourceDir, APPROOT) !== false) { $sRelativeSourceDir = str_replace(APPROOT, '', $sSourceDir); } else { if (strpos($sSourceDir, $oWizard->GetParameter('previous_version_dir')) !== false) { $sRelativeSourceDir = str_replace($oWizard->GetParameter('previous_version_dir'), '', $sSourceDir); } else { throw new Exception('Internal error: AnalyzeInstallation: source_dir is neither under APPROOT nor under previous_installation_dir ???'); } } $aParamValues = array('db_server' => $oWizard->GetParameter('db_server', ''), 'db_user' => $oWizard->GetParameter('db_user', ''), 'db_pwd' => $oWizard->GetParameter('db_pwd', ''), 'db_name' => $oWizard->GetParameter('db_name', ''), 'db_prefix' => $oWizard->GetParameter('db_prefix', ''), 'source_dir' => $sRelativeSourceDir); $oConfig->UpdateFromParams($aParamValues, null); $aDirsToScan = array($sSourceDir); if (is_dir(APPROOT . 'extensions')) { $aDirsToScan[] = APPROOT . 'extensions'; } if (is_dir($oWizard->GetParameter('copy_extensions_from'))) { $aDirsToScan[] = $oWizard->GetParameter('copy_extensions_from'); } $oProductionEnv = new RunTimeEnvironment(); $aAvailableModules = $oProductionEnv->AnalyzeInstallation($oConfig, $aDirsToScan, $bAbortOnMissingDependency, $aModulesToLoad); return $aAvailableModules; }
/** * Get the installed modules (only the installed ones) */ protected function GetMFModulesToCompile($sSourceEnv, $sSourceDir) { $sSourceDirFull = APPROOT . $sSourceDir; if (!is_dir($sSourceDirFull)) { throw new Exception("The source directory '{$sSourceDirFull}' does not exist (or could not be read)"); } $aDirsToCompile = array($sSourceDirFull); if (is_dir(APPROOT . 'extensions')) { $aDirsToCompile[] = APPROOT . 'extensions'; } $aRet = array(); // Determine the installed modules // $oSourceConfig = new Config(APPCONF . $sSourceEnv . '/' . ITOP_CONFIG_FILE); $oSourceEnv = new RunTimeEnvironment($sSourceEnv); $aAvailableModules = $oSourceEnv->AnalyzeInstallation($oSourceConfig, $aDirsToCompile); // Do load the required modules // $oFactory = new ModelFactory($aDirsToCompile); $aModules = $oFactory->FindModules(); foreach ($aModules as $foo => $oModule) { $sModule = $oModule->GetName(); if (array_key_exists($sModule, $aAvailableModules)) { if ($aAvailableModules[$sModule]['version_db'] != '') { $aRet[] = $oModule; } } } $sDeltaFile = APPROOT . 'data/' . $this->sTargetEnv . '.delta.xml'; if (file_exists($sDeltaFile)) { $oDelta = new MFDeltaModule($sDeltaFile); $aRet[] = $oDelta; } return $aRet; }
$sLastInstallDate = $oLastInstall->Get('installed'); $sDataModelVersion = $oLastInstall->Get('version'); $aDataModelInfo = json_decode($oLastInstall->Get('comment'), true); $sDataModelSourceDir = $aDataModelInfo['source_dir']; require_once APPROOT . 'setup/runtimeenv.class.inc.php'; $sCurrEnv = utils::GetCurrentEnvironment(); $oRuntimeEnv = new RunTimeEnvironment($sCurrEnv); $aSearchDirs = array(APPROOT . $sDataModelSourceDir); if (file_exists(APPROOT . 'extensions')) { $aSearchDirs[] = APPROOT . 'extensions'; } $sExtraDir = APPROOT . 'data/' . $sCurrEnv . '-modules/'; if (file_exists($sExtraDir)) { $aSearchDirs[] = $sExtraDir; } $aAvailableModules = $oRuntimeEnv->AnalyzeInstallation(MetaModel::GetConfig(), $aSearchDirs); require_once APPROOT . 'setup/setuputils.class.inc.php'; $aLicenses = SetupUtils::GetLicenses(); $aItopSettings = array('cron_max_execution_time', 'timezone'); $aPHPSettings = array('memory_limit', 'max_execution_time', 'upload_max_filesize', 'post_max_size'); $aMySQLSettings = array('max_allowed_packet', 'key_buffer_size', 'query_cache_size'); $aMySQLStatuses = array('Key_read_requests', 'Key_reads'); if (extension_loaded('suhosin')) { $aPHPSettings[] = 'suhosin.post.max_vars'; $aPHPSettings[] = 'suhosin.get.max_value_length'; } $aMySQLVars = array(); foreach (CMDBSource::QueryToArray('SHOW VARIABLES') as $aRow) { $aMySQLVars[$aRow['Variable_name']] = $aRow['Value']; } $aMySQLStats = array();
/** * * @param bool $bAbortOnMissingDependency ... * @param array $aModulesToLoad List of modules to search for, defaults to all if ommitted */ public static function AnalyzeInstallation($oWizard, $bAbortOnMissingDependency = false, $aModulesToLoad = null) { require_once APPROOT . '/setup/moduleinstaller.class.inc.php'; $oConfig = new Config(); $sSourceDir = $oWizard->GetParameter('source_dir', ''); if (strpos($sSourceDir, APPROOT) !== false) { $sRelativeSourceDir = str_replace(APPROOT, '', $sSourceDir); } else { if (strpos($sSourceDir, $oWizard->GetParameter('previous_version_dir')) !== false) { $sRelativeSourceDir = str_replace($oWizard->GetParameter('previous_version_dir'), '', $sSourceDir); } else { throw new Exception('Internal error: AnalyzeInstallation: source_dir is neither under APPROOT nor under previous_installation_dir ???'); } } $aParamValues = array('db_server' => $oWizard->GetParameter('db_server', ''), 'db_user' => $oWizard->GetParameter('db_user', ''), 'db_pwd' => $oWizard->GetParameter('db_pwd', ''), 'db_name' => $oWizard->GetParameter('db_name', ''), 'db_prefix' => $oWizard->GetParameter('db_prefix', ''), 'source_dir' => $sRelativeSourceDir); $oConfig->UpdateFromParams($aParamValues, null); $aDirsToScan = array($sSourceDir); if (is_dir(APPROOT . 'extensions')) { $aDirsToScan[] = APPROOT . 'extensions'; } if (is_dir(APPROOT . 'data')) { $aDirsToScan[] = APPROOT . 'extensions'; } if (is_dir($oWizard->GetParameter('copy_extensions_from'))) { $aDirsToScan[] = $oWizard->GetParameter('copy_extensions_from'); } $sExtraDir = APPROOT . 'data/production-modules/'; if (is_dir($sExtraDir)) { $aDirsToScan[] = $sExtraDir; } $oProductionEnv = new RunTimeEnvironment(); $aAvailableModules = $oProductionEnv->AnalyzeInstallation($oConfig, $aDirsToScan, $bAbortOnMissingDependency, $aModulesToLoad); foreach ($aAvailableModules as $key => $aModule) { $bIsExtra = array_key_exists('root_dir', $aModule) && strpos($aModule['root_dir'], $sExtraDir) !== false; // Some modules (root, datamodel) have no 'root_dir' if ($bIsExtra) { // Modules in data/production-modules/ are considered as mandatory and always installed $aAvailableModules[$key]['visible'] = false; } } return $aAvailableModules; }
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(); }