mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-18 06:48:50 +02:00
#239 Issue with character set (impacting searches with accents)
SVN:trunk[746]
This commit is contained in:
@@ -69,6 +69,21 @@ class CMDBSource
|
||||
}
|
||||
}
|
||||
|
||||
public static function SetCharacterSet($sCharset = 'utf8', $sCollation = 'utf8_general_ci')
|
||||
{
|
||||
if (strlen($sCharset) > 0)
|
||||
{
|
||||
if (strlen($sCollation) > 0)
|
||||
{
|
||||
self::Query("SET NAMES '$sCharset' COLLATE '$sCollation'");
|
||||
}
|
||||
else
|
||||
{
|
||||
self::Query("SET NAMES '$sCharset'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function ListDB()
|
||||
{
|
||||
$aDBs = self::QueryToCol('SHOW DATABASES', 'Database');
|
||||
|
||||
@@ -33,6 +33,9 @@ class ConfigException extends CoreException
|
||||
{
|
||||
}
|
||||
|
||||
define ('DEFAULT_CHARACTER_SET', 'utf8');
|
||||
define ('DEFAULT_COLLATION', 'utf8_general_ci');
|
||||
|
||||
define ('DEFAULT_LOG_GLOBAL', true);
|
||||
define ('DEFAULT_LOG_NOTIFICATION', true);
|
||||
define ('DEFAULT_LOG_ISSUE', true);
|
||||
@@ -73,6 +76,8 @@ class Config
|
||||
protected $m_sDBPwd;
|
||||
protected $m_sDBName;
|
||||
protected $m_sDBSubname;
|
||||
protected $m_sDBCharacterSet;
|
||||
protected $m_sDBCollation;
|
||||
|
||||
/**
|
||||
* @var integer Event log options (see LOG_... definition)
|
||||
@@ -182,6 +187,8 @@ class Config
|
||||
$this->m_sDBPwd = '';
|
||||
$this->m_sDBName = '';
|
||||
$this->m_sDBSubname = '';
|
||||
$this->m_sDBCharacterSet = DEFAULT_CHARACTER_SET;
|
||||
$this->m_sDBCollation = DEFAULT_COLLATION;
|
||||
$this->m_bLogGlobal = DEFAULT_LOG_GLOBAL;
|
||||
$this->m_bLogNotification = DEFAULT_LOG_NOTIFICATION;
|
||||
$this->m_bLogIssue = DEFAULT_LOG_ISSUE;
|
||||
@@ -284,6 +291,9 @@ class Config
|
||||
$this->m_sDBName = trim($MySettings['db_name']);
|
||||
$this->m_sDBSubname = trim($MySettings['db_subname']);
|
||||
|
||||
$this->m_sDBCharacterSet = isset($MySettings['db_character_set']) ? trim($MySettings['db_character_set']) : DEFAULT_CHARACTER_SET;
|
||||
$this->m_sDBCollation = isset($MySettings['db_collation']) ? trim($MySettings['db_collation']) : DEFAULT_COLLATION;
|
||||
|
||||
$this->m_bLogGlobal = isset($MySettings['log_global']) ? (bool) trim($MySettings['log_global']) : DEFAULT_LOG_GLOBAL;
|
||||
$this->m_bLogNotification = isset($MySettings['log_notification']) ? (bool) trim($MySettings['log_notification']) : DEFAULT_LOG_NOTIFICATION;
|
||||
$this->m_bLogIssue = isset($MySettings['log_issue']) ? (bool) trim($MySettings['log_issue']) : DEFAULT_LOG_ISSUE;
|
||||
@@ -391,6 +401,16 @@ class Config
|
||||
return $this->m_sDBSubname;
|
||||
}
|
||||
|
||||
public function GetDBCharacterSet()
|
||||
{
|
||||
return $this->m_sDBCharacterSet;
|
||||
}
|
||||
|
||||
public function GetDBCollation()
|
||||
{
|
||||
return $this->m_sDBCollation;
|
||||
}
|
||||
|
||||
public function GetDBUser()
|
||||
{
|
||||
return $this->m_sDBUser;
|
||||
@@ -501,6 +521,16 @@ class Config
|
||||
$this->m_sDBSubname = $sDBSubName;
|
||||
}
|
||||
|
||||
public function SetDBCharacterSet($sDBCharacterSet)
|
||||
{
|
||||
$this->m_sDBCharacterSet = $sDBCharacterSet;
|
||||
}
|
||||
|
||||
public function SetDBCollation($sDBCollation)
|
||||
{
|
||||
$this->m_sDBCollation = $sDBCollation;
|
||||
}
|
||||
|
||||
public function SetDBUser($sUser)
|
||||
{
|
||||
$this->m_sDBUser = $sUser;
|
||||
@@ -626,6 +656,8 @@ class Config
|
||||
fwrite($hFile, "\t'db_pwd' => '".addslashes($this->m_sDBPwd)."',\n");
|
||||
fwrite($hFile, "\t'db_name' => '{$this->m_sDBName}',\n");
|
||||
fwrite($hFile, "\t'db_subname' => '{$this->m_sDBSubname}',\n");
|
||||
fwrite($hFile, "\t'db_character_set' => '{$this->m_sDBCharacterSet}',\n");
|
||||
fwrite($hFile, "\t'db_collation' => '{$this->m_sDBCollation}',\n");
|
||||
fwrite($hFile, "\n");
|
||||
fwrite($hFile, "\t'log_global' => {$this->m_bLogGlobal},\n");
|
||||
fwrite($hFile, "\t'log_notification' => {$this->m_bLogNotification},\n");
|
||||
|
||||
@@ -3242,6 +3242,8 @@ abstract class MetaModel
|
||||
$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();
|
||||
|
||||
$oKPI = new ExecutionKPI();
|
||||
|
||||
@@ -3255,6 +3257,7 @@ abstract class MetaModel
|
||||
self::$m_sTablePrefix = $sTablePrefix;
|
||||
|
||||
CMDBSource::Init($sServer, $sUser, $sPwd); // do not select the DB (could not exist)
|
||||
CMDBSource::SetCharacterSet($sCharacterSet, $sCollation);
|
||||
}
|
||||
|
||||
public static function GetModuleSetting($sModule, $sProperty, $defaultvalue = null)
|
||||
|
||||
@@ -361,6 +361,7 @@ abstract class TestScenarioOnDB extends TestHandler
|
||||
$sDBName = $this->GetDBName();
|
||||
|
||||
CMDBSource::Init($sDBHost, $sDBUser, $sDBPwd);
|
||||
CMDBSource::SetCharacterSet();
|
||||
if (CMDBSource::IsDB($sDBName))
|
||||
{
|
||||
CMDBSource::DropDB($sDBName);
|
||||
|
||||
Reference in New Issue
Block a user