Commit 4491fbe6 authored by Marc Egger's avatar Marc Egger
Browse files

Refs #12145 introduce mysqli cache & Create new Database object for FormAsFile where necessary

parent e7b7101e
Pipeline #5108 passed with stages
in 3 minutes and 53 seconds
......@@ -24,6 +24,11 @@ use IMATHUZH\Qfq\Core\Store\Store;
*/
class Database {
/**
* @var \array
*/
private static $mysqliCache = [];
/**
* @var Store
*/
......@@ -58,8 +63,8 @@ class Database {
private $dbIndex = null;
/**
* 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]
* Returns data base handle with requested index from cache.
* If not exists: open database and store the new handle in database cache.
*
* @param string $dbIndex Typically '1' for Data, optional 2 for external Form/FormElement
*
......@@ -84,8 +89,10 @@ class Database {
$config = $this->getConnectionDetails($dbIndex, $storeSystem);
$this->dbName = $config[SYSTEM_DB_NAME];
$this->mysqli = self::$mysqliCache[$dbIndex] ?? null;
if ($this->mysqli === null) {
$this->mysqli = $this->dbConnect($config);
self::$mysqliCache[$dbIndex] = $this->mysqli;
}
// DB Init
......
......@@ -117,6 +117,7 @@ class DragAndDrop {
* @throws \CodeException
* @throws \DbException
* @throws \UserFormException
* @throws \UserReportException
*/
private function reorder(array $rows, $dragId, $setTo, $hoverId, $orderColumn, $orderInterval, $tableName) {
$ord = $orderInterval;
......@@ -128,7 +129,8 @@ class DragAndDrop {
if (FEATURE_FORM_FILE_SYNC) {
// Import Form from file if loaded record is Form/FormElement (If form file was changed, throw exception)
// Note: This is here since this code is called outside QuickFormQuery->doForm
$formFileName = FormAsFile::importFormRecordId($dragId, $tableName, $this->db);
$dbQfq = new Database($this->store->getVar(SYSTEM_DB_INDEX_QFQ, STORE_SYSTEM));
$formFileName = FormAsFile::importFormRecordId($dragId, $tableName, $dbQfq);
}
// Reorder. Get index for 'drag' and 'hover'
......@@ -173,7 +175,8 @@ class DragAndDrop {
if (FEATURE_FORM_FILE_SYNC) {
// Export Form file
if ($formFileName !== null) {
FormAsFile::exportForm($formFileName, $this->db);
$dbQfq = new Database($this->store->getVar(SYSTEM_DB_INDEX_QFQ, STORE_SYSTEM));
FormAsFile::exportForm($formFileName, $dbQfq);
}
}
......
......@@ -394,7 +394,8 @@ class FormAction {
if ($fe[FE_SAVE_FORM_JSON] !== null && $fe[FE_SAVE_FORM_JSON] !== '' && $fe[FE_SAVE_FORM_JSON_NAME] !== null && $fe[FE_SAVE_FORM_JSON_NAME] !== '') {
$jsonContent = $this->evaluate->parse($fe[FE_SAVE_FORM_JSON]);
if ($jsonContent !== '') {
FormAsFile::jsonToDatabase($this->evaluate->parse($fe[FE_SAVE_FORM_JSON_NAME]), $jsonContent, $this->db);
$dbQfq = new Database($this->store->getVar(SYSTEM_DB_INDEX_QFQ, STORE_SYSTEM));
FormAsFile::jsonToDatabase($this->evaluate->parse($fe[FE_SAVE_FORM_JSON_NAME]), $jsonContent, $dbQfq);
}
}
......
......@@ -591,7 +591,8 @@ class Report {
if (FEATURE_FORM_FILE_SYNC) {
// import form files if changed + delete Forms without form file
if (FormAsFile::isFormQuery($sql)) {
FormAsFile::importAllForms($this->db, false, true);
$dbQfq = new Database($this->store->getVar(SYSTEM_DB_INDEX_QFQ, STORE_SYSTEM));
FormAsFile::importAllForms($dbQfq, false, true);
}
}
......@@ -1294,15 +1295,12 @@ class Report {
break;
case COLUMN_FORM_JSON:
// DEBUG !!
// Thrower::userFormException($this->store->getVar(TOKEN_DB_INDEX, STORE_TYPO3));
// END DEBUG !!
$content .= Support::encryptDoubleCurlyBraces(FormAsFile::renderColumnFormJson($columnValue, $this->db));
$dbQfq = new Database($this->store->getVar(SYSTEM_DB_INDEX_QFQ, STORE_SYSTEM));
$content .= Support::encryptDoubleCurlyBraces(FormAsFile::renderColumnFormJson($columnValue, $dbQfq));
break;
case COLUMN_FORM_JSON_BASE_64:
$content .= base64_encode(FormAsFile::renderColumnFormJson($columnValue, $this->db));
$dbQfq = new Database($this->store->getVar(SYSTEM_DB_INDEX_QFQ, STORE_SYSTEM));
$content .= base64_encode(FormAsFile::renderColumnFormJson($columnValue, $dbQfq));
break;
default :
......
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