Commit 043e210e authored by jeremyjaouen's avatar jeremyjaouen Committed by Thomas Untoja
Browse files

fix(login): Use correct database name for api login (#9880)

parent 997f86a5
...@@ -58,7 +58,7 @@ class AuthenticationRepositoryRDB implements AuthenticationRepositoryInterface ...@@ -58,7 +58,7 @@ class AuthenticationRepositoryRDB implements AuthenticationRepositoryInterface
{ {
global $dependencyInjector; global $dependencyInjector;
$pearDB = new \CentreonDB( $pearDB = new \CentreonDB(
$this->db->getCentreonDbName(), \CentreonDB::LABEL_DB_CONFIGURATION,
3, 3,
true true
); );
......
...@@ -48,6 +48,8 @@ require_once __DIR__ . '/centreonLog.class.php'; ...@@ -48,6 +48,8 @@ require_once __DIR__ . '/centreonLog.class.php';
*/ */
class CentreonDB extends \PDO class CentreonDB extends \PDO
{ {
public const LABEL_DB_CONFIGURATION = 'centreon';
public const LABEL_DB_REALTIME = 'centstorage';
private static $instance = []; private static $instance = [];
protected $db_type = "mysql"; protected $db_type = "mysql";
protected $db_port = "3306"; protected $db_port = "3306";
...@@ -77,14 +79,14 @@ class CentreonDB extends \PDO ...@@ -77,14 +79,14 @@ class CentreonDB extends \PDO
/** /**
* Constructor * Constructor
* *
* @param string $db | centreon, centstorage, or ndo * @param string $db | centreon, centstorage
* @param int $retry * @param int $retry
* @param bool $silent | when silent is set to false, it will display an HTML error msg, * @param bool $silent | when silent is set to false, it will display an HTML error msg,
* otherwise it will throw an Exception * otherwise it will throw an Exception
* *
* @throws Exception * @throws Exception
*/ */
public function __construct($db = "centreon", $retry = 3, $silent = false) public function __construct($db = self::LABEL_DB_CONFIGURATION, $retry = 3, $silent = false)
{ {
try { try {
$conf_centreon['hostCentreon'] = hostCentreon; $conf_centreon['hostCentreon'] = hostCentreon;
...@@ -133,12 +135,11 @@ class CentreonDB extends \PDO ...@@ -133,12 +135,11 @@ class CentreonDB extends \PDO
]; ];
switch (strtolower($db)) { switch (strtolower($db)) {
case "centstorage": case self::LABEL_DB_REALTIME:
$this->dsn['hostspec'] = $conf_centreon["hostCentstorage"]; $this->dsn['hostspec'] = $conf_centreon["hostCentstorage"];
$this->dsn['database'] = $conf_centreon["dbcstg"]; $this->dsn['database'] = $conf_centreon["dbcstg"];
break; break;
case "centreon": default:
case "default":
$this->dsn['hostspec'] = $conf_centreon["hostCentreon"]; $this->dsn['hostspec'] = $conf_centreon["hostCentreon"];
$this->dsn['database'] = $conf_centreon["db"]; $this->dsn['database'] = $conf_centreon["db"];
break; break;
...@@ -317,9 +318,9 @@ class CentreonDB extends \PDO ...@@ -317,9 +318,9 @@ class CentreonDB extends \PDO
* @return CentreonDB * @return CentreonDB
* @throws Exception * @throws Exception
*/ */
public static function factory($name = "centreon") public static function factory($name = self::LABEL_DB_CONFIGURATION)
{ {
if (!in_array($name, ['centreon', 'centstorage', 'ndo'])) { if (!in_array($name, [self::LABEL_DB_CONFIGURATION, self::LABEL_DB_REALTIME])) {
throw new Exception("The datasource isn't defined in configuration file."); throw new Exception("The datasource isn't defined in configuration file.");
} }
if (!isset(self::$instance[$name])) { if (!isset(self::$instance[$name])) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment