Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #2193 sql log errors only #2194

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions oc-includes/osclass/Logger/LogDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,41 @@ function writeMessages()
fwrite($fp, '--------------------------------------------------' . PHP_EOL);
}

fwrite($fp, PHP_EOL . PHP_EOL. PHP_EOL);
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);
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);

return true;
}

Expand Down Expand Up @@ -239,6 +272,3 @@ public function getTotalNumberQueries()
return count($this->messages);
}
}

/* file end: ./oc-includes/osclass/Logger/LogDatabase.php */
?>
37 changes: 18 additions & 19 deletions oc-includes/osclass/classes/database/DBConnectionClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -276,7 +276,7 @@ function connectToOsclassDb()
if ( $conn == false ) {
$this->errorConnection();
$this->releaseOsclassDb();

if(MULTISITE) {
return false;
}
Expand Down Expand Up @@ -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
Expand All @@ -530,7 +530,9 @@ function debug($printFrontend = true)
return false;
}

if( OSC_DEBUG_DB_LOG ) {
if( OSC_DEBUG_DB_LOG_ERROR ) {
$log->writeErrorMessages();
} else if( OSC_DEBUG_DB_LOG ) {
$log->writeMessages();
} else if($printFrontend) {
$log->printMessages();
Expand Down Expand Up @@ -615,7 +617,4 @@ function _getDb(&$connId)

return false;
}
}

/* file end: ./oc-includes/osclass/classes/database/DBConnectionClass.php */
?>
}
4 changes: 4 additions & 0 deletions oc-includes/osclass/default-constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down