diff --git a/core/config.class.inc.php b/core/config.class.inc.php index bc6402e072..fedc3de3d3 100644 --- a/core/config.class.inc.php +++ b/core/config.class.inc.php @@ -1,5 +1,5 @@ m_sFile = $sConfigFile; - $this->Load($sConfigFile); - $this->Verify(); + $this->m_aAppModules = array(); + $this->m_aDataModels = array(); + $this->m_aAddons = array(); + + $this->m_sDBHost = ''; + $this->m_sDBUser = ''; + $this->m_sDBPwd = ''; + $this->m_sDBName = ''; + $this->m_sDBSubname = ''; + if ($bLoadConfig) + { + $this->Load($sConfigFile); + $this->Verify(); + } } protected function CheckFile($sPurpose, $sFileName) @@ -145,8 +157,7 @@ class Config { return $this->m_sDBHost; } - - + public function GetDBName() { return $this->m_sDBName; @@ -166,5 +177,96 @@ class Config { return $this->m_sDBPwd; } + + public function SetDBHost($sDBHost) + { + $this->m_sDBHost = $sHost; + } + + public function SetDBName($sDBName) + { + $this->m_sDBName = $sDBName; + } + + public function SetDBSubname($sDBSubName) + { + $this->m_sDBSubname = $sDBSubName; + } + + public function SetDBUser($sUser) + { + $this->m_sDBUser = $sUser; + } + + public function SetDBPwd($sPwd) + { + $this->m_sDBPwd = $sPwd; + } + public function FileIsWritable() + { + return is_writable($this->m_sFile); + } + + /** + * Write the configuration to a file (php format) that can be reloaded later + * By default write to the same file that was specified when constructing the object + * @param $sFileName string Name of the file to write to (emtpy to write to the same file) + * @return boolean True otherwise throws an Exception + */ + public function WriteToFile($sFileName = '') + { + if (empty($sFileName)) + { + $sFileName = $this->m_sFile; + } + $hFile = @fopen($sFileName, 'w'); + if ($hFile !== false) + { + fwrite($hFile, " '{$this->m_sDBHost}',\n"); + fwrite($hFile, "\t'db_user' => '{$this->m_sDBUser}',\n"); + fwrite($hFile, "\t'db_pwd' => '{$this->m_sDBPwd}',\n"); + fwrite($hFile, "\t'db_name' => '{$this->m_sDBName}',\n"); + fwrite($hFile, "\t'db_subname' => '{$this->m_sDBSubname}',\n"); + fwrite($hFile, ");\n"); + + fwrite($hFile, "\n/**\n"); + fwrite($hFile, " *\n"); + fwrite($hFile, " * Data model modules to be loaded. Names should be specified as absolute paths\n"); + fwrite($hFile, " *\n"); + fwrite($hFile, " */\n"); + fwrite($hFile, "\$MyModules = array(\n"); + fwrite($hFile, "\t'application' => array (\n"); + fwrite($hFile, "\t\t'../application/menunode.class.inc.php',\n"); + fwrite($hFile, "\t\t'../application/audit.rule.class.inc.php',\n"); + fwrite($hFile, "\t\t// to be continued...\n"); + fwrite($hFile, "\t),\n"); + fwrite($hFile, "\t'business' => array (\n"); + fwrite($hFile, "\t\t'../business/itop.business.class.inc.php'\n"); + fwrite($hFile, "\t\t// to be continued...\n"); + fwrite($hFile, "\t),\n"); + fwrite($hFile, "\t'addons' => array (\n"); + fwrite($hFile, "\t\t'user rights' => '../addons/userrights/userrightsmatrix.class.inc.php',\n"); + fwrite($hFile, "\t\t// other modules to come later\n"); + fwrite($hFile, "\t)\n"); + fwrite($hFile, ");\n"); + fwrite($hFile, '?'.'>'); // Avoid perturbing the syntax highlighting ! + return fclose($hFile); + } + else + { + throw new ConfigException("Could not write to configuration file", array('file' => $sFileName)); + } + } } ?>