2018-09-17 14:32:03 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* REST API WC System Status Tools Controller
|
|
|
|
*
|
|
|
|
* Handles requests to the /system_status/tools/* endpoints.
|
|
|
|
*
|
2018-09-17 19:13:19 +00:00
|
|
|
* @package WooCommerce Admin/API
|
2018-09-17 14:32:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
defined( 'ABSPATH' ) || exit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* System status tools controller.
|
|
|
|
*
|
2018-09-17 19:13:19 +00:00
|
|
|
* @package WooCommerce Admin/API
|
|
|
|
* @extends WC_REST_System_Status_Tools_Controller
|
2018-09-17 14:32:03 +00:00
|
|
|
*/
|
2018-09-17 19:13:19 +00:00
|
|
|
class WC_Admin_REST_System_Status_Tools_Controller extends WC_REST_System_Status_Tools_Controller {
|
2018-09-17 14:32:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Endpoint namespace.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-01-18 02:52:58 +00:00
|
|
|
protected $namespace = 'wc/v4';
|
2018-09-17 14:32:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A list of available tools for use in the system status section.
|
|
|
|
* 'button' becomes 'action' in the API.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get_tools() {
|
|
|
|
return array_merge(
|
|
|
|
parent::get_tools(),
|
|
|
|
array(
|
|
|
|
'rebuild_stats' => array(
|
2019-03-13 17:14:02 +00:00
|
|
|
'name' => __( 'Rebuild reports data', 'woocommerce-admin' ),
|
|
|
|
'button' => __( 'Rebuild reports', 'woocommerce-admin' ),
|
|
|
|
'desc' => __( 'This tool will rebuild all of the information used by the reports.', 'woocommerce-admin' ),
|
2018-09-17 14:32:03 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Actually executes a tool.
|
|
|
|
*
|
|
|
|
* @param string $tool Tool.
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function execute_tool( $tool ) {
|
2018-10-22 16:20:14 +00:00
|
|
|
$ran = true;
|
2018-09-17 14:32:03 +00:00
|
|
|
$message = '';
|
|
|
|
|
|
|
|
switch ( $tool ) {
|
|
|
|
case 'rebuild_stats':
|
2019-01-12 01:26:30 +00:00
|
|
|
WC_Admin_Api_Init::regenerate_report_data();
|
2019-03-13 17:14:02 +00:00
|
|
|
$message = __( 'Rebuilding reports data in the background . . .', 'woocommerce-admin' );
|
2018-09-17 14:32:03 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return parent::execute_tool( $tool );
|
|
|
|
}
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'success' => $ran,
|
|
|
|
'message' => $message,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|