From d7ca1d8cd88a7fabb112f5c8e495f322861b1180 Mon Sep 17 00:00:00 2001 From: Gerhard Potgieter Date: Thu, 9 Nov 2017 08:02:59 +0200 Subject: [PATCH] Webhook logs update routine to move from comments to wc_logger --- includes/class-wc-install.php | 3 +++ includes/wc-update-functions.php | 36 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/includes/class-wc-install.php b/includes/class-wc-install.php index 21ab4c4d615..9b4f257860c 100644 --- a/includes/class-wc-install.php +++ b/includes/class-wc-install.php @@ -94,6 +94,9 @@ class WC_Install { 'wc_update_320_mexican_states', 'wc_update_320_db_version', ), + '3.3.0' => array( + 'wc_update_330_webhook_logs', + ) ); /** diff --git a/includes/wc-update-functions.php b/includes/wc-update-functions.php index 1a24aff86db..ec9bab54c15 100644 --- a/includes/wc-update-functions.php +++ b/includes/wc-update-functions.php @@ -1409,3 +1409,39 @@ function wc_update_320_mexican_states() { function wc_update_320_db_version() { WC_Install::update_db_version( '3.2.0' ); } + +/** + * Move comment based webhook logs to WC_Logger. + * + * @return void + */ +function wc_update_330_webhook_logs() { + global $wpdb; + + $existing_webhook_logs = $wpdb->get_results( "SELECT comment_ID, comment_post_ID FROM {$wpdb->comments} WHERE comment_type = 'webhook_delivery' ORDER BY comment_post_ID, comment_ID DESC" ); + + if ( $existing_webhook_logs ) { + $logger = wc_get_logger(); + foreach ( $existing_webhook_logs as $webhook_log ) { + $message = print_r( array( + 'Webhook Delivery' => array( + 'Date' => array(), + 'URL' => array(), + 'Request' => array( + 'Method' => get_comment_meta( $webhook_log->comment_ID, '_request_method', true ), + 'Headers' => get_comment_meta( $webhook_log->comment_ID, '_request_headers', true ), + 'Body' => get_comment_meta( $webhook_log->comment_ID, '_request_body', true ), + ), + 'Response' => array( + 'Code' => get_comment_meta( $webhook_log->comment_ID, '_response_code', true ), + 'Message' => get_comment_meta( $webhook_log->comment_ID, '_response_message', true ), + 'Headers' => get_comment_meta( $webhook_log->comment_ID, '_response_headers', true ), + 'Body' => get_comment_meta( $webhook_log->comment_ID, '_response_body', true ), + ), + 'Duration' => get_comment_meta( $webhook_log->comment_ID, '_duration', true ), + ), + ), true ); + $logger->log( 'info', $message, array( 'source' => 'webhook_delivery_' . $webhook_log->comment_post_ID ) ); + } + } +}