Commit f5a0e285 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Implemeted two new STORE_SYSTEM variables: '_dbNameData' and '_dbNameQfq' -...

Implemeted two new STORE_SYSTEM variables: '_dbNameData' and '_dbNameQfq' - those will be automatically filled qfq during instantiation QuickFormQuery(). They can be used in Report to easily access the needed DB.
parent 0b2bcf96
......@@ -371,12 +371,13 @@ const TYPO3_DEBUG_SHOW_BODY_TEXT = 'debugShowBodyText';
const TYPO3_SQL_LOG = 'sqlLog';
const TYPO3_SQL_LOG_MODE = 'sqlLogMode';
// System: old style - still used to read old configuration file.
// Deprecated: legacy config - still used to read old configuration file.
const SYSTEM_DB_USER = 'DB_USER';
const SYSTEM_DB_SERVER = 'DB_SERVER';
const SYSTEM_DB_PASSWORD = 'DB_PASSWORD';
const SYSTEM_DB_NAME = 'DB_NAME';
// Recent DB config
const SYSTEM_DB_1_USER = 'DB_1_USER';
const SYSTEM_DB_1_SERVER = 'DB_1_SERVER';
const SYSTEM_DB_1_PASSWORD = 'DB_1_PASSWORD';
......@@ -387,6 +388,10 @@ const SYSTEM_DB_INIT = 'DB_INIT';
const SYSTEM_DB_INDEX_DATA = "DB_INDEX_DATA";
const SYSTEM_DB_INDEX_QFQ = "DB_INDEX_QFQ";
// Computed dynamically
const SYSTEM_DB_NAME_DATA = '_dbNameData';
const SYSTEM_DB_NAME_QFQ = '_dbNameQfq';
const SYSTEM_SQL_LOG = 'SQL_LOG'; // Logging to file
const SYSTEM_SQL_LOG_FILE = '../../sql.log';
const SYSTEM_SQL_LOG_MODE = 'SQL_LOG_MODE'; // Mode, which statements to log.
......
......@@ -154,12 +154,22 @@ class QuickFormQuery {
$this->store = Store::getInstance($bodytext, $phpUnit);
$this->store->setVar(TYPO3_TT_CONTENT_UID, $t3data[T3DATA_UID], STORE_TYPO3);
$this->dbIndexData = $this->store->getVar(SYSTEM_DB_INDEX_DATA, STORE_SYSTEM);
$this->dbIndexQfq = $this->store->getVar(SYSTEM_DB_INDEX_QFQ, STORE_SYSTEM);
$this->dbArray[$this->dbIndexData] = new Database($this->dbIndexData);
$dbName = $this->dbArray[$this->dbIndexData]->getDbName();
$this->store->setVar(SYSTEM_DB_NAME_DATA, $dbName, STORE_SYSTEM);
if ($this->dbIndexData != $this->dbIndexQfq) {
$this->dbArray[$this->dbIndexQfq] = new Database($this->dbIndexQfq);
$dbName = $this->dbArray[$this->dbIndexQfq]->getDbName();
}
$this->store->setVar(SYSTEM_DB_NAME_QFQ, $dbName, STORE_SYSTEM);
$this->eval = new Evaluate($this->store, $this->dbArray[$this->dbIndexData]);
......
......@@ -56,6 +56,8 @@ class Database {
*/
private $sqlLogModePrio = [SQL_LOG_MODE_NONE => 1, SQL_LOG_MODE_ERROR => 2, SQL_LOG_MODE_MODIFY => 3, SQL_LOG_MODE_ALL => 4];
private $dbName = '';
/**
* Returns current data base handle from Store[System][SYSTEM_DBH].
* If not exists: open database and store the new dbh in Store[System][SYSTEM_DBH]
......@@ -70,10 +72,13 @@ class Database {
$dbInit = '';
$this->store = Store::getInstance();
$this->sqlLog = $this->store->getVar(SYSTEM_SQL_LOG, STORE_SYSTEM);
$dbInit = $this->store->getVar(SYSTEM_DB_INIT, STORE_SYSTEM);
$storeSystem = $this->store->getStore(STORE_SYSTEM);
$this->sqlLog = $storeSystem[SYSTEM_SQL_LOG];
$dbInit = $storeSystem[SYSTEM_DB_INIT];
$config = $this->getConnectionDetails($dbIndex);
$config = $this->getConnectionDetails($dbIndex, $storeSystem);
$this->dbName = $config[SYSTEM_DB_NAME];
if ($this->mysqli === null) {
$this->mysqli = $this->dbConnect($config);
......@@ -85,6 +90,10 @@ class Database {
}
}
public function getDbName() {
return $this->dbName;
}
/**
* Depending on $dbIndex, read DB_?_SERVER ... crendentials.
* If $dbIndex==1 but no DB_1_xxx specified, take the default DB_xxxx - old config.qfq.ini style
......@@ -95,9 +104,7 @@ class Database {
* @throws CodeException
* @throws UserFormException
*/
private function getConnectionDetails($dbIndex) {
$config = $this->store->getStore(STORE_SYSTEM);
private function getConnectionDetails($dbIndex, array $config) {
if (isset($config["DB_" . $dbIndex . "_SERVER"])) {
$config[SYSTEM_DB_SERVER] = $config["DB_" . $dbIndex . "_SERVER"];
......@@ -105,6 +112,7 @@ class Database {
$config[SYSTEM_DB_PASSWORD] = $config["DB_" . $dbIndex . "_PASSWORD"];
$config[SYSTEM_DB_NAME] = $config["DB_" . $dbIndex . "_NAME"];
} elseif ($dbIndex != 1) {
// Backward compatibility: old configs use SYSTEM_DB_SERVER (without index) and index=1 might mean 'legacy config'.
throw new UserFormException("DB Handle not found in config: $dbIndex", ERROR_INVALID_VALUE);
}
......
......@@ -59,8 +59,8 @@ class StoreTest extends \PHPUnit_Framework_TestCase {
public function testGetVarStoreSystem() {
// DBUSER in qfq.ini
$dbuser = $this->store->getVar(SYSTEM_DB_INDEX_DATA, STORE_SYSTEM);
$this->assertTrue($dbuser !== false && $dbuser !== '', "System: DBUSER found in qfq.ini");
$val = $this->store->getVar(SYSTEM_DB_INDEX_DATA, STORE_SYSTEM);
$this->assertTrue($val !== false && $val !== '', "SYSTEM_DB_INDEX_DATA found in qfq.ini");
}
......
Markdown is supported
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