diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-categories-controller.php b/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-categories-controller.php index 394141891c9..602432f1290 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-categories-controller.php +++ b/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-categories-controller.php @@ -59,7 +59,7 @@ class WC_Admin_REST_Reports_Categories_Controller extends WC_REST_Reports_Contro */ public function get_items( $request ) { $query_args = $this->prepare_reports_query( $request ); - $categories_query = new WC_Reports_Categories_Query( $query_args ); + $categories_query = new WC_Admin_Reports_Categories_Query( $query_args ); $report_data = $categories_query->get_data(); if ( is_wp_error( $report_data ) ) { diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-products-controller.php b/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-products-controller.php index a9517af822f..0b5769140cc 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-products-controller.php +++ b/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-products-controller.php @@ -47,7 +47,7 @@ class WC_Admin_REST_Reports_Products_Controller extends WC_REST_Reports_Controll } } - $reports = new WC_Reports_Products_Query( $args ); + $reports = new WC_Admin_Reports_Products_Query( $args ); $products_data = $reports->get_data(); $data = array(); diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-products-stats-controller.php b/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-products-stats-controller.php index 22c45c67ebf..ffc2257fe33 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-products-stats-controller.php +++ b/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-products-stats-controller.php @@ -53,7 +53,7 @@ class WC_Admin_REST_Reports_Products_Stats_Controller extends WC_REST_Reports_Co } } - $query = new WC_Reports_Products_Stats_Query( $query_args ); + $query = new WC_Admin_Reports_Products_Stats_Query( $query_args ); $report_data = $query->get_data(); $out_data = array( diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-revenue-stats-controller.php b/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-revenue-stats-controller.php index 369cce77aee..9de47b44f4e 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-revenue-stats-controller.php +++ b/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-revenue-stats-controller.php @@ -58,7 +58,7 @@ class WC_Admin_REST_Reports_Revenue_Stats_Controller extends WC_REST_Reports_Con */ public function get_items( $request ) { $query_args = $this->prepare_reports_query( $request ); - $reports_revenue = new WC_Reports_Revenue_Query( $query_args ); + $reports_revenue = new WC_Admin_Reports_Revenue_Query( $query_args ); $report_data = $reports_revenue->get_data(); $out_data = array( diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-api-init.php b/plugins/woocommerce-admin/includes/class-wc-admin-api-init.php index 9d703514aa6..3bf86d61e36 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-api-init.php +++ b/plugins/woocommerce-admin/includes/class-wc-admin-api-init.php @@ -12,6 +12,8 @@ class WC_Admin_Api_Init { add_filter( 'woocommerce_install_get_tables', array( 'WC_Admin_Api_Init', 'add_report_tables' ) ); // REST API extensions init. add_action( 'rest_api_init', array( $this, 'rest_api_init' ) ); + add_filter( 'rest_endpoints', array( 'WC_Admin_Api_Init', 'filter_rest_endpoints' ), 10, 1 ); + add_filter( 'woocommerce_debug_tools', array( 'WC_Admin_Api_Init', 'add_regenerate_tool' ) ); // Initialize report classes. add_action( 'woocommerce_after_register_post_type', array( 'WC_Admin_Api_Init', 'orders_data_store_init' ), 20 ); add_action( 'woocommerce_after_register_post_type', array( 'WC_Admin_Api_Init', 'order_product_lookup_store_init' ), 20 ); @@ -23,9 +25,10 @@ class WC_Admin_Api_Init { public function init_classes() { // Interfaces. require_once dirname( __FILE__ ) . '/interfaces/class-wc-admin-reports-data-store-interface.php'; - require_once dirname( __FILE__ ) . '/interfaces/class-wc-reports-data-store-interface.php'; require_once dirname( __FILE__ ) . '/class-wc-admin-reports-query.php'; + // Common date time code. + require_once dirname( __FILE__ ) . '/class-wc-admin-reports-interval.php'; // Query classes for reports. require_once dirname( __FILE__ ) . '/class-wc-admin-reports-revenue-query.php'; @@ -75,6 +78,52 @@ class WC_Admin_Api_Init { } } + public static function filter_rest_endpoints( $endpoints ) { + // Override GET /wc/v3/system_status/tools. + if ( isset( $endpoints['/wc/v3/system_status/tools'] ) + && isset( $endpoints['/wc/v3/system_status/tools'][1] ) + && isset( $endpoints['/wc/v3/system_status/tools'][0] ) + && $endpoints['/wc/v3/system_status/tools'][1]['callback'][0] instanceof WC_Admin_REST_System_Status_Tools_Controller + ) { + $endpoints['/wc/v3/system_status/tools'][0] = $endpoints['/wc/v3/system_status/tools'][1]; + } + // // Override GET & PUT for /wc/v3/system_status/tools. + if ( isset( $endpoints['/wc/v3/system_status/tools/(?P[\w-]+)'] ) + && isset( $endpoints['/wc/v3/system_status/tools/(?P[\w-]+)'][3] ) + && isset( $endpoints['/wc/v3/system_status/tools/(?P[\w-]+)'][2] ) + && $endpoints['/wc/v3/system_status/tools/(?P[\w-]+)'][2]['callback'][0] instanceof WC_Admin_REST_System_Status_Tools_Controller + && $endpoints['/wc/v3/system_status/tools/(?P[\w-]+)'][3]['callback'][0] instanceof WC_Admin_REST_System_Status_Tools_Controller + ) { + $endpoints['/wc/v3/system_status/tools/(?P[\w-]+)'][0] = $endpoints['/wc/v3/system_status/tools/(?P[\w-]+)'][2]; + $endpoints['/wc/v3/system_status/tools/(?P[\w-]+)'][1] = $endpoints['/wc/v3/system_status/tools/(?P[\w-]+)'][3]; + } + + // Override GET /wc/v3/reports. + if ( isset( $endpoints['/wc/v3/reports'] ) + && isset( $endpoints['/wc/v3/reports'][1] ) + && isset( $endpoints['/wc/v3/reports'][0] ) + && $endpoints['/wc/v3/reports'][1]['callback'][0] instanceof WC_Admin_REST_Reports_Controller + ) { + $endpoints['/wc/v3/reports'][0] = $endpoints['/wc/v3/reports'][1]; + } + + return $endpoints; + } + + public static function add_regenerate_tool( $tools ) { + return array_merge( + $tools, + array( + 'rebuild_stats' => array( + 'name' => __( 'Rebuild reports data', 'woocommerce' ), + 'button' => __( 'Rebuild reports', 'woocommerce' ), + 'desc' => __( 'This tool will rebuild all of the information used by the reports.', 'woocommerce' ), + 'callback' => array( 'WC_Admin_Reports_Orders_Data_Store', 'queue_order_stats_repopulate_database' ), + ), + ) + ); + } + public static function orders_data_store_init() { WC_Admin_Reports_Orders_Data_Store::init(); } @@ -134,11 +183,11 @@ class WC_Admin_Api_Init { return array_merge( $data_stores, array( - 'report-revenue-stats' => 'WC_Reports_Orders_Data_Store', - 'report-orders-stats' => 'WC_Reports_Orders_Data_Store', - 'report-products' => 'WC_Reports_Products_Data_Store', - 'report-products-stats' => 'WC_Reports_Products_Stats_Data_Store', - 'report-categories' => 'WC_Reports_Categories_Data_Store', + 'report-revenue-stats' => 'WC_Admin_Reports_Orders_Data_Store', + 'report-orders-stats' => 'WC_Admin_Reports_Orders_Data_Store', + 'report-products' => 'WC_Admin_Reports_Products_Data_Store', + 'report-products-stats' => 'WC_Admin_Reports_Products_Stats_Data_Store', + 'report-categories' => 'WC_Admin_Reports_Categories_Data_Store', ) ); } diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-products-query.php b/plugins/woocommerce-admin/includes/class-wc-admin-reports-products-query.php index f32835851c6..2b3b1efc25d 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-products-query.php +++ b/plugins/woocommerce-admin/includes/class-wc-admin-reports-products-query.php @@ -20,7 +20,7 @@ defined( 'ABSPATH' ) || exit; /** - * WC_Reports_Products_Query + * WC_Admin_Reports_Products_Query * */ class WC_Admin_Reports_Products_Query extends WC_Admin_Reports_Query { diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-orders-data-store.php b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-orders-data-store.php index 131de190c59..82b9e196dd2 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-orders-data-store.php +++ b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-orders-data-store.php @@ -320,8 +320,6 @@ class WC_Admin_Reports_Orders_Data_Store extends WC_Admin_Reports_Data_Store imp {$intervals_query['limit']}", ARRAY_A ); // WPCS: cache ok, DB call ok, unprepared SQL ok. - echo $wpdb->last_query; - if ( null === $intervals ) { return new WP_Error( 'woocommerce_reports_revenue_result_failed', __( 'Sorry, fetching revenue data failed.', 'woocommerce' ) ); } diff --git a/plugins/woocommerce-admin/includes/interfaces/class-wc-admin-reports-data-store-interface.php b/plugins/woocommerce-admin/includes/interfaces/class-wc-admin-reports-data-store-interface.php index 528cf83dd99..1ed81dcfbf4 100644 --- a/plugins/woocommerce-admin/includes/interfaces/class-wc-admin-reports-data-store-interface.php +++ b/plugins/woocommerce-admin/includes/interfaces/class-wc-admin-reports-data-store-interface.php @@ -3,7 +3,7 @@ * Reports Data Store Interface * * @version 3.5.0 - * @package WooCommerce/Interface + * @package WooCommerce Admin/Interface */ if ( ! defined( 'ABSPATH' ) ) { @@ -15,7 +15,7 @@ if ( ! defined( 'ABSPATH' ) ) { * * @since 3.5.0 */ -interface WC_Reports_Data_Store_Interface { +interface WC_Admin_Reports_Data_Store_Interface { /** * Get the data based on args. diff --git a/plugins/woocommerce-admin/includes/interfaces/class-wc-reports-data-store-interface.php b/plugins/woocommerce-admin/includes/interfaces/class-wc-reports-data-store-interface.php deleted file mode 100644 index c17936b9e6a..00000000000 --- a/plugins/woocommerce-admin/includes/interfaces/class-wc-reports-data-store-interface.php +++ /dev/null @@ -1,26 +0,0 @@ -