mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 10:38:45 +02:00
N°1260 Config : migrate DB* variables to the Get() model, create CMDBSource::InitFromConfig
SVN:trunk[5308]
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
// Copyright (C) 2010-2017 Combodo SARL
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
@@ -194,11 +194,11 @@ if (class_exists('ZipArchive')) // The setup must be able to start even if the "
|
||||
if (is_null($sDBHost))
|
||||
{
|
||||
// Defaulting to the current config
|
||||
$sDBHost = MetaModel::GetConfig()->GetDBHost();
|
||||
$sDBUser = MetaModel::GetConfig()->GetDBUser();
|
||||
$sDBPwd = MetaModel::GetConfig()->GetDBPwd();
|
||||
$sDBName = MetaModel::GetConfig()->GetDBName();
|
||||
$sDBSubName = MetaModel::GetConfig()->GetDBSubName();
|
||||
$sDBHost = MetaModel::GetConfig()->Get('db_host');
|
||||
$sDBUser = MetaModel::GetConfig()->Get('db_user');
|
||||
$sDBPwd = MetaModel::GetConfig()->Get('db_pwd');
|
||||
$sDBName = MetaModel::GetConfig()->Get('db_name');
|
||||
$sDBSubName = MetaModel::GetConfig()->Get('db_subname');
|
||||
}
|
||||
|
||||
// Compute the port (if present in the host name)
|
||||
|
||||
@@ -547,11 +547,10 @@ class iTopExtensionsMap
|
||||
{
|
||||
if (CMDBSource::DBName() === null)
|
||||
{
|
||||
CMDBSource::Init($oConfig->GetDBHost(), $oConfig->GetDBUser(), $oConfig->GetDBPwd(), $oConfig->GetDBName());
|
||||
CMDBSource::SetCharacterSet($oConfig->GetDBCharacterSet(), $oConfig->GetDBCollation());
|
||||
CMDBSource::InitFromConfig($oConfig);
|
||||
}
|
||||
$sLatestInstallationDate = CMDBSource::QueryToScalar("SELECT max(installed) FROM ".$oConfig->GetDBSubname()."priv_extension_install");
|
||||
$aInstalledExtensions = CMDBSource::QueryToArray("SELECT * FROM ".$oConfig->GetDBSubname()."priv_extension_install WHERE installed = '".$sLatestInstallationDate."'");
|
||||
$sLatestInstallationDate = CMDBSource::QueryToScalar("SELECT max(installed) FROM ".$oConfig->Get('db_subname')."priv_extension_install");
|
||||
$aInstalledExtensions = CMDBSource::QueryToArray("SELECT * FROM ".$oConfig->Get('db_subname')."priv_extension_install WHERE installed = '".$sLatestInstallationDate."'");
|
||||
}
|
||||
catch (MySQLException $e)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
// Copyright (C) 2010-2017 Combodo SARL
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
@@ -20,7 +20,7 @@
|
||||
/**
|
||||
* Manage a runtime environment
|
||||
*
|
||||
* @copyright Copyright (C) 2010-2017 Combodo SARL
|
||||
* @copyright Copyright (C) 2010-2018 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
@@ -243,9 +243,8 @@ class RunTimeEnvironment
|
||||
try
|
||||
{
|
||||
require_once(APPROOT.'/core/cmdbsource.class.inc.php');
|
||||
CMDBSource::Init($oConfig->GetDBHost(), $oConfig->GetDBUser(), $oConfig->GetDBPwd(), $oConfig->GetDBName(), $oConfig->GetDBSSLKey(), $oConfig->GetDBSSLCert(), $oConfig->GetDBSSLCA(), $oConfig->GetDBSSLCipher());
|
||||
CMDBSource::SetCharacterSet($oConfig->GetDBCharacterSet(), $oConfig->GetDBCollation());
|
||||
$aSelectInstall = CMDBSource::QueryToArray("SELECT * FROM ".$oConfig->GetDBSubname()."priv_module_install");
|
||||
CMDBSource::InitFromConfig($oConfig);
|
||||
$aSelectInstall = CMDBSource::QueryToArray("SELECT * FROM ".$oConfig->Get('db_subname')."priv_module_install");
|
||||
}
|
||||
catch (MySQLException $e)
|
||||
{
|
||||
@@ -577,13 +576,13 @@ class RunTimeEnvironment
|
||||
*/
|
||||
public function CreateDatabaseStructure(Config $oConfig, $sMode)
|
||||
{
|
||||
if (strlen($oConfig->GetDBSubname()) > 0)
|
||||
if (strlen($oConfig->Get('db_subname')) > 0)
|
||||
{
|
||||
$this->log_info("Creating the structure in '".$oConfig->GetDBName()."' (table names prefixed by '".$oConfig->GetDBSubname()."').");
|
||||
$this->log_info("Creating the structure in '".$oConfig->Get('db_name')."' (table names prefixed by '".$oConfig->Get('db_subname')."').");
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->log_info("Creating the structure in '".$oConfig->GetDBSubname()."'.");
|
||||
$this->log_info("Creating the structure in '".$oConfig->Get('db_subname')."'.");
|
||||
}
|
||||
|
||||
//MetaModel::CheckDefinitions();
|
||||
@@ -596,13 +595,13 @@ class RunTimeEnvironment
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strlen($oConfig->GetDBSubname()) > 0)
|
||||
if (strlen($oConfig->Get('db_subname')) > 0)
|
||||
{
|
||||
throw new Exception("Error: found iTop tables into the database '".$oConfig->GetDBName()."' (prefix: '".$oConfig->GetDBSubname()."'). Please, try selecting another database instance or specify another prefix to prevent conflicting table names.");
|
||||
throw new Exception("Error: found iTop tables into the database '".$oConfig->Get('db_name')."' (prefix: '".$oConfig->Get('db_subname')."'). Please, try selecting another database instance or specify another prefix to prevent conflicting table names.");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Error: found iTop tables into the database '".$oConfig->GetDBName()."'. Please, try selecting another database instance or specify a prefix to prevent conflicting table names.");
|
||||
throw new Exception("Error: found iTop tables into the database '".$oConfig->Get('db_name')."'. Please, try selecting another database instance or specify a prefix to prevent conflicting table names.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -641,13 +640,13 @@ class RunTimeEnvironment
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strlen($oConfig->GetDBSubname()) > 0)
|
||||
if (strlen($oConfig->Get('db_subname')) > 0)
|
||||
{
|
||||
throw new Exception("Error: No previous instance of iTop found into the database '".$oConfig->GetDBName()."' (prefix: '".$oConfig->GetDBSubname()."'). Please, try selecting another database instance.");
|
||||
throw new Exception("Error: No previous instance of iTop found into the database '".$oConfig->Get('db_name')."' (prefix: '".$oConfig->Get('db_subname')."'). Please, try selecting another database instance.");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Error: No previous instance of iTop found into the database '".$oConfig->GetDBName()."'. Please, try selecting another database instance.");
|
||||
throw new Exception("Error: No previous instance of iTop found into the database '".$oConfig->Get('db_name')."'. Please, try selecting another database instance.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -724,8 +723,7 @@ class RunTimeEnvironment
|
||||
if (CMDBSource::DBName() == '')
|
||||
{
|
||||
// In case this has not yet been done
|
||||
CMDBSource::Init($oConfig->GetDBHost(), $oConfig->GetDBUser(), $oConfig->GetDBPwd(), $oConfig->GetDBName());
|
||||
CMDBSource::SetCharacterSet($oConfig->GetDBCharacterSet(), $oConfig->GetDBCollation());
|
||||
CMDBSource::InitFromConfig($oConfig);
|
||||
}
|
||||
|
||||
if ($sShortComment === null)
|
||||
@@ -836,15 +834,14 @@ class RunTimeEnvironment
|
||||
try
|
||||
{
|
||||
require_once(APPROOT.'/core/cmdbsource.class.inc.php');
|
||||
CMDBSource::Init($oConfig->GetDBHost(), $oConfig->GetDBUser(), $oConfig->GetDBPwd(), $oConfig->GetDBName(), $oConfig->GetDBSSLKey(), $oConfig->GetDBSSLCert(), $oConfig->GetDBSSLCA(), $oConfig->GetDBSSLCipher());
|
||||
CMDBSource::SetCharacterSet($oConfig->GetDBCharacterSet(), $oConfig->GetDBCollation());
|
||||
$sSQLQuery = "SELECT * FROM ".$oConfig->GetDBSubname()."priv_module_install";
|
||||
CMDBSource::InitFromConfig($oConfig);
|
||||
$sSQLQuery = "SELECT * FROM ".$oConfig->Get('db_subname')."priv_module_install";
|
||||
$aSelectInstall = CMDBSource::QueryToArray($sSQLQuery);
|
||||
}
|
||||
catch (MySQLException $e)
|
||||
{
|
||||
// No database or erroneous information
|
||||
$this->log_error('Can not connect to the database: host: '.$oConfig->GetDBHost().', user:'.$oConfig->GetDBUser().', pwd:'.$oConfig->GetDBPwd().', db name:'.$oConfig->GetDBName());
|
||||
$this->log_error('Can not connect to the database: host: '.$oConfig->Get('db_host').', user:'.$oConfig->Get('db_user').', pwd:'.$oConfig->Get('db_pwd').', db name:'.$oConfig->Get('db_name'));
|
||||
$this->log_error('Exception '.$e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
// Copyright (C) 2010-2017 Combodo SARL
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
@@ -18,7 +18,8 @@
|
||||
|
||||
/**
|
||||
* The standardized result of any pass/fail check performed by the setup
|
||||
* @copyright Copyright (C) 2010-2017 Combodo SARL
|
||||
*
|
||||
* @copyright Copyright (C) 2010-2018 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
class CheckResult
|
||||
@@ -821,11 +822,11 @@ class SetupUtils
|
||||
'source_dir' => $sSourceDir,
|
||||
'source_environment' => $sSourceEnvironment,
|
||||
'configuration_file' => $sConfigFile,
|
||||
'db_server' => $oPrevConf->GetDBHost(),
|
||||
'db_user' => $oPrevConf->GetDBUser(),
|
||||
'db_pwd' => $oPrevConf->GetDBPwd(),
|
||||
'db_name' => $oPrevConf->GetDBName(),
|
||||
'db_prefix' => $oPrevConf->GetDBSubname(),
|
||||
'db_server' => $oPrevConf->Get('db_host'),
|
||||
'db_user' => $oPrevConf->Get('db_user'),
|
||||
'db_pwd' => $oPrevConf->Get('db_pwd'),
|
||||
'db_name' => $oPrevConf->Get('db_name'),
|
||||
'db_prefix' => $oPrevConf->Get('db_subname'),
|
||||
'graphviz_path' => $oPrevConf->Get('graphviz_path'),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user