give complete config object to mxDatabase to resolve issue with undefined ref to it
This commit is contained in:
31
database.php
31
database.php
@@ -35,10 +35,27 @@ class mxDatabase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates mxDatabase object
|
* Creates mxDatabase object
|
||||||
* @param db_input path to the sqlite file where the credentials should be stored
|
* @param config object which has following members:
|
||||||
|
* databaseURI: path to the sqlite file where the credentials should be stored
|
||||||
* or a param which can be used to connect to a database with PDO
|
* or a param which can be used to connect to a database with PDO
|
||||||
|
* databaseUser and databasePass when authentication is required
|
||||||
|
* register_email which email does the register bot have (here used for providing lookup)
|
||||||
*/
|
*/
|
||||||
function __construct($db_input, $user='', $password='') {
|
function __construct($config) {
|
||||||
|
if (empty($config)) {
|
||||||
|
throw new Exception("config is empty");
|
||||||
|
}
|
||||||
|
if (!isset($config["databaseURI"])) {
|
||||||
|
throw new Exception("'databaseURI' not defined");
|
||||||
|
}
|
||||||
|
$db_input = $config["databaseURI"];
|
||||||
|
$user = '';
|
||||||
|
$password = '';
|
||||||
|
if (isset($config["databaseUser"]) && isset($config["databasePass"])) {
|
||||||
|
// only use it when both are defined
|
||||||
|
$user = $config["databaseUser"];
|
||||||
|
$password = $config["databasePass"];
|
||||||
|
}
|
||||||
// create database file when not existent yet
|
// create database file when not existent yet
|
||||||
$this->db = new PDO($db_input, $user, $password);
|
$this->db = new PDO($db_input, $user, $password);
|
||||||
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
@@ -53,7 +70,8 @@ class mxDatabase
|
|||||||
email TEXT,
|
email TEXT,
|
||||||
verify_token TEXT,
|
verify_token TEXT,
|
||||||
admin_token TEXT,
|
admin_token TEXT,
|
||||||
request_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP)");
|
request_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
)");
|
||||||
$this->db->exec("CREATE TABLE IF NOT EXISTS logins (
|
$this->db->exec("CREATE TABLE IF NOT EXISTS logins (
|
||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
active INT DEFAULT 1,
|
active INT DEFAULT 1,
|
||||||
@@ -66,7 +84,6 @@ class mxDatabase
|
|||||||
last_modified TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
last_modified TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
)");
|
)");
|
||||||
// make sure the bot is allowed to login
|
// make sure the bot is allowed to login
|
||||||
require_once("config.php");
|
|
||||||
if (!$this->userRegistered("register_bot")) {
|
if (!$this->userRegistered("register_bot")) {
|
||||||
$password = $this->addUser("Register", "Bot", "register_bot", $config["register_email"]);
|
$password = $this->addUser("Register", "Bot", "register_bot", $config["register_email"]);
|
||||||
$config["register_password"] = $password;
|
$config["register_password"] = $password;
|
||||||
@@ -319,10 +336,6 @@ class mxDatabase
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($mx_db)) {
|
if (!isset($mx_db)) {
|
||||||
if (isset($config["databaseUser"]) && isset($config["databasePass"])) {
|
$mx_db = new mxDatabase($config);
|
||||||
$mx_db = new mxDatabase($config["databaseURI"], $config["databaseUser"], $config["databasePass"]);
|
|
||||||
} else {
|
|
||||||
$mx_db = new mxDatabase($config["databaseURI"]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user