From ab186e05f2df6ad47620392519c4f2d3aeda3bb5 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 5 Jun 2018 15:15:16 -0300 Subject: [PATCH 1/2] Improve how environment data is generated --- .../class-wc-beta-tester-admin-menus.php | 39 ++++++++++++++++--- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester-admin-menus.php b/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester-admin-menus.php index 54b6c5c6b7c..0555afdf130 100644 --- a/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester-admin-menus.php +++ b/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester-admin-menus.php @@ -47,13 +47,39 @@ class WC_Beta_Tester_Admin_Menus { if ( false === $ssr ) { ob_start(); - // Get SSR - // TODO: See what we can re-use from core `includes/admin/views/html-admin-page-status-report.php` - WC_Admin_Status::status_report(); + // Get SSR. + $api = new WC_REST_System_Status_Controller(); + $schema = $api->get_item_schema(); + $mappings = $api->get_item_mappings(); + $response = array(); - $ssr = ob_get_clean(); + foreach ( $mappings as $section => $values ) { + foreach ( $values as $key => $value ) { + if ( isset( $schema['properties'][ $section ]['properties'][ $key ]['type'] ) ) { + settype( $values[ $key ], $schema['properties'][ $section ]['properties'][ $key ]['type'] ); + } + } + settype( $values, $schema['properties'][ $section ]['type'] ); + $response[ $section ] = $values; + } - $ssr = substr( $ssr, 0, 2048 ); + $ssr = ''; + foreach ( $response['environment'] as $key => $value ) { + $index = $key; + // @todo remove this hack after fix schema in WooCommercem, and Claudio never let you folks to forget that need to write schema first, and review after every change, schema is the most important part of the REST API. + if ( 'version' === $index ) { + $index = 'wc_version'; + } elseif ( 'external_object_cache' === $index ) { + $ssr .= sprintf( "%s: %s\n", 'External object cache', wc_bool_to_string( $value ) ); + continue; + } + + if ( is_bool( $value ) ) { + $value = wc_bool_to_string( $value ); + } + + $ssr .= sprintf( "%s: %s\n", $schema['properties']['environment']['properties'][ $index ]['description'], $value ); + } set_transient( $transient_name, $ssr, DAY_IN_SECONDS ); } @@ -70,6 +96,7 @@ class WC_Beta_Tester_Admin_Menus { $bug_tpl = $this->get_ticket_template(); $ssr = $this->construct_ssr(); $body = str_replace( 'Copy and paste the system status report from **WooCommerce > System Status** in WordPress admin.', $ssr, $bug_tpl ); + $body = str_replace( '```', '', $body ); // Remove since this break how is displayed. $wc_plugin_data = get_plugin_data( WC_PLUGIN_FILE ); if ( isset( $wc_plugin_data['Version'] ) ) { @@ -124,7 +151,7 @@ class WC_Beta_Tester_Admin_Menus { break; } } - + // TODO: Implementation of each node. $nodes = array( From add146aee1e19e6e6943135f395379f5578553f6 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 5 Jun 2018 16:04:11 -0300 Subject: [PATCH 2/2] Typo --- .../includes/class-wc-beta-tester-admin-menus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester-admin-menus.php b/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester-admin-menus.php index 57cc1799b60..f58808b2c19 100644 --- a/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester-admin-menus.php +++ b/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester-admin-menus.php @@ -68,7 +68,7 @@ class WC_Beta_Tester_Admin_Menus { $ssr = ''; foreach ( $response['environment'] as $key => $value ) { $index = $key; - // @todo remove this hack after fix schema in WooCommercem, and Claudio never let you folks to forget that need to write schema first, and review after every change, schema is the most important part of the REST API. + // @todo remove this hack after fix schema in WooCommerce, and Claudio never let you folks forget that need to write schema first, and review after every change, schema is the most important part of the REST API. if ( 'version' === $index ) { $index = 'wc_version'; } elseif ( 'external_object_cache' === $index ) {