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

Feature/enrich debug page with site url and cron #695

Open
wants to merge 2 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
46 changes: 42 additions & 4 deletions includes/class-fs-logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,6 @@ public static function download_db_logs(
}
$filepath = rtrim( $upload_dir['path'], '/' ) . "/{$filename}";

$query .= " INTO OUTFILE '{$filepath}' FIELDS TERMINATED BY '\t' ESCAPED BY '\\\\' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\\n'";

$columns = '';
for ( $i = 0, $len = count( self::$_log_columns ); $i < $len; $i ++ ) {
if ( $i > 0 ) {
Expand All @@ -662,22 +660,29 @@ public static function download_db_logs(

$query = "SELECT {$columns} UNION ALL " . $query;

$result = $wpdb->query( $query );
$result = $wpdb->get_results( $query );

if ( false === $result ) {
return false;
}

$write_file = self::write_csv_to_filesystem( $filepath, $result );

if ( false === $write_file ) {
return false;
}

return rtrim( $upload_dir['url'], '/' ) . '/' . $filename;
}

/**
* @author Vova Feldman (@svovaf)
* @since 1.2.1.6
*
* @param string $filename
*
* @return string
* @since 1.2.1.6
*
*/
public static function get_logs_download_url( $filename = '' ) {
$upload_dir = wp_upload_dir();
Expand All @@ -689,4 +694,37 @@ public static function get_logs_download_url( $filename = '' ) {
}

#endregion

/**
* @param $file_path
* @param $query_results
*
* @return bool
*/
public static function write_csv_to_filesystem( $file_path, $query_results ) {
require_once( ABSPATH . 'wp-admin/includes/file.php' );
WP_Filesystem();
global $wp_filesystem;

if ( ! empty( $query_results ) ) {
$headers = array_keys( (array) $query_results[0] );
} else {
return false;
}

$content = implode( "\t", $headers ) . "\n";

foreach ( $query_results as $row ) {
$row_data = array_map( function ( $value ) {
return str_replace( "\n", ' ', $value );
}, (array) $row );
$content .= implode( "\t", $row_data ) . "\n";
}

if ( ! $wp_filesystem->put_contents( $file_path, $content, FS_CHMOD_FILE ) ) {
return false;
}

return true;
}
}
4 changes: 0 additions & 4 deletions includes/debug/class-fs-debug-bar-panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ public function render() {
<div id='debug-bar-php'>
<?php fs_require_template( '/debug/api-calls.php' ) ?>
<br>
<?php fs_require_template( '/debug/scheduled-crons.php' ) ?>
<br>
<?php fs_require_template( '/debug/plugins-themes-sync.php' ) ?>
<br>
<?php fs_require_template( '/debug/logger.php' ) ?>
</div>
<?php
}
Expand Down
Loading
Loading