Update database method connect to use config.conf

This commit is contained in:
FusionPBX 2022-10-10 19:43:07 -06:00 committed by GitHub
parent e3b782e7cb
commit 878e5a10eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 37 additions and 46 deletions

View File

@ -404,55 +404,46 @@
*/
public function connect() {
if (strlen($this->db_name) == 0) {
//set the include path
$conf = glob("{/usr/local/etc,/etc}/fusionpbx/config.conf", GLOB_BRACE);
set_include_path(parse_ini_file($conf[0])['document.root']);
//parset the config.conf file
$conf = parse_ini_file($conf[0]);
//set the include path
$conf = glob("{/usr/local/etc,/etc}/fusionpbx/config.conf", GLOB_BRACE);
set_include_path(parse_ini_file($conf[0])['document.root']);
//get the database connection settings
$db_type = $conf['database.0.type'];
$db_host = $conf['database.0.host'];
$db_port = $conf['database.0.port'];
$db_name = $conf['database.0.name'];
$db_username = $conf['database.0.username'];
$db_password = $conf['database.0.password'];
//includes files
require_once "resources/require.php";
//debug info
//echo "db type:".$db_type."\n";
//echo "db host:".$db_host."\n";
//echo "db port:".$db_port."\n";
//echo "db name:".$db_name."\n";
//echo "db username:".$db_username."\n";
//echo "db password:".$db_password."\n";
//echo "db path:".$db_path."\n";
//echo "</pre>\n";
//include config.php
if (file_exists($_SERVER["PROJECT_ROOT"]."/resources/config.php")) {
include $_SERVER["PROJECT_ROOT"]."/resources/config.php";
} elseif (file_exists($_SERVER["PROJECT_ROOT"]."/resources/config.php")) {
include $_SERVER["PROJECT_ROOT"]."/resources/config.php";
} elseif (file_exists("/etc/fusionpbx/config.php")){
//linux
include "/etc/fusionpbx/config.php";
} elseif (file_exists("/usr/local/etc/fusionpbx/config.php")) {
//bsd
include "/usr/local/etc/fusionpbx/config.php";
}
//backwards compatibility
if (isset($dbtype)) { $db_type = $dbtype; }
if (isset($dbhost)) { $db_host = $dbhost; }
if (isset($dbport)) { $db_port = $dbport; }
if (isset($dbname)) { $db_name = $dbname; }
if (isset($dbusername)) { $db_username = $dbusername; }
if (isset($dbpassword)) { $db_password = $dbpassword; }
if (isset($dbfilepath)) { $db_path = $db_file_path; }
if (isset($dbfilename)) { $db_name = $dbfilename; }
//set defaults
if (!isset($this->driver) && isset($db_type)) { $this->driver = $db_type; }
if (!isset($this->type) && isset($db_type)) { $this->type = $db_type; }
if (!isset($this->host) && isset($db_host)) { $this->host = $db_host; }
if (!isset($this->port) && isset($db_port)) { $this->port = $db_port; }
if (!isset($this->db_name) && isset($db_name)) { $this->db_name = $db_name; }
if (!isset($this->db_secure) && isset($db_secure)) {
$this->db_secure = $db_secure;
}
else {
$this->db_secure = false;
}
if (!isset($this->username) && isset($db_username)) { $this->username = $db_username; }
if (!isset($this->password) && isset($db_password)) { $this->password = $db_password; }
if (!isset($this->path) && isset($db_path)) { $this->path = $db_path; }
}
//set defaults
if (!isset($this->driver) && isset($db_type)) { $this->driver = $db_type; }
if (!isset($this->type) && isset($db_type)) { $this->type = $db_type; }
if (!isset($this->host) && isset($db_host)) { $this->host = $db_host; }
if (!isset($this->port) && isset($db_port)) { $this->port = $db_port; }
if (!isset($this->db_name) && isset($db_name)) { $this->db_name = $db_name; }
if (!isset($this->db_secure) && isset($db_secure)) {
$this->db_secure = $db_secure;
}
else {
$this->db_secure = false;
}
if (!isset($this->username) && isset($db_username)) { $this->username = $db_username; }
if (!isset($this->password) && isset($db_password)) { $this->password = $db_password; }
if (!isset($this->path) && isset($db_path)) { $this->path = $db_path; }
if ($this->driver == "sqlite") {
if (strlen($this->db_name) == 0) {