From 1314158a14832b61295871e5cb258d3ba6aa2519 Mon Sep 17 00:00:00 2001 From: Patrick Garman Date: Sun, 6 Aug 2017 01:15:10 -0400 Subject: [PATCH] =?UTF-8?q?Add=20=E2=80=9Csite=20size=E2=80=9D=20areas=20t?= =?UTF-8?q?o=20system=20status=20report?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The size of the site very much impacts the status of the site. This type of information would be extremely helpful when supporting a site. 1) post counts - can reveal high volumes of specific kinds of post types both within WC (orders, products, etc) or outside (revisions, attachments, third party ones, etc) 2) table sizes - a site with a 5MB postmeta table is very different than a site with a 5GB postmeta table, which is different than a site with a 50GB postmeta table, and require different kinds of support and focus. --- .../views/html-admin-page-status-report.php | 159 +++++++++++------- ...class-wc-rest-system-status-controller.php | 29 ++++ 2 files changed, 131 insertions(+), 57 deletions(-) diff --git a/includes/admin/views/html-admin-page-status-report.php b/includes/admin/views/html-admin-page-status-report.php index b1e06a17003..9940ba697e6 100644 --- a/includes/admin/views/html-admin-page-status-report.php +++ b/includes/admin/views/html-admin-page-status-report.php @@ -13,14 +13,16 @@ if ( ! class_exists( 'WC_REST_System_Status_Controller', false ) ) { wp_die( 'Cannot load the REST API to access WC_REST_System_Status_Controller.' ); } -$system_status = new WC_REST_System_Status_Controller; -$environment = $system_status->get_environment_info(); -$database = $system_status->get_database_info(); -$active_plugins = $system_status->get_active_plugins(); -$theme = $system_status->get_theme_info(); -$security = $system_status->get_security_info(); -$settings = $system_status->get_settings(); -$pages = $system_status->get_pages(); +$system_status = new WC_REST_System_Status_Controller; +$environment = $system_status->get_environment_info(); +$database = $system_status->get_database_info(); +$database_size = $system_status->get_database_table_sizes(); +$post_type_counts = $system_status->get_post_type_counts(); +$active_plugins = $system_status->get_active_plugins(); +$theme = $system_status->get_theme_info(); +$security = $system_status->get_security_info(); +$settings = $system_status->get_settings(); +$pages = $system_status->get_pages(); ?>

@@ -302,57 +304,100 @@ $pages = $system_status->get_pages(); - - - - - - - - - - - - - - - - - $table_exists ) { + + + + + + + + + + + + + + + - - - - - - - - - - - + + $table_exists ) { ?> - + + + + + + + + + + + + + +

:
  20 ) { - echo ' ' . sprintf( __( '%1$s - We recommend using a prefix with less than 20 characters. See: %2$s', 'woocommerce' ), esc_html( $database['database_prefix'] ), '' . __( 'How to update your database table prefix', 'woocommerce' ) . '' ) . ''; - } else { - echo '' . esc_html( $database['database_prefix'] ) . ''; - } - ?> -

:
  20 ) { + echo ' ' . sprintf( __( '%1$s - We recommend using a prefix with less than 20 characters. See: %2$s', 'woocommerce' ), esc_html( $database['database_prefix'] ), '' . __( 'How to update your database table prefix', 'woocommerce' ) . '' ) . ''; + } else { + echo '' . esc_html( $database['database_prefix'] ) . ''; + } ?> -
  ' . __( 'Table does not exist', 'woocommerce' ) . '' : ''; ?>
: ' . esc_html( $database['maxmind_geoip_database'] ) . ' '; - } else { - printf( ' ' . sprintf( __( 'The MaxMind GeoIP Database does not exist - Geolocation will not function. You can download and install it manually from %1$s to the path: %2$s. Scroll down to "Downloads" and download the "Binary / gzip" file next to "GeoLite Country". Please remember to uncompress GeoIP.dat.gz and upload the GeoIP.dat file only.', 'woocommerce' ), make_clickable( 'http://dev.maxmind.com/geoip/legacy/geolite/' ), '' . $database['maxmind_geoip_database'] . '' ) . '', WC_LOG_DIR ); - } - ?>
  ' . __( 'Table does not exist', 'woocommerce' ) . '' : ''; ?>
: ' . esc_html( $database['maxmind_geoip_database'] ) . ' '; + } else { + printf( ' ' . sprintf( __( 'The MaxMind GeoIP Database does not exist - Geolocation will not function. You can download and install it manually from %1$s to the path: %2$s. Scroll down to "Downloads" and download the "Binary / gzip" file next to "GeoLite Country". Please remember to uncompress GeoIP.dat.gz and upload the GeoIP.dat file only.', 'woocommerce' ), make_clickable( 'http://dev.maxmind.com/geoip/legacy/geolite/' ), '' . $database['maxmind_geoip_database'] . '' ) . '', WC_LOG_DIR ); + } + ?>
+ + + + + + + + + + + + + + + +

name ); ?>  + data, 2 ); ?>MB, + index, 2 ); ?>MB +
+ + + + + + + + + + + + + + +

type ); ?> count ); ?>
diff --git a/includes/api/class-wc-rest-system-status-controller.php b/includes/api/class-wc-rest-system-status-controller.php index d3c96c52f09..52064d30509 100644 --- a/includes/api/class-wc-rest-system-status-controller.php +++ b/includes/api/class-wc-rest-system-status-controller.php @@ -670,6 +670,35 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller { ); } + public function get_database_table_sizes() { + global $wpdb; + + $database_table_sizes = $wpdb->get_results( $wpdb->prepare( " + SELECT + table_name AS 'name', + round( ( data_length / 1024 / 1024 ), 2 ) 'data', + round( ( index_length / 1024 / 1024 ), 2 ) 'index' + FROM information_schema.TABLES + WHERE table_schema = %s + ORDER BY name ASC; + ", DB_NAME ) ); + + return is_array( $database_table_sizes ) ? $database_table_sizes : array(); + } + + /** + * Get array of counts of objects. Orders, products, etc. + * + * @return array + */ + public function get_post_type_counts() { + global $wpdb; + + $post_type_counts = $wpdb->get_results( "SELECT post_type AS 'type', count(1) AS 'count' FROM {$wpdb->posts} GROUP BY post_type;" ); + + return is_array( $post_type_counts ) ? $post_type_counts : array(); + } + /** * Get a list of plugins active on the site. *