Skip to content

Commit

Permalink
Fix: avoid logging attempt when table does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
DanieleAlessandra committed Apr 9, 2024
1 parent 2b5cd96 commit 6b0a528
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
33 changes: 32 additions & 1 deletion includes/class-fs-logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
}

class FS_Logger {
/**
* @var bool
*/
public static $ON = false;
private $_id;
private $_on = false;
private $_echo = false;
Expand All @@ -32,6 +36,9 @@ class FS_Logger {
*/
private static $_abspathLength;

/**
* @var FS_Logger[] $LOGGERS
*/
private static $LOGGERS = array();
private static $LOG = array();
private static $CNT = 0;
Expand Down Expand Up @@ -112,7 +119,7 @@ private static function hook_footer() {
}

function is_on() {
return $this->_on;
return $this->_on && self::$ON;
}

function on() {
Expand All @@ -125,6 +132,15 @@ function on() {
self::hook_footer();
}

/**
* Turn off instance
*
* @return void
*/
public function off() {
$this->_on = false;
error_log( $this->get_id() . ' IS NOW ' . $this->_on );
}
function echo_on() {
$this->on();

Expand Down Expand Up @@ -240,6 +256,9 @@ function api_error( $api_result, $wrapper = false ) {
}

function entrance( $message = '', $wrapper = false ) {
if ( ! $this->is_on() ) {
return;
}
$msg = 'Entrance' . ( empty( $message ) ? '' : ' > ' ) . $message;

$this->_log( $msg, 'log', $wrapper );
Expand Down Expand Up @@ -353,9 +372,21 @@ public static function _set_storage_logging( $is_on = true ) {
* Drop logging table.
*/
$result = $wpdb->query( "DROP TABLE IF EXISTS $table;" );
/**
* Since logging table does not exist anymore, we need to turn off all instances
*/
foreach ( self::$LOGGERS as $logger ) {
$logger->off();
}
/**
* Also, we delete all references and turn off global logging
*/
self::$LOGGERS = [];
self::$ON = false;
}

if ( false !== $result ) {
self::$ON = (bool) $is_on;
update_option( 'fs_storage_logger', ( $is_on ? 1 : 0 ) );
}

Expand Down
4 changes: 4 additions & 0 deletions includes/managers/class-fs-debug-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ static function _get_debug_log() {
return;
}

if (!FS_Logger::$ON) {
return;
}

$limit = min( ! empty( $_POST['limit'] ) ? absint( $_POST['limit'] ) : 200, 200 );
$offset = min( ! empty( $_POST['offset'] ) ? absint( $_POST['offset'] ) : 200, 200 );

Expand Down

0 comments on commit 6b0a528

Please sign in to comment.