From 8e7dddeacfefccb22046095ce48cfd64dcc3cf3c Mon Sep 17 00:00:00 2001
From: Till Brehm <tbrehm@ispconfig.org>
Date: Mon, 30 Apr 2018 17:57:05 +0200
Subject: [PATCH] Fixed  #4939 unability to insert into sys_log is an iterative
 tipping point, stalling systems Added a third parameter to $app->log()
 function in server part to turn off logging to database and use this option
 in mysql lib to not log any server side SQL errors to the database.

---
 server/lib/app.inc.php              | 4 ++--
 server/lib/classes/db_mysql.inc.php | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/server/lib/app.inc.php b/server/lib/app.inc.php
index dd8be5aa68..5016bbc9e2 100755
--- a/server/lib/app.inc.php
+++ b/server/lib/app.inc.php
@@ -117,7 +117,7 @@ class app {
          2 = ERROR
         */
 
-	function log($msg, $priority = 0) {
+	function log($msg, $priority = 0, $dblog = true) {
 
 		global $conf;
 
@@ -148,7 +148,7 @@ class app {
 			fclose($fp);
 
 			// Log to database
-			if(isset($this->dbmaster)) {
+			if($dblog === true && isset($this->dbmaster)) {
 				$server_id = $conf['server_id'];
 				$loglevel = $priority;
 				$message = $msg;
diff --git a/server/lib/classes/db_mysql.inc.php b/server/lib/classes/db_mysql.inc.php
index 9b34dc4c1f..424867f095 100644
--- a/server/lib/classes/db_mysql.inc.php
+++ b/server/lib/classes/db_mysql.inc.php
@@ -476,7 +476,7 @@ class db
 		if($this->show_error_messages && $conf['demo_mode'] === false) {
 			echo $sErrormsg . $sAddMsg;
 		} elseif(is_object($app) && method_exists($app, 'log') && $bNoLog == false) {
-			$app->log($sErrormsg . $sAddMsg . ' -> ' . $mysql_errno . ' (' . $mysql_error . ')', LOGLEVEL_WARN);
+			$app->log($sErrormsg . $sAddMsg . ' -> ' . $mysql_errno . ' (' . $mysql_error . ')', LOGLEVEL_WARN, false);
 		} elseif(php_sapi_name() == 'cli') {
 			echo $sErrormsg . $sAddMsg;
 		}
-- 
GitLab