From 75d4fac0aef65fffcd4cd2f2193e34987cf3e681 Mon Sep 17 00:00:00 2001 From: Darko Date: Thu, 4 May 2017 09:36:59 +0200 Subject: [PATCH 1/6] issue #2193 issue #2193 --- oc-includes/osclass/default-constants.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/oc-includes/osclass/default-constants.php b/oc-includes/osclass/default-constants.php index e6fa69404c..e43f50b38b 100755 --- a/oc-includes/osclass/default-constants.php +++ b/oc-includes/osclass/default-constants.php @@ -76,6 +76,10 @@ define('OSC_DEBUG_DB_LOG', false); } + if( !defined('OSC_DEBUG_DB_LOG_ERROR') ) { + define('OSC_DEBUG_DB_LOG_ERROR', false); + } + if( !defined('OSC_DEBUG_DB_EXPLAIN') ) { define('OSC_DEBUG_DB_EXPLAIN', false); } From 914a7ca2f2791d3c3ba0b54964553fe7b8998286 Mon Sep 17 00:00:00 2001 From: Darko Date: Thu, 4 May 2017 09:53:41 +0200 Subject: [PATCH 2/6] issue #2193 issue #2193 --- oc-includes/osclass/Logger/LogDatabase.php | 56 ++++++++++++++-------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/oc-includes/osclass/Logger/LogDatabase.php b/oc-includes/osclass/Logger/LogDatabase.php index b6d9eb884c..36eac5b7cd 100755 --- a/oc-includes/osclass/Logger/LogDatabase.php +++ b/oc-includes/osclass/Logger/LogDatabase.php @@ -136,29 +136,46 @@ function writeMessages() return false; } - fwrite($fp, '==================================================' . PHP_EOL); - if(MULTISITE) { - fwrite($fp, '=' . str_pad('Date: ' . date('Y-m-d').' '.date('H:i:s'), 48, " ", STR_PAD_BOTH) . '=' . PHP_EOL); + if(OSC_DEBUG_DB_LOG_ERROR) { + foreach($this->messages as $msg) { + if( $msg['errno'] > 0 ) { + fwrite($fp, '--------------------------------------------------' . PHP_EOL); + fwrite($fp, 'QUERY TIME' . ' ' . $msg['query_time'] . PHP_EOL); + fwrite($fp, 'Error number: ' . $msg['errno'] . PHP_EOL); + fwrite($fp, 'Error description: ' . $msg['error'] . PHP_EOL); + fwrite($fp, '**************************************************' . PHP_EOL); + fwrite($fp, $msg['query'] . PHP_EOL); + fwrite($fp, '--------------------------------------------------' . PHP_EOL); + fwrite($fp, PHP_EOL . PHP_EOL); + } + } + fclose($fp); } else { - fwrite($fp, '=' . str_pad('Date: ' . date(osc_date_format()!=''?osc_date_format():'Y-m-d').' '.date(osc_time_format()!=''?osc_date_format():'H:i:s'), 48, " ", STR_PAD_BOTH) . '=' . PHP_EOL); - } - fwrite($fp, '=' . str_pad('Total queries: ' . $this->getTotalNumberQueries(), 48, " ", STR_PAD_BOTH) . '=' . PHP_EOL); - fwrite($fp, '=' . str_pad('Total queries time: ' . $this->getTotalQueriesTime(), 48, " ", STR_PAD_BOTH) . '=' . PHP_EOL); - fwrite($fp, '==================================================' . PHP_EOL . PHP_EOL); + fwrite($fp, '==================================================' . PHP_EOL); + if(MULTISITE) { + fwrite($fp, '=' . str_pad('Date: ' . date('Y-m-d').' '.date('H:i:s'), 48, " ", STR_PAD_BOTH) . '=' . PHP_EOL); + } else { + fwrite($fp, '=' . str_pad('Date: ' . date(osc_date_format()!=''?osc_date_format():'Y-m-d').' '.date(osc_time_format()!=''?osc_date_format():'H:i:s'), 48, " ", STR_PAD_BOTH) . '=' . PHP_EOL); + } + fwrite($fp, '=' . str_pad('Total queries: ' . $this->getTotalNumberQueries(), 48, " ", STR_PAD_BOTH) . '=' . PHP_EOL); + fwrite($fp, '=' . str_pad('Total queries time: ' . $this->getTotalQueriesTime(), 48, " ", STR_PAD_BOTH) . '=' . PHP_EOL); + fwrite($fp, '==================================================' . PHP_EOL . PHP_EOL); - foreach($this->messages as $msg) { - fwrite($fp, 'QUERY TIME' . ' ' . $msg['query_time'] . PHP_EOL); - if( $msg['errno'] != 0 ) { - fwrite($fp, 'Error number: ' . $msg['errno'] . PHP_EOL); - fwrite($fp, 'Error description: ' . $msg['error'] . PHP_EOL); + foreach($this->messages as $msg) { + fwrite($fp, 'QUERY TIME' . ' ' . $msg['query_time'] . PHP_EOL); + if( $msg['errno'] != 0 ) { + fwrite($fp, 'Error number: ' . $msg['errno'] . PHP_EOL); + fwrite($fp, 'Error description: ' . $msg['error'] . PHP_EOL); + } + fwrite($fp, '**************************************************' . PHP_EOL); + fwrite($fp, $msg['query'] . PHP_EOL); + fwrite($fp, '--------------------------------------------------' . PHP_EOL); } - fwrite($fp, '**************************************************' . PHP_EOL); - fwrite($fp, $msg['query'] . PHP_EOL); - fwrite($fp, '--------------------------------------------------' . PHP_EOL); + + fwrite($fp, PHP_EOL . PHP_EOL . PHP_EOL); + fclose($fp); } - fwrite($fp, PHP_EOL . PHP_EOL. PHP_EOL); - fclose($fp); return true; } @@ -239,6 +256,3 @@ public function getTotalNumberQueries() return count($this->messages); } } - - /* file end: ./oc-includes/osclass/Logger/LogDatabase.php */ -?> From c6bed58d60215e34076ec84ac9bde847e71c2c6c Mon Sep 17 00:00:00 2001 From: Darko Date: Thu, 4 May 2017 10:22:47 +0200 Subject: [PATCH 3/6] issue #2193 improvements issue #2193 improvements --- .../classes/database/DBConnectionClass.php | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/oc-includes/osclass/classes/database/DBConnectionClass.php b/oc-includes/osclass/classes/database/DBConnectionClass.php index 6dce34c586..5327b72b37 100755 --- a/oc-includes/osclass/classes/database/DBConnectionClass.php +++ b/oc-includes/osclass/classes/database/DBConnectionClass.php @@ -118,13 +118,13 @@ class DBConnectionClass /** A list of incompatible SQL modes. - * - * @since @TODO <----- - * @access protected - * @var array - */ - protected $incompatible_modes = array( 'NO_ZERO_DATE', 'ONLY_FULL_GROUP_BY', - 'STRICT_TRANS_TABLES', 'STRICT_ALL_TABLES', 'TRADITIONAL' ); + * + * @since @TODO <----- + * @access protected + * @var array + */ + protected $incompatible_modes = array( 'NO_ZERO_DATE', 'ONLY_FULL_GROUP_BY', + 'STRICT_TRANS_TABLES', 'STRICT_ALL_TABLES', 'TRADITIONAL' ); /** * It creates a new DBConnection object class or if it has been created before, it @@ -276,7 +276,7 @@ function connectToOsclassDb() if ( $conn == false ) { $this->errorConnection(); $this->releaseOsclassDb(); - + if(MULTISITE) { return false; } @@ -498,15 +498,15 @@ public function set_sql_mode($modes = array(), &$connId) $modes = array_change_key_case( $modes, CASE_UPPER ); $incompatible_modes = $this->incompatible_modes; - foreach ( $modes as $i => $mode ) { - if ( in_array( $mode, $incompatible_modes ) ) { + foreach ( $modes as $i => $mode ) { + if ( in_array( $mode, $incompatible_modes ) ) { unset( $modes[ $i ] ); - } - } + } + } - $modes_str = implode( ',', $modes ); + $modes_str = implode( ',', $modes ); mysqli_query($connId, "SET SESSION sql_mode='$modes_str'" ); - } + } /** * At the end of the execution it prints the database debug if it's necessary @@ -532,6 +532,8 @@ function debug($printFrontend = true) if( OSC_DEBUG_DB_LOG ) { $log->writeMessages(); + } else if( OSC_DEBUG_DB_LOG ) { + $log->writeErrorMessages(); } else if($printFrontend) { $log->printMessages(); } else { @@ -615,7 +617,4 @@ function _getDb(&$connId) return false; } - } - - /* file end: ./oc-includes/osclass/classes/database/DBConnectionClass.php */ -?> \ No newline at end of file + } From 2124c2d5cd59649e85cc341abd95db2263ee5c99 Mon Sep 17 00:00:00 2001 From: Darko Date: Thu, 4 May 2017 10:30:12 +0200 Subject: [PATCH 4/6] issue #2193 improvements split methods --- oc-includes/osclass/Logger/LogDatabase.php | 76 +++++++++++++--------- 1 file changed, 46 insertions(+), 30 deletions(-) diff --git a/oc-includes/osclass/Logger/LogDatabase.php b/oc-includes/osclass/Logger/LogDatabase.php index 36eac5b7cd..bf5485d3f6 100755 --- a/oc-includes/osclass/Logger/LogDatabase.php +++ b/oc-includes/osclass/Logger/LogDatabase.php @@ -136,46 +136,62 @@ function writeMessages() return false; } - if(OSC_DEBUG_DB_LOG_ERROR) { - foreach($this->messages as $msg) { - if( $msg['errno'] > 0 ) { - fwrite($fp, '--------------------------------------------------' . PHP_EOL); - fwrite($fp, 'QUERY TIME' . ' ' . $msg['query_time'] . PHP_EOL); - fwrite($fp, 'Error number: ' . $msg['errno'] . PHP_EOL); - fwrite($fp, 'Error description: ' . $msg['error'] . PHP_EOL); - fwrite($fp, '**************************************************' . PHP_EOL); - fwrite($fp, $msg['query'] . PHP_EOL); - fwrite($fp, '--------------------------------------------------' . PHP_EOL); - fwrite($fp, PHP_EOL . PHP_EOL); - } - } - fclose($fp); + fwrite($fp, '==================================================' . PHP_EOL); + if(MULTISITE) { + fwrite($fp, '=' . str_pad('Date: ' . date('Y-m-d').' '.date('H:i:s'), 48, " ", STR_PAD_BOTH) . '=' . PHP_EOL); } else { - fwrite($fp, '==================================================' . PHP_EOL); - if(MULTISITE) { - fwrite($fp, '=' . str_pad('Date: ' . date('Y-m-d').' '.date('H:i:s'), 48, " ", STR_PAD_BOTH) . '=' . PHP_EOL); - } else { - fwrite($fp, '=' . str_pad('Date: ' . date(osc_date_format()!=''?osc_date_format():'Y-m-d').' '.date(osc_time_format()!=''?osc_date_format():'H:i:s'), 48, " ", STR_PAD_BOTH) . '=' . PHP_EOL); + fwrite($fp, '=' . str_pad('Date: ' . date(osc_date_format()!=''?osc_date_format():'Y-m-d').' '.date(osc_time_format()!=''?osc_date_format():'H:i:s'), 48, " ", STR_PAD_BOTH) . '=' . PHP_EOL); + } + fwrite($fp, '=' . str_pad('Total queries: ' . $this->getTotalNumberQueries(), 48, " ", STR_PAD_BOTH) . '=' . PHP_EOL); + fwrite($fp, '=' . str_pad('Total queries time: ' . $this->getTotalQueriesTime(), 48, " ", STR_PAD_BOTH) . '=' . PHP_EOL); + fwrite($fp, '==================================================' . PHP_EOL . PHP_EOL); + + foreach($this->messages as $msg) { + fwrite($fp, 'QUERY TIME' . ' ' . $msg['query_time'] . PHP_EOL); + if( $msg['errno'] != 0 ) { + fwrite($fp, 'Error number: ' . $msg['errno'] . PHP_EOL); + fwrite($fp, 'Error description: ' . $msg['error'] . PHP_EOL); } - fwrite($fp, '=' . str_pad('Total queries: ' . $this->getTotalNumberQueries(), 48, " ", STR_PAD_BOTH) . '=' . PHP_EOL); - fwrite($fp, '=' . str_pad('Total queries time: ' . $this->getTotalQueriesTime(), 48, " ", STR_PAD_BOTH) . '=' . PHP_EOL); - fwrite($fp, '==================================================' . PHP_EOL . PHP_EOL); + fwrite($fp, '**************************************************' . PHP_EOL); + fwrite($fp, $msg['query'] . PHP_EOL); + fwrite($fp, '--------------------------------------------------' . PHP_EOL); + } - foreach($this->messages as $msg) { + fwrite($fp, PHP_EOL . PHP_EOL . PHP_EOL); + fclose($fp); + + return true; + } + + function writeErrorMessages() + { + $filename = CONTENT_PATH . 'queries.log'; + + if( !file_exists($filename) || !is_writable($filename) ) { + return false; + } + + $fp = fopen($filename, 'a'); + + if( $fp == false ) { + return false; + } + + foreach($this->messages as $msg) { + if( $msg['errno'] > 0 ) { + fwrite($fp, '--------------------------------------------------' . PHP_EOL); fwrite($fp, 'QUERY TIME' . ' ' . $msg['query_time'] . PHP_EOL); - if( $msg['errno'] != 0 ) { - fwrite($fp, 'Error number: ' . $msg['errno'] . PHP_EOL); - fwrite($fp, 'Error description: ' . $msg['error'] . PHP_EOL); - } + fwrite($fp, 'Error number: ' . $msg['errno'] . PHP_EOL); + fwrite($fp, 'Error description: ' . $msg['error'] . PHP_EOL); fwrite($fp, '**************************************************' . PHP_EOL); fwrite($fp, $msg['query'] . PHP_EOL); fwrite($fp, '--------------------------------------------------' . PHP_EOL); + fwrite($fp, PHP_EOL . PHP_EOL); } - - fwrite($fp, PHP_EOL . PHP_EOL . PHP_EOL); - fclose($fp); } + fclose($fp); + return true; } From 60d9a837feba03a050e0b655972715435c86134a Mon Sep 17 00:00:00 2001 From: Darko Date: Thu, 4 May 2017 10:32:57 +0200 Subject: [PATCH 5/6] fix typo --- oc-includes/osclass/classes/database/DBConnectionClass.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oc-includes/osclass/classes/database/DBConnectionClass.php b/oc-includes/osclass/classes/database/DBConnectionClass.php index 5327b72b37..0c40b4d46e 100755 --- a/oc-includes/osclass/classes/database/DBConnectionClass.php +++ b/oc-includes/osclass/classes/database/DBConnectionClass.php @@ -532,7 +532,7 @@ function debug($printFrontend = true) if( OSC_DEBUG_DB_LOG ) { $log->writeMessages(); - } else if( OSC_DEBUG_DB_LOG ) { + } else if( OSC_DEBUG_DB_LOG_ERROR ) { $log->writeErrorMessages(); } else if($printFrontend) { $log->printMessages(); From 5123d0d2f7b22ce30a94ed9f82555429cfe2088e Mon Sep 17 00:00:00 2001 From: Darko Date: Thu, 4 May 2017 11:27:38 +0200 Subject: [PATCH 6/6] issue #2193 fix logic reorder --- oc-includes/osclass/classes/database/DBConnectionClass.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/oc-includes/osclass/classes/database/DBConnectionClass.php b/oc-includes/osclass/classes/database/DBConnectionClass.php index 0c40b4d46e..161239f9c3 100755 --- a/oc-includes/osclass/classes/database/DBConnectionClass.php +++ b/oc-includes/osclass/classes/database/DBConnectionClass.php @@ -530,10 +530,10 @@ function debug($printFrontend = true) return false; } - if( OSC_DEBUG_DB_LOG ) { - $log->writeMessages(); - } else if( OSC_DEBUG_DB_LOG_ERROR ) { + if( OSC_DEBUG_DB_LOG_ERROR ) { $log->writeErrorMessages(); + } else if( OSC_DEBUG_DB_LOG ) { + $log->writeMessages(); } else if($printFrontend) { $log->printMessages(); } else {