Commit 7278efa4 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Merge branch 'F8851-logmode-modifyAll' into 'master'

Fixes #8851 - add sqlLogMode modifyAll and restrict sqlLogMode modify

See merge request !172
parents 92ee0201 3830de7c
Pipeline #2180 passed with stages
in 2 minutes and 51 seconds
...@@ -398,8 +398,10 @@ Extension Manager: QFQ Configuration ...@@ -398,8 +398,10 @@ Extension Manager: QFQ Configuration
+-----------------------------------+-------------------------------------------------------+----------------------------------------------------------------------------+ +-----------------------------------+-------------------------------------------------------+----------------------------------------------------------------------------+
| redirectAllMailTo | john@doe.com | If set, redirect all QFQ generated mails (Form, Report) to the specified. | | 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. | | sqlLogMode | modify | | *all*: every statement will be logged - this might be a lot. |
| | | | *modify*: log only statements who change data. | | | | | *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. | | | | | *error*: log only DB errors. |
| | | | *none*: no SQL log at all. | | | | | *none*: no SQL log at all. |
+-----------------------------------+-------------------------------------------------------+----------------------------------------------------------------------------+ +-----------------------------------+-------------------------------------------------------+----------------------------------------------------------------------------+
......
...@@ -782,6 +782,7 @@ const RANDOM_LENGTH = 32; ...@@ -782,6 +782,7 @@ const RANDOM_LENGTH = 32;
// SQL logging Modes // SQL logging Modes
const SQL_LOG_MODE_ALL = 'all'; const SQL_LOG_MODE_ALL = 'all';
const SQL_LOG_MODE_MODIFY = 'modify'; const SQL_LOG_MODE_MODIFY = 'modify';
const SQL_LOG_MODE_MODIFY_ALL = 'modifyAll';
const SQL_LOG_MODE_NONE = 'none'; const SQL_LOG_MODE_NONE = 'none';
const SQL_LOG_MODE_ERROR = 'error'; const SQL_LOG_MODE_ERROR = 'error';
......
...@@ -50,7 +50,7 @@ class Database { ...@@ -50,7 +50,7 @@ class Database {
/** /**
* @var array * @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 = ''; private $dbName = '';
...@@ -353,7 +353,9 @@ class Database { ...@@ -353,7 +353,9 @@ class Database {
*/ */
private function prepareExecute($sql, array $parameterArray, &$queryType, array &$stat, $specificMessage = '') { 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; $result = 0;
$stat = array(); $stat = array();
$errorMsg[ERROR_MESSAGE_TO_USER] = empty($specificMessage) ? 'SQL error' : $specificMessage; $errorMsg[ERROR_MESSAGE_TO_USER] = empty($specificMessage) ? 'SQL error' : $specificMessage;
...@@ -421,7 +423,7 @@ class Database { ...@@ -421,7 +423,7 @@ class Database {
$stat[DB_INSERT_ID] = $this->mysqli->insert_id; $stat[DB_INSERT_ID] = $this->mysqli->insert_id;
$stat[DB_AFFECTED_ROWS] = $this->mysqli->affected_rows; $stat[DB_AFFECTED_ROWS] = $this->mysqli->affected_rows;
$count = $stat[DB_AFFECTED_ROWS]; $count = $stat[DB_AFFECTED_ROWS];
$msg = 'ID: ' . $this->mysqli->insert_id; $msg = 'ID: ' . $this->mysqli->insert_id . ' - affected rows: ' . $count;
break; break;
case 'UPDATE': case 'UPDATE':
case 'DELETE': case 'DELETE':
...@@ -457,7 +459,17 @@ class Database { ...@@ -457,7 +459,17 @@ class Database {
} }
// Logfile // 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; return $count;
} }
...@@ -479,6 +491,9 @@ class Database { ...@@ -479,6 +491,9 @@ class Database {
case 'DELETE': case 'DELETE':
case 'REPLACE': case 'REPLACE':
case 'TRUNCATE': case 'TRUNCATE':
case 'DROP':
case 'CREATE':
case 'ALTER':
return true; return true;
} }
......
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