mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-21 09:38:48 +02:00
- Added ability to create and save a config file. (Not fully finished yet, modules are still hard-coded)
SVN:code[7]
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
require_once('coreexception.class.inc.php');
|
||||
/**
|
||||
* Config
|
||||
* configuration data
|
||||
@@ -31,11 +31,23 @@ class Config
|
||||
protected $m_sDBName;
|
||||
protected $m_sDBSubname;
|
||||
|
||||
public function __construct($sConfigFile)
|
||||
public function __construct($sConfigFile, $bLoadConfig = true)
|
||||
{
|
||||
$this->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, "<?php\n");
|
||||
fwrite($hFile, "\n/**\n");
|
||||
fwrite($hFile, " *\n");
|
||||
fwrite($hFile, " * phpMyORM configuration file, generated by the iTop configuration wizard\n");
|
||||
fwrite($hFile, " *\n");
|
||||
fwrite($hFile, " * The file is used in MetaModel::LoadConfig() which does all the necessary initialization job\n");
|
||||
fwrite($hFile, " *\n");
|
||||
fwrite($hFile, " */\n");
|
||||
fwrite($hFile, "\n");
|
||||
|
||||
fwrite($hFile, "\$MySettings = array(\n");
|
||||
fwrite($hFile, "\t'db_host' => '{$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));
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user