Commit 3830de7c authored by Elias Villiger's avatar Elias Villiger

Fixes #8851 - add sqlLogMode modifyAll and restrict sqlLogMode modify

parent 14645ce2
Pipeline #2179 passed with stages
in 2 minutes and 47 seconds
......@@ -398,8 +398,10 @@ Extension Manager: QFQ Configuration
+-----------------------------------+-------------------------------------------------------+----------------------------------------------------------------------------+
| redirectAllMailTo | john@doe.com | If set, redirect all QFQ generated mails (Form, Report) to the specified. |
+-----------------------------------+-------------------------------------------------------+----------------------------------------------------------------------------+
| sqlLogMode | modify | | *all*: every statement will be logged - this might a lot. |
| | | | *modify*: log only statements who change data. |
| sqlLogMode | modify | | *all*: every statement will be logged - this might be a lot. |
| | | | *modifyAll*: log all statements which might change data, even if 0 rows |
| | | | affected. |
| | | | *modify*: log only statements which change data (affected rows > 0). |
| | | | *error*: log only DB errors. |
| | | | *none*: no SQL log at all. |
+-----------------------------------+-------------------------------------------------------+----------------------------------------------------------------------------+
......
......@@ -782,6 +782,7 @@ const RANDOM_LENGTH = 32;
// SQL logging Modes
const SQL_LOG_MODE_ALL = 'all';
const SQL_LOG_MODE_MODIFY = 'modify';
const SQL_LOG_MODE_MODIFY_ALL = 'modifyAll';
const SQL_LOG_MODE_NONE = 'none';
const SQL_LOG_MODE_ERROR = 'error';
......
......@@ -50,7 +50,7 @@ class Database {
/**
* @var array
*/
private $sqlLogModePrio = [SQL_LOG_MODE_NONE => 1, SQL_LOG_MODE_ERROR => 2, SQL_LOG_MODE_MODIFY => 3, SQL_LOG_MODE_ALL => 4];
private $sqlLogModePrio = [SQL_LOG_MODE_NONE => 1, SQL_LOG_MODE_ERROR => 2, SQL_LOG_MODE_MODIFY => 3, SQL_LOG_MODE_MODIFY_ALL => 4, SQL_LOG_MODE_ALL => 5];
private $dbName = '';
......@@ -353,7 +353,9 @@ class Database {
*/
private function prepareExecute($sql, array $parameterArray, &$queryType, array &$stat, $specificMessage = '') {
$sqlLogMode = $this->isSqlModify($sql) ? SQL_LOG_MODE_MODIFY : SQL_LOG_MODE_ALL;
// Only log a modify type statement here if sqlLogMode is (at least) modifyAll
// If sqlLogMode is modify, log the statement after it has been executed and we know if there are affected rows.
$sqlLogMode = $this->isSqlModify($sql) ? SQL_LOG_MODE_MODIFY_ALL : SQL_LOG_MODE_ALL;
$result = 0;
$stat = array();
$errorMsg[ERROR_MESSAGE_TO_USER] = empty($specificMessage) ? 'SQL error' : $specificMessage;
......@@ -421,7 +423,7 @@ class Database {
$stat[DB_INSERT_ID] = $this->mysqli->insert_id;
$stat[DB_AFFECTED_ROWS] = $this->mysqli->affected_rows;
$count = $stat[DB_AFFECTED_ROWS];
$msg = 'ID: ' . $this->mysqli->insert_id;
$msg = 'ID: ' . $this->mysqli->insert_id . ' - affected rows: ' . $count;
break;
case 'UPDATE':
case 'DELETE':
......@@ -457,7 +459,17 @@ class Database {
}
// Logfile
$this->dbLog($sqlLogMode, $msg);
$pageContentSqlLogMode = $this->store->getVar(SYSTEM_SQL_LOG_MODE, STORE_SYSTEM);
if ($pageContentSqlLogMode == SQL_LOG_MODE_MODIFY && $sqlLogMode == SQL_LOG_MODE_MODIFY_ALL) {
// sqlLogMode modify: need to log query and query result (if count > 0)
if ($count > 0) {
$this->dbLog(SQL_LOG_MODE_MODIFY, $sql, $parameterArray);
$this->dbLog(SQL_LOG_MODE_MODIFY, $msg);
}
} else {
// Query result
$this->dbLog($sqlLogMode, $msg);
}
return $count;
}
......@@ -479,6 +491,9 @@ class Database {
case 'DELETE':
case 'REPLACE':
case 'TRUNCATE':
case 'DROP':
case 'CREATE':
case 'ALTER':
return true;
}
......
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